Run npm install if the node is created locally.
This commit is contained in:
parent
399d379ff5
commit
67a2035365
@ -5,7 +5,6 @@ var version = require(__dirname + '/../package.json').version;
|
||||
var create = require('../lib/scaffold/create');
|
||||
var add = require('../lib/scaffold/add');
|
||||
var start = require('../lib/scaffold/start');
|
||||
var stop = require('../lib/scaffold/stop');
|
||||
var findConfig = require('../lib/scaffold/find-config');
|
||||
|
||||
program
|
||||
@ -16,10 +15,29 @@ program
|
||||
program
|
||||
.command('create <directory> [name]')
|
||||
.description('Create a new node')
|
||||
.action(function(directory, name){
|
||||
.action(function(dirname, name){
|
||||
var options = {
|
||||
cwd: process.cwd(),
|
||||
dirname: dirname,
|
||||
name: name,
|
||||
datadir: './data',
|
||||
isGlobal: false
|
||||
};
|
||||
create(options, function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
console.log('Successfully created node in directory: ', dirname);
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
.command('start')
|
||||
.option('-b', '--background', 'Will start in the background')
|
||||
.description('Start the current node')
|
||||
.action(function(){
|
||||
var config = findConfig();
|
||||
create(config, directory, name);
|
||||
console.log('Successfully created node in directory: ', directory);
|
||||
start(config);
|
||||
});
|
||||
|
||||
program
|
||||
@ -39,28 +57,8 @@ program
|
||||
console.log();
|
||||
});
|
||||
|
||||
program
|
||||
.command('start')
|
||||
.option('-b', '--background', 'Will start in the background')
|
||||
.description('Start the current node')
|
||||
.action(function(){
|
||||
var config = findConfig();
|
||||
start(config);
|
||||
});
|
||||
|
||||
program
|
||||
.command('stop')
|
||||
.description('Stop the current node')
|
||||
.action(function(){
|
||||
var config = findConfig();
|
||||
stop(config);
|
||||
});
|
||||
|
||||
program
|
||||
.command('*')
|
||||
.description('')
|
||||
.action(function(env){
|
||||
program.help();
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (process.argv.length === 2) {
|
||||
program.help();
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
var bitcore = require('bitcore');
|
||||
var async = require('async');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
var path = require('path');
|
||||
var version = require('../../package.json').version;
|
||||
var packageFile = require('../../package.json');
|
||||
var mkdirp = require('mkdirp');
|
||||
var fs = require('fs');
|
||||
|
||||
@ -17,10 +19,18 @@ var BASE_CONFIG = {
|
||||
network: 'livenet'
|
||||
};
|
||||
|
||||
var version;
|
||||
if (packageFile.version.match('-dev')) {
|
||||
// Use the latest release (todo: update to find the latest release?)
|
||||
version = '^0.2.0-beta.3';
|
||||
} else {
|
||||
version = '^' + packageFile.version;
|
||||
}
|
||||
|
||||
var BASE_PACKAGE = {
|
||||
dependencies: {
|
||||
'bitcore': '^' + bitcore.version,
|
||||
'bitcore-node': '^' + version
|
||||
'bitcore-node': version
|
||||
}
|
||||
};
|
||||
|
||||
@ -50,6 +60,7 @@ function createBitcoinDirectory(datadir, done) {
|
||||
* Will create a base Bitcore Node configuration directory and files.
|
||||
* @param {String} configDir - The absolute path
|
||||
* @param {String} name - The name of the node
|
||||
* @param {Boolean} isGlobal - If the configuration depends on globally installed node modules.
|
||||
* @param {Function} done - The callback function called when finished
|
||||
*/
|
||||
function createConfigDirectory(configDir, name, isGlobal, done) {
|
||||
@ -59,7 +70,7 @@ function createConfigDirectory(configDir, name, isGlobal, done) {
|
||||
}
|
||||
|
||||
var config = BASE_CONFIG;
|
||||
config.name = name;
|
||||
config.name = name || 'Bitcore Node';
|
||||
var configJSON = JSON.stringify(config, null, 2);
|
||||
var packageJSON = JSON.stringify(BASE_PACKAGE, null, 2);
|
||||
try {
|
||||
@ -76,6 +87,9 @@ function createConfigDirectory(configDir, name, isGlobal, done) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Will setup a directory with a Bitcore Node directory, configuration file,
|
||||
* bitcoin configuration, and will install all necessary dependencies.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {String} options.cwd - The current working directory
|
||||
* @param {String} options.dirname - The name of the bitcore node configuration directory
|
||||
@ -90,7 +104,7 @@ function create(options, done) {
|
||||
$.checkArgument(_.isFunction(done));
|
||||
$.checkArgument(_.isString(options.cwd));
|
||||
$.checkArgument(_.isString(options.dirname));
|
||||
$.checkArgument(_.isString(options.name));
|
||||
$.checkArgument(_.isString(options.name) || _.isUndefined(options.name));
|
||||
$.checkArgument(_.isBoolean(options.isGlobal));
|
||||
$.checkArgument(_.isString(options.datadir));
|
||||
|
||||
@ -100,24 +114,46 @@ function create(options, done) {
|
||||
var datadir = options.datadir;
|
||||
var isGlobal = options.isGlobal;
|
||||
|
||||
if (!cwd) {
|
||||
cwd = process.cwd;
|
||||
}
|
||||
|
||||
var absConfigDir = path.resolve(cwd, dirname);
|
||||
var absDataDir = path.resolve(absConfigDir, datadir);
|
||||
|
||||
if (!fs.existsSync(absConfigDir)) {
|
||||
createConfigDirectory(absConfigDir, name, isGlobal, function() {
|
||||
if (!fs.existsSync(absDataDir)) {
|
||||
createBitcoinDirectory(absDataDir, done);
|
||||
async.series([
|
||||
function(next) {
|
||||
if (!fs.existsSync(absConfigDir)) {
|
||||
createConfigDirectory(absConfigDir, name, isGlobal, next);
|
||||
} else {
|
||||
done();
|
||||
next(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
if (!fs.existsSync(absDataDir)) {
|
||||
createBitcoinDirectory(absDataDir, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
if (!isGlobal) {
|
||||
var npm = spawn('npm', ['install'], {cwd: absConfigDir});
|
||||
|
||||
npm.stdout.on('data', function (data) {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
|
||||
npm.stderr.on('data', function (data) {
|
||||
process.stderr.write(data);
|
||||
});
|
||||
|
||||
npm.on('close', function (code) {
|
||||
//todo: handle code
|
||||
next();
|
||||
});
|
||||
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
], done);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var should = require('chai').should();
|
||||
var create = require('../../lib/scaffold/create');
|
||||
var proxyquire = require('proxyquire');
|
||||
var sinon = require('sinon');
|
||||
var create = proxyquire('../../lib/scaffold/create', {
|
||||
'child_process': {
|
||||
spawn: sinon.stub().returns({
|
||||
stdout: {
|
||||
on: sinon.stub()
|
||||
},
|
||||
stderr: {
|
||||
on: sinon.stub()
|
||||
},
|
||||
on: function(event, cb) {
|
||||
cb();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
var fs = require('fs');
|
||||
var mkdirp = require('mkdirp');
|
||||
var rimraf = require('rimraf');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user