diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-01 04:38:12 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-01 04:38:12 +0800 |
commit | 89547332eef489a8f258300224cf632dad12fe61 (patch) | |
tree | 5d4bf5d804b8ae2843b0a6c709ff5290d00d6e0f /packages/abi-gen/src | |
parent | ca55cc99edee3697646e2b4f28622f345c290fd7 (diff) | |
parent | 75539bf67537f202bc1075b096fd70f64705867e (diff) | |
download | dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar.gz dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar.bz2 dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar.lz dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar.xz dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.tar.zst dexon-sol-tools-89547332eef489a8f258300224cf632dad12fe61.zip |
Merge branch 'development' into feature/tslint-config/underscore-protected-members
* development:
Updated contract generation in 0x to new abi-gen CLI
Removed deprecated CLI options
Added PR # to the changelog of abi-gen
Added CLI options for explicit specifying location of partials and main template
Diffstat (limited to 'packages/abi-gen/src')
-rw-r--r-- | packages/abi-gen/src/index.ts | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 527af32b1..5412d11ce 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -17,24 +17,43 @@ 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 +64,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 |