mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-27 05:56:21 +00:00
Installing react packages automatically
This commit is contained in:
parent
deb9c9a838
commit
e5e8d21765
@ -463,7 +463,6 @@ class EmbarkController {
|
|||||||
engine.startService("pipeline");
|
engine.startService("pipeline");
|
||||||
engine.startService("deployment", {onlyCompile: true});
|
engine.startService("deployment", {onlyCompile: true});
|
||||||
engine.startService("web3");
|
engine.startService("web3");
|
||||||
engine.startService("codeGenerator");
|
|
||||||
|
|
||||||
engine.events.request('deploy:contracts', callback);
|
engine.events.request('deploy:contracts', callback);
|
||||||
}
|
}
|
||||||
@ -474,7 +473,6 @@ class EmbarkController {
|
|||||||
} else {
|
} else {
|
||||||
let scaffold = new Scaffolding(engine, options);
|
let scaffold = new Scaffolding(engine, options);
|
||||||
scaffold.generate(options.contract, options.overwrite);
|
scaffold.generate(options.contract, options.overwrite);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,10 @@ class Scaffolding {
|
|||||||
|
|
||||||
const contract = contractsList.find(x => x.className === contractName);
|
const contract = contractsList.find(x => x.className === contractName);
|
||||||
try {
|
try {
|
||||||
build(contract, overwrite);
|
build(contract, overwrite, () => {
|
||||||
this.engine.logger.info(__("finished generating the UI").underline);
|
this.engine.logger.info(__("finished generating the UI").underline);
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
} catch(err){
|
} catch(err){
|
||||||
this.engine.logger.error(err.message);
|
this.engine.logger.error(err.message);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const fs = require('../../core/fs');
|
const fs = require('../../core/fs');
|
||||||
|
let utils = require('../../utils/utils.js');
|
||||||
|
|
||||||
|
|
||||||
Handlebars.registerHelper('capitalize', function(word) {
|
Handlebars.registerHelper('capitalize', function(word) {
|
||||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
@ -64,34 +66,42 @@ class ScaffoldingReact {
|
|||||||
fs.writeFileSync(filePath, result);
|
fs.writeFileSync(filePath, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
build(contract, overwrite){
|
build(contract, overwrite, cb){
|
||||||
const filename = contract.className.toLowerCase();
|
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',
|
const filename = contract.className.toLowerCase();
|
||||||
{
|
|
||||||
'title': contract.className,
|
|
||||||
filename
|
|
||||||
}, overwrite);
|
|
||||||
|
|
||||||
this._generateFile(contract, 'dapp.js.tpl', 'js',
|
this._generateFile(contract, 'index.html.tpl', 'html',
|
||||||
{
|
{
|
||||||
'title': contract.className,
|
'title': contract.className,
|
||||||
'contractName': contract.className,
|
filename
|
||||||
'functions': contract.abiDefinition.filter(x => x.type === 'function')
|
}, overwrite);
|
||||||
}, overwrite);
|
|
||||||
|
this._generateFile(contract, 'dapp.js.tpl', 'js',
|
||||||
|
{
|
||||||
// Update config
|
'title': contract.className,
|
||||||
const contents = fs.readFileSync("./embark.json");
|
'contractName': contract.className,
|
||||||
let embarkJson = JSON.parse(contents);
|
'functions': contract.abiDefinition.filter(x => x.type === 'function')
|
||||||
embarkJson.app["js/" + filename + ".js"] = "app/" + filename + '.js';
|
}, overwrite);
|
||||||
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
|
|
||||||
|
// Update config
|
||||||
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
|
const contents = fs.readFileSync("./embark.json");
|
||||||
|
let embarkJson = JSON.parse(contents);
|
||||||
this.embark.logger.info(filename + ".html generated");
|
embarkJson.app["js/" + filename + ".js"] = "app/" + filename + '.js';
|
||||||
this.embark.logger.info(filename + ".js generated");
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,21 +160,13 @@ class {{capitalize name}}Form{{@index}} extends Component {
|
|||||||
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
class {{contractName}}UI extends Component {
|
function {{contractName}}UI(props) {
|
||||||
constructor (props) {
|
return (<div>
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
render(){
|
|
||||||
return (<div>
|
|
||||||
<h1>{{title}}</h1>
|
<h1>{{title}}</h1>
|
||||||
{{#each functions}}
|
{{#each functions}}
|
||||||
<{{capitalize name}}Form{{@index}} />
|
<{{capitalize name}}Form{{@index}} />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>);
|
</div>);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user