-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement liftoff into grunt-cli #117
Changes from 4 commits
7b8cb3f
ea01dc5
0c5f397
8ae6299
98ba9e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,41 +4,66 @@ | |
|
||
process.title = 'grunt'; | ||
|
||
// Especially badass external libs. | ||
var findup = require('findup-sync'); | ||
var resolve = require('resolve').sync; | ||
var Liftoff = require('liftoff'); | ||
var v8flags = require('v8flags'); | ||
var extensions = require('interpret').jsVariants; | ||
var nopt = require('nopt'); | ||
var gruntOptions = require('grunt-known-options'); | ||
var completion = require('../lib/completion.js'); | ||
var info = require('../lib/info.js'); | ||
var pkg = require('../package.json'); | ||
|
||
// Internal libs. | ||
var options = require('../lib/cli').options; | ||
var completion = require('../lib/completion'); | ||
var info = require('../lib/info'); | ||
var path = require('path'); | ||
// Parse `gruntOptions` into a form that nopt can handle. | ||
var aliases = {}; | ||
var known = {}; | ||
|
||
var basedir = process.cwd(); | ||
var gruntpath; | ||
Object.keys(gruntOptions).forEach(function(key) { | ||
var short = gruntOptions[key].short; | ||
if (short) { | ||
aliases[short] = '--' + key; | ||
} | ||
known[key] = gruntOptions[key].type; | ||
}); | ||
|
||
// Parse them and return an options object. | ||
var options = nopt(known, aliases, process.argv, 2); | ||
|
||
// Do stuff based on CLI options. | ||
if ('completion' in options) { | ||
completion.print(options.completion); | ||
} else if (options.version) { | ||
info.version(); | ||
} else if (options.gruntfile) { //Note: if both `gruntfile` and `base` are set, use `gruntfile` | ||
basedir = path.resolve(path.dirname(options.gruntfile)); | ||
} else if (options.base) { | ||
basedir = path.resolve(options.base); | ||
} | ||
|
||
try { | ||
gruntpath = resolve('grunt', {basedir: basedir}); | ||
} catch (ex) { | ||
gruntpath = findup('lib/grunt.js'); | ||
// No grunt install found! | ||
if (!gruntpath) { | ||
if (options.version) { process.exit(); } | ||
if (options.help) { info.help(); } | ||
info.fatal('Unable to find local grunt.', 99); | ||
} | ||
console.log('grunt-cli v' + pkg.version); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to exit after this line as it will cause an exception in the line 53. Here is what I got when I run
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I runned that command in an arbitrary folder which doesn't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would be fixed by doing the same as the original version of the CLI: exit if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet, fixed. Thanks for the review! |
||
} | ||
|
||
// Everything looks good. Require local grunt and run it. | ||
require(gruntpath).cli(); | ||
v8flags(function (err, v8flags) { | ||
var Grunt = new Liftoff({ | ||
name: 'grunt', | ||
configName: 'Gruntfile', | ||
// Support a number of languages based on file extension | ||
extensions: extensions, | ||
// Flags that are v8 flags will be loaded into node instead of Gruntfile | ||
v8flags: v8flags | ||
}); | ||
Grunt.launch({ | ||
cwd: options.cwd, | ||
configPath: options.gruntfile, | ||
require: options.require, | ||
verbose: options.verbose | ||
}, function (env) { | ||
var tasks = options.argv.remain; | ||
delete options.argv; | ||
// No grunt install found! | ||
if (!env.modulePath) { | ||
if (options.version) { | ||
process.exit(); | ||
} | ||
if (options.help) { | ||
info.help(); | ||
} | ||
info.fatal('Unable to find local grunt.', 99); | ||
} else { | ||
options.gruntfile = env.configPath; | ||
var grunt = require(env.modulePath); | ||
grunt.tasks(tasks, options); | ||
} | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,15 @@ | |
"grunt": "bin/grunt" | ||
}, | ||
"dependencies": { | ||
"findup-sync": "~0.3.0", | ||
"grunt-known-options": "~1.1.0", | ||
"nopt": "~3.0.6", | ||
"resolve": "~1.1.0" | ||
"grunt-known-options": "^1.1.0", | ||
"interpret": "^1.1.0", | ||
"liftoff": "^2.5.0", | ||
"nopt": "^4.0.1", | ||
"v8flags": "^3.0.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure you want to change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! Thanks! |
||
}, | ||
"devDependencies": { | ||
"grunt": "~1.0.1", | ||
"grunt-contrib-jshint": "~1.0.0" | ||
"grunt": "^1.0.2", | ||
"grunt-contrib-jshint": "^1.1.0" | ||
}, | ||
"files": [ | ||
"bin", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to drop the
completion
command line flag? If someone was configuring the auto-completion as pointed in theREADME
, they will only seeGrunt
trying to run their tasks directly after opening a new terminal session, which will result in an exception simular to the one in my other comment.