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 create = require('../lib/scaffold/create');
|
||||||
var add = require('../lib/scaffold/add');
|
var add = require('../lib/scaffold/add');
|
||||||
var start = require('../lib/scaffold/start');
|
var start = require('../lib/scaffold/start');
|
||||||
var stop = require('../lib/scaffold/stop');
|
|
||||||
var findConfig = require('../lib/scaffold/find-config');
|
var findConfig = require('../lib/scaffold/find-config');
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -16,10 +15,29 @@ program
|
|||||||
program
|
program
|
||||||
.command('create <directory> [name]')
|
.command('create <directory> [name]')
|
||||||
.description('Create a new node')
|
.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();
|
var config = findConfig();
|
||||||
create(config, directory, name);
|
start(config);
|
||||||
console.log('Successfully created node in directory: ', directory);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -39,28 +57,8 @@ program
|
|||||||
console.log();
|
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);
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
if (process.argv.length === 2) {
|
||||||
|
program.help();
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var spawn = require('child_process').spawn;
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
var async = require('async');
|
||||||
var $ = bitcore.util.preconditions;
|
var $ = bitcore.util.preconditions;
|
||||||
var _ = bitcore.deps._;
|
var _ = bitcore.deps._;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var version = require('../../package.json').version;
|
var packageFile = require('../../package.json');
|
||||||
var mkdirp = require('mkdirp');
|
var mkdirp = require('mkdirp');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
@ -17,10 +19,18 @@ var BASE_CONFIG = {
|
|||||||
network: 'livenet'
|
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 = {
|
var BASE_PACKAGE = {
|
||||||
dependencies: {
|
dependencies: {
|
||||||
'bitcore': '^' + bitcore.version,
|
'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.
|
* Will create a base Bitcore Node configuration directory and files.
|
||||||
* @param {String} configDir - The absolute path
|
* @param {String} configDir - The absolute path
|
||||||
* @param {String} name - The name of the node
|
* @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
|
* @param {Function} done - The callback function called when finished
|
||||||
*/
|
*/
|
||||||
function createConfigDirectory(configDir, name, isGlobal, done) {
|
function createConfigDirectory(configDir, name, isGlobal, done) {
|
||||||
@ -59,7 +70,7 @@ function createConfigDirectory(configDir, name, isGlobal, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var config = BASE_CONFIG;
|
var config = BASE_CONFIG;
|
||||||
config.name = name;
|
config.name = name || 'Bitcore Node';
|
||||||
var configJSON = JSON.stringify(config, null, 2);
|
var configJSON = JSON.stringify(config, null, 2);
|
||||||
var packageJSON = JSON.stringify(BASE_PACKAGE, null, 2);
|
var packageJSON = JSON.stringify(BASE_PACKAGE, null, 2);
|
||||||
try {
|
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 {Object} options
|
||||||
* @param {String} options.cwd - The current working directory
|
* @param {String} options.cwd - The current working directory
|
||||||
* @param {String} options.dirname - The name of the bitcore node configuration 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(_.isFunction(done));
|
||||||
$.checkArgument(_.isString(options.cwd));
|
$.checkArgument(_.isString(options.cwd));
|
||||||
$.checkArgument(_.isString(options.dirname));
|
$.checkArgument(_.isString(options.dirname));
|
||||||
$.checkArgument(_.isString(options.name));
|
$.checkArgument(_.isString(options.name) || _.isUndefined(options.name));
|
||||||
$.checkArgument(_.isBoolean(options.isGlobal));
|
$.checkArgument(_.isBoolean(options.isGlobal));
|
||||||
$.checkArgument(_.isString(options.datadir));
|
$.checkArgument(_.isString(options.datadir));
|
||||||
|
|
||||||
@ -100,24 +114,46 @@ function create(options, done) {
|
|||||||
var datadir = options.datadir;
|
var datadir = options.datadir;
|
||||||
var isGlobal = options.isGlobal;
|
var isGlobal = options.isGlobal;
|
||||||
|
|
||||||
if (!cwd) {
|
|
||||||
cwd = process.cwd;
|
|
||||||
}
|
|
||||||
|
|
||||||
var absConfigDir = path.resolve(cwd, dirname);
|
var absConfigDir = path.resolve(cwd, dirname);
|
||||||
var absDataDir = path.resolve(absConfigDir, datadir);
|
var absDataDir = path.resolve(absConfigDir, datadir);
|
||||||
|
|
||||||
if (!fs.existsSync(absConfigDir)) {
|
async.series([
|
||||||
createConfigDirectory(absConfigDir, name, isGlobal, function() {
|
function(next) {
|
||||||
if (!fs.existsSync(absDataDir)) {
|
if (!fs.existsSync(absConfigDir)) {
|
||||||
createBitcoinDirectory(absDataDir, done);
|
createConfigDirectory(absConfigDir, name, isGlobal, next);
|
||||||
} else {
|
} else {
|
||||||
done();
|
next(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
} else {
|
function(next) {
|
||||||
done(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
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';
|
'use strict';
|
||||||
|
|
||||||
var should = require('chai').should();
|
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 fs = require('fs');
|
||||||
var mkdirp = require('mkdirp');
|
var mkdirp = require('mkdirp');
|
||||||
var rimraf = require('rimraf');
|
var rimraf = require('rimraf');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user