diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 960fbfd92..cf7920ecc 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -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...) diff --git a/tasks/build-task.coffee b/tasks/build-task.coffee new file mode 100644 index 000000000..dd865d664 --- /dev/null +++ b/tasks/build-task.coffee @@ -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') diff --git a/tasks/clean-task.coffee b/tasks/clean-task.coffee new file mode 100644 index 000000000..4de1a3503 --- /dev/null +++ b/tasks/clean-task.coffee @@ -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') diff --git a/tasks/codesign-task.coffee b/tasks/codesign-task.coffee new file mode 100644 index 000000000..fd4592eba --- /dev/null +++ b/tasks/codesign-task.coffee @@ -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) diff --git a/tasks/copy-info-plist-task.coffee b/tasks/copy-info-plist-task.coffee new file mode 100644 index 000000000..cad121a20 --- /dev/null +++ b/tasks/copy-info-plist-task.coffee @@ -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 diff --git a/tasks/install-task.coffee b/tasks/install-task.coffee new file mode 100644 index 000000000..23cae1bb9 --- /dev/null +++ b/tasks/install-task.coffee @@ -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 diff --git a/tasks/nof-task.coffee b/tasks/nof-task.coffee new file mode 100644 index 000000000..329179e54 --- /dev/null +++ b/tasks/nof-task.coffee @@ -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()) diff --git a/tasks/set-development-version-task.coffee b/tasks/set-development-version-task.coffee new file mode 100644 index 000000000..072f0db4b --- /dev/null +++ b/tasks/set-development-version-task.coffee @@ -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) diff --git a/tasks/task-helpers.coffee b/tasks/task-helpers.coffee new file mode 100644 index 000000000..e8ec11d50 --- /dev/null +++ b/tasks/task-helpers.coffee @@ -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) diff --git a/tasks/test-task.coffee b/tasks/test-task.coffee new file mode 100644 index 000000000..69d0fb0ba --- /dev/null +++ b/tasks/test-task.coffee @@ -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) diff --git a/tasks/update-atom-shell-task.coffee b/tasks/update-atom-shell-task.coffee new file mode 100644 index 000000000..4e95df45e --- /dev/null +++ b/tasks/update-atom-shell-task.coffee @@ -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)