@clarigen/cli 4.0.1 → 4.0.2-alpha.0

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/index.cjs CHANGED
@@ -1,1365 +1,47 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- CONFIG_FILE: () => CONFIG_FILE,
34
- ClarinetConfig: () => ClarinetConfig,
35
- Config: () => Config,
36
- ConfigFile: () => ConfigFile,
37
- DEPLOYMENT_NETWORKS: () => DEPLOYMENT_NETWORKS,
38
- FN_TYPES: () => FN_TYPES,
39
- OutputType: () => OutputType,
40
- TYPE_IMPORTS: () => TYPE_IMPORTS,
41
- VAR_TYPES: () => VAR_TYPES,
42
- abiArgType: () => abiArgType,
43
- abiFunctionType: () => abiFunctionType,
44
- afterDocs: () => afterDocs,
45
- afterESM: () => afterESM,
46
- collectContractDeployments: () => collectContractDeployments,
47
- collectDeploymentFiles: () => collectDeploymentFiles,
48
- configFilePath: () => configFilePath,
49
- createContractDocInfo: () => createContractDocInfo,
50
- cwdRelative: () => cwdRelative,
51
- defaultConfigFile: () => defaultConfigFile,
52
- encodeVariableName: () => encodeVariableName,
53
- encodeVariables: () => encodeVariables,
54
- fileExists: () => fileExists,
55
- flatBatch: () => flatBatch,
56
- generateBaseFile: () => generateBaseFile,
57
- generateContractMeta: () => generateContractMeta,
58
- generateDocs: () => generateDocs,
59
- generateESMFile: () => generateESMFile,
60
- generateMarkdown: () => generateMarkdown,
61
- generateReadme: () => generateReadme,
62
- getArgName: () => getArgName,
63
- getClarinetConfig: () => getClarinetConfig,
64
- getConfig: () => getConfig,
65
- getContractTxs: () => getContractTxs,
66
- getDeploymentContract: () => getDeploymentContract,
67
- getDeploymentTxPath: () => getDeploymentTxPath,
68
- getDeployments: () => getDeployments,
69
- getFnName: () => getFnName,
70
- getIdentifier: () => getIdentifier,
71
- getVariablesV2: () => getVariablesV2,
72
- isComment: () => isComment,
73
- isContractTx: () => isContractTx,
74
- jsTypeFromAbiType: () => jsTypeFromAbiType,
75
- mapVariables: () => mapVariables,
76
- markdownFunction: () => markdownFunction,
77
- parseComments: () => parseComments,
78
- parseDeployment: () => parseDeployment,
79
- saveConfig: () => saveConfig,
80
- serialize: () => serialize,
81
- sortContracts: () => sortContracts,
82
- traceParens: () => traceParens,
83
- writeFile: () => writeFile
84
- });
85
- module.exports = __toCommonJS(src_exports);
86
-
87
- // src/docs/markdown.ts
88
- var import_core2 = require("@clarigen/core");
89
-
90
- // src/logger.ts
91
- var import_pino = require("pino");
92
- var import_pino_pretty = __toESM(require("pino-pretty"), 1);
93
- var colorizedClarigen = `\x1B[33m[Clarigen]\x1B[0m`;
94
- var logger = (0, import_pino.pino)(
95
- (0, import_pino_pretty.default)({
96
- colorize: true,
97
- ignore: "pid,hostname,time",
98
- messageFormat: `${colorizedClarigen} {msg}`,
99
- minimumLevel: "debug"
100
- })
101
- );
102
- logger.level = "info";
103
- var log = logger;
104
-
105
- // src/docs/index.ts
106
- var import_child_process = require("child_process");
107
- var FN_TYPES = ["read-only", "public", "private"];
108
- var VAR_TYPES = ["map", "data-var", "constant"];
109
- function createContractDocInfo({
110
- contractSrc,
111
- abi
112
- }) {
113
- const lines = contractSrc.split("\n");
114
- let comments = [];
115
- let parensCount = 0;
116
- let currentFn;
117
- const contract = {
118
- comments: [],
119
- functions: [],
120
- variables: [],
121
- maps: []
122
- };
123
- lines.forEach((line, lineNumber) => {
124
- if (currentFn) {
125
- currentFn.source.push(line);
126
- parensCount = traceParens(line, parensCount);
127
- if (parensCount === 0) {
128
- pushItem(contract, currentFn);
129
- currentFn = void 0;
130
- }
131
- return;
132
- }
133
- if (isComment(line)) {
134
- const comment = line.replace(/^\s*;;\s*/g, "");
135
- if (contract.comments.length === lineNumber) {
136
- contract.comments.push(comment);
137
- } else {
138
- comments.push(comment);
139
- }
140
- return;
141
- }
142
- const name = findItemNameFromLine(line);
143
- if (typeof name === "undefined") {
144
- comments = [];
145
- } else {
146
- const abiFn = findAbiItemByName(abi, name);
147
- if (!abiFn) {
148
- console.debug(`[claridoc]: Unable to find ABI for function \`${name}\`. Probably a bug.`);
149
- return;
150
- }
151
- parensCount = traceParens(line, 0);
152
- const metaComments = parseComments(comments, abiFn);
153
- currentFn = {
154
- abi: abiFn,
155
- comments: metaComments,
156
- startLine: lineNumber,
157
- source: [line]
158
- };
159
- if (parensCount === 0) {
160
- pushItem(contract, currentFn);
161
- currentFn = void 0;
162
- }
163
- comments = [];
164
- }
165
- });
166
- return contract;
167
- }
168
- function pushItem(contract, item) {
169
- if ("args" in item.abi) {
170
- contract.functions.push(item);
171
- } else if ("key" in item.abi) {
172
- contract.maps.push(item);
173
- } else if ("access" in item.abi) {
174
- contract.variables.push(item);
175
- }
176
- }
177
- function clarityNameMatcher(line) {
178
- return /[\w|\-|\?|\!]+/.exec(line);
179
- }
180
- function findItemNameFromLine(line) {
181
- const fnType = FN_TYPES.find((type3) => {
182
- return line.startsWith(`(define-${type3}`);
183
- });
184
- if (fnType) {
185
- const prefix = `(define-${fnType} (`;
186
- const startString = line.slice(prefix.length);
187
- const match = clarityNameMatcher(startString);
188
- if (!match) {
189
- console.debug(`[claridocs]: Unable to determine function name from line:
190
- \`${line}\``);
191
- return;
192
- }
193
- return match[0];
194
- }
195
- for (const type3 of VAR_TYPES) {
196
- const prefix = `(define-${type3} `;
197
- if (!line.startsWith(prefix)) continue;
198
- const startString = line.slice(prefix.length);
199
- const match = clarityNameMatcher(startString);
200
- if (!match) {
201
- console.debug(`[claridocs]: Unable to determine ${type3} name from line:
202
- \`${line}\``);
203
- return;
204
- }
205
- return match[0];
206
- }
207
- return void 0;
208
- }
209
- function findAbiItemByName(abi, name) {
210
- const fn = abi.functions.find((fn2) => {
211
- return fn2.name === name;
212
- });
213
- if (fn) return fn;
214
- const map = abi.maps.find((m) => m.name === name);
215
- if (map) return map;
216
- const v = abi.variables.find((v2) => v2.name === name);
217
- return v;
218
- }
219
- function isComment(line) {
220
- return line.startsWith(";;");
221
- }
222
- function getFnName(line) {
223
- const fnType = FN_TYPES.find((type3) => {
224
- return line.startsWith(`(define-${type3}`);
225
- });
226
- if (typeof fnType === "undefined") return;
227
- const prefix = `(define-${fnType} (`;
228
- const startString = line.slice(prefix.length);
229
- const match = clarityNameMatcher(startString);
230
- if (!match) {
231
- console.debug(`[claridocs]: Unable to determine function name from line:
232
- \`${line}\``);
233
- return;
234
- }
235
- return match[0];
236
- }
237
- function traceParens(line, count) {
238
- let newCount = count;
239
- line.split("").forEach((char) => {
240
- if (char === "(") newCount++;
241
- if (char === ")") newCount--;
242
- });
243
- return newCount;
244
- }
245
- function parseComments(comments, abi) {
246
- let curParam;
247
- const parsed = {
248
- text: [],
249
- params: {}
250
- };
251
- comments.forEach((line) => {
252
- const paramMatches = /\s*@param\s([\w|\-]+)([;|-|\s]*)(.*)/.exec(line);
253
- if (paramMatches === null) {
254
- if (!curParam || line.trim() === "") {
255
- curParam = void 0;
256
- parsed.text.push(line);
257
- } else {
258
- parsed.params[curParam].comments.push(line);
259
- }
260
- return;
261
- }
262
- if (!("args" in abi)) return;
263
- const [_full, name, _separator, rest] = paramMatches;
264
- const arg = abi.args.find((arg2) => arg2.name === name);
265
- if (!arg) {
266
- console.debug(`[claridocs]: Unable to find ABI for @param ${name}`);
267
- return;
268
- }
269
- curParam = name;
270
- parsed.params[curParam] = {
271
- abi: arg,
272
- comments: [rest]
273
- };
274
- });
275
- if ("args" in abi) {
276
- abi.args.forEach((arg) => {
277
- if (!parsed.params[arg.name]) {
278
- parsed.params[arg.name] = {
279
- abi: arg,
280
- comments: []
281
- };
282
- }
283
- });
284
- }
285
- return parsed;
286
- }
287
- async function afterDocs(config) {
288
- var _a;
289
- const command = (_a = config.docs) == null ? void 0 : _a.after;
290
- if (!command) return;
291
- logger.debug(`Running after docs command: ${command}`);
292
- const parts = command.split(" ");
293
- const [cmd, ...args] = parts;
294
- return new Promise((resolve3, reject) => {
295
- const child = (0, import_child_process.spawn)(cmd, args, {
296
- cwd: config.cwd,
297
- stdio: "inherit"
298
- });
299
- child.on("error", reject);
300
- child.on("exit", (code) => {
301
- if (code === 0) {
302
- resolve3();
303
- } else {
304
- reject(new Error(`Command failed with code ${code ?? "unknown"}`));
305
- }
306
- });
307
- });
308
- }
309
-
310
- // src/docs/markdown.ts
311
- var import_path2 = require("path");
312
-
313
- // src/utils.ts
314
- var import_core = require("@clarigen/core");
315
- var import_promises = require("fs/promises");
316
- var import_path = require("path");
317
- function encodeVariableName(name) {
318
- if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
319
- return (0, import_core.toCamelCase)(name);
320
- }
321
- async function fileExists(filename) {
322
- try {
323
- await (0, import_promises.stat)(filename);
324
- return true;
325
- } catch (error) {
326
- return false;
327
- }
328
- }
329
- async function writeFile(path, contents) {
330
- const dir = (0, import_path.dirname)(path);
331
- await (0, import_promises.mkdir)(dir, { recursive: true });
332
- await (0, import_promises.writeFile)(path, contents, "utf-8");
333
- return path;
334
- }
335
- function cwdRelative(path) {
336
- return (0, import_path.relative)(process.cwd(), path);
337
- }
338
- function sortContracts(contracts) {
339
- const nameSorted = [...contracts].sort((a, b) => {
340
- if ((0, import_core.getContractName)(a.contract_id, false) < (0, import_core.getContractName)(b.contract_id, false)) {
341
- return -1;
342
- }
343
- return 1;
344
- });
345
- return nameSorted;
346
- }
347
-
348
- // src/docs/markdown.ts
349
- function generateMarkdown({
350
- contract,
351
- contractFile,
352
- withToc = true
353
- }) {
354
- const contractName = (0, import_core2.getContractName)(contract.contract_id, false);
355
- const doc = createContractDocInfo({
356
- contractSrc: contract.source,
357
- abi: contract.contract_interface
358
- });
359
- const functions = doc.functions.map((fn) => markdownFunction(fn, contractFile));
360
- const maps = doc.maps.map((map) => markdownMap(map, contractFile));
361
- const vars = doc.variables.filter((v) => v.abi.access === "variable").map((v) => markdownVar(v, contractFile));
362
- const constants = doc.variables.filter((v) => v.abi.access === "constant").map((v) => markdownVar(v, contractFile));
363
- let fileLine = "";
364
- if (contractFile) {
365
- const fileName = (0, import_path2.basename)(contractFile);
366
- fileLine = `
367
- [\`${fileName}\`](${contractFile})`;
368
- }
369
- return `
370
- # ${contractName}
371
- ${fileLine}
372
-
373
- ${doc.comments.join("\n\n")}
374
-
375
- ${withToc ? markdownTOC(doc) : ""}
376
-
377
- ## Functions
378
-
379
- ${functions.join("\n\n")}
380
-
381
- ## Maps
382
-
383
- ${maps.join("\n\n")}
384
-
385
- ## Variables
386
-
387
- ${vars.join("\n\n")}
388
-
389
- ## Constants
390
-
391
- ${constants.join("\n\n")}
392
- `;
393
- }
394
- function markdownFunction(fn, contractFile) {
395
- const params = mdParams(fn);
396
- const returnType = (0, import_core2.getTypeString)(fn.abi.outputs.type);
397
- const paramSigs = fn.abi.args.map((arg) => {
398
- return `(${arg.name} ${(0, import_core2.getTypeString)(arg.type)})`;
399
- });
400
- const startLine = fn.startLine + 1;
401
- let link = "";
402
- if (contractFile) {
403
- link = `[View in file](${contractFile}#L${startLine})`;
404
- }
405
- const source = `<details>
406
- <summary>Source code:</summary>
407
-
408
- \`\`\`clarity
409
- ${fn.source.join("\n")}
410
- \`\`\`
411
- </details>
412
- `;
413
- const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
414
- " "
415
- )}) ${returnType})`;
416
- return `### ${fn.abi.name}
417
-
418
- ${link}
419
-
420
- \`${sig}\`
421
-
422
- ${fn.comments.text.join("\n")}
423
-
424
- ${source}
425
-
426
- ${params}`;
427
- }
428
- function mdParams(fn) {
429
- if (fn.abi.args.length === 0) return "";
430
- const hasDescription = Object.values(fn.comments.params).some((p) => p.comments.length > 0);
431
- const params = Object.values(fn.comments.params).map((p) => markdownParam(p, hasDescription));
432
- return `**Parameters:**
433
-
434
- | Name | Type | ${hasDescription ? "Description |" : ""}
435
- | --- | --- | ${hasDescription ? "--- |" : ""}
436
- ${params.join("\n")}`;
437
- }
438
- function markdownParam(param, withDescription) {
439
- const typeString = (0, import_core2.getTypeString)(param.abi.type);
440
- const base = `| ${param.abi.name} | ${typeString} |`;
441
- if (!withDescription) return base;
442
- return `${base} ${param.comments.join(" ")} |`;
443
- }
444
- function markdownMap(map, contractFile) {
445
- const startLine = map.startLine + 1;
446
- let link = "";
447
- if (contractFile) {
448
- link = `[View in file](${contractFile}#L${startLine})`;
449
- }
450
- return `### ${map.abi.name}
451
-
452
- ${map.comments.text.join("\n")}
453
-
454
- \`\`\`clarity
455
- ${map.source.join("\n")}
456
- \`\`\`
457
-
458
- ${link}`;
459
- }
460
- function markdownVar(variable, contractFile) {
461
- const startLine = variable.startLine + 1;
462
- let link = "";
463
- if (contractFile) {
464
- link = `[View in file](${contractFile}#L${startLine})`;
465
- }
466
- const sig = variable.abi.access === "variable" ? (0, import_core2.getTypeString)(variable.abi.type) : "";
467
- return `### ${variable.abi.name}
468
-
469
- ${sig}
470
-
471
- ${variable.comments.text.join("\n")}
472
-
473
- \`\`\`clarity
474
- ${variable.source.join("\n")}
475
- \`\`\`
476
-
477
- ${link}`;
478
- }
479
- function markdownTOC(contract) {
480
- const publics = contract.functions.filter((fn) => fn.abi.access === "public");
481
- const readOnly = contract.functions.filter((fn) => fn.abi.access === "read_only");
482
- const privates = contract.functions.filter((fn) => fn.abi.access === "private");
483
- const maps = contract.maps;
484
- const constants = contract.variables.filter((v) => v.abi.access === "constant");
485
- const vars = contract.variables.filter((v) => v.abi.access === "variable");
486
- function tocLine(fn) {
487
- const name = fn.abi.name;
488
- return `- [\`${name}\`](#${name.toLowerCase().replaceAll("?", "")})`;
489
- }
490
- return `**Public functions:**
491
-
492
- ${publics.map(tocLine).join("\n")}
493
-
494
- **Read-only functions:**
495
-
496
- ${readOnly.map(tocLine).join("\n")}
497
-
498
- **Private functions:**
499
-
500
- ${privates.map(tocLine).join("\n")}
501
-
502
- **Maps**
503
-
504
- ${maps.map(tocLine).join("\n")}
505
-
506
- **Variables**
507
-
508
- ${vars.map(tocLine).join("\n")}
509
-
510
- **Constants**
511
-
512
- ${constants.map(tocLine).join("\n")}
513
- `;
514
- }
515
- function generateReadme(session, excluded) {
516
- const contractLines = [];
517
- sortContracts(session.contracts).forEach((contract) => {
518
- const name = (0, import_core2.getContractName)(contract.contract_id, false);
519
- if (excluded[name]) return;
520
- const fileName = `${name}.md`;
521
- const line = `- [\`${name}\`](${fileName})`;
522
- contractLines.push(line);
523
- });
524
- const fileContents = `# Contracts
525
-
526
- ${contractLines.join("\n")}
527
- `;
528
- return fileContents;
529
- }
530
-
531
- // src/config.ts
532
- var import_arktype2 = require("arktype");
533
-
534
- // src/clarinet-config.ts
535
- var import_arktype = require("arktype");
536
- var import_promises2 = require("fs/promises");
537
- var import_toml = require("@iarna/toml");
538
- var ClarinetConfig = (0, import_arktype.type)({
539
- project: (0, import_arktype.type)({
540
- requirements: (0, import_arktype.type)({
541
- contract_id: (0, import_arktype.type)("string").describe("Contract ID")
542
- }).array().describe("Project requirements").optional(),
543
- cache_location: (0, import_arktype.type)({
544
- path: (0, import_arktype.type)("string").describe("Cache location path")
545
- }).optional()
546
- }),
547
- contracts: (0, import_arktype.type)({
548
- "[string]": (0, import_arktype.type)({
549
- path: (0, import_arktype.type)("string").describe("Contract path")
550
- })
551
- }).optional()
552
- });
553
- async function getClarinetConfig(path) {
554
- const file = await (0, import_promises2.readFile)(path, "utf-8");
555
- const config = ClarinetConfig.assert((0, import_toml.parse)(file));
556
- return config;
557
- }
558
-
559
- // src/config.ts
560
- var import_path3 = require("path");
561
- var import_toml2 = require("@iarna/toml");
562
- var import_promises3 = require("fs/promises");
563
- var CONFIG_FILE = "Clarigen.toml";
564
- var OutputType = /* @__PURE__ */ ((OutputType2) => {
565
- OutputType2["ESM"] = "types";
566
- OutputType2["ESM_OLD"] = "esm";
567
- OutputType2["Docs"] = "docs";
568
- return OutputType2;
569
- })(OutputType || {});
570
- var typesSchema = (0, import_arktype2.type)({
571
- "output?": (0, import_arktype2.type)("string").describe("Path to the output file"),
572
- "outputs?": (0, import_arktype2.type)("string[]").describe("Paths to the output files"),
573
- "include_accounts?": (0, import_arktype2.type)("boolean").describe("Include accounts in the output"),
574
- "after?": (0, import_arktype2.type)("string").describe("Script to run after the output is generated"),
575
- "include_boot_contracts?": (0, import_arktype2.type)("boolean").describe("Include boot contracts in the output"),
576
- "watch_folders?": (0, import_arktype2.type)("string[]").describe("Folders to watch for changes")
577
- }).optional();
578
- var ConfigFile = (0, import_arktype2.type)({
579
- clarinet: (0, import_arktype2.type)("string").describe("Path to the Clarinet config file"),
580
- ["types" /* ESM */]: typesSchema,
581
- ["esm" /* ESM_OLD */]: typesSchema,
582
- ["docs" /* Docs */]: (0, import_arktype2.type)({
583
- "output?": (0, import_arktype2.type)("string").describe("Path to docs output folder. Defaults to ./docs"),
584
- "outputs?": (0, import_arktype2.type)("string[]").describe("Paths to docs output folders"),
585
- "exclude?": (0, import_arktype2.type)("string[]").describe("Contracts to exclude from docs generation"),
586
- "after?": (0, import_arktype2.type)("string").describe("Script to run after docs are generated")
587
- }).optional()
588
- });
589
- var defaultConfigFile = {
590
- clarinet: "./Clarinet.toml"
591
- };
592
- var Config = class {
593
- configFile;
594
- clarinet;
595
- cwd;
596
- constructor(config, clarinet, cwd) {
597
- this.configFile = config;
598
- this.clarinet = clarinet;
599
- this.cwd = cwd ?? process.cwd();
600
- }
601
- static async load(cwd) {
602
- const config = await getConfig(cwd);
603
- if (config["esm" /* ESM_OLD */]) {
604
- config["types" /* ESM */] = config["esm" /* ESM_OLD */];
605
- delete config["esm" /* ESM_OLD */];
606
- }
607
- const clarinet = await getClarinetConfig((0, import_path3.resolve)(cwd ?? "", config.clarinet));
608
- return new this(config, clarinet, cwd);
609
- }
610
- getOutputs(type3) {
611
- var _a, _b;
612
- const singlePath = (_a = this.configFile[type3]) == null ? void 0 : _a.output;
613
- const multiPath = ((_b = this.configFile[type3]) == null ? void 0 : _b.outputs) || [];
614
- if (singlePath !== void 0) return [singlePath];
615
- return multiPath;
616
- }
617
- outputResolve(type3, filePath) {
618
- const outputs = this.getOutputs(type3);
619
- if (!this.supports(type3)) return null;
620
- return outputs.map((path) => {
621
- return (0, import_path3.resolve)(this.cwd, path, filePath || "");
622
- });
623
- }
624
- async writeOutput(type3, contents, filePath) {
625
- const paths = this.outputResolve(type3, filePath);
626
- if (paths === null) return null;
627
- await Promise.all(
628
- paths.map(async (path) => {
629
- await writeFile(path, contents);
630
- log.debug(`Generated ${type3} file at ${(0, import_path3.relative)(this.cwd, path)}`);
631
- })
632
- );
633
- return paths;
634
- }
635
- supports(type3) {
636
- return this.getOutputs(type3).length > 0;
637
- }
638
- type(type3) {
639
- return this.configFile[type3];
640
- }
641
- get esm() {
642
- return this.configFile["types" /* ESM */];
643
- }
644
- get docs() {
645
- return this.configFile["docs" /* Docs */];
646
- }
647
- clarinetFile() {
648
- return (0, import_path3.resolve)(this.cwd, this.configFile.clarinet);
649
- }
650
- joinFromClarinet(filePath) {
651
- const baseDir = (0, import_path3.dirname)(this.clarinetFile());
652
- return (0, import_path3.join)(baseDir, filePath);
653
- }
654
- };
655
- function configFilePath(cwd) {
656
- return (0, import_path3.resolve)(cwd ?? process.cwd(), CONFIG_FILE);
657
- }
658
- async function saveConfig(config) {
659
- const configToml = (0, import_toml2.stringify)({ ...config });
660
- await writeFile(configFilePath(), configToml);
661
- }
662
- var sessionConfig;
663
- async function getConfig(cwd) {
664
- if (typeof sessionConfig !== "undefined") return sessionConfig;
665
- const path = configFilePath(cwd);
666
- if (await fileExists(path)) {
667
- const toml = await (0, import_promises3.readFile)(path, "utf-8");
668
- const parsedToml = (0, import_toml2.parse)(toml);
669
- const parsed = ConfigFile(parsedToml);
670
- if (parsed instanceof import_arktype2.type.errors) {
671
- logger.error(`Error parsing Clarigen config: ${parsed.summary}`);
672
- throw new Error(`Error parsing Clarigen config: ${parsed.summary}`);
673
- }
674
- sessionConfig = parsed;
675
- } else {
676
- sessionConfig = defaultConfigFile;
677
- }
678
- return sessionConfig;
679
- }
680
-
681
- // src/files/docs.ts
682
- var import_core3 = require("@clarigen/core");
683
- var import_path4 = require("path");
684
- async function generateDocs({
685
- session,
686
- config
687
- }) {
688
- const docs = config.configFile["docs" /* Docs */];
689
- const docsBase = docs == null ? void 0 : docs.output;
690
- if (!docsBase) {
691
- warnNoDocs();
692
- return;
693
- }
694
- const docsPathExt = (0, import_path4.extname)(docsBase);
695
- if (docsPathExt) {
696
- log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
697
- }
698
- const excluded = Object.fromEntries(
699
- (docs.exclude || []).map((e) => {
700
- return [e, true];
701
- })
702
- );
703
- log.debug(`Generating docs at path \`${docsBase}\``);
704
- const docsBaseFolder = config.outputResolve("docs" /* Docs */, "./")[0];
705
- const paths = await Promise.all(
706
- session.contracts.map(async (contract) => {
707
- var _a, _b;
708
- const name = (0, import_core3.getContractName)(contract.contract_id, false);
709
- if (excluded[name]) return null;
710
- const docFile = `${name}.md`;
711
- const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
712
- let contractFile;
713
- if (contractPathDef) {
714
- const contractPathFull = config.joinFromClarinet(contractPathDef);
715
- contractFile = (0, import_path4.relative)(docsBaseFolder, contractPathFull);
716
- } else {
717
- log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
718
- }
719
- const md = generateMarkdown({ contract, contractFile });
720
- const path = await config.writeOutput("docs" /* Docs */, md, docFile);
721
- return path[0];
722
- })
723
- );
724
- const readme = generateReadme(session, excluded);
725
- paths.push((await config.writeOutput("docs" /* Docs */, readme, "README.md"))[0]);
726
- await afterDocs(config);
727
- }
728
- function warnNoDocs() {
729
- log.warn(
730
- `
731
- Clarigen config file doesn't include an output directory for docs.
732
-
733
- To generate docs, specify 'docs.output' in your config file:
734
-
735
- [docs]
736
- output = "docs/"
737
- `.trimEnd()
738
- );
739
- }
740
-
741
- // src/files/variables.ts
742
- var import_core8 = require("@clarigen/core");
743
-
744
- // src/declaration.ts
745
- var import_core4 = require("@clarigen/core");
746
- var import_core5 = require("@clarigen/core");
747
- var jsTypeFromAbiType = (val, isArgument = false) => {
748
- if ((0, import_core4.isClarityAbiPrimitive)(val)) {
749
- if (val === "uint128") {
750
- if (isArgument) return "number | bigint";
751
- return "bigint";
752
- } else if (val === "int128") {
753
- if (isArgument) return "number | bigint";
754
- return "bigint";
755
- } else if (val === "bool") {
756
- return "boolean";
757
- } else if (val === "principal") {
758
- return "string";
759
- } else if (val === "none") {
760
- return "null";
761
- } else if (val === "trait_reference") {
762
- return "string";
763
- } else {
764
- throw new Error(`Unexpected Clarity ABI type primitive: ${JSON.stringify(val)}`);
765
- }
766
- } else if ((0, import_core4.isClarityAbiBuffer)(val)) {
767
- return "Uint8Array";
768
- } else if ((0, import_core4.isClarityAbiResponse)(val)) {
769
- const ok = jsTypeFromAbiType(val.response.ok, isArgument);
770
- const err = jsTypeFromAbiType(val.response.error, isArgument);
771
- return `Response<${ok}, ${err}>`;
772
- } else if ((0, import_core4.isClarityAbiOptional)(val)) {
773
- const innerType = jsTypeFromAbiType(val.optional, isArgument);
774
- return `${innerType} | null`;
775
- } else if ((0, import_core4.isClarityAbiTuple)(val)) {
776
- const tupleDefs = [];
777
- val.tuple.forEach(({ name, type: type3 }) => {
778
- const camelName = (0, import_core5.toCamelCase)(name);
779
- const innerType = jsTypeFromAbiType(type3, isArgument);
780
- tupleDefs.push(`"${camelName}": ${innerType};`);
781
- });
782
- return `{
783
- ${tupleDefs.join("\n ")}
784
- }`;
785
- } else if ((0, import_core4.isClarityAbiList)(val)) {
786
- const innerType = jsTypeFromAbiType(val.list.type, isArgument);
787
- return `${innerType}[]`;
788
- } else if ((0, import_core4.isClarityAbiStringAscii)(val)) {
789
- return "string";
790
- } else if ((0, import_core4.isClarityAbiStringUtf8)(val)) {
791
- return "string";
792
- } else if ((0, import_core4.isClarityAbiTraitReference)(val)) {
793
- return "string";
794
- } else {
795
- throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(val)}`);
796
- }
797
- };
798
- function abiArgType(arg) {
799
- const nativeType = jsTypeFromAbiType(arg.type, true);
800
- const argName = getArgName(arg.name);
801
- return `${argName}: TypedAbiArg<${nativeType}, "${argName}">`;
802
- }
803
- function abiFunctionType(abiFunction) {
804
- const args = abiFunction.args.map(abiArgType);
805
- const retType = jsTypeFromAbiType(abiFunction.outputs.type);
806
- const argsTuple = `[${args.join(", ")}]`;
807
- return `TypedAbiFunction<${argsTuple}, ${retType}>`;
808
- }
809
- function getArgName(name) {
810
- const camel = (0, import_core5.toCamelCase)(name);
811
- const prefix = RESERVED[camel] ? "_" : "";
812
- return `${prefix}${camel}`;
813
- }
814
- function _hash(...words) {
815
- const h = {};
816
- for (const word of words) {
817
- h[word] = true;
818
- }
819
- return h;
820
- }
821
- var RESERVED = _hash(
822
- // Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
823
- "break",
824
- "do",
825
- "in",
826
- "typeof",
827
- "case",
828
- "else",
829
- "instanceof",
830
- "var",
831
- "catch",
832
- "export",
833
- "new",
834
- "void",
835
- "class",
836
- "extends",
837
- "return",
838
- "while",
839
- "const",
840
- "finally",
841
- "super",
842
- "with",
843
- "continue",
844
- "for",
845
- "switch",
846
- "yield",
847
- "debugger",
848
- "function",
849
- "this",
850
- "default",
851
- "if",
852
- "throw",
853
- "delete",
854
- "import",
855
- "try",
856
- // Future Reserved Words, ES6 11.6.2.2
857
- // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
858
- "enum",
859
- "await",
860
- // NullLiteral & BooleanLiteral
861
- "null",
862
- "true",
863
- "false"
864
- );
865
-
866
- // src/files/base.ts
867
- var import_core7 = require("@clarigen/core");
868
-
869
- // src/files/accounts.ts
870
- function generateAccountsCode(accounts) {
871
- const sortedAccounts = sortAccounts(accounts);
872
- const namedAccounts = Object.fromEntries(
873
- sortedAccounts.map((a) => {
874
- const { name, ...rest } = a;
875
- return [name, rest];
876
- })
877
- );
878
- return JSON.stringify(namedAccounts);
879
- }
880
- function sortAccounts(accounts) {
881
- const nameSorted = [...accounts].sort((a, b) => {
882
- if (a.name < b.name) {
883
- return -1;
884
- }
885
- return 1;
886
- });
887
- return nameSorted;
888
- }
889
-
890
- // src/files/identifiers.ts
891
- var import_core6 = require("@clarigen/core");
892
- function generateIdentifiers(session) {
893
- const identifiers = Object.fromEntries(
894
- sortContracts(session.contracts).map((c) => {
895
- const contractName = (0, import_core6.getContractName)(c.contract_id);
896
- return [contractName, c.contract_id];
897
- })
898
- );
899
- return identifiers;
900
- }
901
- function generateIdentifiersCode(session) {
902
- const identifiers = generateIdentifiers(session);
903
- return `export const identifiers = ${JSON.stringify(identifiers)} as const`;
904
- }
905
-
906
- // src/files/base.ts
907
- var import_util = require("util");
908
- function generateContractMeta(contract, constants) {
909
- const abi = contract.contract_interface;
910
- const functionLines = [];
911
- const { functions, maps, variables, non_fungible_tokens, ...rest } = abi;
912
- functions.forEach((func) => {
913
- let functionLine = `${(0, import_core7.toCamelCase)(func.name)}: `;
914
- const funcDef = JSON.stringify(func);
915
- functionLine += funcDef;
916
- const functionType = abiFunctionType(func);
917
- functionLine += ` as ${functionType}`;
918
- functionLines.push(functionLine);
919
- });
920
- const mapLines = maps.map((map) => {
921
- let mapLine = `${(0, import_core7.toCamelCase)(map.name)}: `;
922
- const keyType = jsTypeFromAbiType(map.key, true);
923
- const valType = jsTypeFromAbiType(map.value);
924
- mapLine += JSON.stringify(map);
925
- mapLine += ` as TypedAbiMap<${keyType}, ${valType}>`;
926
- return mapLine;
927
- });
928
- const otherAbi = JSON.stringify(rest);
929
- const contractName = contract.contract_id.split(".")[1];
930
- const variableLines = encodeVariables(variables);
931
- const nftLines = non_fungible_tokens.map((nft) => {
932
- return JSON.stringify(nft);
933
- });
934
- return `{
935
- ${serializeLines("functions", functionLines)}
936
- ${serializeLines("maps", mapLines)}
937
- ${serializeLines("variables", variableLines)}
938
- constants: ${constants},
939
- ${serializeArray("non_fungible_tokens", nftLines)}
940
- ${otherAbi.slice(1, -1)},
941
- contractName: '${contractName}',
942
- }`;
943
- }
944
- var TYPE_IMPORTS = `import type { TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, Response } from '@clarigen/core';`;
945
- function generateBaseFile(session) {
946
- const combined = session.contracts.map((c, i) => ({
947
- ...c,
948
- constants: session.variables[i]
949
- }));
950
- const contractDefs = sortContracts(combined).map((contract) => {
951
- const meta = generateContractMeta(contract, contract.constants);
952
- const id = contract.contract_id.split(".")[1];
953
- const keyName = (0, import_core7.toCamelCase)(id);
954
- return `${keyName}: ${meta}`;
955
- });
956
- const file = `
957
- ${TYPE_IMPORTS}
958
-
959
- export const contracts = {
960
- ${contractDefs.join(",\n")}
961
- } as const;
962
-
963
- export const accounts = ${generateAccountsCode(session.accounts)} as const;
964
-
965
- ${generateIdentifiersCode(session)}
966
-
967
- export const simnet = {
968
- accounts,
969
- contracts,
970
- identifiers,
971
- } as const;
972
-
973
- `;
974
- return file;
975
- }
976
- function encodeVariables(variables) {
977
- return variables.map((v) => {
978
- let varLine = `${encodeVariableName(v.name)}: `;
979
- const type3 = jsTypeFromAbiType(v.type);
980
- const varJSON = serialize(v);
981
- varLine += `${varJSON} as TypedAbiVariable<${type3}>`;
982
- return varLine;
983
- });
984
- }
985
- Uint8Array.prototype[import_util.inspect.custom] = function(depth, options) {
986
- return `Uint8Array.from([${this.join(",")}])`;
987
- };
988
- function serialize(obj) {
989
- return (0, import_util.inspect)(obj, {
990
- // showHidden: false,
991
- // depth: 100,
992
- // colors: false,
993
- showHidden: false,
994
- // iterableLimit: 100000,
995
- compact: false,
996
- // trailingComma: true,
997
- depth: 100,
998
- colors: false,
999
- maxArrayLength: Infinity,
1000
- maxStringLength: Infinity,
1001
- breakLength: Infinity,
1002
- numericSeparator: true
1003
- // strAbbreviateSize: 100000,
1004
- });
1005
- }
1006
- function serializeLines(key, lines) {
1007
- return `"${key}": {
1008
- ${lines.join(",\n ")}
1009
- },`;
1010
- }
1011
- function serializeArray(key, lines) {
1012
- return `"${key}": [
1013
- ${lines.join(",\n ")}
1014
- ],`;
1015
- }
1016
-
1017
- // src/files/variables.ts
1018
- function clarityVersionForContract(contract) {
1019
- switch (contract.contract_interface.clarity_version) {
1020
- case "Clarity1":
1021
- return 1;
1022
- case "Clarity2":
1023
- return 2;
1024
- case "Clarity3":
1025
- return 3;
1026
- case "Clarity4":
1027
- return 4;
1028
- default:
1029
- return 3;
1030
- }
1031
- }
1032
- function getVariablesV2(contract, simnet, verbose) {
1033
- const [deployer] = contract.contract_id.split(".");
1034
- const fakeId = `${(0, import_core8.getContractName)(contract.contract_id)}-vars`;
1035
- logger.debug(`Deploying ${contract.contract_id} for variables.`);
1036
- if (!contract.source) {
1037
- logger.debug(
1038
- `Contract ${(0, import_core8.getContractName)(contract.contract_id)} has no source. Skipping variables.`
1039
- );
1040
- return {};
1041
- }
1042
- if (contract.contract_interface.variables.length === 0) {
1043
- logger.info(`Contract ${(0, import_core8.getContractName)(contract.contract_id, false)} has no variables`);
1044
- return {};
1045
- }
1046
- let varFn = `{
1047
- `;
1048
- const varLines = contract.contract_interface.variables.map((variable) => {
1049
- let varLine = `${variable.name}: `;
1050
- if (variable.access === "constant") {
1051
- varLine += `${variable.name}`;
1052
- } else {
1053
- varLine += `(var-get ${variable.name})`;
1054
- }
1055
- return varLine;
1056
- });
1057
- varFn += varLines.map((l) => ` ${l},`).join("\n");
1058
- varFn += "\n}";
1059
- const fullSrc = contract.source + `
1060
-
1061
- ${varFn}`;
1062
- try {
1063
- const receipt = simnet.deployContract(
1064
- fakeId,
1065
- fullSrc,
1066
- {
1067
- clarityVersion: clarityVersionForContract(contract)
1068
- },
1069
- deployer
1070
- );
1071
- const result = receipt.result;
1072
- const varsAbi = {
1073
- tuple: []
1074
- };
1075
- contract.contract_interface.variables.forEach((v) => {
1076
- const _v = v;
1077
- varsAbi.tuple.push({
1078
- type: _v.type,
1079
- name: _v.name
1080
- });
1081
- });
1082
- if (verbose) {
1083
- logger.info((0, import_core8.cvToValue)(result, true));
1084
- }
1085
- return (0, import_core8.cvToValue)(result, true);
1086
- } catch (error) {
1087
- logger.warn(
1088
- { err: error },
1089
- `Error getting variables for ${(0, import_core8.getContractName)(contract.contract_id, false)}`
1090
- );
1091
- return {};
1092
- }
1093
- }
1094
- function mapVariables(session, simnet) {
1095
- return session.contracts.map((contract) => {
1096
- const vars = getVariablesV2(contract, simnet);
1097
- return serialize(vars);
1098
- });
1099
- }
1100
-
1101
- // src/files/esm.ts
1102
- var import_promises4 = require("fs/promises");
1103
- var import_path5 = require("path");
1104
- var import_yaml = require("yaml");
1105
-
1106
- // src/deployments.ts
1107
- function flatBatch(batches) {
1108
- const txs = [];
1109
- batches.forEach((batch) => txs.push(...batch.transactions));
1110
- return txs;
1111
- }
1112
- function getContractTxs(batches) {
1113
- const txs = flatBatch(batches);
1114
- return txs.filter(isContractTx);
1115
- }
1116
- function getDeploymentContract(contractName, deployment) {
1117
- const txs = flatBatch(deployment.plan.batches);
1118
- for (const tx of txs) {
1119
- if (!isContractTx(tx)) continue;
1120
- if ("requirement-publish" in tx) {
1121
- const [_, name] = tx["requirement-publish"]["contract-id"].split(".");
1122
- if (name === contractName) {
1123
- return tx;
1124
- }
1125
- } else if ("emulated-contract-publish" in tx) {
1126
- if (tx["emulated-contract-publish"]["contract-name"] === contractName) {
1127
- return tx;
1128
- }
1129
- } else if ("contract-publish" in tx) {
1130
- const contract = tx["contract-publish"];
1131
- if (contract["contract-name"] === contractName) {
1132
- return tx;
1133
- }
1134
- }
1135
- }
1136
- throw new Error(`Unable to find deployment tx for contract '${contractName}'`);
1137
- }
1138
- function getDeploymentTxPath(tx) {
1139
- if (!isContractTx(tx)) {
1140
- throw new Error("Unable to get path for tx type.");
1141
- }
1142
- if ("requirement-publish" in tx) {
1143
- return tx["requirement-publish"].path;
1144
- } else if ("emulated-contract-publish" in tx) {
1145
- const contract = tx["emulated-contract-publish"];
1146
- return contract.path;
1147
- } else if ("contract-publish" in tx) {
1148
- const contract = tx["contract-publish"];
1149
- return contract.path;
1150
- }
1151
- throw new Error("Couldnt get path for deployment tx.");
1152
- }
1153
- function getIdentifier(tx) {
1154
- if (!isContractTx(tx)) {
1155
- throw new Error("Unable to get ID for tx type.");
1156
- }
1157
- if ("requirement-publish" in tx) {
1158
- const spec = tx["requirement-publish"];
1159
- const [_, name] = spec["contract-id"].split(".");
1160
- return `${spec["remap-sender"]}.${name}`;
1161
- } else if ("emulated-contract-publish" in tx) {
1162
- const contract = tx["emulated-contract-publish"];
1163
- return `${contract["emulated-sender"]}.${contract["contract-name"]}`;
1164
- } else if ("contract-publish" in tx) {
1165
- const contract = tx["contract-publish"];
1166
- return `${contract["expected-sender"]}.${contract["contract-name"]}`;
1167
- }
1168
- throw new Error(`Unable to find ID for contract.`);
1169
- }
1170
- function isContractTx(tx) {
1171
- if ("contract-call" in tx) return false;
1172
- if ("btc-transfer" in tx) return false;
1173
- if ("emulated-contract-call" in tx) return false;
1174
- return true;
1175
- }
1176
-
1177
- // src/files/esm.ts
1178
- var import_core9 = require("@clarigen/core");
1179
- var import_child_process2 = require("child_process");
1180
- async function parseDeployment(path) {
1181
- const contents = await (0, import_promises4.readFile)(path, "utf-8");
1182
- const parsed = (0, import_yaml.parse)(contents);
1183
- return parsed;
1184
- }
1185
- var DEPLOYMENT_NETWORKS = ["devnet", "simnet", "testnet", "mainnet"];
1186
- async function getDeployments(config) {
1187
- const entries = await Promise.all(
1188
- DEPLOYMENT_NETWORKS.map(async (network) => {
1189
- const file = `default.${network}-plan.yaml`;
1190
- const path = (0, import_path5.join)((0, import_path5.dirname)(config.clarinetFile()), "deployments", file);
1191
- let plan;
1192
- try {
1193
- plan = await parseDeployment(path);
1194
- } catch (_) {
1195
- }
1196
- return [network, plan];
1197
- })
1198
- );
1199
- return Object.fromEntries(entries);
1200
- }
1201
- async function generateESMFile({
1202
- baseFile,
1203
- session,
1204
- config
1205
- }) {
1206
- const deployments = await getDeployments(config);
1207
- const contractDeployments = collectContractDeployments(session, deployments, config);
1208
- const simnet = generateSimnetCode(config, deployments, session);
1209
- return `${baseFile}
1210
- export const deployments = ${JSON.stringify(contractDeployments)} as const;
1211
- ${simnet}
1212
- export const project = {
1213
- contracts,
1214
- deployments,
1215
- } as const;
1216
- `;
1217
- }
1218
- function insertNetworkId(deployments, identifier, network) {
1219
- const name = (0, import_core9.getContractName)(identifier);
1220
- if (!deployments[name]) {
1221
- return;
1222
- }
1223
- if (deployments[name][network] === null) {
1224
- deployments[name][network] = identifier;
1225
- }
1226
- }
1227
- function collectContractDeployments(session, deployments, config) {
1228
- var _a;
1229
- const full = Object.fromEntries(
1230
- sortContracts(session.contracts).map((contract) => {
1231
- const contractName = (0, import_core9.getContractName)(contract.contract_id);
1232
- const contractDeployments = Object.fromEntries(
1233
- DEPLOYMENT_NETWORKS.map((network) => {
1234
- const deployment = deployments[network];
1235
- if (typeof deployment === "undefined") {
1236
- return [network, null];
1237
- }
1238
- try {
1239
- const contractName2 = contract.contract_id.split(".")[1];
1240
- const tx = getDeploymentContract(contractName2, deployment);
1241
- const id = getIdentifier(tx);
1242
- return [network, id];
1243
- } catch (_) {
1244
- return [network, null];
1245
- }
1246
- })
1247
- );
1248
- return [contractName, contractDeployments];
1249
- })
1250
- );
1251
- const deployer = session.accounts.find((a) => a.name === "deployer");
1252
- (_a = config.clarinet.project.requirements) == null ? void 0 : _a.forEach(({ contract_id }) => {
1253
- insertNetworkId(full, contract_id, "mainnet");
1254
- const contractName = contract_id.split(".")[1];
1255
- if (deployer) {
1256
- const devnetId = `${deployer.address}.${contractName}`;
1257
- insertNetworkId(full, devnetId, "devnet");
1258
- }
1259
- });
1260
- session.contracts.forEach((contract) => {
1261
- insertNetworkId(full, contract.contract_id, "devnet");
1262
- insertNetworkId(full, contract.contract_id, "simnet");
1263
- });
1264
- return full;
1265
- }
1266
- function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
1267
- if (!deployments.simnet) return [];
1268
- const simnet = deployments.simnet;
1269
- const txs = getContractTxs(simnet.plan.batches);
1270
- const entries = txs.map((tx) => {
1271
- const id = getIdentifier(tx);
1272
- const contractFile = getDeploymentTxPath(tx);
1273
- return {
1274
- identifier: id,
1275
- file: (0, import_path5.relative)(cwd, (0, import_path5.join)(clarinetFolder, contractFile))
1276
- };
1277
- });
1278
- return entries;
1279
- }
1280
- function generateSimnetCode(config, deployments, _session) {
1281
- var _a;
1282
- if (!((_a = config.esm) == null ? void 0 : _a.include_accounts)) return "";
1283
- const clarinetFolder = (0, import_path5.dirname)(config.clarinetFile());
1284
- const files = collectDeploymentFiles(deployments, clarinetFolder, config.cwd);
1285
- return `
1286
- export const simnetDeployment = ${JSON.stringify(files)};
1287
- `;
1288
- }
1289
- async function afterESM(config) {
1290
- var _a;
1291
- const command = (_a = config.esm) == null ? void 0 : _a.after;
1292
- if (!command) return;
1293
- logger.debug(`Running after ESM command: ${command}`);
1294
- const parts = command.split(" ");
1295
- const [cmd, ...args] = parts;
1296
- return new Promise((resolve3, reject) => {
1297
- const child = (0, import_child_process2.spawn)(cmd, args, {
1298
- cwd: config.cwd,
1299
- stdio: "inherit"
1300
- });
1301
- child.on("error", reject);
1302
- child.on("exit", (code) => {
1303
- if (code === 0) {
1304
- resolve3();
1305
- } else {
1306
- reject(new Error(`Command failed with code ${code ?? "unknown"}`));
1307
- }
1308
- });
1309
- });
1310
- }
1311
- // Annotate the CommonJS export names for ESM import in node:
1312
- 0 && (module.exports = {
1313
- CONFIG_FILE,
1314
- ClarinetConfig,
1315
- Config,
1316
- ConfigFile,
1317
- DEPLOYMENT_NETWORKS,
1318
- FN_TYPES,
1319
- OutputType,
1320
- TYPE_IMPORTS,
1321
- VAR_TYPES,
1322
- abiArgType,
1323
- abiFunctionType,
1324
- afterDocs,
1325
- afterESM,
1326
- collectContractDeployments,
1327
- collectDeploymentFiles,
1328
- configFilePath,
1329
- createContractDocInfo,
1330
- cwdRelative,
1331
- defaultConfigFile,
1332
- encodeVariableName,
1333
- encodeVariables,
1334
- fileExists,
1335
- flatBatch,
1336
- generateBaseFile,
1337
- generateContractMeta,
1338
- generateDocs,
1339
- generateESMFile,
1340
- generateMarkdown,
1341
- generateReadme,
1342
- getArgName,
1343
- getClarinetConfig,
1344
- getConfig,
1345
- getContractTxs,
1346
- getDeploymentContract,
1347
- getDeploymentTxPath,
1348
- getDeployments,
1349
- getFnName,
1350
- getIdentifier,
1351
- getVariablesV2,
1352
- isComment,
1353
- isContractTx,
1354
- jsTypeFromAbiType,
1355
- mapVariables,
1356
- markdownFunction,
1357
- parseComments,
1358
- parseDeployment,
1359
- saveConfig,
1360
- serialize,
1361
- sortContracts,
1362
- traceParens,
1363
- writeFile
1364
- });
1365
- //# sourceMappingURL=index.cjs.map
1
+ const require_esm = require('./esm-CRbGFHSR.cjs');
2
+
3
+ exports.CONFIG_FILE = require_esm.CONFIG_FILE;
4
+ exports.ClarinetConfig = require_esm.ClarinetConfig;
5
+ exports.Config = require_esm.Config;
6
+ exports.ConfigFile = require_esm.ConfigFile;
7
+ exports.DEPLOYMENT_NETWORKS = require_esm.DEPLOYMENT_NETWORKS;
8
+ exports.FN_TYPES = require_esm.FN_TYPES;
9
+ exports.OutputType = require_esm.OutputType;
10
+ exports.TYPE_IMPORTS = require_esm.TYPE_IMPORTS;
11
+ exports.VAR_TYPES = require_esm.VAR_TYPES;
12
+ exports.abiArgType = require_esm.abiArgType;
13
+ exports.abiFunctionType = require_esm.abiFunctionType;
14
+ exports.afterDocs = require_esm.afterDocs;
15
+ exports.afterESM = require_esm.afterESM;
16
+ exports.collectContractDeployments = require_esm.collectContractDeployments;
17
+ exports.collectDeploymentFiles = require_esm.collectDeploymentFiles;
18
+ exports.configFilePath = require_esm.configFilePath;
19
+ exports.createContractDocInfo = require_esm.createContractDocInfo;
20
+ exports.cwdRelative = require_esm.cwdRelative;
21
+ exports.defaultConfigFile = require_esm.defaultConfigFile;
22
+ exports.encodeVariableName = require_esm.encodeVariableName;
23
+ exports.encodeVariables = require_esm.encodeVariables;
24
+ exports.fileExists = require_esm.fileExists;
25
+ exports.generateBaseFile = require_esm.generateBaseFile;
26
+ exports.generateContractMeta = require_esm.generateContractMeta;
27
+ exports.generateDocs = require_esm.generateDocs;
28
+ exports.generateESMFile = require_esm.generateESMFile;
29
+ exports.generateMarkdown = require_esm.generateMarkdown;
30
+ exports.generateReadme = require_esm.generateReadme;
31
+ exports.getArgName = require_esm.getArgName;
32
+ exports.getClarinetConfig = require_esm.getClarinetConfig;
33
+ exports.getConfig = require_esm.getConfig;
34
+ exports.getDeployments = require_esm.getDeployments;
35
+ exports.getFnName = require_esm.getFnName;
36
+ exports.getVariablesV2 = require_esm.getVariablesV2;
37
+ exports.isComment = require_esm.isComment;
38
+ exports.jsTypeFromAbiType = require_esm.jsTypeFromAbiType;
39
+ exports.mapVariables = require_esm.mapVariables;
40
+ exports.markdownFunction = require_esm.markdownFunction;
41
+ exports.parseComments = require_esm.parseComments;
42
+ exports.parseDeployment = require_esm.parseDeployment;
43
+ exports.saveConfig = require_esm.saveConfig;
44
+ exports.serialize = require_esm.serialize;
45
+ exports.sortContracts = require_esm.sortContracts;
46
+ exports.traceParens = require_esm.traceParens;
47
+ exports.writeFile = require_esm.writeFile;