Skip to content

Commit

Permalink
Merge pull request #3 from tkellen/liftoff
Browse files Browse the repository at this point in the history
implement liftoff
  • Loading branch information
Rich-Harris committed Sep 23, 2014
2 parents 3fcea3e + 910c444 commit 6c727d4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 37 deletions.
94 changes: 61 additions & 33 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env node

var findup = require( 'findup-sync' ),
resolve = require( 'resolve' ),
var Liftoff = require( 'liftoff' ),
interpret = require( 'interpret' ),
v8flags = require ( 'v8flags' ),
path = require( 'path' ),
parseOptions = require( './utils/parseOptions' ),
serve = require( './serve' ),
build = require( './build' ),
help = require( './help' ),
gobblefile,
gobbledir,
cwd;
help = require( './help' );

require( 'colors' );

Expand All @@ -21,40 +19,70 @@ var command = parseOptions({
v: 'version'
});

if ( command.options.version ) {
return console.log( require( '../package.json' ).version );
}
var cli = new Liftoff({
name: 'gobble',
extensions: interpret.jsVariants,
nodeFlags: v8flags.fetch()
});

if ( command.options.help ) {
return help( command );
}
cli.on('require', function (name) {
console.log( 'Requiring external module:', name.cyan );
});

// find nearest gobblefile
gobblefile = findup( 'gobblefile.js', { nocase: true });
cli.on('requireFail', function (name) {
console.log( 'Failed to load external module:', name.red );
});

cli.on('respawn', function (flags, child) {
var nodeFlags = flags.join(', ')
var pid = String(child.pid);
console.log('Node flags detected:', nodeFlags.cyan );
console.log('Respawned to PID:', pid.cyan );
});

if ( !gobblefile ) {
console.log( 'You must have a gobblefile.js in your project\'s root folder in order to use gobble from the command line.\n\nSee ' + 'https://github.com/gobblejs/gobble/wiki/How-to-write-a-gobblefile'.cyan + ' for help getting started' );
process.exit( 1 );
}
cli.launch({
/*
configPath: argv.gobblefile,
cwd: argv.cwd,
require: argv.require
*/
}, function (env) {

cwd = path.dirname( gobblefile );
process.chdir( cwd );
var gobbledir;

if ( !resolve.sync( 'gobble', { basedir: cwd }) ) {
console.log( 'Could not find a local copy of gobble. You should probably install it with ' + 'npm install --save-dev gobble'.cyan );
}
if ( command.options.version ) {
return console.log( require( '../package.json' ).version );
}

gobbledir = path.join( cwd, '.gobble' );
if ( command.options.help ) {
return help( command );
}

if ( !env.modulePath ) {
console.log( 'Could not find a local copy of gobble. You should probably install it with ' + 'npm install --save-dev gobble'.cyan );
process.exit( 1 );
}

// Execute command
if ( command.args[0] === 'build' ) {
process.env.GOBBLE_ENV = command.options.env || 'production';
return build( command, gobblefile, gobbledir );
}
if ( !env.configPath ) {
console.log( 'You must have a gobblefile.js in your project\'s root folder in order to use gobble from the command line.\n\nSee ' + 'https://github.com/gobblejs/gobble/wiki/How-to-write-a-gobblefile'.cyan + ' for help getting started' );
process.exit( 1 );
}

if ( !command.args[0] || command.args[0] === 'serve' ) {
return serve( command, gobblefile, gobbledir );
}
if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
}

return help( command );
gobbledir = path.join( process.cwd(), '.gobble' );

// Execute command
if ( command.args[0] === 'build' ) {
process.env.GOBBLE_ENV = command.options.env || 'production';
return build( command, env.configPath, gobbledir );
}

if ( !command.args[0] || command.args[0] === 'serve' ) {
return serve( command, env.configPath, gobbledir );
}

return help( command );
});
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
"gobble": "lib/index.js"
},
"dependencies": {
"findup-sync": "~0.1.3",
"cli-spinner": "~0.1.5",
"colors": "~0.6.2",
"resolve": "~1.0.0",
"graceful-chokidar": "~0.1.0",
"interpret": "^0.3.7",
"liftoff": "^0.13.2",
"prompt": "~0.2.13",
"cli-spinner": "~0.1.5",
"stevedore": "~0.1.3",
"graceful-chokidar": "~0.1.0"
"v8flags": "^1.0.1"
},
"files": [
"lib"
Expand Down

0 comments on commit 6c727d4

Please sign in to comment.