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);
this.engine.logger.info(__("finished generating the UI").underline);
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,34 +66,42 @@ class ScaffoldingReact {
fs.writeFileSync(filePath, result);
}
build(contract, overwrite){
const filename = contract.className.toLowerCase();
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);
}
this._generateFile(contract, 'index.html.tpl', 'html',
{
'title': contract.className,
filename
}, overwrite);
const filename = contract.className.toLowerCase();
this._generateFile(contract, 'dapp.js.tpl', 'js',
{
'title': contract.className,
'contractName': contract.className,
'functions': contract.abiDefinition.filter(x => x.type === 'function')
}, overwrite);
// Update config
const contents = fs.readFileSync("./embark.json");
let embarkJson = JSON.parse(contents);
embarkJson.app["js/" + filename + ".js"] = "app/" + filename + '.js';
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
this.embark.logger.info(filename + ".html generated");
this.embark.logger.info(filename + ".js generated");
this._generateFile(contract, 'index.html.tpl', 'html',
{
'title': contract.className,
filename
}, overwrite);
this._generateFile(contract, 'dapp.js.tpl', 'js',
{
'title': contract.className,
'contractName': contract.className,
'functions': contract.abiDefinition.filter(x => x.type === 'function')
}, overwrite);
// Update config
const contents = fs.readFileSync("./embark.json");
let embarkJson = JSON.parse(contents);
embarkJson.app["js/" + filename + ".js"] = "app/" + filename + '.js';
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
this.embark.logger.info(filename + ".html generated");
this.embark.logger.info(filename + ".js generated");
cb();
});
}
}

View File

@ -160,21 +160,13 @@ class {{capitalize name}}Form{{@index}} extends Component {
{{/each}}
class {{contractName}}UI extends Component {
constructor (props) {
super(props);
this.state = {
};
}
render(){
return (<div>
function {{contractName}}UI(props) {
return (<div>
<h1>{{title}}</h1>
{{#each functions}}
<{{capitalize name}}Form{{@index}} />
{{/each}}
</div>);
}
}