diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-07-12 17:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 17:53:21 +0800 |
commit | 34a903516439ec64073cfcb10cee87a9c4db902e (patch) | |
tree | 44f8a25ecfd3d860ffb9dc05f7494593744b1a0e /packages/abi-gen/src/index.ts | |
parent | b82fdd59e70e92ef139f5eeed8ed383a89866c7d (diff) | |
parent | 4b60a3cbab3a97125499cb89d9c253deebfb7d2d (diff) | |
download | dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.gz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.bz2 dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.lz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.xz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.zst dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.zip |
Merge pull request #788 from feuGeneA/abi-gen-ignore-unchanged
Using timestamps, skip generation of already-up-to-date contract wrappers
Diffstat (limited to 'packages/abi-gen/src/index.ts')
-rw-r--r-- | packages/abi-gen/src/index.ts | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 47f2c404b..753bb2cce 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -3,16 +3,12 @@ import { abiUtils, logUtils } from '@0xproject/utils'; import chalk from 'chalk'; import { AbiDefinition, ConstructorAbi, EventAbi, MethodAbi } from 'ethereum-types'; -import * as fs from 'fs'; import { sync as globSync } from 'glob'; import * as Handlebars from 'handlebars'; import * as _ from 'lodash'; import * as mkdirp from 'mkdirp'; -import * as rimraf from 'rimraf'; import * as yargs from 'yargs'; -import toSnakeCase = require('to-snake-case'); - import { ContextData, ContractsBackend, ParamKind } from './types'; import { utils } from './utils'; @@ -71,16 +67,6 @@ function registerPartials(partialsGlob: string): void { } } -function writeOutputFile(name: string, renderedTsCode: string): void { - let fileName = toSnakeCase(name); - // HACK: Snake case doesn't make a lot of sense for abbreviated names but we can't reliably detect abbreviations - // so we special-case the abbreviations we use. - fileName = fileName.replace('z_r_x', 'zrx').replace('e_r_c', 'erc'); - const filePath = `${args.output}/${fileName}.ts`; - fs.writeFileSync(filePath, renderedTsCode); - logUtils.log(`Created: ${chalk.bold(filePath)}`); -} - Handlebars.registerHelper('parameterType', utils.solTypeToTsType.bind(utils, ParamKind.Input, args.backend)); Handlebars.registerHelper('returnType', utils.solTypeToTsType.bind(utils, ParamKind.Output, args.backend)); if (args.partials) { @@ -97,7 +83,6 @@ if (_.isEmpty(abiFileNames)) { process.exit(1); } else { logUtils.log(`Found ${chalk.green(`${abiFileNames.length}`)} ${chalk.bold('ABI')} files`); - rimraf.sync(args.output); mkdirp.sync(args.output); } for (const abiFileName of abiFileNames) { @@ -120,6 +105,14 @@ for (const abiFileName of abiFileNames) { process.exit(1); } + const outFileName = utils.makeOutputFileName(namedContent.name); + const outFilePath = `${args.output}/${outFileName}.ts`; + + if (utils.isOutputFileUpToDate(abiFileName, outFilePath)) { + logUtils.log(`Aready up to date: ${chalk.bold(outFilePath)}`); + continue; + } + let ctor = ABI.find((abi: AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as ConstructorAbi; if (_.isUndefined(ctor)) { ctor = utils.getEmptyConstructor(); // The constructor exists, but it's implicit in JSON's ABI definition @@ -154,5 +147,6 @@ for (const abiFileName of abiFileNames) { events: eventAbis, }; const renderedTsCode = template(contextData); - writeOutputFile(namedContent.name, renderedTsCode); + utils.writeOutputFile(outFilePath, renderedTsCode); + logUtils.log(`Created: ${chalk.bold(outFilePath)}`); } |