Installing react packages automatically

This commit is contained in:
Richard Ramos 2018-10-05 16:54:02 -04:00 committed by Pascal Precht
parent deb9c9a838
commit e5e8d21765
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 41 additions and 39 deletions

View File

@ -463,7 +463,6 @@ class EmbarkController {
engine.startService("pipeline");
engine.startService("deployment", {onlyCompile: true});
engine.startService("web3");
engine.startService("codeGenerator");
engine.events.request('deploy:contracts', callback);
}
@ -474,7 +473,6 @@ class EmbarkController {
} else {
let scaffold = new Scaffolding(engine, options);
scaffold.generate(options.contract, options.overwrite);
process.exit();
}
});
}

View File

@ -39,8 +39,10 @@ class Scaffolding {
const contract = contractsList.find(x => x.className === contractName);
try {
build(contract, overwrite);
build(contract, overwrite, () => {
this.engine.logger.info(__("finished generating the UI").underline);
process.exit();
});
} catch(err){
this.engine.logger.error(err.message);
}

View File

@ -1,6 +1,8 @@
const Handlebars = require('handlebars');
const fs = require('../../core/fs');
let utils = require('../../utils/utils.js');
Handlebars.registerHelper('capitalize', function(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
@ -64,7 +66,14 @@ class ScaffoldingReact {
fs.writeFileSync(filePath, result);
}
build(contract, overwrite){
build(contract, overwrite, cb){
const packageInstallCmd = 'npm install react react-bootstrap react-dom';
utils.runCmd(packageInstallCmd, null, (err) => {
if (err) {
this.embark.logger.error(err.message);
process.exit(1);
}
const filename = contract.className.toLowerCase();
this._generateFile(contract, 'index.html.tpl', 'html',
@ -80,7 +89,6 @@ class ScaffoldingReact {
'functions': contract.abiDefinition.filter(x => x.type === 'function')
}, overwrite);
// Update config
const contents = fs.readFileSync("./embark.json");
let embarkJson = JSON.parse(contents);
@ -92,6 +100,8 @@ class ScaffoldingReact {
this.embark.logger.info(filename + ".html generated");
this.embark.logger.info(filename + ".js generated");
cb();
});
}
}

View File

@ -160,14 +160,7 @@ class {{capitalize name}}Form{{@index}} extends Component {
{{/each}}
class {{contractName}}UI extends Component {
constructor (props) {
super(props);
this.state = {
};
}
render(){
function {{contractName}}UI(props) {
return (<div>
<h1>{{title}}</h1>
{{#each functions}}
@ -175,7 +168,6 @@ class {{contractName}}UI extends Component {
{{/each}}
</div>);
}
}
ReactDOM.render(<{{contractName}}UI />, document.getElementById('app'));