Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"maxstatements": 25,
"maxcomplexity": 10,
"maxdepth": 4,
"maxlen": 120,
"maxlen": 140,
"multistr": true,
"predef": [
"after",
Expand Down
4 changes: 2 additions & 2 deletions lib/scaffold/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var path = require('path');
var packageFile = require('../../package.json');
var mkdirp = require('mkdirp');
var fs = require('fs');
var defaultBaseConfig = require('./default-base-config');
var defaultConfig = require('./default-config');

var version = '^' + packageFile.version;

Expand Down Expand Up @@ -55,7 +55,7 @@ function createConfigDirectory(options, configDir, isGlobal, done) {
if (err) {
throw err;
}
var configInfo = defaultBaseConfig(options);
var configInfo = defaultConfig(options);
var config = configInfo.config;

var configJSON = JSON.stringify(config, null, 2);
Expand Down
34 changes: 0 additions & 34 deletions lib/scaffold/default-base-config.js

This file was deleted.

63 changes: 43 additions & 20 deletions lib/scaffold/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
var path = require('path');
var mkdirp = require('mkdirp');
var fs = require('fs');
var packageJson = require('../../package');

function getMajorVersion(versionString) {
return parseInt(versionString.split('.')[0]);
}

/**
* Will return the path and default bitcore-node configuration. It will search for the
Expand All @@ -24,6 +29,29 @@ function getDefaultConfig(options) {
mkdirp.sync(defaultPath);
}

if (fs.existsSync(defaultConfigFile)) {
var currentConfig = require(defaultConfigFile);

// config must have a `version` field with major equal to package major version
if(currentConfig.version && getMajorVersion(packageJson.version) === getMajorVersion(currentConfig.version)) {
return {
path: defaultPath,
config: currentConfig
};
}

console.log(`The configuration file at '${defaultConfigFile}' is incompatible with this version of Bitcore.`);

var now = new Date();
// bitcore-node.YYYY-MM-DD.UnixTimestamp.json
var backupFileName = `bitcore-node.${now.getUTCFullYear()}-${now.getUTCMonth()}-${now.getUTCDate()}.${now.getTime()}.json`;
var backupFile = path.resolve(defaultPath, backupFileName);
fs.renameSync(defaultConfigFile, backupFile);
console.log(`The previous configuration file has been moved to: ${backupFile}.`);
}

console.log(`Creating a new configuration file at: ${defaultConfigFile}.`);

var defaultServices = [
'address',
'block',
Expand All @@ -37,33 +65,28 @@ function getDefaultConfig(options) {
'web'
];

if (options.additionalServices) {
defaultServices = defaultServices.concat(options.additionalServices);
}

var defaultDataDir = path.resolve(defaultPath, './data');

if (!fs.existsSync(defaultDataDir)) {
mkdirp.sync(defaultDataDir);
}

if (!fs.existsSync(defaultConfigFile)) {
var defaultConfig = {
network: 'testnet',
port: 3001,
services: defaultServices,
datadir: defaultDataDir,
servicesConfig: {
'insight-api': {
cwdRequirePath: 'node_modules/insight-api'
},
'insight-ui': {
cwdRequirePath: 'node_modules/insight-ui'
}
var defaultConfig = {
version: packageJson.version,
network: 'livenet',
port: 3001,
services: options.additionalServices ? defaultServices.concat(options.additionalServices) : defaultServices,
datadir: defaultDataDir,
servicesConfig: {
'insight-api': {
cwdRequirePath: 'node_modules/insight-api'
},
'insight-ui': {
cwdRequirePath: 'node_modules/insight-ui'
}
};
fs.writeFileSync(defaultConfigFile, JSON.stringify(defaultConfig, null, 2));
}
}
};
fs.writeFileSync(defaultConfigFile, JSON.stringify(defaultConfig, null, 2));

var config = JSON.parse(fs.readFileSync(defaultConfigFile, 'utf-8'));

Expand Down
10 changes: 7 additions & 3 deletions lib/scaffold/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ function lookInRequirePathConfig(req, service) {
}

function lookInCwd(req, service) {
var location = service.config.cwdRequirePath ? service.config.cwdRequirePath : service.name
var location = service.config.cwdRequirePath ? service.config.cwdRequirePath : service.name;
try {
return req(process.cwd() + '/' + location);
} catch(e) {
if(e.code !== 'MODULE_NOT_FOUND') log.error(e);
if(e.code !== 'MODULE_NOT_FOUND') {
log.error(e);
}
log.info('Checked the current working directory for service: ' + location);
}
}
Expand All @@ -100,7 +102,9 @@ function lookInBuiltInPath(req, service) {
var serviceFile = path.resolve(__dirname, '../services/' + service.name);
return req(serviceFile);
} catch(e) {
if(e.code !== 'MODULE_NOT_FOUND') log.error(e);
if(e.code !== 'MODULE_NOT_FOUND') {
log.error(e);
}
log.info('Checked the built-in path: lib/services, for service: ' + service.name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/p2p/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ P2P.prototype._setResourceFilter = function(filter, resource) {
};

P2P.prototype._startBcoin = function() {
const network = ['livenet', 'live', 'main', 'mainnet'].indexOf(this.node.network) !== -1? 'main' : 'testnet';
var network = ['livenet', 'live', 'main', 'mainnet'].indexOf(this.node.network) !== -1? 'main' : 'testnet';
this._bcoin = new Bcoin({
network: network,
prefix: this.node.datadir
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"node": ">=8.2.0"
},
"author": "BitPay <dev@bitpay.com>",
"version": "4.0.0",
"version": "5.0.0",
"main": "./index.js",
"repository": "git://github.com/bitpay/bitcore-node.git",
"homepage": "https://github.com/bitpay/bitcore-node",
Expand Down