Expose cli methods.
This commit is contained in:
parent
1dec93edd4
commit
58894bc4b2
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
// vi: ft=javascript -*- mode: JavaScript; -*-
|
||||
|
||||
var node = require('..');
|
||||
node.cli.bitcore();
|
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var semver = require('semver');
|
||||
var Liftoff = require('liftoff');
|
||||
var cliPackage = require('../package.json');
|
||||
|
||||
var liftoff = new Liftoff({
|
||||
name: 'bitcore-node',
|
||||
moduleName: 'bitcore-node',
|
||||
configName: 'bitcore-node',
|
||||
processTitle: 'bitcore-node'
|
||||
}).on('require', function (name, module) {
|
||||
console.log('Loading:', name);
|
||||
}).on('requireFail', function (name, err) {
|
||||
console.log('Unable to load:', name, err);
|
||||
}).on('respawn', function (flags, child) {
|
||||
console.log('Detected node flags:', flags);
|
||||
console.log('Respawned to PID:', child.pid);
|
||||
});
|
||||
|
||||
liftoff.launch({
|
||||
cwd: process.cwd()
|
||||
}, function(env){
|
||||
|
||||
var bitcorenode;
|
||||
if (env.modulePackage && env.configPath) {
|
||||
// use the local version
|
||||
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
|
||||
throw new Error(
|
||||
'Version mismatch, global bitcore-node is ' + cliPackage.version +
|
||||
' and local bitcore-node is ' + env.modulePackage.version
|
||||
);
|
||||
}
|
||||
bitcorenode = require(env.modulePath);
|
||||
} else {
|
||||
// use the global version
|
||||
bitcorenode = require('..');
|
||||
}
|
||||
|
||||
bitcorenode.cli.main();
|
||||
|
||||
});
|
|
@ -26,8 +26,8 @@ Bitcore includes a Command Line Interface (CLI) for managing, configuring and in
|
|||
```bash
|
||||
bitcore create -d <bitcoin-data-dir> mynode
|
||||
cd mynode
|
||||
bitcore add <service>
|
||||
bitcore add https://github.com/yourname/helloworld
|
||||
bitcore install <service>
|
||||
bitcore install https://github.com/yourname/helloworld
|
||||
```
|
||||
|
||||
This will create a directory with configuration files for your node and install the necessary dependencies. For more information about (and developing) services, please see the [Service Documentation](services.md).
|
||||
|
|
|
@ -6,11 +6,7 @@ description: Description of functions for Bitcore Node configuration
|
|||
|
||||
A collection of functions for creating, managing, starting, stopping and interacting with a Bitcore Node.
|
||||
|
||||
## Create
|
||||
|
||||
This function will create a new directory and the initial configuration files/directories, including 'bitcore-node.json', 'package.json', 'bitcoin.conf', install the necessary Node.js modules, and create a data directory.
|
||||
|
||||
## Add
|
||||
## Install
|
||||
|
||||
This function will add a service to a node by installing the necessary dependencies and modifying the `bitcore-node.json` configuration.
|
||||
|
||||
|
@ -26,7 +22,7 @@ This function will recursively find a configuration `bitcore-node.json` file in
|
|||
|
||||
This function will return a default configuration with the default services based on environment variables, and will default to using the standard `~/.bitcoin` data directory.
|
||||
|
||||
## Remove
|
||||
## Uninstall
|
||||
|
||||
This function will remove a service from a node by uninstalling the necessary dependencies and modifying the `bitcore-node.json` configuration.
|
||||
|
||||
|
|
5
index.js
5
index.js
|
@ -22,4 +22,7 @@ module.exports.scaffold.findConfig = require('./lib/scaffold/find-config');
|
|||
module.exports.scaffold.defaultConfig = require('./lib/scaffold/default-config');
|
||||
|
||||
module.exports.cli = {};
|
||||
module.exports.cli.main = require('./cli/main');
|
||||
module.exports.cli.main = require('./lib/cli/main');
|
||||
module.exports.cli.daemon = require('./lib/cli/daemon');
|
||||
module.exports.cli.bitcore = require('./lib/cli/bitcore');
|
||||
module.exports.cli.bitcored = require('./lib/cli/bitcored');
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
var Liftoff = require('liftoff');
|
||||
|
||||
function main() {
|
||||
|
||||
var liftoff = new Liftoff({
|
||||
name: 'bitcore',
|
||||
moduleName: 'bitcore-node',
|
||||
configName: 'bitcore-node',
|
||||
processTitle: 'bitcore'
|
||||
}).on('require', function (name, module) {
|
||||
console.log('Loading:', name);
|
||||
}).on('requireFail', function (name, err) {
|
||||
console.log('Unable to load:', name, err);
|
||||
}).on('respawn', function (flags, child) {
|
||||
console.log('Detected node flags:', flags);
|
||||
console.log('Respawned to PID:', child.pid);
|
||||
});
|
||||
|
||||
liftoff.launch({
|
||||
cwd: process.cwd()
|
||||
}, function(env){
|
||||
|
||||
var node;
|
||||
if (env.modulePackage && env.configPath) {
|
||||
// use the configured version
|
||||
node = require(env.modulePath);
|
||||
} else {
|
||||
// use this version
|
||||
node = require('..');
|
||||
}
|
||||
|
||||
node.cli.main();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = main;
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
var Liftoff = require('liftoff');
|
||||
|
||||
function main() {
|
||||
|
||||
var liftoff = new Liftoff({
|
||||
name: 'bitcored',
|
||||
moduleName: 'bitcore-node',
|
||||
configName: 'bitcore-node',
|
||||
processTitle: 'bitcored'
|
||||
}).on('require', function (name, module) {
|
||||
console.log('Loading:', name);
|
||||
}).on('requireFail', function (name, err) {
|
||||
console.log('Unable to load:', name, err);
|
||||
}).on('respawn', function (flags, child) {
|
||||
console.log('Detected node flags:', flags);
|
||||
console.log('Respawned to PID:', child.pid);
|
||||
});
|
||||
|
||||
liftoff.launch({
|
||||
cwd: process.cwd()
|
||||
}, function(env){
|
||||
|
||||
var node;
|
||||
if (env.modulePackage && env.configPath) {
|
||||
// use the configured version
|
||||
node = require(env.modulePath);
|
||||
} else {
|
||||
// use this version
|
||||
node = require('..');
|
||||
}
|
||||
|
||||
node.cli.daemon();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = main;
|
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
|
||||
var program = require('commander');
|
||||
var path = require('path');
|
||||
var bitcore = require('..');
|
||||
|
||||
function main() {
|
||||
/* jshint maxstatements: 100 */
|
||||
|
||||
var version = bitcore.version;
|
||||
var start = bitcore.scaffold.start;
|
||||
var findConfig = bitcore.scaffold.findConfig;
|
||||
var defaultConfig = bitcore.scaffold.defaultConfig;
|
||||
|
||||
program
|
||||
.version(version)
|
||||
.description('Start the current node')
|
||||
.option('-c, --config <dir>', 'Specify the directory with Bitcore Node configuration')
|
||||
.option('-d, --daemon', 'Make bitcore a daemon (running in the background)');
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (program.config) {
|
||||
program.config = path.resolve(process.cwd(), program.config);
|
||||
}
|
||||
var configInfo = findConfig(program.config || process.cwd());
|
||||
if (!configInfo) {
|
||||
configInfo = defaultConfig();
|
||||
}
|
||||
if(program.daemon) {
|
||||
configInfo.config.daemon = true;
|
||||
}
|
||||
start(configInfo);
|
||||
}
|
||||
|
||||
module.exports = main;
|
|
@ -20,17 +20,18 @@ function main() {
|
|||
.version(version);
|
||||
|
||||
program
|
||||
.command('create <directory> [name]')
|
||||
.command('create <directory>')
|
||||
.description('Create a new node')
|
||||
.option('-d, --datadir <dir>', 'Specify the bitcoin database directory')
|
||||
.action(function(dirname, name, cmd){
|
||||
.action(function(dirname, cmd){
|
||||
console.log('dirname', dirname);
|
||||
console.log('cmd', cmd);
|
||||
if (cmd.datadir) {
|
||||
cmd.datadir = path.resolve(process.cwd(), cmd.datadir);
|
||||
}
|
||||
var opts = {
|
||||
cwd: process.cwd(),
|
||||
dirname: dirname,
|
||||
name: name,
|
||||
datadir: cmd.datadir || './data',
|
||||
isGlobal: false
|
||||
};
|
||||
|
@ -62,8 +63,8 @@ function main() {
|
|||
});
|
||||
|
||||
program
|
||||
.command('add <services...>')
|
||||
.alias('install')
|
||||
.command('install <services...>')
|
||||
.alias('add')
|
||||
.description('Install a service for the current node')
|
||||
.action(function(services){
|
||||
var configInfo = findConfig(process.cwd());
|
||||
|
@ -89,8 +90,8 @@ function main() {
|
|||
});
|
||||
|
||||
program
|
||||
.command('remove <services...>')
|
||||
.alias('uninstall')
|
||||
.command('uninstall <services...>')
|
||||
.alias('remove')
|
||||
.description('Uninstall a service for the current node')
|
||||
.action(function(services){
|
||||
var configInfo = findConfig(process.cwd());
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('bitcore');
|
||||
var async = require('async');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
@ -20,7 +20,7 @@ if (packageFile.version.match('-dev')) {
|
|||
|
||||
var BASE_PACKAGE = {
|
||||
dependencies: {
|
||||
'bitcore-lib': '^' + bitcore.version,
|
||||
'bitcore': '^' + bitcore.version,
|
||||
'bitcore-node': version
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"version": "0.2.0-dev",
|
||||
"lastBuild": "0.2.0-beta.11",
|
||||
"main": "./index.js",
|
||||
"bin": "./cli/bitcore-node.js",
|
||||
"repository": "git://github.com/bitpay/bitcore-node.git",
|
||||
"homepage": "https://github.com/bitpay/bitcore-node.js",
|
||||
"bugs": {
|
||||
|
@ -28,6 +27,9 @@
|
|||
"email": "patrick@bitpay.com"
|
||||
}
|
||||
],
|
||||
"bin": {
|
||||
"bitcore-node": "./bin/bitcore-node"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "./bin/install",
|
||||
"build": "./bin/build",
|
||||
|
@ -54,7 +56,6 @@
|
|||
"express": "^4.13.3",
|
||||
"leveldown": "^1.4.1",
|
||||
"levelup": "^1.2.1",
|
||||
"liftoff": "^2.1.0",
|
||||
"memdown": "^1.0.0",
|
||||
"mkdirp": "0.5.0",
|
||||
"nan": "^2.0.9",
|
||||
|
|
Loading…
Reference in New Issue