@rocketh/export 0.10.11 → 0.10.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.d.ts.map +1 -0
- package/dist/esm/cli.js +31 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/index.d.ts +90 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +114 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +14 -16
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -76
- package/dist/cli.cjs +0 -90
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.mjs +0 -87
- package/dist/cli.mjs.map +0 -1
- package/dist/index.cjs +0 -136
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -376
- package/dist/index.mjs +0 -134
- package/dist/index.mjs.map +0 -1
- package/src/cli.ts +0 -40
- package/src/index.ts +0 -271
- package/tsconfig.json +0 -15
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import {Abi, Address} from 'abitype';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {Deployment, ResolvedConfig, chainTypes, getChain, loadDeployments} from 'rocketh';\n\nexport interface ContractExport {\n\taddress: `0x${string}`;\n\tabi: Abi;\n\targsData?: string;\n\tbytecode?: `0x${string}`;\n\t// linkedData?: any; TODO\n}\n\ntype ChainBlockExplorer = {\n\tname: string;\n\turl: string;\n\tapiUrl?: string | undefined;\n};\ntype ChainContract = {\n\taddress: Address;\n\tblockCreated?: number | undefined;\n};\n\ntype ChainNativeCurrency = {\n\tname: string;\n\t/** 2-6 characters long */\n\tsymbol: string;\n\tdecimals: number;\n};\n\ntype ChainRpcUrls = {\n\thttp: readonly string[];\n\twebSocket?: readonly string[] | undefined;\n};\n\n/**\n * @description Combines members of an intersection into a readable type.\n *\n * @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}\n * @example\n * Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>\n * => { a: string, b: string, c: number, d: bigint }\n */\ntype Prettify<T> = {\n\t[K in keyof T]: T[K];\n} & {};\n\nexport type ChainInfo = {\n\t/** ID in number form */\n\tid: number;\n\t/** Human-readable name */\n\tname: string;\n\t/** Collection of block explorers */\n\tblockExplorers?:\n\t\t| {\n\t\t\t\t[key: string]: ChainBlockExplorer;\n\t\t\t\tdefault: ChainBlockExplorer;\n\t\t }\n\t\t| undefined;\n\t/** Collection of contracts */\n\tcontracts?:\n\t\t| Prettify<\n\t\t\t\t{\n\t\t\t\t\t[key: string]: ChainContract | {[sourceId: number]: ChainContract | undefined} | undefined;\n\t\t\t\t} & {\n\t\t\t\t\tensRegistry?: ChainContract | undefined;\n\t\t\t\t\tensUniversalResolver?: ChainContract | undefined;\n\t\t\t\t\tmulticall3?: ChainContract | undefined;\n\t\t\t\t}\n\t\t >\n\t\t| undefined;\n\t/** Currency used by chain */\n\tnativeCurrency: ChainNativeCurrency;\n\t/** Collection of RPC endpoints */\n\trpcUrls: {\n\t\t[key: string]: ChainRpcUrls;\n\t\tdefault: ChainRpcUrls;\n\t};\n\t/** Source Chain ID (ie. the L1 chain) */\n\tsourceId?: number | undefined;\n\t/** Flag for test networks */\n\ttestnet?: boolean | undefined;\n\n\tchainType: 'zksync' | 'op-stack' | 'celo' | 'default';\n\n\t// this will bring in the following when reconstructed from the data above\n\n\t// /** Custom chain data. */\n\t// custom?: any;\n\n\t// /**\n\t// * Modifies how chain data structures (ie. Blocks, Transactions, etc)\n\t// * are formatted & typed.\n\t// */\n\t// formatters?: any | undefined;\n\t// /** Modifies how data (ie. Transactions) is serialized. */\n\t// serializers?: any | undefined;\n\t// /** Modifies how fees are derived. */\n\t// fees?: any | undefined;\n};\n\nexport type ExportedDeployments = {\n\tchainId: string;\n\tgenesisHash?: string;\n\tchainInfo: ChainInfo;\n\tname: string;\n\tcontracts: {[name: string]: ContractExport};\n};\n\ntype Trandformed<O, Value> = {\n\t[Property in keyof O]: Value;\n};\n\nfunction objectMap<V, N, O extends Trandformed<{}, V> = Trandformed<{}, V>>(\n\tobject: O,\n\tmapFn: (v: V) => N\n): Trandformed<O, N> {\n\treturn Object.keys(object).reduce((result, key) => {\n\t\t(result as any)[key] = mapFn((object as any)[key]);\n\t\treturn result;\n\t}, {} as Trandformed<O, N>);\n}\n\nexport async function run(\n\tconfig: ResolvedConfig,\n\toptions: {\n\t\ttojs?: string[];\n\t\ttots?: string[];\n\t\ttojson?: string[];\n\t\ttotsm?: string[];\n\t\ttojsm?: string[];\n\t\tincludeBytecode?: boolean;\n\t}\n) {\n\tif (!options.tots && !options.tojs && !options.tojson && !options.tojsm && !options.totsm) {\n\t\tconsole.log(`no filepath to export to are specified`);\n\t\treturn;\n\t}\n\n\tconst {deployments, chainId, genesisHash} = loadDeployments(config.deployments, config.network.name);\n\n\tif (!deployments || Object.keys(deployments).length === 0) {\n\t\tconsole.log(`no deployments to export`);\n\t\treturn;\n\t}\n\n\tif (!chainId) {\n\t\tthrow new Error(`no chainId found for ${config.network.name}`);\n\t}\n\n\tconst chain = getChain(chainId);\n\n\tconst chainInfo: ChainInfo = {\n\t\tid: chain.id,\n\t\tname: chain.name,\n\t\tnativeCurrency: chain.nativeCurrency,\n\t\trpcUrls: chain.rpcUrls,\n\t\tblockExplorers: chain.blockExplorers,\n\t\tchainType: chainTypes[chainId] || 'default',\n\t\tcontracts: chain.contracts,\n\t\tsourceId: chain.sourceId,\n\t\ttestnet: chain.testnet,\n\t};\n\n\tconst exportData: ExportedDeployments = {\n\t\tchainId,\n\t\tgenesisHash,\n\t\tchainInfo,\n\t\tcontracts: objectMap<Deployment<Abi>, ContractExport>(deployments, (d) => ({\n\t\t\tabi: d.abi,\n\t\t\taddress: d.address,\n\t\t\tlinkedData: d.linkedData,\n\t\t\tbytecode: options.includeBytecode ? d.bytecode : undefined,\n\t\t\targsData: options.includeBytecode ? d.argsData : undefined,\n\t\t\tstartBlock: d.receipt?.blockNumber ? parseInt(d.receipt.blockNumber.slice(2), 16) : undefined,\n\t\t})),\n\t\tname: config.network.name,\n\t};\n\n\tconst js = typeof options.tojs === 'string' ? [options.tojs] : options.tojs || [];\n\tconst ts = typeof options.tots === 'string' ? [options.tots] : options.tots || [];\n\tconst json = typeof options.tojson === 'string' ? [options.tojson] : options.tojson || [];\n\n\tconst tsmodule = typeof options.totsm === 'string' ? [options.totsm] : options.totsm || [];\n\tconst jsmodule = typeof options.tojsm === 'string' ? [options.tojsm] : options.tojsm || [];\n\n\tif (ts.length > 0) {\n\t\tconst newContent = `export default ${JSON.stringify(exportData, null, 2)} as const;`;\n\t\tfor (const tsFile of ts) {\n\t\t\tconst folderPath = path.dirname(tsFile);\n\t\t\tfs.mkdirSync(folderPath, {recursive: true});\n\t\t\tfs.writeFileSync(tsFile, newContent);\n\t\t}\n\t}\n\n\tif (js.length > 0) {\n\t\tconst newContent = `export default /** @type {const} **/ (${JSON.stringify(exportData, null, 2)});`;\n\t\tconst dtsContent = `export = ${JSON.stringify(exportData, null, 2)} as const;`;\n\t\tfor (const jsFile of js) {\n\t\t\tconst folderPath = path.dirname(jsFile);\n\t\t\tfs.mkdirSync(folderPath, {recursive: true});\n\t\t\tfs.writeFileSync(jsFile, newContent);\n\t\t\tfs.writeFileSync(jsFile.replace('.js', '.d.ts'), dtsContent);\n\t\t}\n\t}\n\n\tif (json.length > 0) {\n\t\tconst newContent = JSON.stringify(exportData, null, 2);\n\t\tfor (const jsonFile of json) {\n\t\t\tconst folderPath = path.dirname(jsonFile);\n\t\t\tfs.mkdirSync(folderPath, {recursive: true});\n\t\t\tfs.writeFileSync(jsonFile, newContent);\n\t\t}\n\t}\n\n\tif (tsmodule.length > 0) {\n\t\tlet newContent = `export const chain = ${JSON.stringify(\n\t\t\t{\n\t\t\t\tchainId: exportData.chainId,\n\t\t\t\tgenesisHash: exportData.genesisHash,\n\t\t\t\tchainInfo: exportData.chainInfo,\n\t\t\t\tname: exportData.name,\n\t\t\t},\n\t\t\tnull,\n\t\t\t2\n\t\t)} as const;\\n`;\n\n\t\tfor (const contractName of Object.keys(exportData.contracts)) {\n\t\t\tnewContent += `export const ${contractName} = ${JSON.stringify(\n\t\t\t\t(exportData.contracts as any)[contractName],\n\t\t\t\tnull,\n\t\t\t\t2\n\t\t\t)} as const;`;\n\t\t}\n\n\t\tfor (const tsFile of tsmodule) {\n\t\t\tconst folderPath = path.dirname(tsFile);\n\t\t\tfs.mkdirSync(folderPath, {recursive: true});\n\t\t\tfs.writeFileSync(tsFile, newContent);\n\t\t}\n\t}\n\n\tif (jsmodule.length > 0) {\n\t\t// TODO test\n\t\tlet newContent = `export const chain = /** @type {const} **/ (${JSON.stringify(\n\t\t\t{\n\t\t\t\tchainId: exportData.chainId,\n\t\t\t\tgenesisHash: exportData.genesisHash,\n\t\t\t\tchainInfo: exportData.chainInfo,\n\t\t\t\tname: exportData.name,\n\t\t\t},\n\t\t\tnull,\n\t\t\t2\n\t\t)});\\n`;\n\n\t\tfor (const contractName of Object.keys(exportData.contracts)) {\n\t\t\tnewContent += `export const ${contractName} = /** @type {const} **/ (${JSON.stringify(\n\t\t\t\t(exportData.contracts as any)[contractName],\n\t\t\t\tnull,\n\t\t\t\t2\n\t\t\t)});`;\n\t\t}\n\n\t\tfor (const jsFile of jsmodule) {\n\t\t\tconst folderPath = path.dirname(jsFile);\n\t\t\tfs.mkdirSync(folderPath, {recursive: true});\n\t\t\tfs.writeFileSync(jsFile, newContent);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;AAIA,SAAS,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE;AAClC,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK;AACrD,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG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,QAAQ,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC;AAC1C,QAAQ,IAAI;AACZ,QAAQ,CAAC;AACT,OAAO,CAAC,EAAE,CAAC,CAAC;AACZ,KAAK;AACL,IAAI,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE;AACnC,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC9C,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC3C,KAAK;AACL,GAAG;AACH;;;;"}
|
package/src/cli.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import {readAndResolveConfig} from 'rocketh';
|
|
3
|
-
import {run} from '.';
|
|
4
|
-
import {Command} from 'commander';
|
|
5
|
-
import pkg from '../package.json';
|
|
6
|
-
import {ConfigOptions} from 'rocketh';
|
|
7
|
-
|
|
8
|
-
const commandName = pkg.name;
|
|
9
|
-
|
|
10
|
-
const program = new Command();
|
|
11
|
-
program
|
|
12
|
-
.name(commandName)
|
|
13
|
-
.description('export deployments to consume elswhere')
|
|
14
|
-
.version(pkg.version)
|
|
15
|
-
.option('-d, --deployments <value>', 'folder where deployments are saved')
|
|
16
|
-
.option('--ts <value>', 'list of filepath where the typescript export will be written, separated by commas')
|
|
17
|
-
.option('--js <value>', 'list of filepath where the javascript export will be written, separated by commas')
|
|
18
|
-
.option('--json <value>', 'list of filepath where the json export will be written, separated by commas')
|
|
19
|
-
.option(
|
|
20
|
-
'--tsm <value>',
|
|
21
|
-
'list of filepath where the typescript export with individual export will be written, separated by commas'
|
|
22
|
-
)
|
|
23
|
-
.option(
|
|
24
|
-
'--jsm <value>',
|
|
25
|
-
'list of filepath where the javascript export with individual exportwill be written, separated by commas'
|
|
26
|
-
)
|
|
27
|
-
.option('-b, --bytecode', 'if set, the bytecode will also be part of the output')
|
|
28
|
-
.requiredOption('-n, --network <value>', 'network context to use')
|
|
29
|
-
.parse(process.argv);
|
|
30
|
-
|
|
31
|
-
const options = program.opts();
|
|
32
|
-
const resolvedConfig = readAndResolveConfig({...(options as ConfigOptions), ignoreMissingRPC: true});
|
|
33
|
-
run(resolvedConfig, {
|
|
34
|
-
tots: options.ts ? options.ts.split(',') : undefined,
|
|
35
|
-
tojson: options.json ? options.json.split(',') : undefined,
|
|
36
|
-
tojs: options.js ? options.js.split(',') : undefined,
|
|
37
|
-
totsm: options.tsm ? options.tsm.split(',') : undefined,
|
|
38
|
-
tojsm: options.jsm ? options.jsm.split(',') : undefined,
|
|
39
|
-
includeBytecode: options.bytecode,
|
|
40
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import {Abi, Address} from 'abitype';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {Deployment, ResolvedConfig, chainTypes, getChain, loadDeployments} from 'rocketh';
|
|
6
|
-
|
|
7
|
-
export interface ContractExport {
|
|
8
|
-
address: `0x${string}`;
|
|
9
|
-
abi: Abi;
|
|
10
|
-
argsData?: string;
|
|
11
|
-
bytecode?: `0x${string}`;
|
|
12
|
-
// linkedData?: any; TODO
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ChainBlockExplorer = {
|
|
16
|
-
name: string;
|
|
17
|
-
url: string;
|
|
18
|
-
apiUrl?: string | undefined;
|
|
19
|
-
};
|
|
20
|
-
type ChainContract = {
|
|
21
|
-
address: Address;
|
|
22
|
-
blockCreated?: number | undefined;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ChainNativeCurrency = {
|
|
26
|
-
name: string;
|
|
27
|
-
/** 2-6 characters long */
|
|
28
|
-
symbol: string;
|
|
29
|
-
decimals: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type ChainRpcUrls = {
|
|
33
|
-
http: readonly string[];
|
|
34
|
-
webSocket?: readonly string[] | undefined;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @description Combines members of an intersection into a readable type.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
|
|
41
|
-
* @example
|
|
42
|
-
* Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
|
|
43
|
-
* => { a: string, b: string, c: number, d: bigint }
|
|
44
|
-
*/
|
|
45
|
-
type Prettify<T> = {
|
|
46
|
-
[K in keyof T]: T[K];
|
|
47
|
-
} & {};
|
|
48
|
-
|
|
49
|
-
export type ChainInfo = {
|
|
50
|
-
/** ID in number form */
|
|
51
|
-
id: number;
|
|
52
|
-
/** Human-readable name */
|
|
53
|
-
name: string;
|
|
54
|
-
/** Collection of block explorers */
|
|
55
|
-
blockExplorers?:
|
|
56
|
-
| {
|
|
57
|
-
[key: string]: ChainBlockExplorer;
|
|
58
|
-
default: ChainBlockExplorer;
|
|
59
|
-
}
|
|
60
|
-
| undefined;
|
|
61
|
-
/** Collection of contracts */
|
|
62
|
-
contracts?:
|
|
63
|
-
| Prettify<
|
|
64
|
-
{
|
|
65
|
-
[key: string]: ChainContract | {[sourceId: number]: ChainContract | undefined} | undefined;
|
|
66
|
-
} & {
|
|
67
|
-
ensRegistry?: ChainContract | undefined;
|
|
68
|
-
ensUniversalResolver?: ChainContract | undefined;
|
|
69
|
-
multicall3?: ChainContract | undefined;
|
|
70
|
-
}
|
|
71
|
-
>
|
|
72
|
-
| undefined;
|
|
73
|
-
/** Currency used by chain */
|
|
74
|
-
nativeCurrency: ChainNativeCurrency;
|
|
75
|
-
/** Collection of RPC endpoints */
|
|
76
|
-
rpcUrls: {
|
|
77
|
-
[key: string]: ChainRpcUrls;
|
|
78
|
-
default: ChainRpcUrls;
|
|
79
|
-
};
|
|
80
|
-
/** Source Chain ID (ie. the L1 chain) */
|
|
81
|
-
sourceId?: number | undefined;
|
|
82
|
-
/** Flag for test networks */
|
|
83
|
-
testnet?: boolean | undefined;
|
|
84
|
-
|
|
85
|
-
chainType: 'zksync' | 'op-stack' | 'celo' | 'default';
|
|
86
|
-
|
|
87
|
-
// this will bring in the following when reconstructed from the data above
|
|
88
|
-
|
|
89
|
-
// /** Custom chain data. */
|
|
90
|
-
// custom?: any;
|
|
91
|
-
|
|
92
|
-
// /**
|
|
93
|
-
// * Modifies how chain data structures (ie. Blocks, Transactions, etc)
|
|
94
|
-
// * are formatted & typed.
|
|
95
|
-
// */
|
|
96
|
-
// formatters?: any | undefined;
|
|
97
|
-
// /** Modifies how data (ie. Transactions) is serialized. */
|
|
98
|
-
// serializers?: any | undefined;
|
|
99
|
-
// /** Modifies how fees are derived. */
|
|
100
|
-
// fees?: any | undefined;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export type ExportedDeployments = {
|
|
104
|
-
chainId: string;
|
|
105
|
-
genesisHash?: string;
|
|
106
|
-
chainInfo: ChainInfo;
|
|
107
|
-
name: string;
|
|
108
|
-
contracts: {[name: string]: ContractExport};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
type Trandformed<O, Value> = {
|
|
112
|
-
[Property in keyof O]: Value;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
function objectMap<V, N, O extends Trandformed<{}, V> = Trandformed<{}, V>>(
|
|
116
|
-
object: O,
|
|
117
|
-
mapFn: (v: V) => N
|
|
118
|
-
): Trandformed<O, N> {
|
|
119
|
-
return Object.keys(object).reduce((result, key) => {
|
|
120
|
-
(result as any)[key] = mapFn((object as any)[key]);
|
|
121
|
-
return result;
|
|
122
|
-
}, {} as Trandformed<O, N>);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function run(
|
|
126
|
-
config: ResolvedConfig,
|
|
127
|
-
options: {
|
|
128
|
-
tojs?: string[];
|
|
129
|
-
tots?: string[];
|
|
130
|
-
tojson?: string[];
|
|
131
|
-
totsm?: string[];
|
|
132
|
-
tojsm?: string[];
|
|
133
|
-
includeBytecode?: boolean;
|
|
134
|
-
}
|
|
135
|
-
) {
|
|
136
|
-
if (!options.tots && !options.tojs && !options.tojson && !options.tojsm && !options.totsm) {
|
|
137
|
-
console.log(`no filepath to export to are specified`);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const {deployments, chainId, genesisHash} = loadDeployments(config.deployments, config.network.name);
|
|
142
|
-
|
|
143
|
-
if (!deployments || Object.keys(deployments).length === 0) {
|
|
144
|
-
console.log(`no deployments to export`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!chainId) {
|
|
149
|
-
throw new Error(`no chainId found for ${config.network.name}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const chain = getChain(chainId);
|
|
153
|
-
|
|
154
|
-
const chainInfo: ChainInfo = {
|
|
155
|
-
id: chain.id,
|
|
156
|
-
name: chain.name,
|
|
157
|
-
nativeCurrency: chain.nativeCurrency,
|
|
158
|
-
rpcUrls: chain.rpcUrls,
|
|
159
|
-
blockExplorers: chain.blockExplorers,
|
|
160
|
-
chainType: chainTypes[chainId] || 'default',
|
|
161
|
-
contracts: chain.contracts,
|
|
162
|
-
sourceId: chain.sourceId,
|
|
163
|
-
testnet: chain.testnet,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const exportData: ExportedDeployments = {
|
|
167
|
-
chainId,
|
|
168
|
-
genesisHash,
|
|
169
|
-
chainInfo,
|
|
170
|
-
contracts: objectMap<Deployment<Abi>, ContractExport>(deployments, (d) => ({
|
|
171
|
-
abi: d.abi,
|
|
172
|
-
address: d.address,
|
|
173
|
-
linkedData: d.linkedData,
|
|
174
|
-
bytecode: options.includeBytecode ? d.bytecode : undefined,
|
|
175
|
-
argsData: options.includeBytecode ? d.argsData : undefined,
|
|
176
|
-
startBlock: d.receipt?.blockNumber ? parseInt(d.receipt.blockNumber.slice(2), 16) : undefined,
|
|
177
|
-
})),
|
|
178
|
-
name: config.network.name,
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const js = typeof options.tojs === 'string' ? [options.tojs] : options.tojs || [];
|
|
182
|
-
const ts = typeof options.tots === 'string' ? [options.tots] : options.tots || [];
|
|
183
|
-
const json = typeof options.tojson === 'string' ? [options.tojson] : options.tojson || [];
|
|
184
|
-
|
|
185
|
-
const tsmodule = typeof options.totsm === 'string' ? [options.totsm] : options.totsm || [];
|
|
186
|
-
const jsmodule = typeof options.tojsm === 'string' ? [options.tojsm] : options.tojsm || [];
|
|
187
|
-
|
|
188
|
-
if (ts.length > 0) {
|
|
189
|
-
const newContent = `export default ${JSON.stringify(exportData, null, 2)} as const;`;
|
|
190
|
-
for (const tsFile of ts) {
|
|
191
|
-
const folderPath = path.dirname(tsFile);
|
|
192
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
193
|
-
fs.writeFileSync(tsFile, newContent);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (js.length > 0) {
|
|
198
|
-
const newContent = `export default /** @type {const} **/ (${JSON.stringify(exportData, null, 2)});`;
|
|
199
|
-
const dtsContent = `export = ${JSON.stringify(exportData, null, 2)} as const;`;
|
|
200
|
-
for (const jsFile of js) {
|
|
201
|
-
const folderPath = path.dirname(jsFile);
|
|
202
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
203
|
-
fs.writeFileSync(jsFile, newContent);
|
|
204
|
-
fs.writeFileSync(jsFile.replace('.js', '.d.ts'), dtsContent);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (json.length > 0) {
|
|
209
|
-
const newContent = JSON.stringify(exportData, null, 2);
|
|
210
|
-
for (const jsonFile of json) {
|
|
211
|
-
const folderPath = path.dirname(jsonFile);
|
|
212
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
213
|
-
fs.writeFileSync(jsonFile, newContent);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (tsmodule.length > 0) {
|
|
218
|
-
let newContent = `export const chain = ${JSON.stringify(
|
|
219
|
-
{
|
|
220
|
-
chainId: exportData.chainId,
|
|
221
|
-
genesisHash: exportData.genesisHash,
|
|
222
|
-
chainInfo: exportData.chainInfo,
|
|
223
|
-
name: exportData.name,
|
|
224
|
-
},
|
|
225
|
-
null,
|
|
226
|
-
2
|
|
227
|
-
)} as const;\n`;
|
|
228
|
-
|
|
229
|
-
for (const contractName of Object.keys(exportData.contracts)) {
|
|
230
|
-
newContent += `export const ${contractName} = ${JSON.stringify(
|
|
231
|
-
(exportData.contracts as any)[contractName],
|
|
232
|
-
null,
|
|
233
|
-
2
|
|
234
|
-
)} as const;`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
for (const tsFile of tsmodule) {
|
|
238
|
-
const folderPath = path.dirname(tsFile);
|
|
239
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
240
|
-
fs.writeFileSync(tsFile, newContent);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (jsmodule.length > 0) {
|
|
245
|
-
// TODO test
|
|
246
|
-
let newContent = `export const chain = /** @type {const} **/ (${JSON.stringify(
|
|
247
|
-
{
|
|
248
|
-
chainId: exportData.chainId,
|
|
249
|
-
genesisHash: exportData.genesisHash,
|
|
250
|
-
chainInfo: exportData.chainInfo,
|
|
251
|
-
name: exportData.name,
|
|
252
|
-
},
|
|
253
|
-
null,
|
|
254
|
-
2
|
|
255
|
-
)});\n`;
|
|
256
|
-
|
|
257
|
-
for (const contractName of Object.keys(exportData.contracts)) {
|
|
258
|
-
newContent += `export const ${contractName} = /** @type {const} **/ (${JSON.stringify(
|
|
259
|
-
(exportData.contracts as any)[contractName],
|
|
260
|
-
null,
|
|
261
|
-
2
|
|
262
|
-
)});`;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
for (const jsFile of jsmodule) {
|
|
266
|
-
const folderPath = path.dirname(jsFile);
|
|
267
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
268
|
-
fs.writeFileSync(jsFile, newContent);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"moduleResolution": "Node",
|
|
4
|
-
"lib": ["ES2020", "dom"],
|
|
5
|
-
"target": "ES2020",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"module": "ES6"
|
|
14
|
-
}
|
|
15
|
-
}
|