From 7b8cb3fbeb8e080ae8d0d9b84ff3499af09ffaf1 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Fri, 9 Feb 2018 21:20:54 -0800 Subject: [PATCH 1/5] Implement liftoff into grunt-cli --- bin/grunt | 81 ++++++++++++++++++++++++++++------------------------ lib/cli.js | 33 --------------------- lib/info.js | 51 --------------------------------- package.json | 13 +++++---- 4 files changed, 51 insertions(+), 127 deletions(-) delete mode 100644 lib/cli.js delete mode 100644 lib/info.js diff --git a/bin/grunt b/bin/grunt index 930271c..08c14db 100755 --- a/bin/grunt +++ b/bin/grunt @@ -4,41 +4,48 @@ process.title = 'grunt'; -// Especially badass external libs. -var findup = require('findup-sync'); -var resolve = require('resolve').sync; - -// Internal libs. -var options = require('../lib/cli').options; -var completion = require('../lib/completion'); -var info = require('../lib/info'); -var path = require('path'); - -var basedir = process.cwd(); -var gruntpath; - -// 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); +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'); + +// Parse `gruntOptions` into a form that nopt can handle. +var aliases = {}; +var known = {}; + +Object.keys(gruntOptions).forEach(function(key) { + var short = gruntOptions[key].short; + if (short) { + aliases[short] = '--' + key; } -} - -// Everything looks good. Require local grunt and run it. -require(gruntpath).cli(); + known[key] = gruntOptions[key].type; +}); + +// Parse them and return an options object. +var options = nopt(known, aliases, process.argv, 2); + +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, + completion: completion, + verbose: options.verbose + }, function (env) { + var tasks = options.argv.remain; + delete options.argv; + options.gruntfile = env.configPath; + var grunt = require(env.modulePath); + grunt.tasks(tasks, options); + }); +}); diff --git a/lib/cli.js b/lib/cli.js deleted file mode 100644 index 0946006..0000000 --- a/lib/cli.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * grunt-cli - * http://gruntjs.com/ - * - * Copyright (c) 2016 Tyler Kellen, contributors - * Licensed under the MIT license. - * https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT - */ - -'use strict'; - -// External lib. -var nopt = require('nopt'); -var gruntOptions = require('grunt-known-options'); - -// Parse `gruntOptions` into a form that nopt can handle. -exports.aliases = {}; -exports.known = {}; - -Object.keys(gruntOptions).forEach(function(key) { - var short = gruntOptions[key].short; - if (short) { - exports.aliases[short] = '--' + key; - } - exports.known[key] = gruntOptions[key].type; -}); - -// Parse them and return an options object. -Object.defineProperty(exports, 'options', { - get: function() { - return nopt(exports.known, exports.aliases, process.argv, 2); - } -}); diff --git a/lib/info.js b/lib/info.js deleted file mode 100644 index a184930..0000000 --- a/lib/info.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * grunt-cli - * http://gruntjs.com/ - * - * Copyright (c) 2016 Tyler Kellen, contributors - * Licensed under the MIT license. - * https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT - */ - -'use strict'; - -// Project metadata. -var pkg = require('../package.json'); - -// Display grunt-cli version. -exports.version = function() { - console.log('grunt-cli v' + pkg.version); -}; - -// Show help, then exit with a message and error code. -exports.fatal = function(msg, code) { - exports.helpHeader(); - console.log('Fatal error: ' + msg); - console.log(''); - exports.helpFooter(); - process.exit(code); -}; - -// Show help and exit. -exports.help = function() { - exports.helpHeader(); - exports.helpFooter(); - process.exit(); -}; - -// Help header. -exports.helpHeader = function() { - console.log('grunt-cli: ' + pkg.description + ' (v' + pkg.version + ')'); - console.log(''); -}; - -// Help footer. -exports.helpFooter = function() { - [ - 'If you\'re seeing this message, grunt hasn\'t been installed locally to', - 'your project. For more information about installing and configuring grunt,', - 'please see the Getting Started guide:', - '', - 'http://gruntjs.com/getting-started', - ].forEach(function(str) { console.log(str); }); -}; diff --git a/package.json b/package.json index fc267a4..e7bf9f7 100644 --- a/package.json +++ b/package.json @@ -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" }, "devDependencies": { - "grunt": "~1.0.1", - "grunt-contrib-jshint": "~1.0.0" + "grunt": "^1.0.2", + "grunt-contrib-jshint": "^1.1.0" }, "files": [ "bin", From ea01dc5423262f2ac8c0408bef0e84a1d00118c2 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Fri, 9 Feb 2018 21:30:51 -0800 Subject: [PATCH 2/5] Include grunt-cli version with --version --- bin/grunt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/grunt b/bin/grunt index 08c14db..329fe70 100755 --- a/bin/grunt +++ b/bin/grunt @@ -10,6 +10,7 @@ var extensions = require('interpret').jsVariants; var nopt = require('nopt'); var gruntOptions = require('grunt-known-options'); var completion = require('../lib/completion.js'); +var pkg = require('../package.json'); // Parse `gruntOptions` into a form that nopt can handle. var aliases = {}; @@ -26,6 +27,10 @@ Object.keys(gruntOptions).forEach(function(key) { // Parse them and return an options object. var options = nopt(known, aliases, process.argv, 2); +if (options.version) { + console.log('grunt-cli v' + pkg.version); +} + v8flags(function (err, v8flags) { var Grunt = new Liftoff({ name: 'grunt', From 0c5f39708630cdd0b775617af96a0e7014409767 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Tue, 6 Mar 2018 15:09:38 -0800 Subject: [PATCH 3/5] Fix version and help with no gruntfile --- bin/grunt | 18 +++++++++++++++--- lib/info.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 lib/info.js diff --git a/bin/grunt b/bin/grunt index 329fe70..6857f54 100755 --- a/bin/grunt +++ b/bin/grunt @@ -10,6 +10,7 @@ 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'); // Parse `gruntOptions` into a form that nopt can handle. @@ -49,8 +50,19 @@ v8flags(function (err, v8flags) { }, function (env) { var tasks = options.argv.remain; delete options.argv; - options.gruntfile = env.configPath; - var grunt = require(env.modulePath); - grunt.tasks(tasks, options); + // 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); + } }); }); diff --git a/lib/info.js b/lib/info.js new file mode 100644 index 0000000..ba56f52 --- /dev/null +++ b/lib/info.js @@ -0,0 +1,51 @@ +/* + * grunt-cli + * http://gruntjs.com/ + * + * Copyright (c) 2016 Tyler Kellen, contributors + * Licensed under the MIT license. + * https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT + */ + +'use strict'; + +// Project metadata. +var pkg = require('../package.json'); + +// Display grunt-cli version. +exports.version = function() { + console.log('grunt-cli v' + pkg.version); +}; + +// Show help, then exit with a message and error code. +exports.fatal = function(msg, code) { + exports.helpHeader(); + console.log('Fatal error: ' + msg); + console.log(''); + exports.helpFooter(); + process.exit(code); +}; + +// Show help and exit. +exports.help = function() { + exports.helpHeader(); + exports.helpFooter(); + process.exit(); +}; + +// Help header. +exports.helpHeader = function() { + console.log('grunt-cli: ' + pkg.description + ' (v' + pkg.version + ')'); + console.log(''); +}; + +// Help footer. +exports.helpFooter = function() { + [ + 'If you\'re seeing this message, grunt hasn\'t been installed locally to', + 'your project. For more information about installing and configuring grunt,', + 'please see the Getting Started guide:', + '', + 'https://gruntjs.com/getting-started', + ].forEach(function(str) { console.log(str); }); +}; From 8ae6299a1f3c99c36c2fb5b5e96adfc45a525ee3 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Tue, 6 Mar 2018 15:22:34 -0800 Subject: [PATCH 4/5] Fix completions to use old Grunt style for now --- bin/grunt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/grunt b/bin/grunt index 6857f54..2d0e3f2 100755 --- a/bin/grunt +++ b/bin/grunt @@ -28,7 +28,9 @@ Object.keys(gruntOptions).forEach(function(key) { // Parse them and return an options object. var options = nopt(known, aliases, process.argv, 2); -if (options.version) { +if ('completion' in options) { + completion.print(options.completion); +} else if (options.version) { console.log('grunt-cli v' + pkg.version); } @@ -45,7 +47,6 @@ v8flags(function (err, v8flags) { cwd: options.cwd, configPath: options.gruntfile, require: options.require, - completion: completion, verbose: options.verbose }, function (env) { var tasks = options.argv.remain; From 98ba9e672bf42ebb61b2c0fe9463b98a9d776588 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Thu, 15 Mar 2018 12:33:51 -0700 Subject: [PATCH 5/5] Use ~ for deps and update v8flags to 3.0.2 --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e7bf9f7..a55971d 100644 --- a/package.json +++ b/package.json @@ -15,15 +15,15 @@ "grunt": "bin/grunt" }, "dependencies": { - "grunt-known-options": "^1.1.0", - "interpret": "^1.1.0", - "liftoff": "^2.5.0", - "nopt": "^4.0.1", - "v8flags": "^3.0.1" + "grunt-known-options": "~1.1.0", + "interpret": "~1.1.0", + "liftoff": "~2.5.0", + "nopt": "~4.0.1", + "v8flags": "~3.0.2" }, "devDependencies": { - "grunt": "^1.0.2", - "grunt-contrib-jshint": "^1.1.0" + "grunt": "~1.0.2", + "grunt-contrib-jshint": "~1.1.0" }, "files": [ "bin",