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>')
|
.command('create <directory>')
|
||||||
.description('Create a new node')
|
.description('Create a new node')
|
||||||
.option('-d, --datadir <dir>', 'Specify the bitcoin database directory')
|
.option('-d, --datadir <dir>', 'Specify the bitcoin database directory')
|
||||||
|
.option('-t, --testnet', 'Enable testnet as the network')
|
||||||
.action(function(dirname, cmd){
|
.action(function(dirname, cmd){
|
||||||
if (cmd.datadir) {
|
if (cmd.datadir) {
|
||||||
cmd.datadir = path.resolve(process.cwd(), cmd.datadir);
|
cmd.datadir = path.resolve(process.cwd(), cmd.datadir);
|
||||||
|
@ -33,6 +34,9 @@ function main(servicesPath, additionalServices) {
|
||||||
datadir: cmd.datadir || './data',
|
datadir: cmd.datadir || './data',
|
||||||
isGlobal: false
|
isGlobal: false
|
||||||
};
|
};
|
||||||
|
if (cmd.testnet) {
|
||||||
|
opts.network = 'testnet';
|
||||||
|
}
|
||||||
create(opts, function(err) {
|
create(opts, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -48,21 +48,21 @@ 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 {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} configDir - The absolute path
|
||||||
* @param {String} datadir - The bitcoin database directory
|
|
||||||
* @param {Boolean} isGlobal - If the configuration depends on globally installed node services.
|
* @param {Boolean} isGlobal - If the configuration depends on globally installed node services.
|
||||||
* @param {Function} done - The callback function called when finished
|
* @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) {
|
mkdirp(configDir, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
var configInfo = defaultBaseConfig(options);
|
||||||
var configInfo = defaultBaseConfig();
|
|
||||||
var config = configInfo.config;
|
var config = configInfo.config;
|
||||||
|
|
||||||
config.datadir = datadir;
|
|
||||||
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 {
|
||||||
|
@ -110,7 +110,11 @@ function create(options, done) {
|
||||||
function(next) {
|
function(next) {
|
||||||
// Setup the the bitcore-node directory and configuration
|
// Setup the the bitcore-node directory and configuration
|
||||||
if (!fs.existsSync(absConfigDir)) {
|
if (!fs.existsSync(absConfigDir)) {
|
||||||
createConfigDirectory(absConfigDir, datadir, isGlobal, next);
|
var createOptions = {
|
||||||
|
network: options.network,
|
||||||
|
datadir: datadir
|
||||||
|
};
|
||||||
|
createConfigDirectory(createOptions, absConfigDir, isGlobal, next);
|
||||||
} else {
|
} else {
|
||||||
next(new Error('Directory "' + absConfigDir+ '" already exists.'));
|
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
|
* Will return the path and default bitcore-node configuration on environment variables
|
||||||
* or default locations.
|
* or default locations.
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {String} options.network - "testnet" or "livenet"
|
||||||
*/
|
*/
|
||||||
function getDefaultBaseConfig() {
|
function getDefaultBaseConfig(options) {
|
||||||
|
if (!options) {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
path: process.cwd(),
|
path: process.cwd(),
|
||||||
config: {
|
config: {
|
||||||
datadir: path.resolve(process.env.HOME, '.bitcoin'),
|
datadir: options.datadir || path.resolve(process.env.HOME, '.bitcoin'),
|
||||||
network: 'livenet',
|
network: options.network || 'livenet',
|
||||||
port: 3001,
|
port: 3001,
|
||||||
services: ['bitcoind', 'db', 'address', 'web']
|
services: ['bitcoind', 'db', 'address', 'web']
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
var should = require('chai').should();
|
var should = require('chai').should();
|
||||||
var defaultBaseConfig = require('../../lib/scaffold/default-base-config');
|
var defaultBaseConfig = require('../../lib/scaffold/default-base-config');
|
||||||
|
|
||||||
describe('#defaultConfig', function() {
|
describe('#defaultBaseConfig', function() {
|
||||||
it('will return expected configuration', function() {
|
it('will return expected configuration', function() {
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
var home = process.env.HOME;
|
var home = process.env.HOME;
|
||||||
|
@ -14,4 +14,24 @@ describe('#defaultConfig', function() {
|
||||||
info.config.port.should.equal(3001);
|
info.config.port.should.equal(3001);
|
||||||
info.config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']);
|
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