diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-05 19:33:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-05 19:33:40 +0800 |
commit | 7b4f2b47de393b7ed6d5c264c8e80864d196180c (patch) | |
tree | 8e86af8000e0aedd7241a00c2189d8f7ca0fc2ad /packages/abi-gen | |
parent | 400a97e7a8f76d894d47368425bbe1e33fa5b255 (diff) | |
parent | c7ad6ebad6ab65a4b1e4a2084e744c6ca2bc09b8 (diff) | |
download | dexon-0x-contracts-7b4f2b47de393b7ed6d5c264c8e80864d196180c.tar.gz dexon-0x-contracts-7b4f2b47de393b7ed6d5c264c8e80864d196180c.tar.zst dexon-0x-contracts-7b4f2b47de393b7ed6d5c264c8e80864d196180c.zip |
Merge branch 'development' into fix/ether_token_address
Diffstat (limited to 'packages/abi-gen')
-rw-r--r-- | packages/abi-gen/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/abi-gen/package.json | 11 | ||||
-rw-r--r-- | packages/abi-gen/src/index.ts | 54 |
3 files changed, 47 insertions, 22 deletions
diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md index fb2c6eb24..ffa8a7a35 100644 --- a/packages/abi-gen/CHANGELOG.md +++ b/packages/abi-gen/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.2.0 - _???_ + +* Added CLI options for explicit specifying location of partials and main template (#346) + ## v0.1.0 - _January 11, 2018_ * Fixed array typings with union types (#295) diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index b43df00fe..e6173e182 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -1,10 +1,11 @@ { "name": "@0xproject/abi-gen", - "version": "0.1.5", + "version": "0.1.6", "description": "Generate contract wrappers from ABI and handlebars templates", "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { + "build:watch": "tsc -w", "lint": "tslint --project . 'src/**/*.ts'", "clean": "shx rm -rf lib", "build": "tsc" @@ -22,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/abi-gen/README.md", "dependencies": { - "@0xproject/utils": "^0.2.3", + "@0xproject/utils": "^0.2.4", "chalk": "^2.3.0", "glob": "^7.1.2", "handlebars": "^4.0.11", @@ -33,7 +34,7 @@ "yargs": "^10.0.3" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.5", + "@0xproject/tslint-config": "^0.4.6", "@types/glob": "^5.0.33", "@types/handlebars": "^4.0.36", "@types/mkdirp": "^0.5.1", @@ -42,7 +43,7 @@ "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", - "typescript": "~2.6.1", - "web3-typescript-typings": "^0.9.7" + "typescript": "2.7.1", + "web3-typescript-typings": "^0.9.8" } } 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 |