mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-26 09:05:13 +01:00
added optional help module
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
const Generator = require('yeoman-generator');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const wrap = require('wordwrap')(86);
|
||||
const validator = require('validator');
|
||||
const path = require("path");
|
||||
const featureChoices = require(path.join(__dirname, "features.json"));
|
||||
const coinstring = require('coinstring');
|
||||
const Archive = require('./lib/archive.js');
|
||||
const ApiKey = require('./lib/apikey.js');
|
||||
const help = require('./lib/help.js');
|
||||
|
||||
const uaCommentRegexp = /^[a-zA-Z0-9 \.,:_\-\?\/@]+$/; // TODO: look for spec of unsafe chars
|
||||
const userRegexp = /^[a-zA-Z0-9\._\-]+$/;
|
||||
@@ -40,7 +40,9 @@ action_conf=internal
|
||||
action_executecallbacks=internal
|
||||
`;
|
||||
|
||||
|
||||
const prefix = function() {
|
||||
return chalk.green('Cyphernode')+': ';
|
||||
};
|
||||
|
||||
let prompters = [];
|
||||
fs.readdirSync(path.join(__dirname, "prompters")).forEach(function(file) {
|
||||
@@ -116,7 +118,7 @@ module.exports = class extends Generator {
|
||||
r = await this.prompt([{
|
||||
type: 'password',
|
||||
name: 'password',
|
||||
message: chalk.bold.blue('Enter your configuration password?'),
|
||||
message: prefix()+chalk.bold.blue('Enter your configuration password?'),
|
||||
filter: this._trimFilter
|
||||
}]);
|
||||
}
|
||||
@@ -156,13 +158,13 @@ module.exports = class extends Generator {
|
||||
r = await this.prompt([{
|
||||
type: 'password',
|
||||
name: 'password0',
|
||||
message: chalk.bold.blue('Choose your configuration password'),
|
||||
message: prefix()+chalk.bold.blue('Choose your configuration password'),
|
||||
filter: this._trimFilter
|
||||
},
|
||||
{
|
||||
type: 'password',
|
||||
name: 'password1',
|
||||
message: chalk.bold.blue('Confirm your configuration password'),
|
||||
message: prefix()+chalk.bold.blue('Confirm your configuration password'),
|
||||
filter: this._trimFilter
|
||||
}]);
|
||||
}
|
||||
@@ -192,6 +194,15 @@ module.exports = class extends Generator {
|
||||
// save auth key password to check if it changed
|
||||
this.auth_clientkeyspassword = this.props.auth_clientkeyspassword;
|
||||
|
||||
let r = await this.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'enablehelp',
|
||||
message: prefix()+'Enable help?',
|
||||
default: this._getDefault( 'enablehelp' ),
|
||||
}]);
|
||||
|
||||
this.props.enablehelp = r.enablehelp;
|
||||
|
||||
let prompts = [];
|
||||
for( let m of prompters ) {
|
||||
prompts = prompts.concat(m.prompts(this));
|
||||
@@ -286,6 +297,7 @@ module.exports = class extends Generator {
|
||||
_assignConfigDefaults() {
|
||||
this.props = Object.assign( {
|
||||
features: [],
|
||||
enablehelp: true,
|
||||
net: 'testnet',
|
||||
xpub: '',
|
||||
derivation_path: '0/n',
|
||||
@@ -387,12 +399,18 @@ module.exports = class extends Generator {
|
||||
return (input+"").trim();
|
||||
}
|
||||
|
||||
_wrap(text) {
|
||||
return wrap(text);
|
||||
}
|
||||
|
||||
_featureChoices() {
|
||||
return this.featureChoices;
|
||||
}
|
||||
|
||||
_getHelp( topic ) {
|
||||
if( !this.props.enablehelp )
|
||||
return '';
|
||||
const helpText = help.text( topic );
|
||||
if( !helpText ||helpText === '' ) {
|
||||
return '';
|
||||
}
|
||||
return "\n\n"+helpText+"\n\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
69
install/generator-cyphernode/generators/app/lib/help.js
Normal file
69
install/generator-cyphernode/generators/app/lib/help.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const chalk = require('chalk');
|
||||
const wrap = require('wrap-ansi');
|
||||
|
||||
module.exports = {
|
||||
text: function( topic ) {
|
||||
let r=wrap('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam', 82);
|
||||
switch( topic ) {
|
||||
case 'features':
|
||||
break;
|
||||
case 'net':
|
||||
break;
|
||||
case 'username':
|
||||
break;
|
||||
case 'xpub':
|
||||
break;
|
||||
case 'derivation_path':
|
||||
break;
|
||||
case 'auth_clientkeyspassword':
|
||||
break;
|
||||
case 'auth_recreatekeys':
|
||||
break;
|
||||
case 'auth_edit_ipwhitelist':
|
||||
break;
|
||||
case 'auth_ipwhitelist':
|
||||
break;
|
||||
case 'auth_edit_apiproperties':
|
||||
break;
|
||||
case 'auth_apiproperties':
|
||||
break;
|
||||
case 'bitcoin_mode':
|
||||
break;
|
||||
case 'bitcoin_node_ip':
|
||||
break;
|
||||
case 'bitcoin_rpcuser':
|
||||
break;
|
||||
case 'bitcoin_rpcpassword':
|
||||
break;
|
||||
case 'bitcoin_prune':
|
||||
break;
|
||||
case 'bitcoin_uacomment':
|
||||
break;
|
||||
case 'lightning_implementation':
|
||||
break;
|
||||
case 'lightning_external_ip':
|
||||
break;
|
||||
case 'lightning_nodename':
|
||||
break;
|
||||
case 'lightning_nodecolor':
|
||||
break;
|
||||
case 'electrum_implementation':
|
||||
break;
|
||||
case 'proxy_datapath':
|
||||
break;
|
||||
case 'bitcoin_datapath':
|
||||
break;
|
||||
case 'lightning_datapath':
|
||||
break;
|
||||
case 'bitcoin_expose':
|
||||
break;
|
||||
case 'docker_mode':
|
||||
break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@ module.exports = {
|
||||
// input, confirm, list, rawlist, expand, checkbox, password, editor
|
||||
type: 'checkbox',
|
||||
name: 'features',
|
||||
message: prefix()+'What features do you want to add to your cyphernode?',
|
||||
message: prefix()+'What features do you want to add to your cyphernode?'+utils._getHelp('features'),
|
||||
choices: utils._featureChoices()
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'net',
|
||||
default: utils._getDefault( 'net' ),
|
||||
message: prefix()+'What net do you want to run on?',
|
||||
message: prefix()+'What net do you want to run on?'+utils._getHelp('net'),
|
||||
choices: [{
|
||||
name: "Testnet",
|
||||
value: "testnet"
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
type: 'input',
|
||||
name: 'username',
|
||||
default: utils._getDefault( 'username' ),
|
||||
message: prefix()+'What username will cyphernode run under?',
|
||||
message: prefix()+'What username will cyphernode run under?'+utils._getHelp('username'),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._usernameValidator
|
||||
},
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
type: 'input',
|
||||
name: 'xpub',
|
||||
default: utils._getDefault( 'xpub' ),
|
||||
message: prefix()+'What is your xpub to watch?',
|
||||
message: prefix()+'What is your xpub to watch?'+utils._getHelp('xpub'),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._xkeyValidator
|
||||
},
|
||||
@@ -56,7 +56,7 @@ module.exports = {
|
||||
type: 'input',
|
||||
name: 'derivation_path',
|
||||
default: utils._getDefault( 'derivation_path' ),
|
||||
message: prefix()+'What is your address derivation path?',
|
||||
message: prefix()+'What is your address derivation path?'+utils._getHelp('derivation_path'),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._derivationPathValidator
|
||||
}];
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
type: 'password',
|
||||
name: 'auth_clientkeyspassword',
|
||||
default: utils._getDefault( 'auth_clientkeyspassword' ),
|
||||
message: prefix()+'Enter a password to protect your client keys with',
|
||||
message: prefix()+'Enter a password to protect your client keys with'+utils._getHelp('auth_clientkeyspassword'),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._notEmptyValidator
|
||||
},
|
||||
@@ -29,13 +29,13 @@ module.exports = {
|
||||
type: 'confirm',
|
||||
name: 'auth_recreatekeys',
|
||||
default: false,
|
||||
message: prefix()+'Recreate auth keys?'
|
||||
message: prefix()+'Recreate auth keys?'+utils._getHelp('auth_recreatekeys')
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'auth_edit_ipwhitelist',
|
||||
default: false,
|
||||
message: prefix()+'Edit IP whitelist?'
|
||||
message: prefix()+'Edit IP whitelist?'+utils._getHelp('auth_edit_ipwhitelist')
|
||||
},
|
||||
{
|
||||
when: function( props ) {
|
||||
@@ -45,14 +45,14 @@ module.exports = {
|
||||
},
|
||||
type: 'editor',
|
||||
name: 'auth_ipwhitelist',
|
||||
message: 'IP whitelist',
|
||||
message: prefix()+'IP whitelist'+utils._getHelp('auth_ipwhitelist'),
|
||||
default: utils._getDefault( 'auth_ipwhitelist' )
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'auth_edit_apiproperties',
|
||||
default: false,
|
||||
message: prefix()+'Edit API properties?'
|
||||
message: prefix()+'Edit API properties?'+utils._getHelp('auth_edit_apiproperties')
|
||||
},
|
||||
{
|
||||
when: function( props ) {
|
||||
@@ -62,7 +62,7 @@ module.exports = {
|
||||
},
|
||||
type: 'editor',
|
||||
name: 'auth_apiproperties',
|
||||
message: 'API properties',
|
||||
message: prefix()+'API properties'+utils._getHelp('auth_apiproperties'),
|
||||
default: utils._getDefault( 'auth_apiproperties' )
|
||||
}];
|
||||
},
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
type: 'list',
|
||||
name: 'bitcoin_mode',
|
||||
default: utils._getDefault( 'bitcoin_mode' ),
|
||||
message: prefix()+'Where is your bitcoin full node running?',
|
||||
message: prefix()+'Where is your bitcoin full node running?'+utils._getHelp('bitcoin_mode'),
|
||||
choices: [
|
||||
{
|
||||
name: 'Nowhere! I want cyphernode to run one.',
|
||||
@@ -47,20 +47,20 @@ module.exports = {
|
||||
default: utils._getDefault( 'bitcoin_node_ip' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._ipOrFQDNValidator,
|
||||
message: prefix()+'What is your full node ip address?',
|
||||
message: prefix()+'What is your full node ip address?'+utils._getHelp('bitcoin_node_ip'),
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'bitcoin_rpcuser',
|
||||
default: utils._getDefault( 'bitcoin_rpcuser' ),
|
||||
message: prefix()+'Name of bitcoin rpc user?',
|
||||
message: prefix()+'Name of bitcoin rpc user?'+utils._getHelp('bitcoin_rpcuser'),
|
||||
filter: utils._trimFilter,
|
||||
},
|
||||
{
|
||||
type: 'password',
|
||||
name: 'bitcoin_rpcpassword',
|
||||
default: utils._getDefault( 'bitcoin_rpcpassword' ),
|
||||
message: prefix()+'Password of bitcoin rpc user?',
|
||||
message: prefix()+'Password of bitcoin rpc user?'+utils._getHelp('bitcoin_rpcpassword'),
|
||||
filter: utils._trimFilter,
|
||||
},
|
||||
{
|
||||
@@ -68,14 +68,14 @@ module.exports = {
|
||||
type: 'confirm',
|
||||
name: 'bitcoin_prune',
|
||||
default: utils._getDefault( 'bitcoin_prune' ),
|
||||
message: prefix()+'Run bitcoin node in prune mode?',
|
||||
},
|
||||
message: prefix()+'Run bitcoin node in prune mode?'+utils._getHelp('bitcoin_prune'),
|
||||
}, // TODO: ask for size of prune
|
||||
{
|
||||
when: bitcoinInternal,
|
||||
type: 'input',
|
||||
name: 'bitcoin_uacomment',
|
||||
default: utils._getDefault( 'bitcoin_uacomment' ),
|
||||
message: prefix()+'Any UA comment?',
|
||||
message: prefix()+'Any UA comment?'+utils._getHelp('bitcoin_uacomment'),
|
||||
filter: utils._trimFilter,
|
||||
validate: (input)=> {return utils._optional(input,utils._UACommentValidator) }
|
||||
}];
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = {
|
||||
type: 'list',
|
||||
name: 'lightning_implementation',
|
||||
default: utils._getDefault( 'lightning_implementation' ),
|
||||
message: prefix()+'What lightning implementation do you want to use?',
|
||||
message: prefix()+'What lightning implementation do you want to use?'+utils._getHelp('lightning_implementation'),
|
||||
choices: [
|
||||
{
|
||||
name: 'C-lightning',
|
||||
@@ -51,7 +51,7 @@ module.exports = {
|
||||
default: utils._getDefault( 'lightning_external_ip' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._ipOrFQDNValidator,
|
||||
message: prefix()+'What external ip does your lightning node have?',
|
||||
message: prefix()+'What external ip does your lightning node have?'+utils._getHelp('lightning_external_ip'),
|
||||
},
|
||||
{
|
||||
when: featureCondition,
|
||||
@@ -60,7 +60,7 @@ module.exports = {
|
||||
default: utils._getDefault( 'lightning_nodename' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._notEmptyValidator,
|
||||
message: prefix()+'What name has your lightning node?',
|
||||
message: prefix()+'What name has your lightning node?'+utils._getHelp('lightning_nodename'),
|
||||
},
|
||||
{
|
||||
when: featureCondition,
|
||||
@@ -69,7 +69,7 @@ module.exports = {
|
||||
default: utils._getDefault( 'lightning_nodecolor' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._colorValidator,
|
||||
message: prefix()+'What color has your lightning node?',
|
||||
message: prefix()+'What color has your lightning node?'+utils._getHelp('lightning_nodecolor'),
|
||||
}];
|
||||
},
|
||||
templates: function( props ) {
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = {
|
||||
type: 'list',
|
||||
name: 'electrum_implementation',
|
||||
default: utils._getDefault( 'electrum_implementation' ),
|
||||
message: prefix()+'What electrum implementation do you want to use?',
|
||||
message: prefix()+'What electrum implementation do you want to use?'+utils._getHelp('electrum_implementation'),
|
||||
choices: [
|
||||
{
|
||||
name: 'Electrum personal server',
|
||||
|
||||
@@ -47,7 +47,7 @@ module.exports = {
|
||||
default: utils._getDefault( 'proxy_datapath' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._pathValidator,
|
||||
message: prefix()+'Where to store your proxy db?',
|
||||
message: prefix()+'Where to store your proxy db?'+utils._getHelp('proxy_datapath'),
|
||||
},
|
||||
{
|
||||
when: function(props) { return installerDocker(props) && props.bitcoin_mode === 'internal' },
|
||||
@@ -56,7 +56,7 @@ module.exports = {
|
||||
default: utils._getDefault( 'bitcoin_datapath' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._pathValidator,
|
||||
message: prefix()+'Where is your blockchain data?',
|
||||
message: prefix()+'Where is your blockchain data?'+utils._getHelp('bitcoin_datapath'),
|
||||
},
|
||||
{
|
||||
when: function(props) { return installerDocker(props) && props.features.indexOf('lightning') !== -1 },
|
||||
@@ -65,21 +65,21 @@ module.exports = {
|
||||
default: utils._getDefault( 'lightning_datapath' ),
|
||||
filter: utils._trimFilter,
|
||||
validate: utils._pathValidator,
|
||||
message: prefix()+'Where is your lightning node data?',
|
||||
message: prefix()+'Where is your lightning node data?'+utils._getHelp('lightning_datapath'),
|
||||
},
|
||||
{
|
||||
when: function(props) { return installerDocker(props) && props.bitcoin_mode === 'internal' },
|
||||
type: 'confirm',
|
||||
name: 'bitcoin_expose',
|
||||
default: utils._getDefault( 'bitcoin_expose' ),
|
||||
message: prefix()+'Expose bitcoin full node outside of the docker network?',
|
||||
message: prefix()+'Expose bitcoin full node outside of the docker network?'+utils._getHelp('bitcoin_expose'),
|
||||
},
|
||||
{
|
||||
when: installerDocker,
|
||||
type: 'list',
|
||||
name: 'docker_mode',
|
||||
default: utils._getDefault( 'docker_mode' ),
|
||||
message: prefix()+'What docker mode: docker swarm or docker-compose?',
|
||||
message: prefix()+'What docker mode: docker swarm or docker-compose?'+utils._getHelp('docker_mode'),
|
||||
choices: [{
|
||||
name: "docker swarm",
|
||||
value: "swarm"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"chalk": "^2.1.0",
|
||||
"coinstring": "^2.3.0",
|
||||
"validator": "^10.8.0",
|
||||
"wordwrap": "^1.0.0",
|
||||
"wrap-ansi": "^4.0.0",
|
||||
"yeoman-generator": "^2.0.1"
|
||||
},
|
||||
"repository": "git@github.com:schulterklopfer/cyphernode.git",
|
||||
|
||||
Reference in New Issue
Block a user