aboutsummaryrefslogtreecommitdiffstats
path: root/packages/abi-gen/src/utils.ts
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-07-02 04:05:15 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-07-09 22:45:21 +0800
commita0e3676e3aef4692732375c02c274223b3349f63 (patch)
tree73060cfac9340899492c4d586d2722c9e01781f4 /packages/abi-gen/src/utils.ts
parent2276793629292c6ff38ae107c8eac7a7ba2c4b81 (diff)
downloaddexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar.gz
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar.bz2
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar.lz
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar.xz
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.tar.zst
dexon-sol-tools-a0e3676e3aef4692732375c02c274223b3349f63.zip
move abi-gen funcs from index to utils for testing
preparing for unit testing. purely refactoring (no functionality changed).
Diffstat (limited to 'packages/abi-gen/src/utils.ts')
-rw-r--r--packages/abi-gen/src/utils.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts
index 66390174c..56b996ce3 100644
--- a/packages/abi-gen/src/utils.ts
+++ b/packages/abi-gen/src/utils.ts
@@ -2,6 +2,7 @@ import { AbiType, ConstructorAbi, DataItem } from 'ethereum-types';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
+import toSnakeCase = require('to-snake-case');
import { ContractsBackend, ParamKind } from './types';
@@ -92,4 +93,27 @@ export const utils = {
inputs: [],
};
},
+ makeOutputFileName(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');
+ return fileName;
+ },
+ writeOutputFile(filePath: string, renderedTsCode: string): void {
+ fs.writeFileSync(filePath, renderedTsCode);
+ },
+ isOutputFileUpToDate(abiFile: string, outputFile: string): boolean {
+ const abiFileModTimeMs = fs.statSync(abiFile).mtimeMs;
+ try {
+ const outFileModTimeMs = fs.statSync(outputFile).mtimeMs;
+ return outFileModTimeMs > abiFileModTimeMs;
+ } catch (err) {
+ if (err.code === 'ENOENT') {
+ return false;
+ } else {
+ throw err;
+ }
+ }
+ },
};