Skip to content

Commit

Permalink
Implement liftoff into grunt-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Feb 10, 2018
1 parent 7f6298e commit 7b8cb3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 127 deletions.
81 changes: 44 additions & 37 deletions bin/grunt
Expand Up @@ -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);
});
});
33 changes: 0 additions & 33 deletions lib/cli.js

This file was deleted.

51 changes: 0 additions & 51 deletions lib/info.js

This file was deleted.

13 changes: 7 additions & 6 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"
"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",
Expand Down

0 comments on commit 7b8cb3f

Please sign in to comment.