aboutsummaryrefslogtreecommitdiffstats
path: root/packages/abi-gen/src
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-06-28 09:34:28 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-07-09 22:36:41 +0800
commit2276793629292c6ff38ae107c8eac7a7ba2c4b81 (patch)
tree47c075d82f51bf0cc65f36690805f930a6e53183 /packages/abi-gen/src
parent16dc4e9f6606b977ea75a6bd2d444dcf060e1617 (diff)
downloaddexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar.gz
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar.bz2
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar.lz
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar.xz
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.tar.zst
dexon-sol-tools-2276793629292c6ff38ae107c8eac7a7ba2c4b81.zip
using timestamps, skip gen of up-to-date wrappers
Diffstat (limited to 'packages/abi-gen/src')
-rw-r--r--packages/abi-gen/src/index.ts29
1 files changed, 25 insertions, 4 deletions
diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts
index 47f2c404b..f38a162aa 100644
--- a/packages/abi-gen/src/index.ts
+++ b/packages/abi-gen/src/index.ts
@@ -8,7 +8,6 @@ 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');
@@ -71,16 +70,34 @@ function registerPartials(partialsGlob: string): void {
}
}
-function writeOutputFile(name: string, renderedTsCode: string): void {
+function makeOutputFilePath(name: string): string {
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`;
+ return `${args.output}/${fileName}.ts`;
+}
+
+function writeOutputFile(name: string, renderedTsCode: string): void {
+ const filePath = makeOutputFilePath(name);
fs.writeFileSync(filePath, renderedTsCode);
logUtils.log(`Created: ${chalk.bold(filePath)}`);
}
+function isOutputFileUpToDate(abiFile: string, outFile: string): boolean {
+ const abiFileModTimeMs = fs.statSync(abiFile).mtimeMs;
+ try {
+ const outFileModTimeMs = fs.statSync(makeOutputFilePath(outFile)).mtimeMs;
+ return outFileModTimeMs > abiFileModTimeMs;
+ } catch (err) {
+ if (err.code === 'ENOENT') {
+ return false;
+ } else {
+ throw err;
+ }
+ }
+}
+
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 +114,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 +136,11 @@ for (const abiFileName of abiFileNames) {
process.exit(1);
}
+ if (isOutputFileUpToDate(abiFileName, namedContent.name)) {
+ logUtils.log(`Already up to date: ${chalk.bold(makeOutputFilePath(namedContent.name))}`);
+ 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