added generation of environment files for later installation step

This commit is contained in:
jash
2018-10-06 18:43:14 +02:00
committed by kexkey
parent 574766095f
commit 5176d867e8
5 changed files with 110 additions and 72 deletions

View File

@@ -1,21 +1,30 @@
const name = 'bitcoin';
const featureCondition = function(props) {
return props.features && props.features.indexOf( 'bitcoin' ) != -1;
return props.features && props.features.indexOf( name ) != -1;
};
module.exports = function( utils ) {
return [{
when: featureCondition,
type: 'confirm',
name: 'bitcoin_prune',
default: utils._getDefault( 'bitcoin_prune' ),
message: 'Run bitcoin node in prune mode?'+'\n',
},
{
when: featureCondition,
type: 'input',
name: 'bitcoin_external_ip',
default: utils._getDefault( 'bitcoin_external_ip' ),
validate: utils._ipValidator,
message: 'What external ip does your bitcoin full node have?'+'\n',
}];
module.exports = {
name: function() {
return name;
},
prompts: function( utils ) {
return [{
when: featureCondition,
type: 'confirm',
name: 'bitcoin_prune',
default: utils._getDefault( 'bitcoin_prune' ),
message: 'Run bitcoin node in prune mode?'+'\n',
},
{
when: featureCondition,
type: 'input',
name: 'bitcoin_external_ip',
default: utils._getDefault( 'bitcoin_external_ip' ),
validate: utils._ipValidator,
message: 'What external ip does your bitcoin full node have?'+'\n',
}];
},
env: function( props ) {
return 'VAR0=VALUE0\nVAR1=VALUE1'
}
};

View File

@@ -1,23 +1,32 @@
const name = 'electrum';
const featureCondition = function(props) {
return props.features && props.features.indexOf( 'electrum' ) != -1;
return props.features && props.features.indexOf( name ) != -1;
}
module.exports = function( utils ) {
return [{
when: featureCondition,
type: 'list',
name: 'electrum_implementation',
default: utils._getDefault( 'electrum_implementation' ),
message: 'What electrum implementation do you want to use?'+'\n',
choices: [
{
name: 'Electrum personal server',
value: 'eps'
},
{
name: 'Electrumx server',
value: 'elx'
}
]
}];
module.exports = {
name: function() {
return name;
},
prompts: function( utils ) {
return [{
when: featureCondition,
type: 'list',
name: 'electrum_implementation',
default: utils._getDefault( 'electrum_implementation' ),
message: 'What electrum implementation do you want to use?'+'\n',
choices: [
{
name: 'Electrum personal server',
value: 'eps'
},
{
name: 'Electrumx server',
value: 'elx'
}
]
}];
},
env: function( props ) {
return 'VAR0=VALUE0\nVAR1=VALUE1'
}
};

View File

@@ -1,23 +1,32 @@
const name = 'lightning';
const featureCondition = function(props) {
return props.features && props.features.indexOf( 'lightning' ) != -1;
return props.features && props.features.indexOf( name ) != -1;
}
module.exports = function( utils ) {
return [{
when: featureCondition,
type: 'list',
name: 'lightning_implementation',
default: utils._getDefault( 'lightning_implementation' ),
message: 'What lightning implementation do you want to use?'+'\n',
choices: [
{
name: 'C-lightning',
value: 'c-lightning'
},
{
name: 'LND',
value: 'lnd'
}
]
}];
module.exports = {
name: function() {
return name;
},
prompts: function( utils ) {
return [{
when: featureCondition,
type: 'list',
name: 'lightning_implementation',
default: utils._getDefault( 'lightning_implementation' ),
message: 'What lightning implementation do you want to use?'+'\n',
choices: [
{
name: 'C-lightning',
value: 'c-lightning'
},
{
name: 'LND',
value: 'lnd'
}
]
}];
},
env: function( props ) {
return 'VAR0=VALUE0\nVAR1=VALUE1'
}
};

View File

@@ -1,7 +1,17 @@
const name = 'opentimestamps';
const featureCondition = function(props) {
return props.features && props.features.indexOf( 'opentimestamps' ) != -1;
return props.features && props.features.indexOf( name ) != -1;
}
module.exports = function( utils ) {
return [];
module.exports = {
name: function() {
return name;
},
prompts: function( utils ) {
return [];
},
env: function( props ) {
return 'VAR0=VALUE0\nVAR1=VALUE1';
}
};

View File

@@ -35,10 +35,17 @@ module.exports = class extends Generator {
const splash = fs.readFileSync(this.templatePath('splash.txt'));
this.log(splash.toString());
var prompts = this._configureFeatures()
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: this.featureChoices
}];
for( let m of featurePromptModules ) {
prompts = prompts.concat(m(this));
prompts = prompts.concat(m.prompts(this));
}
return this.prompt(prompts).then(props => {
@@ -48,6 +55,12 @@ module.exports = class extends Generator {
writing() {
fs.writeFileSync('/data/props.json', JSON.stringify(this.props, null, 2));
for( let m of featurePromptModules ) {
const name = m.name();
const env = m.env();
fs.writeFileSync('/data/'+name+'.sh', env);
}
/*
this.fs.copy(
this.templatePath('dummyfile.txt'),
@@ -60,18 +73,6 @@ module.exports = class extends Generator {
}
/* some utils */
_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: this.featureChoices
}];
}
_isChecked( name, value ) {
return this.props && this.props[name] && this.props[name].indexOf(value) != -1 ;
}