diff --git a/install/generator-cyphernode/generators/app/features/bitcoin.js b/install/generator-cyphernode/generators/app/features/bitcoin.js index 9ea5e84..1277546 100644 --- a/install/generator-cyphernode/generators/app/features/bitcoin.js +++ b/install/generator-cyphernode/generators/app/features/bitcoin.js @@ -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' + } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/electrum.js b/install/generator-cyphernode/generators/app/features/electrum.js index b8d73f7..137e3df 100644 --- a/install/generator-cyphernode/generators/app/features/electrum.js +++ b/install/generator-cyphernode/generators/app/features/electrum.js @@ -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' + } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/lightning.js b/install/generator-cyphernode/generators/app/features/lightning.js index b6622f2..a695231 100644 --- a/install/generator-cyphernode/generators/app/features/lightning.js +++ b/install/generator-cyphernode/generators/app/features/lightning.js @@ -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' + } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/opentimestamps.js b/install/generator-cyphernode/generators/app/features/opentimestamps.js index 6c0e7e8..789f319 100644 --- a/install/generator-cyphernode/generators/app/features/opentimestamps.js +++ b/install/generator-cyphernode/generators/app/features/opentimestamps.js @@ -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'; + } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/index.js b/install/generator-cyphernode/generators/app/index.js index ff6d82e..b5fe620 100644 --- a/install/generator-cyphernode/generators/app/index.js +++ b/install/generator-cyphernode/generators/app/index.js @@ -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 ; }