From a394504e2396bb07733ed9cc2dd6a9b1e4b3050b Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 17 Oct 2018 13:18:33 -0400 Subject: [PATCH] quality improvements for the cmd --- cmd/cmd.js | 28 ++++++++++++++-------------- cmd/cmd_controller.js | 7 ++++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cmd/cmd.js b/cmd/cmd.js index 19c32b47..4ed3be7b 100644 --- a/cmd/cmd.js +++ b/cmd/cmd.js @@ -330,33 +330,33 @@ class Cmd { .option('--framework ', 'UI framework to use. (default: react)') .option('--contract-language ', 'Language used for the smart contract generation (default: solidity)') .option('--overwrite', 'Overwrite existing files. (default: false)') - - .action(function(contract, fields, options){ - if(contract === undefined){ + .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) { + if (contract === undefined) { console.log("contract name is required"); process.exit(0); } - - const fieldMapping = {}; - if(fields.length > 0){ + + let fieldMapping = {}; + if (fields.length > 0) { 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_]*$/; - - fields.forEach(curr => { + fieldMapping = fields.reduce((acc, curr) => { const c = curr.split(':'); - if(!varRegex.test(c[0])){ + if (!varRegex.test(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"); - process.exit(0); + process.exit(1); } - fieldMapping[c[0]] = c[1]; - }); + acc[c[0]] = c[1]; + return acc; + }, {}); } checkDeps(); diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 23d1054f..03c67926 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -494,8 +494,13 @@ class EmbarkController { callback(); }); } - ], function (_err) { + ], function(_err) { 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(); }); }