mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-17 01:37:26 +00:00
quality improvements for the cmd
This commit is contained in:
parent
2205a26236
commit
a394504e23
28
cmd/cmd.js
28
cmd/cmd.js
@ -330,33 +330,33 @@ class Cmd {
|
|||||||
.option('--framework <framework>', 'UI framework to use. (default: react)')
|
.option('--framework <framework>', 'UI framework to use. (default: react)')
|
||||||
.option('--contract-language <language>', 'Language used for the smart contract generation (default: solidity)')
|
.option('--contract-language <language>', 'Language used for the smart contract generation (default: solidity)')
|
||||||
.option('--overwrite', 'Overwrite existing files. (default: false)')
|
.option('--overwrite', 'Overwrite existing files. (default: false)')
|
||||||
|
.description(__('Generates a contract and a function tester for you\nExample: ContractName field1:uint field2:address --contract-language solidity --framework react'))
|
||||||
.action(function(contract, fields, options){
|
.action(function(contract, fields, options) {
|
||||||
if(contract === undefined){
|
if (contract === undefined) {
|
||||||
console.log("contract name is required");
|
console.log("contract name is required");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldMapping = {};
|
let fieldMapping = {};
|
||||||
if(fields.length > 0){
|
if (fields.length > 0) {
|
||||||
const typeRegex = /^(u?int[0-9]{0,3}(\[\])?|string|bool|address|bytes[0-9]{0,3})(\[\])?$/;
|
const typeRegex = /^(u?int[0-9]{0,3}(\[\])?|string|bool|address|bytes[0-9]{0,3})(\[\])?$/;
|
||||||
const varRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
const varRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
||||||
|
fieldMapping = fields.reduce((acc, curr) => {
|
||||||
fields.forEach(curr => {
|
|
||||||
const c = curr.split(':');
|
const c = curr.split(':');
|
||||||
|
|
||||||
if(!varRegex.test(c[0])){
|
if (!varRegex.test(c[0])) {
|
||||||
console.log("Invalid variable name: " + c[0]);
|
console.log("Invalid variable name: " + c[0]);
|
||||||
process.exit(0);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!typeRegex.test(c[1])){
|
if (!typeRegex.test(c[1])) {
|
||||||
console.log("Invalid datatype: " + c[1] + " - The dApp generator might not support this type at the moment");
|
console.log("Invalid datatype: " + c[1] + " - The dApp generator might not support this type at the moment");
|
||||||
process.exit(0);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldMapping[c[0]] = c[1];
|
acc[c[0]] = c[1];
|
||||||
});
|
return acc;
|
||||||
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDeps();
|
checkDeps();
|
||||||
|
@ -494,8 +494,13 @@ class EmbarkController {
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function (_err) {
|
], function(_err) {
|
||||||
engine.logger.info(__("finished generating the UI").underline);
|
engine.logger.info(__("finished generating the UI").underline);
|
||||||
|
engine.logger.info(__("You can add the UI to your Dapp easily by adding the following in embark.json:"));
|
||||||
|
engine.logger.info((` "js/${options.contract}.js": [\n` +
|
||||||
|
` "${options.contract}.js"\n` +
|
||||||
|
` ],\n` +
|
||||||
|
` "index.html": "app/${options.contract}.html"`).cyan);
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user