using timestamps, skip gen of up-to-date wrappers

This commit is contained in:
F. Eugene Aumson
2018-06-27 21:34:28 -04:00
parent 16dc4e9f66
commit 2276793629
3 changed files with 35 additions and 7 deletions

View File

@@ -1,4 +1,13 @@
[
{
"version": "0.4.1",
"changes": [
{
"note": "skip generation of wrappers that are already up to date",
"pr": 788
}
]
},
{
"version": "0.4.0",
"changes": [

View File

@@ -29,12 +29,11 @@
"dependencies": {
"@0xproject/typescript-typings": "^0.4.1",
"@0xproject/utils": "^0.7.1",
"ethereum-types": "^0.0.2",
"chalk": "^2.3.0",
"ethereum-types": "^0.0.2",
"glob": "^7.1.2",
"handlebars": "^4.0.11",
"lodash": "^4.17.4",
"rimraf": "^2.6.2",
"mkdirp": "^0.5.1",
"to-snake-case": "^1.0.0",
"yargs": "^10.0.3"
@@ -43,7 +42,6 @@
"@0xproject/monorepo-scripts": "^0.2.1",
"@0xproject/tslint-config": "^0.4.20",
"@types/glob": "^5.0.33",
"@types/rimraf": "^2.0.2",
"@types/handlebars": "^4.0.36",
"@types/mkdirp": "^0.5.1",
"@types/node": "^8.0.53",

View File

@@ -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