Skip to content

Commit

Permalink
Merge pull request #117 from gruntjs/liftoff
Browse files Browse the repository at this point in the history
Implement liftoff into grunt-cli
  • Loading branch information
vladikoff committed Aug 15, 2018
2 parents 7f6298e + 98ba9e6 commit eaf78d6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 69 deletions.
85 changes: 55 additions & 30 deletions bin/grunt
Expand Up @@ -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);
}

// 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);
}
});
});
33 changes: 0 additions & 33 deletions lib/cli.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/info.js
Expand Up @@ -46,6 +46,6 @@ exports.helpFooter = function() {
'your project. For more information about installing and configuring grunt,',
'please see the Getting Started guide:',
'',
'http://gruntjs.com/getting-started',
'https://gruntjs.com/getting-started',
].forEach(function(str) { console.log(str); });
};
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -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"
"interpret": "~1.1.0",
"liftoff": "~2.5.0",
"nopt": "~4.0.1",
"v8flags": "~3.0.2"
},
"devDependencies": {
"grunt": "~1.0.1",
"grunt-contrib-jshint": "~1.0.0"
"grunt": "~1.0.2",
"grunt-contrib-jshint": "~1.1.0"
},
"files": [
"bin",
Expand Down

0 comments on commit eaf78d6

Please sign in to comment.