Error handling, added overwrite, fixed duplication of components
This commit is contained in:
parent
fe51abc2bb
commit
b93d2d1145
|
@ -328,6 +328,8 @@ class Cmd {
|
|||
program
|
||||
.command('scaffold [contract] [environment]')
|
||||
.option('--framework <framework>', 'UI framework to use. (default: react)')
|
||||
.option('--overwrite', 'Overwrite existing files. (default: false)')
|
||||
|
||||
.action(function(contract, env, options){
|
||||
if(contract === undefined){
|
||||
console.log("contract name is required");
|
||||
|
@ -344,6 +346,8 @@ class Cmd {
|
|||
options.webpackConfigName = options.pipeline || 'development';
|
||||
options.contract = contract;
|
||||
options.framework = options.framework || 'react';
|
||||
options.overwrite = options.overwrite || false;
|
||||
|
||||
embark.scaffold(options);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -494,9 +494,7 @@ class EmbarkController {
|
|||
|
||||
|
||||
let scaffold = new Scaffolding(engine, options);
|
||||
scaffold.generate(options.contract);
|
||||
|
||||
engine.logger.info(__("finished generating the UI").underline);
|
||||
scaffold.generate(options.contract, options.overwrite);
|
||||
callback(err, true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class Scaffolding {
|
|||
return this.engine.config.contractsConfig.contracts[contractName] !== undefined;
|
||||
}
|
||||
|
||||
generate(contractName){
|
||||
generate(contractName, overwrite){
|
||||
if(this.framework === 'react'){
|
||||
this.engine.plugins.loadInternalPlugin('scaffolding-react', this.options);
|
||||
}
|
||||
|
@ -38,7 +38,12 @@ class Scaffolding {
|
|||
if(_err) throw new Error(_err);
|
||||
|
||||
const contract = contractsList.find(x => x.className === contractName);
|
||||
build(contract);
|
||||
try {
|
||||
build(contract, overwrite);
|
||||
this.engine.logger.info(__("finished generating the UI").underline);
|
||||
} catch(err){
|
||||
this.engine.logger.error(err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ class ScaffoldingReact {
|
|||
this.embark.registerDappGenerator('react', this.build.bind(this));
|
||||
}
|
||||
|
||||
_generateFile(contract, templateFilename, extension, data){
|
||||
_generateFile(contract, templateFilename, extension, data, overwrite){
|
||||
const filename = contract.className.toLowerCase() + '.' + extension;
|
||||
const filePath = './app/' + filename;
|
||||
if (fs.existsSync(filePath)){
|
||||
if (!overwrite && fs.existsSync(filePath)){
|
||||
throw new Error("file '" + filePath + "' already exists");
|
||||
}
|
||||
|
||||
|
@ -64,26 +64,22 @@ class ScaffoldingReact {
|
|||
fs.writeFileSync(filePath, result);
|
||||
}
|
||||
|
||||
_buildHTML(contract){
|
||||
build(contract, overwrite){
|
||||
const filename = contract.className.toLowerCase();
|
||||
|
||||
this._generateFile(contract, 'index.html.tpl', 'html',
|
||||
{
|
||||
'title': contract.className,
|
||||
'filename': filename
|
||||
});
|
||||
}
|
||||
|
||||
async build(contract){
|
||||
this._buildHTML(contract);
|
||||
|
||||
const filename = contract.className.toLowerCase();
|
||||
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");
|
||||
|
@ -94,6 +90,8 @@ class ScaffoldingReact {
|
|||
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
|
||||
|
||||
this.embark.logger.info(filename + ".html generated");
|
||||
this.embark.logger.info(filename + ".js generated");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,23 +179,6 @@ class {{contractName}}UI extends React.Component {
|
|||
}
|
||||
|
||||
|
||||
class {{contractName}}UI extends React.Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
};
|
||||
}
|
||||
|
||||
render(){
|
||||
return (<div>
|
||||
{{#each functions}}
|
||||
<{{capitalize name}}_{{@index}}_Form />
|
||||
{{/each}}
|
||||
</div>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReactDOM.render(<div>
|
||||
<h1>{{title}}</h1>
|
||||
<{{contractName}}UI />
|
||||
|
|
Loading…
Reference in New Issue