mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-02-07 13:34:20 +01:00
some cleanup and validation tests
This commit is contained in:
@@ -3,6 +3,7 @@ const Generator = require('yeoman-generator');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const wrap = require('wordwrap')(86);
|
||||
const validator = require('validator');
|
||||
|
||||
module.exports = class extends Generator {
|
||||
|
||||
@@ -10,89 +11,134 @@ module.exports = class extends Generator {
|
||||
super(args, opts);
|
||||
|
||||
this.props = {
|
||||
name: 'supercollider-project',
|
||||
type: 'simple',
|
||||
description: ''
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
prompting() {
|
||||
/* values */
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'someAnswer',
|
||||
message: 'Would you like to enable this option?',
|
||||
default: true
|
||||
}
|
||||
];
|
||||
|
||||
return this.prompt(prompts).then(props => {
|
||||
// To access props later use this.props.someAnswer;
|
||||
this.props = props;
|
||||
});
|
||||
_isChecked( name, value ) {
|
||||
return value=='bitcoin';
|
||||
}
|
||||
|
||||
_getConfirmDefault( name ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_getListDefault( name ) {
|
||||
return 'lnd';
|
||||
}
|
||||
|
||||
_getInputDefault( name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/* validators */
|
||||
_ipValidator( ip ) {
|
||||
return validator.isIP((ip+"").trim());
|
||||
}
|
||||
|
||||
/* filters */
|
||||
|
||||
_trimFilter( input ) {
|
||||
return input.trim();
|
||||
}
|
||||
|
||||
/* prompts */
|
||||
_configureFeatures() {
|
||||
return [{
|
||||
// https://github.com/SBoudrias/Inquirer.js#question
|
||||
// input, confirm, list, rawlist, expand, checkbox, password, editor
|
||||
type: 'checkbox',
|
||||
name: 'features',
|
||||
message: wrap('What features do you want to add to your cyphernode?')+'\n',
|
||||
choices: [
|
||||
{
|
||||
name: 'Bitcoin full node',
|
||||
value: 'bitcoin',
|
||||
checked: this._isChecked( 'features', 'bitcoin' )
|
||||
},
|
||||
{
|
||||
name: 'Lightning node',
|
||||
value: 'lightning',
|
||||
checked: this._isChecked( 'features', 'lightning' )
|
||||
|
||||
},
|
||||
{
|
||||
name: 'Open timestamps server',
|
||||
value: 'ots',
|
||||
checked: this._isChecked( 'features', 'ots' )
|
||||
}
|
||||
|
||||
]
|
||||
}];
|
||||
}
|
||||
|
||||
_configureBitcoinFullNode() {
|
||||
return [{
|
||||
when: function(answers) {
|
||||
return answers.features &&
|
||||
answers.features.indexOf( 'bitcoin' ) != -1;
|
||||
},
|
||||
type: 'confirm',
|
||||
name: 'bitcoin_prune',
|
||||
default: this._getConfirmDefault( 'bitcoin_prune' ),
|
||||
message: wrap('Run bitcoin node in prune mode?')+'\n',
|
||||
},
|
||||
{
|
||||
when: function(answers) {
|
||||
return answers.features &&
|
||||
answers.features.indexOf( 'bitcoin' ) != -1;
|
||||
},
|
||||
type: 'input',
|
||||
name: 'bitcoin_external_ip',
|
||||
default: this._getInputDefault( 'bitcoin_external_ip' ),
|
||||
validate: this._ipValidator,
|
||||
message: wrap('What external ip does your bitcoin full node have?')+'\n',
|
||||
}];
|
||||
}
|
||||
|
||||
_configureLightningImplementation() {
|
||||
return [{
|
||||
when: function(answers) {
|
||||
return answers.features &&
|
||||
answers.features.indexOf( 'lightning' ) != -1;
|
||||
},
|
||||
type: 'list',
|
||||
name: 'lightning_implementation',
|
||||
default: this._getListDefault( 'lightning_implementation' ),
|
||||
message: wrap('What lightning implementation do you want to use?')+'\n',
|
||||
choices: [
|
||||
{
|
||||
name: 'C-lightning',
|
||||
value: 'c-lightning'
|
||||
},
|
||||
{
|
||||
name: 'LND',
|
||||
value: 'lnd'
|
||||
}
|
||||
]
|
||||
}];
|
||||
}
|
||||
|
||||
_configureCLightning() {
|
||||
return [{}];
|
||||
}
|
||||
|
||||
_configureLND() {
|
||||
return [{}];
|
||||
}
|
||||
*/
|
||||
|
||||
// fountainPrompting() {
|
||||
prompting() {
|
||||
const splash = fs.readFileSync(this.templatePath('splash.txt'));
|
||||
this.log(splash.toString());
|
||||
|
||||
var prompts = [
|
||||
{
|
||||
// https://github.com/SBoudrias/Inquirer.js#question
|
||||
// input, confirm, list, rawlist, expand, checkbox, password, editor
|
||||
type: 'checkbox',
|
||||
name: 'features',
|
||||
message: wrap('What features do you want to add to your cyphernode?')+'\n',
|
||||
choices: [
|
||||
{
|
||||
name: 'Bitcoin full node',
|
||||
value: 'bitcoin'
|
||||
},
|
||||
{
|
||||
name: 'Lightning node',
|
||||
value: 'lightning'
|
||||
},
|
||||
{
|
||||
name: 'Open timestamps server',
|
||||
value: 'ots'
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
when: function(answers) {
|
||||
return answers.features &&
|
||||
answers.features.indexOf( 'bitcoin' ) != -1;
|
||||
},
|
||||
type: 'confirm',
|
||||
default: false,
|
||||
name: 'lightning_implementation',
|
||||
message: wrap('Run bitcoin node in prune mode?')+'\n',
|
||||
},
|
||||
{
|
||||
when: function(answers) {
|
||||
return answers.features &&
|
||||
answers.features.indexOf( 'lightning' ) != -1;
|
||||
},
|
||||
type: 'list',
|
||||
name: 'lightning_implementation',
|
||||
message: wrap('What lightning implementation do you want to use?')+'\n',
|
||||
choices: [
|
||||
{
|
||||
name: 'C-lightning',
|
||||
value: 'c-lightning'
|
||||
},
|
||||
{
|
||||
name: 'LND',
|
||||
value: 'lnd'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
var prompts =
|
||||
this._configureFeatures()
|
||||
.concat(this._configureBitcoinFullNode())
|
||||
.concat(this._configureLightningImplementation())
|
||||
//.concat(this._configureCLightning())
|
||||
//.concat(this._configureLND())
|
||||
|
||||
return this.prompt(prompts).then(props => {
|
||||
this.props = Object.assign(this.props, props);
|
||||
@@ -100,6 +146,7 @@ module.exports = class extends Generator {
|
||||
}
|
||||
|
||||
writing() {
|
||||
console.log( JSON.stringify(this.props, null, 2));
|
||||
/*
|
||||
this.fs.copy(
|
||||
this.templatePath('dummyfile.txt'),
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.1.0",
|
||||
"validator": "^10.8.0",
|
||||
"wordwrap": "^1.0.0",
|
||||
"yeoman-generator": "^2.0.1"
|
||||
},
|
||||
|
||||
@@ -9,10 +9,8 @@
|
||||
|
||||
cyphernodeconf_configure() {
|
||||
local current_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
local data_path=$current_path/../data
|
||||
local docker_image="cyphernodeconf:latest"
|
||||
|
||||
docker run -v $data_path:/data \
|
||||
docker run -v $current_path/../data:/data \
|
||||
--log-driver=none\
|
||||
--rm -it $docker_image
|
||||
--rm -it cyphernodeconf:latest
|
||||
}
|
||||
@@ -24,3 +24,5 @@ build_docker_image ../ cyphernodeconf && clear && echo "Thinking..."
|
||||
|
||||
# configure features of cyphernode
|
||||
cyphernodeconf_configure
|
||||
|
||||
#docker image rm cyphernodeconf:latest
|
||||
|
||||
Reference in New Issue
Block a user