mirror of https://github.com/embarklabs/embark.git
fix indentation
This commit is contained in:
parent
9a41e58679
commit
2205a26236
|
@ -1,4 +1,3 @@
|
|||
|
||||
const Handlebars = require('handlebars');
|
||||
const fs = require('../../core/fs');
|
||||
let utils = require('../../utils/utils.js');
|
||||
|
@ -16,15 +15,15 @@ Handlebars.registerHelper('ifview', function(stateMutability, options) {
|
|||
return options.inverse(this);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('ifeq', function(elem, value, options){
|
||||
Handlebars.registerHelper('ifeq', function(elem, value, options) {
|
||||
if (elem === value) {
|
||||
return options.fn(this);
|
||||
}
|
||||
return options.inverse(this);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('ifarr', function(elem, options){
|
||||
if(elem.indexOf('[]') > -1){
|
||||
Handlebars.registerHelper('ifarr', function(elem, options) {
|
||||
if (elem.indexOf('[]') > -1) {
|
||||
return options.fn(this);
|
||||
}
|
||||
return options.inverse(this);
|
||||
|
@ -47,25 +46,25 @@ Handlebars.registerHelper('trim', function(name) {
|
|||
});
|
||||
|
||||
|
||||
Handlebars.registerHelper('methodname', function(abiDefinition, functionName, inputs){
|
||||
Handlebars.registerHelper('methodname', function(abiDefinition, functionName, inputs) {
|
||||
let funCount = abiDefinition.filter(x => x.name === functionName).length;
|
||||
if(funCount === 1){
|
||||
if (funCount === 1) {
|
||||
return '.' + functionName;
|
||||
}
|
||||
return new Handlebars.SafeString(`['${functionName}(${inputs !== null ? inputs.map(input => input.type).join(',') : ''})']`);
|
||||
});
|
||||
|
||||
class ScaffoldingReact {
|
||||
constructor(embark, options){
|
||||
constructor(embark, options) {
|
||||
this.embark = embark;
|
||||
this.options = options;
|
||||
this.embark.registerDappGenerator('react', this.build.bind(this));
|
||||
}
|
||||
|
||||
_generateFile(contract, templateFilename, extension, data, overwrite){
|
||||
_generateFile(contract, templateFilename, extension, data, overwrite) {
|
||||
const filename = contract.className.toLowerCase() + '.' + extension;
|
||||
const filePath = './app/' + filename;
|
||||
if (!overwrite && fs.existsSync(filePath)){
|
||||
if (!overwrite && fs.existsSync(filePath)) {
|
||||
throw new Error("file '" + filePath + "' already exists");
|
||||
}
|
||||
|
||||
|
@ -78,7 +77,7 @@ class ScaffoldingReact {
|
|||
fs.writeFileSync(filePath, result);
|
||||
}
|
||||
|
||||
build(contract, overwrite, cb){
|
||||
build(contract, overwrite, cb) {
|
||||
const packageInstallCmd = 'npm install react react-bootstrap react-dom';
|
||||
utils.runCmd(packageInstallCmd, null, (err) => {
|
||||
if (err) {
|
||||
|
@ -113,7 +112,7 @@ class ScaffoldingReact {
|
|||
this.embark.logger.info('app/' + filename + ".html generated");
|
||||
this.embark.logger.info('app/' + filename + ".js generated");
|
||||
|
||||
} catch(error){
|
||||
} catch (error) {
|
||||
this.embark.logger.error(error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Scaffolding {
|
||||
constructor(engine, _options){
|
||||
constructor(engine, _options) {
|
||||
this.engine = engine;
|
||||
this.options = _options;
|
||||
this.plugins = _options.plugins;
|
||||
|
@ -17,12 +17,12 @@ class Scaffolding {
|
|||
});
|
||||
}
|
||||
|
||||
getScaffoldPlugin(framework){
|
||||
getScaffoldPlugin(framework) {
|
||||
let dappGenerators = this.plugins.getPluginsFor('dappGenerator');
|
||||
let builder;
|
||||
let builder = null;
|
||||
dappGenerators.forEach((plugin) => {
|
||||
plugin.dappGenerators.forEach((d) => {
|
||||
if(d.framework === framework){
|
||||
if (d.framework === framework) {
|
||||
builder = d.cb;
|
||||
}
|
||||
});
|
||||
|
@ -30,8 +30,8 @@ class Scaffolding {
|
|||
return builder;
|
||||
}
|
||||
|
||||
loadFrameworkModule(){
|
||||
switch(this.framework){
|
||||
loadFrameworkModule() {
|
||||
switch (this.framework) {
|
||||
case 'react':
|
||||
this.plugins.loadInternalPlugin('scaffolding-react', this.options);
|
||||
break;
|
||||
|
@ -42,18 +42,18 @@ class Scaffolding {
|
|||
}
|
||||
}
|
||||
|
||||
generate(contractName, overwrite, isContractGeneration, cb){
|
||||
generate(contractName, overwrite, isContractGeneration, cb) {
|
||||
this.loadFrameworkModule();
|
||||
|
||||
const build = this.getScaffoldPlugin(this.framework);
|
||||
if(!build){
|
||||
if (!build) {
|
||||
this.engine.logger.error("Could not find plugin for framework '" + this.framework + "'");
|
||||
process.exit();
|
||||
}
|
||||
|
||||
const hasFields = Object.getOwnPropertyNames(this.fields).length !== 0;
|
||||
|
||||
if(isContractGeneration && !hasFields){
|
||||
if (isContractGeneration && !hasFields) {
|
||||
// This happens when you execute "scaffold ContractName",
|
||||
// assuming the contract already exists in a .sol file
|
||||
cb();
|
||||
|
@ -61,19 +61,19 @@ class Scaffolding {
|
|||
}
|
||||
|
||||
let contract;
|
||||
if(isContractGeneration && hasFields){
|
||||
if (isContractGeneration && hasFields) {
|
||||
contract = {className: contractName, fields: this.fields};
|
||||
try {
|
||||
build(contract, overwrite, cb);
|
||||
} catch(err){
|
||||
} catch (err) {
|
||||
this.engine.logger.error(err.message);
|
||||
}
|
||||
} else {
|
||||
// Contract already exists
|
||||
this.engine.events.request("contracts:list", (_err, contractsList) => {
|
||||
if(_err) throw new Error(_err);
|
||||
if (_err) throw new Error(_err);
|
||||
const contract = contractsList.find(x => x.className === contractName);
|
||||
if(!contract){
|
||||
if (!contract) {
|
||||
this.engine.logger.error("contract '" + contractName + "' does not exist");
|
||||
cb();
|
||||
return;
|
||||
|
@ -81,7 +81,7 @@ class Scaffolding {
|
|||
|
||||
try {
|
||||
build(contract, overwrite, cb);
|
||||
} catch(err){
|
||||
} catch (err) {
|
||||
this.engine.logger.error(err.message);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue