diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 1f7a789c4..4ab2ce088 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -431,80 +431,51 @@ class EmbarkController { } scaffold(options) { - this.context = options.context || [constants.contexts.build]; + + this.context = options.context || [constants.contexts.scaffold]; + options.onlyCompile = true; const Scaffolding = require('../lib/cmds/scaffolding.js'); - const Engine = require('../lib/core/engine.js'); + const engine = new Engine({ env: options.env, - client: options.client, - locale: options.locale, version: this.version, - embarkConfig: 'embark.json', - interceptLogs: false, + embarkConfig: options.embarkConfig || 'embark.json', logFile: options.logFile, - logLevel: options.logLevel, - events: options.events, - logger: options.logger, - config: options.config, - plugins: options.plugins, - context: this.context, - webpackConfigName: options.webpackConfigName + context: this.context }); async.waterfall([ - function initEngine(callback) { + function (callback) { engine.init({}, callback); }, - function startServices(callback) { + function (callback) { let pluginList = engine.plugins.listPlugins(); if (pluginList.length > 0) { engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); } engine.startService("processManager"); + engine.startService("serviceMonitor"); engine.startService("libraryManager"); - engine.startService("codeRunner"); + engine.startService("pipeline"); + engine.startService("deployment", {onlyCompile: true}); engine.startService("web3"); - if (!options.onlyCompile) { - engine.startService("pipeline"); - } - engine.startService("deployment", {onlyCompile: options.onlyCompile}); - if (!options.onlyCompile) { - engine.startService("storage"); - engine.startService("codeGenerator"); - } + engine.startService("codeGenerator"); - callback(); - }, - function deploy(callback) { - engine.events.request('deploy:contracts', function (err) { - callback(err); - }); - }, - function waitForWriteFinish(callback) { - if (options.onlyCompile) { - engine.logger.info("Finished compiling".underline); - return callback(null, true); - } - - engine.events.on('outputDone', (err) => { - - - let scaffold = new Scaffolding(engine, options); - scaffold.generate(options.contract, options.overwrite); - callback(err, true); - }); + engine.events.request('deploy:contracts', callback); } - ], function (_err, canExit) { - // TODO: this should be moved out and determined somewhere else - if (canExit || !engine.config.contractsConfig.afterDeploy || !engine.config.contractsConfig.afterDeploy.length) { + ], (err) => { + if (err) { + engine.logger.error(err.message); + engine.logger.info(err.stack); + } else { + let scaffold = new Scaffolding(engine, options); + scaffold.generate(options.contract, options.overwrite); process.exit(); } - engine.logger.info(__('Waiting for after deploy to finish...')); - engine.logger.info(__('You can exit with CTRL+C when after deploy completes')); }); } diff --git a/lib/modules/scaffolding-react/templates/dapp.js.tpl b/lib/modules/scaffolding-react/templates/dapp.js.tpl index c02bba74b..ff9fcd2d2 100644 --- a/lib/modules/scaffolding-react/templates/dapp.js.tpl +++ b/lib/modules/scaffolding-react/templates/dapp.js.tpl @@ -30,22 +30,27 @@ class {{capitalize name}}Form{{@index}} extends Component { } handleChange(e, name){ - this.state.input[name] = e.target.value; - this.setState(this.state); + const {input} = this.state; + input[name] = e.target.value; + this.setState({input}); } handleCheckbox(e, name){ - this.state.input[name] = e.target.checked; - this.setState(this.state); + const {input} = this.state; + input[name] = e.target.checked; + this.setState({input}); } async handleClick(e){ e.preventDefault(); + + const {input, value} = this.state; + this.setState({output: null, error: null, receipt: null}); - + try { {{#ifview stateMutability}} - const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call() + const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call() {{#iflengthgt outputs 1}} this.setState({output: { {{#each outputs}} @@ -56,13 +61,13 @@ class {{capitalize name}}Form{{@index}} extends Component { this.setState({output: result}); {{/iflengthgt}} {{else}} - const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}); + const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}); const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount}); const receipt = await toSend.send({ {{#if payable}} - value: this.state.value, + value: value, {{/if}} from: web3.eth.defaultAccount, gasLimit: estimatedGas @@ -158,7 +163,7 @@ class {{capitalize name}}Form{{@index}} extends Component { class {{contractName}}UI extends Component { constructor (props) { super(props); - this.state = { + this.state = { }; }