Move Grunt tasks to tasks directory

This commit is contained in:
Kevin Sawicki 2013-06-27 09:07:33 -07:00
parent e434f7c0a9
commit bd14aeee17
11 changed files with 178 additions and 138 deletions

View File

@ -1,18 +1,18 @@
fs = require 'fs'
path = require 'path'
walkdir = require 'walkdir'
module.exports = (grunt) ->
APP_NAME = "Atom.app"
BUILD_DIR = grunt.option('build-dir') ? "/tmp/atom-build/"
SHELL_APP_DIR = path.join(BUILD_DIR, APP_NAME)
CONTENTS_DIR = path.join(SHELL_APP_DIR, 'Contents')
APP_DIR = path.join(CONTENTS_DIR, "Resources", "app")
INSTALL_DIR = path.join('/Applications', APP_NAME)
appName = 'Atom.app'
buildDir = grunt.option('build-dir') ? '/tmp/atom-build'
shellAppDir = path.join(buildDir, appName)
contentsDir = path.join(shellAppDir, 'Contents')
appDir = path.join(contentsDir, 'Resources', 'app')
installDir = path.join('/Applications', appName)
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
atom: {appDir, appName, buildDir, contentsDir, installDir, shellAppDir}
coffee:
options:
sourceMap: true
@ -23,7 +23,7 @@ module.exports = (grunt) ->
'src/**/*.coffee'
'static/**/*.coffee'
]
dest: APP_DIR
dest: appDir
ext: '.js'
less:
@ -39,7 +39,7 @@ module.exports = (grunt) ->
'static/**/*.less'
'themes/**/*.less'
]
dest: APP_DIR
dest: appDir
ext: '.css'
cson:
@ -52,7 +52,7 @@ module.exports = (grunt) ->
'static/**/*.cson'
'themes/**/*.cson'
]
dest: APP_DIR
dest: appDir
ext: '.json'
coffeelint:
@ -110,136 +110,10 @@ module.exports = (grunt) ->
grunt.loadNpmTasks('grunt-contrib-csslint')
grunt.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-less')
grunt.registerTask 'partial-clean', 'Delete some of the build files', ->
rm BUILD_DIR
rm '/tmp/atom-coffee-cache'
rm '/tmp/atom-cached-atom-shells'
rm 'node'
grunt.registerTask 'clean', 'Delete all the build files', ->
rm 'node_modules'
grunt.task.run('partial-clean')
grunt.registerTask 'build', 'Build the application', ->
rm SHELL_APP_DIR
mkdir path.dirname(BUILD_DIR)
cp 'atom-shell/Atom.app', SHELL_APP_DIR
mkdir APP_DIR
cp 'atom.sh', path.join(APP_DIR, 'atom.sh')
cp 'package.json', path.join(APP_DIR, 'package.json')
directories = [
'benchmark'
'dot-atom'
'spec'
'vendor'
]
{devDependencies, dependencies} = grunt.file.readJSON('package.json')
for child in fs.readdirSync('node_modules')
directory = path.join('node_modules', child)
try
{name} = grunt.file.readJSON(path.join(directory, 'package.json'))
if not devDependencies[name]? or dependencies[name]?
directories.push(directory)
catch e
directories.push(directory)
ignoredPaths = [
path.join('git-utils', 'deps')
path.join('oniguruma', 'deps')
path.join('vendor', 'apm')
path.join('vendor', 'bootstrap', 'docs')
]
ignoredPaths = ignoredPaths.map (ignoredPath) -> "(#{ignoredPath})"
nodeModulesFilter = new RegExp(ignoredPaths.join('|'))
for directory in directories
cp directory, path.join(APP_DIR, directory), filter: nodeModulesFilter
cp 'src', path.join(APP_DIR, 'src'), filter: /.+\.(cson|coffee|less)$/
cp 'static', path.join(APP_DIR, 'static'), filter: /.+\.less$/
cp 'themes', path.join(APP_DIR, 'themes'), filter: /.+\.(cson|less)$/
grunt.file.recurse path.join('resources', 'mac'), (sourcePath, rootDirectory, subDirectory='', filename) ->
unless /.+\.plist/.test(sourcePath)
grunt.file.copy(sourcePath, path.resolve(APP_DIR, '..', subDirectory, filename))
grunt.task.run('compile', 'copy-info-plist')
grunt.registerTask 'copy-info-plist', 'Copy plist', ->
plistPath = path.join(CONTENTS_DIR, 'Info.plist')
helperPlistPath = path.join(CONTENTS_DIR, 'Frameworks/Atom Helper.app/Contents/Info.plist')
# Copy custom plist files
cp 'resources/mac/atom-Info.plist', plistPath
cp 'resources/mac/helper-Info.plist', helperPlistPath
grunt.registerTask 'set-development-version', "Sets version to current sha", ->
done = @async()
spawn cmd: 'script/set-version', args: [BUILD_DIR], (error, result, code) ->
done(error)
grunt.registerTask 'codesign', 'Codesign the app', ->
done = @async()
args = ["-f", "-v", "-s", "Developer ID Application: GitHub", SHELL_APP_DIR]
spawn cmd: "codesign", args: args, (error) -> done(error)
grunt.registerTask 'install', 'Install the built application', ->
rm INSTALL_DIR
mkdir path.dirname(INSTALL_DIR)
cp SHELL_APP_DIR, INSTALL_DIR
grunt.registerTask 'update-atom-shell', 'Update atom-shell', ->
done = @async()
spawn cmd: 'script/update-atom-shell', (error) -> done(error)
grunt.registerTask 'test', 'Run the specs', ->
done = @async()
commands = []
commands.push (callback) ->
spawn cmd: 'pkill', args: ['Atom'], -> callback()
commands.push (callback) ->
atomBinary = path.join(CONTENTS_DIR, 'MacOS', 'Atom')
spawn cmd: atomBinary, args: ['--test', "--resource-path=#{__dirname}"], (error) -> callback(error)
grunt.util.async.waterfall commands, (error) -> done(error)
grunt.registerTask 'nof', 'Un-focus all specs', ->
nof = require.resolve('.bin/nof')
spawn({cmd: nof, args: ['spec', 'src']}, @async())
grunt.loadTasks('tasks')
grunt.registerTask('compile', ['coffee', 'less', 'cson'])
grunt.registerTask('lint', ['coffeelint', 'csslint', 'lesslint'])
grunt.registerTask('ci', ['lint', 'partial-clean', 'update-atom-shell', 'build', 'test'])
grunt.registerTask('deploy', ['update-atom-shell', 'build', 'codesign'])
grunt.registerTask('default', ['update-atom-shell', 'build', 'set-development-version', 'install'])
spawn = (options, callback) ->
grunt.util.spawn options, (error, results, code) ->
grunt.log.errorlns results.stderr if results.stderr
callback(error, results, code)
cp = (source, destination, {filter}={}) ->
walkdir.sync source, (sourcePath, stats) ->
return if filter?.test(sourcePath)
destinationPath = path.join(destination, path.relative(source, sourcePath))
if stats.isSymbolicLink()
grunt.file.mkdir(path.dirname(destinationPath))
fs.symlinkSync(fs.readlinkSync(sourcePath), destinationPath)
else if stats.isFile()
grunt.file.copy(sourcePath, destinationPath)
if grunt.file.exists(destinationPath)
fs.chmodSync(destinationPath, fs.statSync(sourcePath).mode)
grunt.log.writeln("Copied #{source.cyan} to #{destination.cyan}.")
mkdir = (args...) ->
grunt.file.mkdir(args...)
rm = (args...) ->
grunt.file.delete(args..., force: true) if grunt.file.exists(args...)

57
tasks/build-task.coffee Normal file
View File

@ -0,0 +1,57 @@
fs = require 'fs'
path = require 'path'
module.exports = (grunt) ->
{cp, mkdir, rm} = require('./task-helpers')(grunt)
grunt.registerTask 'build', 'Build the application', ->
shellAppDir = grunt.config.get('atom.shellAppDir')
buildDir = grunt.config.get('atom.buildDir')
appDir = grunt.config.get('atom.appDir')
rm shellAppDir
mkdir path.dirname(buildDir)
cp 'atom-shell/Atom.app', shellAppDir
mkdir appDir
cp 'atom.sh', path.join(appDir, 'atom.sh')
cp 'package.json', path.join(appDir, 'package.json')
directories = [
'benchmark'
'dot-atom'
'spec'
'vendor'
]
{devDependencies, dependencies} = grunt.file.readJSON('package.json')
for child in fs.readdirSync('node_modules')
directory = path.join('node_modules', child)
try
{name} = grunt.file.readJSON(path.join(directory, 'package.json'))
if not devDependencies[name]? or dependencies[name]?
directories.push(directory)
catch e
directories.push(directory)
ignoredPaths = [
path.join('git-utils', 'deps')
path.join('oniguruma', 'deps')
path.join('vendor', 'apm')
path.join('vendor', 'bootstrap', 'docs')
]
ignoredPaths = ignoredPaths.map (ignoredPath) -> "(#{ignoredPath})"
nodeModulesFilter = new RegExp(ignoredPaths.join('|'))
for directory in directories
cp directory, path.join(appDir, directory), filter: nodeModulesFilter
cp 'src', path.join(appDir, 'src'), filter: /.+\.(cson|coffee|less)$/
cp 'static', path.join(appDir, 'static'), filter: /.+\.less$/
cp 'themes', path.join(appDir, 'themes'), filter: /.+\.(cson|less)$/
grunt.file.recurse path.join('resources', 'mac'), (sourcePath, rootDirectory, subDirectory='', filename) ->
unless /.+\.plist/.test(sourcePath)
grunt.file.copy(sourcePath, path.resolve(appDir, '..', subDirectory, filename))
grunt.task.run('compile', 'copy-info-plist')

12
tasks/clean-task.coffee Normal file
View File

@ -0,0 +1,12 @@
module.exports = (grunt) ->
{rm} = require('./task-helpers')(grunt)
grunt.registerTask 'partial-clean', 'Delete some of the build files', ->
rm grunt.config.get('globals.buildDir')
rm '/tmp/atom-coffee-cache'
rm '/tmp/atom-cached-atom-shells'
rm 'node'
grunt.registerTask 'clean', 'Delete all the build files', ->
rm 'node_modules'
grunt.task.run('partial-clean')

View File

@ -0,0 +1,8 @@
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
grunt.registerTask 'codesign', 'Codesign the app', ->
done = @async()
cmd = 'codesign'
args = ['-f', '-v', '-s', 'Developer ID Application: GitHub', grunt.config.get('atom.shellAppDir')]
spawn {cmd, args}, (error) -> done(error)

View File

@ -0,0 +1,13 @@
path = require 'path'
module.exports = (grunt) ->
{cp} = require('./task-helpers')(grunt)
grunt.registerTask 'copy-info-plist', 'Copy plist', ->
contentsDir = grunt.config.get('atom.contentsDir')
plistPath = path.join(contentsDir, 'Info.plist')
helperPlistPath = path.join(contentsDir, 'Frameworks/Atom Helper.app/Contents/Info.plist')
# Copy custom plist files
cp 'resources/mac/atom-Info.plist', plistPath
cp 'resources/mac/helper-Info.plist', helperPlistPath

11
tasks/install-task.coffee Normal file
View File

@ -0,0 +1,11 @@
path = require 'path'
module.exports = (grunt) ->
{cp, mkdir, rm} = require('./task-helpers')(grunt)
grunt.registerTask 'install', 'Install the built application', ->
installDir = grunt.config.get('atom.installDir')
shellAppDir = grunt.config.get('atom.shellAppDir')
rm installDir
mkdir path.dirname(installDir)
cp shellAppDir, installDir

6
tasks/nof-task.coffee Normal file
View File

@ -0,0 +1,6 @@
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
grunt.registerTask 'nof', 'Un-focus all specs', ->
nof = require.resolve('.bin/nof')
spawn({cmd: nof, args: ['spec', 'src']}, @async())

View File

@ -0,0 +1,8 @@
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
grunt.registerTask 'set-development-version', 'Sets version to current SHA-1', ->
done = @async()
cmd = 'script/set-version'
args = [grunt.config.get('atom.buildDir')]
spawn {cmd, args}, (error, result, code) -> done(error)

31
tasks/task-helpers.coffee Normal file
View File

@ -0,0 +1,31 @@
fs = require 'fs'
path = require 'path'
walkdir = require 'walkdir'
module.exports = (grunt) ->
cp: (source, destination, {filter}={}) ->
walkdir.sync source, (sourcePath, stats) ->
return if filter?.test(sourcePath)
destinationPath = path.join(destination, path.relative(source, sourcePath))
if stats.isSymbolicLink()
grunt.file.mkdir(path.dirname(destinationPath))
fs.symlinkSync(fs.readlinkSync(sourcePath), destinationPath)
else if stats.isFile()
grunt.file.copy(sourcePath, destinationPath)
if grunt.file.exists(destinationPath)
fs.chmodSync(destinationPath, fs.statSync(sourcePath).mode)
grunt.log.writeln("Copied #{source.cyan} to #{destination.cyan}.")
mkdir: (args...) ->
grunt.file.mkdir(args...)
rm: (args...) ->
grunt.file.delete(args..., force: true) if grunt.file.exists(args...)
spawn: (options, callback) ->
grunt.util.spawn options, (error, results, code) ->
grunt.log.errorlns results.stderr if results.stderr
callback(error, results, code)

14
tasks/test-task.coffee Normal file
View File

@ -0,0 +1,14 @@
path = require 'path'
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
grunt.registerTask 'test', 'Run the specs', ->
done = @async()
commands = []
commands.push (callback) ->
spawn cmd: 'pkill', args: ['Atom'], -> callback()
commands.push (callback) ->
atomBinary = path.join(CONTENTS_DIR, 'MacOS', 'Atom')
spawn cmd: atomBinary, args: ['--test', "--resource-path=#{__dirname}"], (error) -> callback(error)
grunt.util.async.waterfall commands, (error) -> done(error)

View File

@ -0,0 +1,6 @@
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
grunt.registerTask 'update-atom-shell', 'Update atom-shell', ->
done = @async()
spawn cmd: 'script/update-atom-shell', (error) -> done(error)