rocketh 0.4.41 → 0.5.1

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/cli.cjs ADDED
@@ -0,0 +1,697 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var import_ldenv = require("ldenv");
28
+
29
+ // src/utils/fs.ts
30
+ var import_node_fs = __toESM(require("fs"), 1);
31
+ var import_node_path = __toESM(require("path"), 1);
32
+ function traverseMultipleDirectory(dirs) {
33
+ const filepaths = [];
34
+ for (const dir of dirs) {
35
+ let filesStats = traverse(dir);
36
+ filesStats = filesStats.filter((v) => !v.directory);
37
+ for (const filestat of filesStats) {
38
+ filepaths.push(import_node_path.default.join(dir, filestat.relativePath));
39
+ }
40
+ }
41
+ return filepaths;
42
+ }
43
+ var traverse = function(dir, result = [], topDir, filter) {
44
+ import_node_fs.default.readdirSync(dir).forEach((name) => {
45
+ const fPath = import_node_path.default.resolve(dir, name);
46
+ const stats = import_node_fs.default.statSync(fPath);
47
+ if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
48
+ const fileStats = {
49
+ name,
50
+ path: fPath,
51
+ relativePath: import_node_path.default.relative(topDir || dir, fPath),
52
+ mtimeMs: stats.mtimeMs,
53
+ directory: stats.isDirectory()
54
+ };
55
+ if (fileStats.directory) {
56
+ result.push(fileStats);
57
+ return traverse(fPath, result, topDir || dir, filter);
58
+ }
59
+ result.push(fileStats);
60
+ }
61
+ });
62
+ return result;
63
+ };
64
+
65
+ // src/executor/index.ts
66
+ var import_node_path4 = __toESM(require("path"), 1);
67
+ var import_node_fs4 = __toESM(require("fs"), 1);
68
+
69
+ // src/environment/index.ts
70
+ var import_node_fs3 = __toESM(require("fs"), 1);
71
+ var import_viem = require("viem");
72
+ var import_eip_1193_json_provider = require("eip-1193-json-provider");
73
+ var import_node_path3 = __toESM(require("path"), 1);
74
+
75
+ // src/utils/json.ts
76
+ function bnReplacer(k, v) {
77
+ if (typeof v === "bigint") {
78
+ return v.toString() + "n";
79
+ }
80
+ return v;
81
+ }
82
+ function bnReviver(k, v) {
83
+ if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
84
+ return BigInt(v.slice(0, -1));
85
+ }
86
+ return v;
87
+ }
88
+ function JSONToString(json, space) {
89
+ return JSON.stringify(json, bnReplacer, space);
90
+ }
91
+ function stringToJSON(str) {
92
+ return JSON.parse(str, bnReviver);
93
+ }
94
+
95
+ // src/environment/deployments.ts
96
+ var import_node_path2 = __toESM(require("path"), 1);
97
+ var import_node_fs2 = __toESM(require("fs"), 1);
98
+ function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChainId) {
99
+ const deploymentsFound = {};
100
+ const deployPath = import_node_path2.default.join(deploymentsPath, subPath);
101
+ let filesStats;
102
+ try {
103
+ filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
104
+ } catch (e) {
105
+ return { deployments: {} };
106
+ }
107
+ let chainId;
108
+ if (filesStats.length > 0) {
109
+ const chainIdFilepath = import_node_path2.default.join(deployPath, ".chainId");
110
+ if (import_node_fs2.default.existsSync(chainIdFilepath)) {
111
+ chainId = import_node_fs2.default.readFileSync(chainIdFilepath).toString().trim();
112
+ } else {
113
+ throw new Error(`A .chainId' file is expected to be present in the deployment folder for network ${subPath}`);
114
+ }
115
+ if (expectedChainId) {
116
+ if (expectedChainId !== chainId) {
117
+ throw new Error(
118
+ `Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChainId})`
119
+ );
120
+ }
121
+ }
122
+ } else {
123
+ return { deployments: {} };
124
+ }
125
+ let fileNames = filesStats.map((a) => a.relativePath);
126
+ fileNames = fileNames.sort((a, b) => {
127
+ if (a < b) {
128
+ return -1;
129
+ }
130
+ if (a > b) {
131
+ return 1;
132
+ }
133
+ return 0;
134
+ });
135
+ for (const fileName of fileNames) {
136
+ if (fileName.substring(fileName.length - 5) === ".json") {
137
+ const deploymentFileName = import_node_path2.default.join(deployPath, fileName);
138
+ let deployment = JSON.parse(import_node_fs2.default.readFileSync(deploymentFileName).toString());
139
+ if (onlyABIAndAddress) {
140
+ deployment = {
141
+ address: deployment.address,
142
+ abi: deployment.abi,
143
+ linkedData: deployment.linkedData
144
+ };
145
+ }
146
+ const name = fileName.slice(0, fileName.length - 5);
147
+ deploymentsFound[name] = deployment;
148
+ }
149
+ }
150
+ return { deployments: deploymentsFound, chainId };
151
+ }
152
+
153
+ // src/environment/index.ts
154
+ globalThis.extensions = [];
155
+ globalThis.signerProtocols = {};
156
+ async function createEnvironment(config2, providedContext) {
157
+ const provider = "provider" in config2 ? config2.provider : new import_eip_1193_json_provider.JSONRPCHTTPProvider(config2.nodeUrl);
158
+ const transport = (0, import_viem.custom)(provider);
159
+ const viemClient = (0, import_viem.createPublicClient)({ transport });
160
+ const chainId = (await viemClient.getChainId()).toString();
161
+ let networkName;
162
+ let saveDeployments;
163
+ let tags = {};
164
+ if ("nodeUrl" in config2) {
165
+ networkName = config2.networkName;
166
+ saveDeployments = true;
167
+ } else {
168
+ if (config2.networkName) {
169
+ networkName = config2.networkName;
170
+ } else {
171
+ networkName = "memory";
172
+ }
173
+ if (networkName === "memory" || networkName === "hardhat") {
174
+ tags["memory"] = true;
175
+ saveDeployments = false;
176
+ } else {
177
+ saveDeployments = true;
178
+ }
179
+ }
180
+ const resolvedAccounts = {};
181
+ const accountCache = {};
182
+ async function getAccount(name, accounts, accountDef) {
183
+ if (accountCache[name]) {
184
+ return accountCache[name];
185
+ }
186
+ let account;
187
+ if (typeof accountDef === "number") {
188
+ const accounts2 = await provider.request({ method: "eth_accounts" });
189
+ const accountPerIndex = accounts2[accountDef];
190
+ if (accountPerIndex) {
191
+ accountCache[name] = account = {
192
+ type: "remote",
193
+ address: accountPerIndex,
194
+ signer: provider
195
+ };
196
+ }
197
+ } else if (typeof accountDef === "string") {
198
+ if (accountDef.startsWith("0x")) {
199
+ if (accountDef.length === 66) {
200
+ const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
201
+ if (privateKeyProtocol) {
202
+ const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
203
+ const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
204
+ accountCache[name] = account = {
205
+ ...namedSigner,
206
+ address
207
+ };
208
+ }
209
+ } else {
210
+ accountCache[name] = account = {
211
+ type: "remote",
212
+ address: accountDef,
213
+ signer: provider
214
+ };
215
+ }
216
+ } else {
217
+ if (accountDef.indexOf(":") > 0) {
218
+ const [protocolID, extra] = accountDef.split(":");
219
+ const protocol = globalThis.signerProtocols[protocolID];
220
+ if (!protocol) {
221
+ throw new Error(`protocol: ${protocol} is not supported`);
222
+ }
223
+ const namedSigner = await protocol.getSigner(accountDef);
224
+ const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
225
+ accountCache[name] = account = {
226
+ ...namedSigner,
227
+ address
228
+ };
229
+ } else {
230
+ const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
231
+ if (accountFetched) {
232
+ accountCache[name] = account = accountFetched;
233
+ }
234
+ }
235
+ }
236
+ } else {
237
+ const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
238
+ if (accountForNetwork) {
239
+ const accountFetched = await getAccount(name, accounts, accountForNetwork);
240
+ if (accountFetched) {
241
+ accountCache[name] = account = accountFetched;
242
+ }
243
+ }
244
+ }
245
+ return account;
246
+ }
247
+ if (providedContext.accounts) {
248
+ const accountNames = Object.keys(providedContext.accounts);
249
+ for (const accountName of accountNames) {
250
+ let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
251
+ resolvedAccounts[accountName] = account;
252
+ }
253
+ }
254
+ const context = {
255
+ accounts: resolvedAccounts,
256
+ artifacts: providedContext.artifacts,
257
+ network: {
258
+ name: networkName,
259
+ saveDeployments,
260
+ tags
261
+ }
262
+ };
263
+ const { deployments } = loadDeployments(config2.deployments, context.network.name, false, chainId);
264
+ const namedAccounts = {};
265
+ const namedSigners = {};
266
+ const addressSigners = {};
267
+ for (const entry of Object.entries(resolvedAccounts)) {
268
+ const name = entry[0];
269
+ const { address, ...namedSigner } = entry[1];
270
+ namedAccounts[name] = address;
271
+ addressSigners[address] = namedSigner;
272
+ namedSigners[name] = namedSigner;
273
+ }
274
+ const perliminaryEnvironment = {
275
+ config: config2,
276
+ deployments,
277
+ accounts: namedAccounts,
278
+ signers: namedSigners,
279
+ addressSigners,
280
+ artifacts: context.artifacts,
281
+ network: {
282
+ chainId,
283
+ name: context.network.name,
284
+ tags: context.network.tags,
285
+ provider
286
+ }
287
+ };
288
+ function ensureDeploymentFolder() {
289
+ const folderPath = import_node_path3.default.join(config2.deployments, context.network.name);
290
+ import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
291
+ const chainIdFilepath = import_node_path3.default.join(folderPath, ".chainId");
292
+ if (!import_node_fs3.default.existsSync(chainIdFilepath)) {
293
+ import_node_fs3.default.writeFileSync(chainIdFilepath, chainId);
294
+ }
295
+ return folderPath;
296
+ }
297
+ function get(name) {
298
+ return deployments[name];
299
+ }
300
+ async function save(name, deployment) {
301
+ deployments[name] = deployment;
302
+ if (context.network.saveDeployments) {
303
+ const folderPath = ensureDeploymentFolder();
304
+ import_node_fs3.default.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
305
+ }
306
+ return deployment;
307
+ }
308
+ async function recoverTransactionsIfAny() {
309
+ const filepath = import_node_path3.default.join(config2.deployments, context.network.name, ".pending_transactions.json");
310
+ let existingPendingDeployments;
311
+ try {
312
+ existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
313
+ } catch {
314
+ existingPendingDeployments = [];
315
+ }
316
+ if (existingPendingDeployments.length > 0) {
317
+ while (existingPendingDeployments.length > 0) {
318
+ const pendingTransaction = existingPendingDeployments.shift();
319
+ if (pendingTransaction) {
320
+ console.log(
321
+ `recovering ${pendingTransaction.name} with transaction ${pendingTransaction.transaction.txHash}`
322
+ );
323
+ await waitForTransactionAndSave(pendingTransaction.name, pendingTransaction.transaction);
324
+ console.log(`transaction ${pendingTransaction.transaction.txHash} complete`);
325
+ import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
326
+ }
327
+ }
328
+ import_node_fs3.default.rmSync(filepath);
329
+ }
330
+ }
331
+ async function saveTransaction(name, transaction) {
332
+ if (context.network.saveDeployments) {
333
+ const folderPath = ensureDeploymentFolder();
334
+ const filepath = import_node_path3.default.join(folderPath, ".pending_transactions.json");
335
+ let existingPendingDeployments;
336
+ try {
337
+ existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
338
+ } catch {
339
+ existingPendingDeployments = [];
340
+ }
341
+ existingPendingDeployments.push({ name, transaction });
342
+ import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
343
+ }
344
+ return deployments;
345
+ }
346
+ async function deleteTransaction(hash) {
347
+ if (context.network.saveDeployments) {
348
+ const filepath = import_node_path3.default.join(config2.deployments, context.network.name, ".pending_transactions.json");
349
+ let existingPendingDeployments;
350
+ try {
351
+ existingPendingDeployments = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
352
+ } catch {
353
+ existingPendingDeployments = [];
354
+ }
355
+ existingPendingDeployments = existingPendingDeployments.filter((v) => v.transaction.txHash !== hash);
356
+ if (existingPendingDeployments.length === 0) {
357
+ import_node_fs3.default.rmSync(filepath);
358
+ } else {
359
+ import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
360
+ }
361
+ }
362
+ }
363
+ async function exportDeploymentsAsTypes() {
364
+ const folderPath = "./generated";
365
+ import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
366
+ import_node_fs3.default.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
367
+ }
368
+ async function waitForTransactionAndSave(name, pendingDeployment) {
369
+ const receipt = await viemClient.waitForTransactionReceipt({
370
+ hash: pendingDeployment.txHash
371
+ });
372
+ if (!receipt.contractAddress) {
373
+ throw new Error(`failed to deploy contract ${name}`);
374
+ }
375
+ const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
376
+ if (!artifactObjectWithoutABI.nonce) {
377
+ const transaction = await provider.request({
378
+ method: "eth_getTransactionByHash",
379
+ params: [pendingDeployment.txHash]
380
+ });
381
+ if (transaction) {
382
+ artifactObjectWithoutABI.nonce = transaction.nonce;
383
+ artifactObjectWithoutABI.txOrigin = transaction.from;
384
+ }
385
+ }
386
+ for (const key of Object.keys(artifactObjectWithoutABI)) {
387
+ if (key.startsWith("_")) {
388
+ delete artifactObjectWithoutABI[key];
389
+ }
390
+ if (key === "evm") {
391
+ const { gasEstimates } = artifactObjectWithoutABI.evm;
392
+ artifactObjectWithoutABI.evm = {
393
+ gasEstimates
394
+ };
395
+ }
396
+ }
397
+ const deployment = {
398
+ address: receipt.contractAddress,
399
+ txHash: pendingDeployment.txHash,
400
+ abi,
401
+ ...artifactObjectWithoutABI
402
+ };
403
+ return save(name, deployment);
404
+ }
405
+ async function saveWhilePending(name, pendingDeployment) {
406
+ await saveTransaction(name, pendingDeployment);
407
+ const transaction = await provider.request({
408
+ method: "eth_getTransactionByHash",
409
+ params: [pendingDeployment.txHash]
410
+ });
411
+ const deployment = waitForTransactionAndSave(
412
+ name,
413
+ transaction ? {
414
+ ...pendingDeployment,
415
+ nonce: transaction.nonce,
416
+ txOrigin: transaction.from
417
+ } : pendingDeployment
418
+ );
419
+ await deleteTransaction(pendingDeployment.txHash);
420
+ return deployment;
421
+ }
422
+ let env = {
423
+ ...perliminaryEnvironment,
424
+ save,
425
+ saveWhilePending,
426
+ get
427
+ };
428
+ for (const extension of globalThis.extensions) {
429
+ env = extension(env);
430
+ }
431
+ return {
432
+ external: env,
433
+ internal: {
434
+ exportDeploymentsAsTypes,
435
+ recoverTransactionsIfAny
436
+ }
437
+ };
438
+ }
439
+
440
+ // src/executor/index.ts
441
+ require("esbuild-register/dist/node").register();
442
+ function readConfig(options2, extra) {
443
+ let configFile;
444
+ try {
445
+ const configString = import_node_fs4.default.readFileSync("./rocketh.json", "utf-8");
446
+ configFile = JSON.parse(configString);
447
+ } catch {
448
+ }
449
+ let nodeUrl;
450
+ const fromEnv = process.env["ETH_NODE_URI_" + options2.network];
451
+ if (typeof fromEnv === "string") {
452
+ nodeUrl = fromEnv;
453
+ } else {
454
+ if (configFile) {
455
+ const network = configFile.networks && configFile.networks[options2.network];
456
+ if (network) {
457
+ nodeUrl = network.rpcUrl;
458
+ } else {
459
+ if (extra?.ignoreMissingRPC) {
460
+ nodeUrl = "";
461
+ } else {
462
+ console.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
463
+ process.exit(1);
464
+ }
465
+ }
466
+ } else {
467
+ if (extra?.ignoreMissingRPC) {
468
+ nodeUrl = "";
469
+ } else {
470
+ console.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
471
+ process.exit(1);
472
+ }
473
+ }
474
+ }
475
+ return {
476
+ nodeUrl,
477
+ networkName: options2.network,
478
+ deployments: options2.deployments,
479
+ scripts: options2.scripts,
480
+ tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(",")
481
+ };
482
+ }
483
+ function resolveConfig(config2) {
484
+ const resolvedConfig = {
485
+ ...config2,
486
+ networkName: config2.networkName || "memory",
487
+ deployments: config2.deployments || "deployments",
488
+ scripts: config2.scripts || "deploy",
489
+ tags: config2.tags || []
490
+ };
491
+ return resolvedConfig;
492
+ }
493
+ async function loadAndExecuteDeployments(config2) {
494
+ const resolvedConfig = resolveConfig(config2);
495
+ return executeDeployScripts(resolvedConfig);
496
+ }
497
+ async function executeDeployScripts(config2) {
498
+ let filepaths;
499
+ filepaths = traverseMultipleDirectory([config2.scripts]);
500
+ filepaths = filepaths.filter((v) => !import_node_path4.default.basename(v).startsWith("_")).sort((a, b) => {
501
+ if (a < b) {
502
+ return -1;
503
+ }
504
+ if (a > b) {
505
+ return 1;
506
+ }
507
+ return 0;
508
+ });
509
+ let providedContext;
510
+ const scriptModuleByFilePath = {};
511
+ const scriptPathBags = {};
512
+ const scriptFilePaths = [];
513
+ for (const filepath of filepaths) {
514
+ const scriptFilePath = import_node_path4.default.resolve(filepath);
515
+ let scriptModule;
516
+ try {
517
+ if (require.cache) {
518
+ delete require.cache[scriptFilePath];
519
+ }
520
+ scriptModule = require(scriptFilePath);
521
+ if (scriptModule.default) {
522
+ scriptModule = scriptModule.default;
523
+ if (scriptModule.default) {
524
+ console.warn(`double default...`);
525
+ scriptModule = scriptModule.default;
526
+ }
527
+ }
528
+ scriptModuleByFilePath[scriptFilePath] = scriptModule;
529
+ if (providedContext && providedContext !== scriptModule.providedContext) {
530
+ throw new Error(`context between 2 scripts is different, please share the same across them`);
531
+ }
532
+ providedContext = scriptModule.providedContext;
533
+ } catch (e) {
534
+ console.error(`could not import ${filepath}`);
535
+ throw e;
536
+ }
537
+ let scriptTags = scriptModule.tags;
538
+ if (scriptTags !== void 0) {
539
+ if (typeof scriptTags === "string") {
540
+ scriptTags = [scriptTags];
541
+ }
542
+ for (const tag of scriptTags) {
543
+ if (tag.indexOf(",") >= 0) {
544
+ throw new Error("Tag cannot contains commas");
545
+ }
546
+ const bag = scriptPathBags[tag] || [];
547
+ scriptPathBags[tag] = bag;
548
+ bag.push(scriptFilePath);
549
+ }
550
+ }
551
+ if (config2.tags !== void 0 && config2.tags.length > 0) {
552
+ let found = false;
553
+ if (scriptTags !== void 0) {
554
+ for (const tagToFind of config2.tags) {
555
+ for (const tag of scriptTags) {
556
+ if (tag === tagToFind) {
557
+ scriptFilePaths.push(scriptFilePath);
558
+ found = true;
559
+ break;
560
+ }
561
+ }
562
+ if (found) {
563
+ break;
564
+ }
565
+ }
566
+ }
567
+ } else {
568
+ scriptFilePaths.push(scriptFilePath);
569
+ }
570
+ }
571
+ if (!providedContext) {
572
+ throw new Error(`no context loaded`);
573
+ }
574
+ const { internal, external } = await createEnvironment(config2, providedContext);
575
+ await internal.recoverTransactionsIfAny();
576
+ const scriptsRegisteredToRun = {};
577
+ const scriptsToRun = [];
578
+ const scriptsToRunAtTheEnd = [];
579
+ function recurseDependencies(scriptFilePath) {
580
+ if (scriptsRegisteredToRun[scriptFilePath]) {
581
+ return;
582
+ }
583
+ const scriptModule = scriptModuleByFilePath[scriptFilePath];
584
+ if (scriptModule.dependencies) {
585
+ for (const dependency of scriptModule.dependencies) {
586
+ const scriptFilePathsToAdd = scriptPathBags[dependency];
587
+ if (scriptFilePathsToAdd) {
588
+ for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
589
+ recurseDependencies(scriptFilenameToAdd);
590
+ }
591
+ }
592
+ }
593
+ }
594
+ if (!scriptsRegisteredToRun[scriptFilePath]) {
595
+ if (scriptModule.runAtTheEnd) {
596
+ scriptsToRunAtTheEnd.push({
597
+ filePath: scriptFilePath,
598
+ func: scriptModule
599
+ });
600
+ } else {
601
+ scriptsToRun.push({
602
+ filePath: scriptFilePath,
603
+ func: scriptModule
604
+ });
605
+ }
606
+ scriptsRegisteredToRun[scriptFilePath] = true;
607
+ }
608
+ }
609
+ for (const scriptFilePath of scriptFilePaths) {
610
+ recurseDependencies(scriptFilePath);
611
+ }
612
+ for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
613
+ const filename = import_node_path4.default.basename(deployScript.filePath);
614
+ let skip = false;
615
+ if (deployScript.func.skip) {
616
+ try {
617
+ skip = await deployScript.func.skip(external);
618
+ } catch (e) {
619
+ console.error(`skip failed for ${deployScript.filePath}`);
620
+ throw e;
621
+ }
622
+ }
623
+ if (!skip) {
624
+ let result;
625
+ try {
626
+ result = await deployScript.func(external);
627
+ } catch (e) {
628
+ console.error(`execution failed for ${deployScript.filePath}`);
629
+ throw e;
630
+ }
631
+ if (result && typeof result === "boolean") {
632
+ const deploymentFolderPath = config2.deployments;
633
+ }
634
+ }
635
+ }
636
+ return external.deployments;
637
+ }
638
+
639
+ // src/cli.ts
640
+ var import_commander = require("commander");
641
+
642
+ // package.json
643
+ var package_default = {
644
+ name: "rocketh",
645
+ version: "0.5.0",
646
+ description: "deploy smart contract on ethereum-compatible networks",
647
+ publishConfig: {
648
+ access: "public"
649
+ },
650
+ type: "module",
651
+ main: "dist/index.cjs",
652
+ module: "dist/index.js",
653
+ types: "dist/index.d.ts",
654
+ bin: {
655
+ rocketh: "dist/cli.cjs"
656
+ },
657
+ devDependencies: {
658
+ "@types/figlet": "^1.5.5",
659
+ "@types/node": "^18.15.5",
660
+ abitype: "^0.7.1",
661
+ "eip-1193": "^0.4.4",
662
+ "ipfs-gateway-emulator": "4.2.1-ipfs.2",
663
+ rimraf: "^4.4.1",
664
+ tsup: "^6.7.0",
665
+ typedoc: "^0.23.28",
666
+ typescript: "^5.0.4"
667
+ },
668
+ dependencies: {
669
+ commander: "^10.0.0",
670
+ "eip-1193-json-provider": "^0.1.5",
671
+ esbuild: "^0.17.12",
672
+ "esbuild-register": "^3.4.2",
673
+ figlet: "^1.5.2",
674
+ ldenv: "^0.3.5",
675
+ viem: "^0.3.50"
676
+ },
677
+ scripts: {
678
+ build: "rimraf dist && tsup --entry src/index.ts --entry src/cli.ts --dts --format esm,cjs",
679
+ dev: "rimraf dist && tsup --entry src/index.ts --entry src/cli.ts --dts --format esm,cjs --watch",
680
+ "gen-docs": "typedoc --out docs src",
681
+ "serve-docs": "ipfs-emulator --only -d docs -p 8080"
682
+ }
683
+ };
684
+
685
+ // src/cli.ts
686
+ var import_figlet = __toESM(require("figlet"), 1);
687
+ (0, import_ldenv.loadEnv)();
688
+ console.log(`------------------------------------------------`);
689
+ console.log(import_figlet.default.textSync("rocketh"));
690
+ console.log(`------------------------------------------------`);
691
+ var commandName = `rocketh`;
692
+ var program = new import_commander.Command();
693
+ program.name(commandName).version(package_default.version).usage(`${commandName}`).description("execute deploy scripts and store the deployments").option("-s, --scripts <value>", "path the folder containing the deploy scripts to execute").option("-t, --tags <value>", "comma separated list of tags to execute").option("-d, --deployments <value>", "folder where deployments are saved").requiredOption("-n, --network <value>", "network context to use").parse(process.argv);
694
+ var options = program.opts();
695
+ var config = readConfig(options);
696
+ loadAndExecuteDeployments(config);
697
+ //# sourceMappingURL=cli.cjs.map