diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-01 07:30:09 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-01 07:30:09 +0800 |
commit | 03cb7233dc5b8556952b4481f87a292e0fca1acf (patch) | |
tree | 4c203211a7ce7b0f44ebc45bb6c40621d4ee5b7e /packages/abi-gen/src/index.ts | |
parent | 3a1ca32ff172f735e4b69f125fea4237c83643f0 (diff) | |
parent | 6682abf89dcdf566f05f8d88cb6af06c4bb1f6a2 (diff) | |
download | dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar.gz dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar.bz2 dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar.lz dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar.xz dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.tar.zst dexon-sol-tools-03cb7233dc5b8556952b4481f87a292e0fca1acf.zip |
Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development: (49 commits)
Prettier
Updated contract generation in 0x to new abi-gen CLI
Add PR number to changelog
Fix lint errors
Removed deprecated CLI options
Add protected keyword to underscore lint rule
Remove unused prop
Fix prettier
Uppercase Networks enum values
Make default gasPrice more readable
Fix prettier mess
Fix linter errors
Shrink img
Fix all setState calls after unmounted errors. Decided to create our own flag rather then using a cancellablePromise since there was little to be gained from this alternative
Fix bug where we were return undefined instead of the empty object
Default the derivation path to that found in the Ledger subprovider
Add browser data to dialog info
Add Rinkeby support
Pass in whether we want the personal message prefix appended and never append it for Ledger. This fixes signing when Ledger is used and the backing node is not Parity
Wholesale replace the tokenByAddress and de-dup properly
...
Diffstat (limited to 'packages/abi-gen/src/index.ts')
-rw-r--r-- | packages/abi-gen/src/index.ts | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 527af32b1..fe2b56524 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -17,24 +17,45 @@ import { utils } from './utils'; const ABI_TYPE_CONSTRUCTOR = 'constructor'; const ABI_TYPE_METHOD = 'function'; const ABI_TYPE_EVENT = 'event'; -const MAIN_TEMPLATE_NAME = 'contract.mustache'; const args = yargs - .option('abiGlob', { + .option('abis', { describe: 'Glob pattern to search for ABI JSON files', type: 'string', - demand: true, - }) - .option('templates', { - describe: 'Folder where to search for templates', - type: 'string', - demand: true, + demandOption: true, }) .option('output', { + alias: ['o', 'out'], describe: 'Folder where to put the output files', type: 'string', - demand: true, - }).argv; + normalize: true, + demandOption: true, + }) + .option('partials', { + describe: 'Glob pattern for the partial template files', + type: 'string', + implies: 'template', + }) + .option('template', { + describe: 'Path for the main template file that will be used to generate each contract', + type: 'string', + demandOption: true, + normalize: true, + }) + .example( + "$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'", + 'Full usage example', + ).argv; + +function registerPartials(partialsGlob: string) { + const partialTemplateFileNames = globSync(partialsGlob); + utils.log(`Found ${chalk.green(`${partialTemplateFileNames.length}`)} ${chalk.bold('partial')} templates`); + for (const partialTemplateFileName of partialTemplateFileNames) { + const namedContent = utils.getNamedContent(partialTemplateFileName); + Handlebars.registerPartial(namedContent.name, namedContent.content); + } + return partialsGlob; +} function writeOutputFile(name: string, renderedTsCode: string): void { const fileName = toSnakeCase(name); @@ -45,15 +66,14 @@ function writeOutputFile(name: string, renderedTsCode: string): void { Handlebars.registerHelper('parameterType', utils.solTypeToTsType.bind(utils, ParamKind.Input)); Handlebars.registerHelper('returnType', utils.solTypeToTsType.bind(utils, ParamKind.Output)); -const partialTemplateFileNames = globSync(`${args.templates}/partials/**/*.mustache`); -for (const partialTemplateFileName of partialTemplateFileNames) { - const namedContent = utils.getNamedContent(partialTemplateFileName); - Handlebars.registerPartial(namedContent.name, namedContent.content); -} -const mainTemplate = utils.getNamedContent(`${args.templates}/${MAIN_TEMPLATE_NAME}`); +if (args.partials) { + registerPartials(args.partials); +} +const mainTemplate = utils.getNamedContent(args.template); const template = Handlebars.compile<ContextData>(mainTemplate.content); -const abiFileNames = globSync(args.abiGlob); +const abiFileNames = globSync(args.abis); + if (_.isEmpty(abiFileNames)) { utils.log(`${chalk.red(`No ABI files found.`)}`); utils.log(`Please make sure you've passed the correct folder name and that the files have |