-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathupdate-python-abis.js
More file actions
26 lines (23 loc) · 947 Bytes
/
update-python-abis.js
File metadata and controls
26 lines (23 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const glob = require('glob');
const path = require('path');
// eslint-disable-next-line node/no-extraneous-require
const { readFileSync, outputFile } = require('fs-extra');
const globPattern = 'packages/cardpay-sdk/contracts/abi/latest/*.ts';
const pythonPackages = ['cardpay-reward-api', 'cardpay-reward-scheduler', 'reward-root-submitter'];
glob(globPattern, {}, (err, files) => {
if (err) {
throw new Error(err);
}
files.map((file) => {
const typescriptModuleContents = readFileSync(file).toString();
const contractAbi = typescriptModuleContents
.replace('export default ', '')
.replace('function noop() {};', '')
.replace('noop();', '');
const jsonAbi = JSON.stringify(eval(contractAbi), null, 2);
let fileName = path.basename(file, '.ts') + '.json';
pythonPackages.map((pythonPackage) => {
outputFile(path.join('packages', pythonPackage, 'abis', fileName), jsonAbi);
});
});
});