Merge pull request #339 from braydonf/create-testnet
Add --testnet option to create command.
This commit is contained in:
commit
0c88a540fd
|
@ -23,6 +23,7 @@ function main(servicesPath, additionalServices) {
|
|||
.command('create <directory>')
|
||||
.description('Create a new node')
|
||||
.option('-d, --datadir <dir>', 'Specify the bitcoin database directory')
|
||||
.option('-t, --testnet', 'Enable testnet as the network')
|
||||
.action(function(dirname, cmd){
|
||||
if (cmd.datadir) {
|
||||
cmd.datadir = path.resolve(process.cwd(), cmd.datadir);
|
||||
|
@ -33,6 +34,9 @@ function main(servicesPath, additionalServices) {
|
|||
datadir: cmd.datadir || './data',
|
||||
isGlobal: false
|
||||
};
|
||||
if (cmd.testnet) {
|
||||
opts.network = 'testnet';
|
||||
}
|
||||
create(opts, function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
|
|
|
@ -48,21 +48,21 @@ function createBitcoinDirectory(datadir, done) {
|
|||
|
||||
/**
|
||||
* Will create a base Bitcore Node configuration directory and files.
|
||||
* @param {Object} options
|
||||
* @param {String} options.network - "testnet" or "livenet"
|
||||
* @param {String} options.datadir - The bitcoin database directory
|
||||
* @param {String} configDir - The absolute path
|
||||
* @param {String} datadir - The bitcoin database directory
|
||||
* @param {Boolean} isGlobal - If the configuration depends on globally installed node services.
|
||||
* @param {Function} done - The callback function called when finished
|
||||
*/
|
||||
function createConfigDirectory(configDir, datadir, isGlobal, done) {
|
||||
function createConfigDirectory(options, configDir, isGlobal, done) {
|
||||
mkdirp(configDir, function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var configInfo = defaultBaseConfig();
|
||||
var configInfo = defaultBaseConfig(options);
|
||||
var config = configInfo.config;
|
||||
|
||||
config.datadir = datadir;
|
||||
var configJSON = JSON.stringify(config, null, 2);
|
||||
var packageJSON = JSON.stringify(BASE_PACKAGE, null, 2);
|
||||
try {
|
||||
|
@ -110,7 +110,11 @@ function create(options, done) {
|
|||
function(next) {
|
||||
// Setup the the bitcore-node directory and configuration
|
||||
if (!fs.existsSync(absConfigDir)) {
|
||||
createConfigDirectory(absConfigDir, datadir, isGlobal, next);
|
||||
var createOptions = {
|
||||
network: options.network,
|
||||
datadir: datadir
|
||||
};
|
||||
createConfigDirectory(createOptions, absConfigDir, isGlobal, next);
|
||||
} else {
|
||||
next(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
||||
}
|
||||
|
|
|
@ -5,13 +5,18 @@ var path = require('path');
|
|||
/**
|
||||
* Will return the path and default bitcore-node configuration on environment variables
|
||||
* or default locations.
|
||||
* @param {Object} options
|
||||
* @param {String} options.network - "testnet" or "livenet"
|
||||
*/
|
||||
function getDefaultBaseConfig() {
|
||||
function getDefaultBaseConfig(options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
return {
|
||||
path: process.cwd(),
|
||||
config: {
|
||||
datadir: path.resolve(process.env.HOME, '.bitcoin'),
|
||||
network: 'livenet',
|
||||
datadir: options.datadir || path.resolve(process.env.HOME, '.bitcoin'),
|
||||
network: options.network || 'livenet',
|
||||
port: 3001,
|
||||
services: ['bitcoind', 'db', 'address', 'web']
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
var should = require('chai').should();
|
||||
var defaultBaseConfig = require('../../lib/scaffold/default-base-config');
|
||||
|
||||
describe('#defaultConfig', function() {
|
||||
describe('#defaultBaseConfig', function() {
|
||||
it('will return expected configuration', function() {
|
||||
var cwd = process.cwd();
|
||||
var home = process.env.HOME;
|
||||
|
@ -14,4 +14,24 @@ describe('#defaultConfig', function() {
|
|||
info.config.port.should.equal(3001);
|
||||
info.config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']);
|
||||
});
|
||||
it('be able to specify a network', function() {
|
||||
var cwd = process.cwd();
|
||||
var home = process.env.HOME;
|
||||
var info = defaultBaseConfig({network: 'testnet'});
|
||||
info.path.should.equal(cwd);
|
||||
info.config.datadir.should.equal(home + '/.bitcoin');
|
||||
info.config.network.should.equal('testnet');
|
||||
info.config.port.should.equal(3001);
|
||||
info.config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']);
|
||||
});
|
||||
it('be able to specify a datadir', function() {
|
||||
var cwd = process.cwd();
|
||||
var home = process.env.HOME;
|
||||
var info = defaultBaseConfig({datadir: './data2', network: 'testnet'});
|
||||
info.path.should.equal(cwd);
|
||||
info.config.datadir.should.equal('./data2');
|
||||
info.config.network.should.equal('testnet');
|
||||
info.config.port.should.equal(3001);
|
||||
info.config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue