Merge pull request #1118 from atom/cj-less-verbose-grunt

Less verbose grunt
This commit is contained in:
Corey Johnson 2013-11-15 09:05:11 -08:00
commit 941fc97e79
8 changed files with 86 additions and 68 deletions

View File

@ -8,6 +8,10 @@ _ = require 'underscore-plus'
packageJson = require './package.json' packageJson = require './package.json'
module.exports = (grunt) -> module.exports = (grunt) ->
if not grunt.option('verbose')
grunt.log.writeln = (args...) -> grunt.log
grunt.log.write = (args...) -> grunt.log
[major, minor, patch] = packageJson.version.split('.') [major, minor, patch] = packageJson.version.split('.')
if process.platform is 'win32' if process.platform is 'win32'
appName = 'Atom' appName = 'Atom'

View File

@ -1,29 +1,28 @@
measure 'spec suite require time', -> {_, fs, Git} = require 'atom'
{_, fs, Git} = require 'atom' path = require 'path'
path = require 'path' require './spec-helper'
require './spec-helper'
requireSpecs = (specDirectory, specType) -> requireSpecs = (specDirectory, specType) ->
for specFilePath in fs.listTreeSync(specDirectory) when /-spec\.coffee$/.test specFilePath for specFilePath in fs.listTreeSync(specDirectory) when /-spec\.coffee$/.test specFilePath
require specFilePath require specFilePath
# Set spec directory on spec for setting up the project in spec-helper # Set spec directory on spec for setting up the project in spec-helper
setSpecDirectory(specDirectory) setSpecDirectory(specDirectory)
setSpecField = (name, value) -> setSpecField = (name, value) ->
specs = jasmine.getEnv().currentRunner().specs() specs = jasmine.getEnv().currentRunner().specs()
return if specs.length is 0 return if specs.length is 0
for index in [specs.length-1..0] for index in [specs.length-1..0]
break if specs[index][name]? break if specs[index][name]?
specs[index][name] = value specs[index][name] = value
setSpecType = (specType) -> setSpecType = (specType) ->
setSpecField('specType', specType) setSpecField('specType', specType)
setSpecDirectory = (specDirectory) -> setSpecDirectory = (specDirectory) ->
setSpecField('specDirectory', specDirectory) setSpecField('specDirectory', specDirectory)
runAllSpecs = -> runAllSpecs = ->
# Only run core specs when resource path is the Atom repository # Only run core specs when resource path is the Atom repository
if Git.exists(window.resourcePath) if Git.exists(window.resourcePath)
requireSpecs(path.join(window.resourcePath, 'spec')) requireSpecs(path.join(window.resourcePath, 'spec'))
@ -47,8 +46,8 @@ measure 'spec suite require time', ->
requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.user ? [] requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.user ? []
setSpecType('user') setSpecType('user')
if specDirectory = atom.getLoadSettings().specDirectory if specDirectory = atom.getLoadSettings().specDirectory
requireSpecs(specDirectory) requireSpecs(specDirectory)
setSpecType('user') setSpecType('user')
else else
runAllSpecs() runAllSpecs()

View File

@ -62,7 +62,7 @@ delegate.browserMainParts.preMainMessageLoopRun = ->
AtomApplication = require './atom-application' AtomApplication = require './atom-application'
AtomApplication.open(args) AtomApplication.open(args)
console.log("App load time: #{Date.now() - startTime}ms") console.log("App load time: #{Date.now() - startTime}ms") unless args.test
global.devResourcePath = path.join(app.getHomeDir(), 'github', 'atom') global.devResourcePath = path.join(app.getHomeDir(), 'github', 'atom')

View File

@ -30,16 +30,16 @@ module.exports = (grunt) ->
themeMains.push(mainPath) if grunt.file.isFile(mainPath) themeMains.push(mainPath) if grunt.file.isFile(mainPath)
importPaths.unshift(stylesheetsDir) if grunt.file.isDir(stylesheetsDir) importPaths.unshift(stylesheetsDir) if grunt.file.isDir(stylesheetsDir)
grunt.log.writeln("Building LESS cache for #{configuration.join(', ').yellow}") grunt.verbose.writeln("Building LESS cache for #{configuration.join(', ').yellow}")
lessCache = new LessCache lessCache = new LessCache
cacheDir: directory cacheDir: directory
resourcePath: path.resolve('.') resourcePath: path.resolve('.')
importPaths: importPaths importPaths: importPaths
for file in @filesSrc for file in @filesSrc
grunt.log.writeln("File #{file.cyan} created in cache.") grunt.verbose.writeln("File #{file.cyan} created in cache.")
lessCache.readFileSync(file) lessCache.readFileSync(file)
for file in themeMains for file in themeMains
grunt.log.writeln("File #{file.cyan} created in cache.") grunt.verbose.writeln("File #{file.cyan} created in cache.")
lessCache.readFileSync(file) lessCache.readFileSync(file)

View File

@ -84,7 +84,7 @@ module.exports = (grunt) ->
for name, version of packageDependencies for name, version of packageDependencies
do (name, version) -> do (name, version) ->
tasks.push (callback) -> tasks.push (callback) ->
grunt.log.writeln("Publishing #{name}@#{version}") grunt.verbose.writeln("Publishing #{name}@#{version}")
tag = "v#{version}" tag = "v#{version}"
packageExists name, token, (error, exists) -> packageExists name, token, (error, exists) ->
if error? if error?

View File

@ -2,6 +2,7 @@ fs = require 'fs'
path = require 'path' path = require 'path'
_ = require 'underscore-plus' _ = require 'underscore-plus'
async = require 'async' async = require 'async'
module.exports = (grunt) -> module.exports = (grunt) ->
@ -10,7 +11,7 @@ module.exports = (grunt) ->
packageSpecQueue = null packageSpecQueue = null
runPackageSpecs = (callback) -> runPackageSpecs = (callback) ->
passed = true failedPackages = []
rootDir = grunt.config.get('atom.shellAppDir') rootDir = grunt.config.get('atom.shellAppDir')
appDir = grunt.config.get('atom.appDir') appDir = grunt.config.get('atom.appDir')
atomPath = path.join(appDir, 'atom.sh') atomPath = path.join(appDir, 'atom.sh')
@ -23,10 +24,10 @@ module.exports = (grunt) ->
opts: opts:
cwd: packagePath cwd: packagePath
env: _.extend({}, process.env, ATOM_PATH: rootDir) env: _.extend({}, process.env, ATOM_PATH: rootDir)
grunt.log.writeln("Launching #{path.basename(packagePath)} specs.") grunt.verbose.writeln "Launching #{path.basename(packagePath)} specs."
spawn options, (error, results, code) -> spawn options, (error, results, code) ->
grunt.log.writeln()
passed = passed and not error and code is 0 failedPackages.push path.basename(packagePath) if error
callback() callback()
modulesDirectory = path.resolve('node_modules') modulesDirectory = path.resolve('node_modules')
@ -37,7 +38,7 @@ module.exports = (grunt) ->
packageSpecQueue.push(packagePath) packageSpecQueue.push(packagePath)
packageSpecQueue.concurrency = 1 packageSpecQueue.concurrency = 1
packageSpecQueue.drain = -> callback(null, passed) packageSpecQueue.drain = -> callback(null, failedPackages)
runCoreSpecs = (callback) -> runCoreSpecs = (callback) ->
contentsDir = grunt.config.get('atom.contentsDir') contentsDir = grunt.config.get('atom.contentsDir')
@ -49,15 +50,20 @@ module.exports = (grunt) ->
cmd: appPath cmd: appPath
args: ['--test', "--resource-path=#{resourcePath}", "--spec-directory=#{coreSpecsPath}"] args: ['--test', "--resource-path=#{resourcePath}", "--spec-directory=#{coreSpecsPath}"]
spawn options, (error, results, code) -> spawn options, (error, results, code) ->
grunt.log.writeln()
packageSpecQueue.concurrency = 2 packageSpecQueue.concurrency = 2
callback(null, not error and code is 0) callback(null, error)
grunt.registerTask 'run-specs', 'Run the specs', -> grunt.registerTask 'run-specs', 'Run the specs', ->
done = @async() done = @async()
startTime = Date.now() startTime = Date.now()
async.parallel [runCoreSpecs, runPackageSpecs], (error, results) -> async.parallel [runCoreSpecs, runPackageSpecs], (error, results) ->
[coreSpecPassed, packageSpecsPassed] = results [coreSpecFailed, failedPackages] = results
elapsedTime = Math.round((Date.now() - startTime) / 100) / 10 elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
grunt.log.writeln("Total spec time: #{elapsedTime}s") grunt.verbose.writeln("Total spec time: #{elapsedTime}s")
done(coreSpecPassed and packageSpecsPassed) failures = failedPackages
failures.push "atom core" if coreSpecFailed
grunt.log.error("[Error]".red + " #{failures.join(', ')} spec(s) failed") if failures.length > 0
done(!coreSpecFailed and failedPackages.length == 0)

View File

@ -23,7 +23,7 @@ module.exports = (grunt) ->
catch error catch error
grunt.fatal(error) grunt.fatal(error)
grunt.log.writeln("Copied #{source.cyan} to #{destination.cyan}.") grunt.verbose.writeln("Copied #{source.cyan} to #{destination.cyan}.")
mkdir: (args...) -> mkdir: (args...) ->
grunt.file.mkdir(args...) grunt.file.mkdir(args...)
@ -32,9 +32,18 @@ module.exports = (grunt) ->
grunt.file.delete(args..., force: true) if grunt.file.exists(args...) grunt.file.delete(args..., force: true) if grunt.file.exists(args...)
spawn: (options, callback) -> spawn: (options, callback) ->
grunt.util.spawn options, (error, results, code) -> childProcess = require 'child_process'
grunt.log.errorlns results.stderr if results.stderr stdout = []
callback(error, results, code) stderr = []
error = null
proc = childProcess.spawn(options.cmd, options.args, options.opts)
proc.stdout.on 'data', (data) -> stdout.push(data.toString())
proc.stderr.on 'data', (data) -> stderr.push(data.toString())
proc.on 'exit', (exitCode, signal) ->
error = new Error(signal) if exitCode != 0
results = {stderr: stderr.join(''), stdout: stdout.join(''), code: exitCode}
grunt.log.error results.stderr if exitCode != 0
callback(error, results, exitCode)
isAtomPackage: (packagePath) -> isAtomPackage: (packagePath) ->
try try

View File

@ -112,7 +112,7 @@ module.exports = (grunt) ->
# Manually handle redirection so headers would not be sent for S3. # Manually handle redirection so headers would not be sent for S3.
downloadAtomShell(version, response.headers.location, callback) downloadAtomShell(version, response.headers.location, callback)
else if response.statusCode is 200 else if response.statusCode is 200
grunt.log.writeln("Downloading atom-shell version #{version.cyan}") grunt.verbose.writeln("Downloading atom-shell version #{version.cyan}")
cacheDirectory = getCachePath(version) cacheDirectory = getCachePath(version)
rm(cacheDirectory) rm(cacheDirectory)
mkdir(cacheDirectory) mkdir(cacheDirectory)
@ -146,7 +146,7 @@ module.exports = (grunt) ->
downloadAtomShell version, url, callback downloadAtomShell version, url, callback
unzipAtomShell = (zipPath, callback) -> unzipAtomShell = (zipPath, callback) ->
grunt.log.writeln('Unzipping atom-shell') grunt.verbose.writeln('Unzipping atom-shell')
directoryPath = path.dirname(zipPath) directoryPath = path.dirname(zipPath)
if process.platform is 'darwin' if process.platform is 'darwin'
@ -167,7 +167,7 @@ module.exports = (grunt) ->
rebuildNativeModules = (previousVersion, callback) -> rebuildNativeModules = (previousVersion, callback) ->
newVersion = getAtomShellVersion() newVersion = getAtomShellVersion()
if newVersion and newVersion isnt previousVersion if newVersion and newVersion isnt previousVersion
grunt.log.writeln("Rebuilding native modules for new atom-shell version #{newVersion.cyan}.") grunt.verbose.writeln("Rebuilding native modules for new atom-shell version #{newVersion.cyan}.")
cmd = path.join('node_modules', '.bin', 'apm') cmd = path.join('node_modules', '.bin', 'apm')
cmd += ".cmd" if process.platform is 'win32' cmd += ".cmd" if process.platform is 'win32'
spawn {cmd, args: ['rebuild']}, (error) -> callback(error) spawn {cmd, args: ['rebuild']}, (error) -> callback(error)
@ -186,7 +186,7 @@ module.exports = (grunt) ->
currentAtomShellVersion = getAtomShellVersion() currentAtomShellVersion = getAtomShellVersion()
if atomShellVersion isnt currentAtomShellVersion if atomShellVersion isnt currentAtomShellVersion
if isAtomShellVersionCached(atomShellVersion) if isAtomShellVersionCached(atomShellVersion)
grunt.log.writeln("Installing cached atom-shell #{atomShellVersion.cyan}") grunt.verbose.writeln("Installing cached atom-shell #{atomShellVersion.cyan}")
installAtomShell(atomShellVersion) installAtomShell(atomShellVersion)
rebuildNativeModules(currentAtomShellVersion, done) rebuildNativeModules(currentAtomShellVersion, done)
else else
@ -198,7 +198,7 @@ module.exports = (grunt) ->
if error? if error?
done(error) done(error)
else else
grunt.log.writeln("Installing atom-shell #{atomShellVersion.cyan}") grunt.verbose.writeln("Installing atom-shell #{atomShellVersion.cyan}")
installAtomShell(atomShellVersion) installAtomShell(atomShellVersion)
rebuildNativeModules(currentAtomShellVersion, done) rebuildNativeModules(currentAtomShellVersion, done)
else else