@clarigen/cli 2.1.1 → 2.1.3

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/run-cli.cjs CHANGED
@@ -1,39 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
7
  var __getProtoOf = Object.getPrototypeOf;
10
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
9
  var __copyProps = (to, from, except, desc) => {
38
10
  if (from && typeof from === "object" || typeof from === "function") {
39
11
  for (let key of __getOwnPropNames(from))
@@ -42,11 +14,14 @@ var __copyProps = (to, from, except, desc) => {
42
14
  }
43
15
  return to;
44
16
  };
45
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
46
- var __publicField = (obj, key, value) => {
47
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
48
- return value;
49
- };
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
+ ));
50
25
 
51
26
  // src/run-cli.ts
52
27
  var import_clipanion6 = require("clipanion");
@@ -61,12 +36,14 @@ var import_zod2 = require("zod");
61
36
  var import_pino = require("pino");
62
37
  var import_pino_pretty = __toESM(require("pino-pretty"), 1);
63
38
  var colorizedClarigen = `\x1B[33m[Clarigen]\x1B[0m`;
64
- var logger = (0, import_pino.pino)((0, import_pino_pretty.default)({
65
- colorize: true,
66
- ignore: "pid,hostname,time",
67
- messageFormat: `${colorizedClarigen} {msg}`,
68
- minimumLevel: "debug"
69
- }));
39
+ var logger = (0, import_pino.pino)(
40
+ (0, import_pino_pretty.default)({
41
+ colorize: true,
42
+ ignore: "pid,hostname,time",
43
+ messageFormat: `${colorizedClarigen} {msg}`,
44
+ minimumLevel: "debug"
45
+ })
46
+ );
70
47
  logger.level = "info";
71
48
  var log = logger;
72
49
 
@@ -75,8 +52,7 @@ var import_core = require("@clarigen/core");
75
52
  var import_promises = require("fs/promises");
76
53
  var import_path = require("path");
77
54
  function encodeVariableName(name) {
78
- if (/^[A-Z\-_]*$/.test(name))
79
- return name.replaceAll("-", "_");
55
+ if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
80
56
  return (0, import_core.toCamelCase)(name);
81
57
  }
82
58
  async function fileExists(filename) {
@@ -130,7 +106,8 @@ var typesSchema = import_zod2.z.object({
130
106
  outputs: import_zod2.z.array(import_zod2.z.string()).optional(),
131
107
  include_accounts: import_zod2.z.boolean().optional(),
132
108
  after: import_zod2.z.string().optional(),
133
- include_boot_contracts: import_zod2.z.boolean().optional()
109
+ include_boot_contracts: import_zod2.z.boolean().optional(),
110
+ watch_folders: import_zod2.z.array(import_zod2.z.string()).optional()
134
111
  }).optional();
135
112
  var ConfigFileSchema = import_zod2.z.object({
136
113
  clarinet: import_zod2.z.string(),
@@ -168,26 +145,25 @@ var Config = class {
168
145
  var _a, _b;
169
146
  const singlePath = (_a = this.configFile[type]) == null ? void 0 : _a.output;
170
147
  const multiPath = ((_b = this.configFile[type]) == null ? void 0 : _b.outputs) || [];
171
- if (singlePath !== void 0)
172
- return [singlePath];
148
+ if (singlePath !== void 0) return [singlePath];
173
149
  return multiPath;
174
150
  }
175
151
  outputResolve(type, filePath) {
176
152
  const outputs = this.getOutputs(type);
177
- if (!this.supports(type))
178
- return null;
153
+ if (!this.supports(type)) return null;
179
154
  return outputs.map((path) => {
180
155
  return (0, import_path2.resolve)(this.cwd, path, filePath || "");
181
156
  });
182
157
  }
183
158
  async writeOutput(type, contents, filePath) {
184
159
  const paths = this.outputResolve(type, filePath);
185
- if (paths === null)
186
- return null;
187
- await Promise.all(paths.map(async (path) => {
188
- await writeFile(path, contents);
189
- log.debug(`Generated ${type} file at ${(0, import_path2.relative)(this.cwd, path)}`);
190
- }));
160
+ if (paths === null) return null;
161
+ await Promise.all(
162
+ paths.map(async (path) => {
163
+ await writeFile(path, contents);
164
+ log.debug(`Generated ${type} file at ${(0, import_path2.relative)(this.cwd, path)}`);
165
+ })
166
+ );
191
167
  return paths;
192
168
  }
193
169
  supports(type) {
@@ -215,8 +191,7 @@ function configFilePath(cwd) {
215
191
  }
216
192
  var sessionConfig;
217
193
  async function getConfig(cwd) {
218
- if (typeof sessionConfig !== "undefined")
219
- return sessionConfig;
194
+ if (typeof sessionConfig !== "undefined") return sessionConfig;
220
195
  const path = configFilePath(cwd);
221
196
  if (await fileExists(path)) {
222
197
  const toml = await (0, import_promises3.readFile)(path, "utf-8");
@@ -249,6 +224,7 @@ var BaseCommand = class extends import_clipanion.Command {
249
224
  logger.level = "debug";
250
225
  }
251
226
  }
227
+ // eslint-disable-next-line @typescript-eslint/require-await
252
228
  async catch(error) {
253
229
  if (error instanceof import_zod3.ZodError) {
254
230
  logger.error(error.issues, "Your configuration file is invalid.");
@@ -264,6 +240,10 @@ var BaseCommand = class extends import_clipanion.Command {
264
240
 
265
241
  // src/commands/session-info.ts
266
242
  var SessionInfoCommand = class extends BaseCommand {
243
+ static paths = [["session-info"]];
244
+ static usage = import_clipanion2.Command.Usage({
245
+ description: "Log info about this project's Clarinet session"
246
+ });
267
247
  cwd = import_clipanion2.Option.String({ required: false });
268
248
  async execute() {
269
249
  this.preexecute();
@@ -271,10 +251,6 @@ var SessionInfoCommand = class extends BaseCommand {
271
251
  logger.info(config);
272
252
  }
273
253
  };
274
- __publicField(SessionInfoCommand, "paths", [["session-info"]]);
275
- __publicField(SessionInfoCommand, "usage", import_clipanion2.Command.Usage({
276
- description: "Log info about this project's Clarinet session"
277
- }));
278
254
 
279
255
  // src/commands/default-command.ts
280
256
  var import_clipanion3 = require("clipanion");
@@ -293,12 +269,10 @@ var import_core3 = require("@clarigen/core");
293
269
  var jsTypeFromAbiType = (val, isArgument = false) => {
294
270
  if ((0, import_core2.isClarityAbiPrimitive)(val)) {
295
271
  if (val === "uint128") {
296
- if (isArgument)
297
- return "number | bigint";
272
+ if (isArgument) return "number | bigint";
298
273
  return "bigint";
299
274
  } else if (val === "int128") {
300
- if (isArgument)
301
- return "number | bigint";
275
+ if (isArgument) return "number | bigint";
302
276
  return "bigint";
303
277
  } else if (val === "bool") {
304
278
  return "boolean";
@@ -366,7 +340,50 @@ function _hash(...words) {
366
340
  }
367
341
  return h;
368
342
  }
369
- var RESERVED = _hash("break", "do", "in", "typeof", "case", "else", "instanceof", "var", "catch", "export", "new", "void", "class", "extends", "return", "while", "const", "finally", "super", "with", "continue", "for", "switch", "yield", "debugger", "function", "this", "default", "if", "throw", "delete", "import", "try", "enum", "await", "null", "true", "false");
343
+ var RESERVED = _hash(
344
+ // Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
345
+ "break",
346
+ "do",
347
+ "in",
348
+ "typeof",
349
+ "case",
350
+ "else",
351
+ "instanceof",
352
+ "var",
353
+ "catch",
354
+ "export",
355
+ "new",
356
+ "void",
357
+ "class",
358
+ "extends",
359
+ "return",
360
+ "while",
361
+ "const",
362
+ "finally",
363
+ "super",
364
+ "with",
365
+ "continue",
366
+ "for",
367
+ "switch",
368
+ "yield",
369
+ "debugger",
370
+ "function",
371
+ "this",
372
+ "default",
373
+ "if",
374
+ "throw",
375
+ "delete",
376
+ "import",
377
+ "try",
378
+ // Future Reserved Words, ES6 11.6.2.2
379
+ // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
380
+ "enum",
381
+ "await",
382
+ // NullLiteral & BooleanLiteral
383
+ "null",
384
+ "true",
385
+ "false"
386
+ );
370
387
 
371
388
  // src/files/base.ts
372
389
  var import_core5 = require("@clarigen/core");
@@ -374,10 +391,12 @@ var import_core5 = require("@clarigen/core");
374
391
  // src/files/accounts.ts
375
392
  function generateAccountsCode(accounts) {
376
393
  const sortedAccounts = sortAccounts(accounts);
377
- const namedAccounts = Object.fromEntries(sortedAccounts.map((a) => {
378
- const _a = a, { name } = _a, rest = __objRest(_a, ["name"]);
379
- return [name, rest];
380
- }));
394
+ const namedAccounts = Object.fromEntries(
395
+ sortedAccounts.map((a) => {
396
+ const { name, ...rest } = a;
397
+ return [name, rest];
398
+ })
399
+ );
381
400
  return JSON.stringify(namedAccounts);
382
401
  }
383
402
  function sortAccounts(accounts) {
@@ -393,10 +412,12 @@ function sortAccounts(accounts) {
393
412
  // src/files/identifiers.ts
394
413
  var import_core4 = require("@clarigen/core");
395
414
  function generateIdentifiers(session) {
396
- const identifiers = Object.fromEntries(sortContracts(session.contracts).map((c) => {
397
- const contractName = (0, import_core4.getContractName)(c.contract_id);
398
- return [contractName, c.contract_id];
399
- }));
415
+ const identifiers = Object.fromEntries(
416
+ sortContracts(session.contracts).map((c) => {
417
+ const contractName = (0, import_core4.getContractName)(c.contract_id);
418
+ return [contractName, c.contract_id];
419
+ })
420
+ );
400
421
  return identifiers;
401
422
  }
402
423
  function generateIdentifiersCode(session) {
@@ -409,7 +430,7 @@ var import_util = require("util");
409
430
  function generateContractMeta(contract, constants) {
410
431
  const abi = contract.contract_interface;
411
432
  const functionLines = [];
412
- const _a = abi, { functions, maps, variables, non_fungible_tokens } = _a, rest = __objRest(_a, ["functions", "maps", "variables", "non_fungible_tokens"]);
433
+ const { functions, maps, variables, non_fungible_tokens, ...rest } = abi;
413
434
  functions.forEach((func) => {
414
435
  let functionLine = `${(0, import_core5.toCamelCase)(func.name)}: `;
415
436
  const funcDef = JSON.stringify(func);
@@ -444,7 +465,8 @@ function generateContractMeta(contract, constants) {
444
465
  }
445
466
  var TYPE_IMPORTS = `import type { TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, Response } from '@clarigen/core';`;
446
467
  function generateBaseFile(session) {
447
- const combined = session.contracts.map((c, i) => __spreadProps(__spreadValues({}, c), {
468
+ const combined = session.contracts.map((c, i) => ({
469
+ ...c,
448
470
  constants: session.variables[i]
449
471
  }));
450
472
  const contractDefs = sortContracts(combined).map((contract) => {
@@ -487,14 +509,20 @@ Uint8Array.prototype[import_util.inspect.custom] = function(depth, options) {
487
509
  };
488
510
  function serialize(obj) {
489
511
  return (0, import_util.inspect)(obj, {
512
+ // showHidden: false,
513
+ // depth: 100,
514
+ // colors: false,
490
515
  showHidden: false,
516
+ // iterableLimit: 100000,
491
517
  compact: false,
518
+ // trailingComma: true,
492
519
  depth: 100,
493
520
  colors: false,
494
521
  maxArrayLength: Infinity,
495
522
  maxStringLength: Infinity,
496
523
  breakLength: Infinity,
497
524
  numericSeparator: true
525
+ // strAbbreviateSize: 100000,
498
526
  });
499
527
  }
500
528
  function serializeLines(key, lines) {
@@ -514,7 +542,9 @@ function getVariablesV2(contract, simnet, verbose) {
514
542
  const fakeId = `${(0, import_core6.getContractName)(contract.contract_id)}-vars`;
515
543
  logger.debug(`Deploying ${contract.contract_id} for variables.`);
516
544
  if (!contract.source) {
517
- logger.debug(`Contract ${(0, import_core6.getContractName)(contract.contract_id)} has no source. Skipping variables.`);
545
+ logger.debug(
546
+ `Contract ${(0, import_core6.getContractName)(contract.contract_id)} has no source. Skipping variables.`
547
+ );
518
548
  return {};
519
549
  }
520
550
  if (contract.contract_interface.variables.length === 0) {
@@ -538,9 +568,14 @@ function getVariablesV2(contract, simnet, verbose) {
538
568
 
539
569
  ${varFn}`;
540
570
  try {
541
- const receipt = simnet.deployContract(fakeId, fullSrc, {
542
- clarityVersion: 3
543
- }, deployer);
571
+ const receipt = simnet.deployContract(
572
+ fakeId,
573
+ fullSrc,
574
+ {
575
+ clarityVersion: 3
576
+ },
577
+ deployer
578
+ );
544
579
  const result = receipt.result;
545
580
  const varsAbi = {
546
581
  tuple: []
@@ -557,10 +592,10 @@ ${varFn}`;
557
592
  }
558
593
  return (0, import_core6.cvToValue)(result, true);
559
594
  } catch (error) {
560
- logger.error(`Error getting variables for ${(0, import_core6.getContractName)(contract.contract_id, false)}`);
561
- logger.error(`Source code: ${contract.source} with type ${String(typeof contract.source)}`);
562
- logger.error(error);
563
- logger.error(fullSrc);
595
+ logger.warn(
596
+ { err: error },
597
+ `Error getting variables for ${(0, import_core6.getContractName)(contract.contract_id, false)}`
598
+ );
564
599
  return {};
565
600
  }
566
601
  }
@@ -588,24 +623,26 @@ async function getSession(config) {
588
623
  balance: resultCV.toString()
589
624
  };
590
625
  });
591
- const contracts = (await Promise.all([...interfaces.entries()].map(async ([contract_id, contract_interface]) => {
592
- var _a, _b, _c;
593
- if (contract_id.startsWith(import_core7.MAINNET_BURN_ADDRESS) && ((_a = config.esm) == null ? void 0 : _a.include_boot_contracts) !== true || contract_id.startsWith(import_core7.TESTNET_BURN_ADDRESS)) {
594
- return void 0;
595
- }
596
- const name = (0, import_core7.getContractName)(contract_id, false);
597
- const contractPathDef = (_c = (_b = config.clarinet.contracts) == null ? void 0 : _b[name]) == null ? void 0 : _c.path;
598
- let source;
599
- if (contractPathDef) {
600
- const contractPathFull = config.joinFromClarinet(contractPathDef);
601
- source = await (0, import_promises4.readFile)(contractPathFull, "utf-8");
602
- }
603
- return {
604
- contract_id,
605
- contract_interface,
606
- source: source ?? ""
607
- };
608
- }))).filter((x) => x !== void 0);
626
+ const contracts = (await Promise.all(
627
+ [...interfaces.entries()].map(async ([contract_id, contract_interface]) => {
628
+ var _a, _b, _c;
629
+ if (contract_id.startsWith(import_core7.MAINNET_BURN_ADDRESS) && ((_a = config.esm) == null ? void 0 : _a.include_boot_contracts) !== true || contract_id.startsWith(import_core7.TESTNET_BURN_ADDRESS)) {
630
+ return void 0;
631
+ }
632
+ const name = (0, import_core7.getContractName)(contract_id, false);
633
+ const contractPathDef = (_c = (_b = config.clarinet.contracts) == null ? void 0 : _b[name]) == null ? void 0 : _c.path;
634
+ let source;
635
+ if (contractPathDef) {
636
+ const contractPathFull = config.joinFromClarinet(contractPathDef);
637
+ source = await (0, import_promises4.readFile)(contractPathFull, "utf-8");
638
+ }
639
+ return {
640
+ contract_id,
641
+ contract_interface,
642
+ source: source ?? ""
643
+ };
644
+ })
645
+ )).filter((x) => x !== void 0);
609
646
  const session = {
610
647
  session_id: 0,
611
648
  accounts: allAccounts,
@@ -617,6 +654,7 @@ async function getSession(config) {
617
654
  accounts: allAccounts,
618
655
  contracts,
619
656
  variables
657
+ // variables: [],
620
658
  };
621
659
  }
622
660
 
@@ -638,8 +676,7 @@ function getContractTxs(batches) {
638
676
  function getDeploymentContract(contractName, deployment) {
639
677
  const txs = flatBatch(deployment.plan.batches);
640
678
  for (const tx of txs) {
641
- if (!isContractTx(tx))
642
- continue;
679
+ if (!isContractTx(tx)) continue;
643
680
  if ("requirement-publish" in tx) {
644
681
  const [_, name] = tx["requirement-publish"]["contract-id"].split(".");
645
682
  if (name === contractName) {
@@ -691,12 +728,9 @@ function getIdentifier(tx) {
691
728
  throw new Error(`Unable to find ID for contract.`);
692
729
  }
693
730
  function isContractTx(tx) {
694
- if ("contract-call" in tx)
695
- return false;
696
- if ("btc-transfer" in tx)
697
- return false;
698
- if ("emulated-contract-call" in tx)
699
- return false;
731
+ if ("contract-call" in tx) return false;
732
+ if ("btc-transfer" in tx) return false;
733
+ if ("emulated-contract-call" in tx) return false;
700
734
  return true;
701
735
  }
702
736
 
@@ -710,16 +744,18 @@ async function parseDeployment(path) {
710
744
  }
711
745
  var DEPLOYMENT_NETWORKS = ["devnet", "simnet", "testnet", "mainnet"];
712
746
  async function getDeployments(config) {
713
- const entries = await Promise.all(DEPLOYMENT_NETWORKS.map(async (network) => {
714
- const file = `default.${network}-plan.yaml`;
715
- const path = (0, import_path3.join)((0, import_path3.dirname)(config.clarinetFile()), "deployments", file);
716
- let plan;
717
- try {
718
- plan = await parseDeployment(path);
719
- } catch (_) {
720
- }
721
- return [network, plan];
722
- }));
747
+ const entries = await Promise.all(
748
+ DEPLOYMENT_NETWORKS.map(async (network) => {
749
+ const file = `default.${network}-plan.yaml`;
750
+ const path = (0, import_path3.join)((0, import_path3.dirname)(config.clarinetFile()), "deployments", file);
751
+ let plan;
752
+ try {
753
+ plan = await parseDeployment(path);
754
+ } catch (_) {
755
+ }
756
+ return [network, plan];
757
+ })
758
+ );
723
759
  return Object.fromEntries(entries);
724
760
  }
725
761
  async function generateESMFile({
@@ -750,24 +786,28 @@ function insertNetworkId(deployments, identifier, network) {
750
786
  }
751
787
  function collectContractDeployments(session, deployments, config) {
752
788
  var _a;
753
- const full = Object.fromEntries(sortContracts(session.contracts).map((contract) => {
754
- const contractName = (0, import_core8.getContractName)(contract.contract_id);
755
- const contractDeployments = Object.fromEntries(DEPLOYMENT_NETWORKS.map((network) => {
756
- const deployment = deployments[network];
757
- if (typeof deployment === "undefined") {
758
- return [network, null];
759
- }
760
- try {
761
- const contractName2 = contract.contract_id.split(".")[1];
762
- const tx = getDeploymentContract(contractName2, deployment);
763
- const id = getIdentifier(tx);
764
- return [network, id];
765
- } catch (_) {
766
- return [network, null];
767
- }
768
- }));
769
- return [contractName, contractDeployments];
770
- }));
789
+ const full = Object.fromEntries(
790
+ sortContracts(session.contracts).map((contract) => {
791
+ const contractName = (0, import_core8.getContractName)(contract.contract_id);
792
+ const contractDeployments = Object.fromEntries(
793
+ DEPLOYMENT_NETWORKS.map((network) => {
794
+ const deployment = deployments[network];
795
+ if (typeof deployment === "undefined") {
796
+ return [network, null];
797
+ }
798
+ try {
799
+ const contractName2 = contract.contract_id.split(".")[1];
800
+ const tx = getDeploymentContract(contractName2, deployment);
801
+ const id = getIdentifier(tx);
802
+ return [network, id];
803
+ } catch (_) {
804
+ return [network, null];
805
+ }
806
+ })
807
+ );
808
+ return [contractName, contractDeployments];
809
+ })
810
+ );
771
811
  const deployer = session.accounts.find((a) => a.name === "deployer");
772
812
  (_a = config.clarinet.project.requirements) == null ? void 0 : _a.forEach(({ contract_id }) => {
773
813
  insertNetworkId(full, contract_id, "mainnet");
@@ -784,8 +824,7 @@ function collectContractDeployments(session, deployments, config) {
784
824
  return full;
785
825
  }
786
826
  function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
787
- if (!deployments.simnet)
788
- return [];
827
+ if (!deployments.simnet) return [];
789
828
  const simnet = deployments.simnet;
790
829
  const txs = getContractTxs(simnet.plan.batches);
791
830
  const entries = txs.map((tx) => {
@@ -800,8 +839,7 @@ function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
800
839
  }
801
840
  function generateSimnetCode(config, deployments, _session) {
802
841
  var _a;
803
- if (!((_a = config.esm) == null ? void 0 : _a.include_accounts))
804
- return "";
842
+ if (!((_a = config.esm) == null ? void 0 : _a.include_accounts)) return "";
805
843
  const clarinetFolder = (0, import_path3.dirname)(config.clarinetFile());
806
844
  const files = collectDeploymentFiles(deployments, clarinetFolder, config.cwd);
807
845
  return `
@@ -811,8 +849,7 @@ export const simnetDeployment = ${JSON.stringify(files)};
811
849
  async function afterESM(config) {
812
850
  var _a;
813
851
  const command = (_a = config.esm) == null ? void 0 : _a.after;
814
- if (!command)
815
- return;
852
+ if (!command) return;
816
853
  logger.debug(`Running after ESM command: ${command}`);
817
854
  const parts = command.split(" ");
818
855
  const [cmd, ...args2] = parts;
@@ -854,16 +891,19 @@ async function generate(config) {
854
891
  }
855
892
  async function watch(config, cwd) {
856
893
  return new Promise(async (resolve3, reject) => {
857
- const clarinetFolder = (0, import_path4.dirname)(config.clarinetFile());
858
- const contractsFolder = (0, import_path4.join)(clarinetFolder, "/contracts/**/*.clar");
894
+ var _a;
859
895
  try {
860
896
  await generate(config);
861
897
  } catch (error) {
862
898
  logger.error({ error }, "Error generating types");
863
899
  }
900
+ const clarinetFolder = (0, import_path4.dirname)(config.clarinetFile());
901
+ const contractsFolder = (0, import_path4.join)(clarinetFolder, "/contracts/**/*.clar");
864
902
  const relativeFolder = (0, import_path4.relative)(cwd || process.cwd(), contractsFolder);
865
- logger.info(`Watching for changes in ${relativeFolder}`);
866
- const watcher = import_chokidar.default.watch(contractsFolder, { persistent: true, cwd: clarinetFolder });
903
+ const watchFolders = ((_a = config.esm) == null ? void 0 : _a.watch_folders) ?? [];
904
+ watchFolders.push(relativeFolder);
905
+ logger.info(`Watching for changes in ${watchFolders}`);
906
+ const watcher = import_chokidar.default.watch(watchFolders, { persistent: true, cwd: clarinetFolder });
867
907
  let running = false;
868
908
  let start = 0;
869
909
  const isVerbose = logger.level !== "info";
@@ -879,7 +919,9 @@ async function watch(config, cwd) {
879
919
  process.stdout.moveCursor(0, -1);
880
920
  process.stdout.clearLine(1);
881
921
  const elapsed = Date.now() - start;
882
- logger.info(`Types generated (${(elapsed / 1e3).toFixed(2)}s). Watching for changes...`);
922
+ logger.info(
923
+ `Types generated (${(elapsed / 1e3).toFixed(2)}s). Watching for changes...`
924
+ );
883
925
  running = false;
884
926
  });
885
927
  });
@@ -888,6 +930,16 @@ async function watch(config, cwd) {
888
930
  });
889
931
  }
890
932
  var DefaultCommand = class extends BaseCommand {
933
+ static paths = [import_clipanion3.Command.Default, ["generate"]];
934
+ // static description = 'Generate types for your Clarity contracts';
935
+ static usage = import_clipanion3.Command.Usage({
936
+ description: "Generate types for your Clarity contracts",
937
+ examples: [
938
+ ["Basic usage:", "clarigen"],
939
+ ["When your `Clarigen.toml` is in a different directory:", "clarigen /path/to/your/project"],
940
+ ["Watch for changes and regenerate types:", "clarigen --watch"]
941
+ ]
942
+ });
891
943
  cwd = import_clipanion3.Option.String({
892
944
  required: false
893
945
  });
@@ -905,15 +957,6 @@ var DefaultCommand = class extends BaseCommand {
905
957
  }
906
958
  }
907
959
  };
908
- __publicField(DefaultCommand, "paths", [import_clipanion3.Command.Default, ["generate"]]);
909
- __publicField(DefaultCommand, "usage", import_clipanion3.Command.Usage({
910
- description: "Generate types for your Clarity contracts",
911
- examples: [
912
- ["Basic usage:", "clarigen"],
913
- ["When your `Clarigen.toml` is in a different directory:", "clarigen /path/to/your/project"],
914
- ["Watch for changes and regenerate types:", "clarigen --watch"]
915
- ]
916
- }));
917
960
 
918
961
  // src/commands/docs-command.ts
919
962
  var import_clipanion4 = require("clipanion");
@@ -1017,8 +1060,7 @@ function findItemNameFromLine(line) {
1017
1060
  }
1018
1061
  for (const type of VAR_TYPES) {
1019
1062
  const prefix = `(define-${type} `;
1020
- if (!line.startsWith(prefix))
1021
- continue;
1063
+ if (!line.startsWith(prefix)) continue;
1022
1064
  const startString = line.slice(prefix.length);
1023
1065
  const match = clarityNameMatcher(startString);
1024
1066
  if (!match) {
@@ -1034,11 +1076,9 @@ function findAbiItemByName(abi, name) {
1034
1076
  const fn = abi.functions.find((fn2) => {
1035
1077
  return fn2.name === name;
1036
1078
  });
1037
- if (fn)
1038
- return fn;
1079
+ if (fn) return fn;
1039
1080
  const map = abi.maps.find((m) => m.name === name);
1040
- if (map)
1041
- return map;
1081
+ if (map) return map;
1042
1082
  const v = abi.variables.find((v2) => v2.name === name);
1043
1083
  return v;
1044
1084
  }
@@ -1048,10 +1088,8 @@ function isComment(line) {
1048
1088
  function traceParens(line, count) {
1049
1089
  let newCount = count;
1050
1090
  line.split("").forEach((char) => {
1051
- if (char === "(")
1052
- newCount++;
1053
- if (char === ")")
1054
- newCount--;
1091
+ if (char === "(") newCount++;
1092
+ if (char === ")") newCount--;
1055
1093
  });
1056
1094
  return newCount;
1057
1095
  }
@@ -1072,8 +1110,7 @@ function parseComments(comments, abi) {
1072
1110
  }
1073
1111
  return;
1074
1112
  }
1075
- if (!("args" in abi))
1076
- return;
1113
+ if (!("args" in abi)) return;
1077
1114
  const [_full, name, _separator, rest] = paramMatches;
1078
1115
  const arg = abi.args.find((arg2) => arg2.name === name);
1079
1116
  if (!arg) {
@@ -1101,8 +1138,7 @@ function parseComments(comments, abi) {
1101
1138
  async function afterDocs(config) {
1102
1139
  var _a;
1103
1140
  const command = (_a = config.docs) == null ? void 0 : _a.after;
1104
- if (!command)
1105
- return;
1141
+ if (!command) return;
1106
1142
  logger.debug(`Running after docs command: ${command}`);
1107
1143
  const parts = command.split(" ");
1108
1144
  const [cmd, ...args2] = parts;
@@ -1188,7 +1224,9 @@ ${fn.source.join("\n")}
1188
1224
  \`\`\`
1189
1225
  </details>
1190
1226
  `;
1191
- const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(" ")}) ${returnType})`;
1227
+ const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
1228
+ " "
1229
+ )}) ${returnType})`;
1192
1230
  return `### ${fn.abi.name}
1193
1231
 
1194
1232
  ${link}
@@ -1202,8 +1240,7 @@ ${source}
1202
1240
  ${params}`;
1203
1241
  }
1204
1242
  function mdParams(fn) {
1205
- if (fn.abi.args.length === 0)
1206
- return "";
1243
+ if (fn.abi.args.length === 0) return "";
1207
1244
  const hasDescription = Object.values(fn.comments.params).some((p) => p.comments.length > 0);
1208
1245
  const params = Object.values(fn.comments.params).map((p) => markdownParam(p, hasDescription));
1209
1246
  return `**Parameters:**
@@ -1215,8 +1252,7 @@ ${params.join("\n")}`;
1215
1252
  function markdownParam(param, withDescription) {
1216
1253
  const typeString = (0, import_core9.getTypeString)(param.abi.type);
1217
1254
  const base = `| ${param.abi.name} | ${typeString} |`;
1218
- if (!withDescription)
1219
- return base;
1255
+ if (!withDescription) return base;
1220
1256
  return `${base} ${param.comments.join(" ")} |`;
1221
1257
  }
1222
1258
  function markdownMap(map, contractFile) {
@@ -1294,8 +1330,7 @@ function generateReadme(session, excluded) {
1294
1330
  const contractLines = [];
1295
1331
  sortContracts(session.contracts).forEach((contract) => {
1296
1332
  const name = (0, import_core9.getContractName)(contract.contract_id, false);
1297
- if (excluded[name])
1298
- return;
1333
+ if (excluded[name]) return;
1299
1334
  const fileName = `${name}.md`;
1300
1335
  const line = `- [\`${name}\`](${fileName})`;
1301
1336
  contractLines.push(line);
@@ -1322,63 +1357,69 @@ async function generateDocs({
1322
1357
  if (docsPathExt) {
1323
1358
  log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
1324
1359
  }
1325
- const excluded = Object.fromEntries((docs.exclude || []).map((e) => {
1326
- return [e, true];
1327
- }));
1360
+ const excluded = Object.fromEntries(
1361
+ (docs.exclude || []).map((e) => {
1362
+ return [e, true];
1363
+ })
1364
+ );
1328
1365
  log.debug(`Generating docs at path \`${docsBase}\``);
1329
1366
  const docsBaseFolder = config.outputResolve("docs" /* Docs */, "./")[0];
1330
- const paths = await Promise.all(session.contracts.map(async (contract) => {
1331
- var _a, _b;
1332
- const name = (0, import_core10.getContractName)(contract.contract_id, false);
1333
- if (excluded[name])
1334
- return null;
1335
- const docFile = `${name}.md`;
1336
- const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
1337
- let contractFile;
1338
- if (contractPathDef) {
1339
- const contractPathFull = config.joinFromClarinet(contractPathDef);
1340
- contractFile = (0, import_path6.relative)(docsBaseFolder, contractPathFull);
1341
- } else {
1342
- log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
1343
- }
1344
- const md = generateMarkdown({ contract, contractFile });
1345
- const path = await config.writeOutput("docs" /* Docs */, md, docFile);
1346
- return path[0];
1347
- }));
1367
+ const paths = await Promise.all(
1368
+ session.contracts.map(async (contract) => {
1369
+ var _a, _b;
1370
+ const name = (0, import_core10.getContractName)(contract.contract_id, false);
1371
+ if (excluded[name]) return null;
1372
+ const docFile = `${name}.md`;
1373
+ const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
1374
+ let contractFile;
1375
+ if (contractPathDef) {
1376
+ const contractPathFull = config.joinFromClarinet(contractPathDef);
1377
+ contractFile = (0, import_path6.relative)(docsBaseFolder, contractPathFull);
1378
+ } else {
1379
+ log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
1380
+ }
1381
+ const md = generateMarkdown({ contract, contractFile });
1382
+ const path = await config.writeOutput("docs" /* Docs */, md, docFile);
1383
+ return path[0];
1384
+ })
1385
+ );
1348
1386
  const readme = generateReadme(session, excluded);
1349
1387
  paths.push((await config.writeOutput("docs" /* Docs */, readme, "README.md"))[0]);
1350
1388
  await afterDocs(config);
1351
1389
  }
1352
1390
  function warnNoDocs() {
1353
- log.warn(`
1391
+ log.warn(
1392
+ `
1354
1393
  Clarigen config file doesn't include an output directory for docs.
1355
1394
 
1356
1395
  To generate docs, specify 'docs.output' in your config file:
1357
1396
 
1358
1397
  [docs]
1359
1398
  output = "docs/"
1360
- `.trimEnd());
1399
+ `.trimEnd()
1400
+ );
1361
1401
  }
1362
1402
 
1363
1403
  // src/commands/docs-command.ts
1364
1404
  var DocsCommand = class extends BaseCommand {
1405
+ static paths = [["docs"]];
1406
+ static usage = BaseCommand.Usage({
1407
+ description: "Generate markdown documentation for your Clarity contracts"
1408
+ });
1365
1409
  cwd = import_clipanion4.Option.String({ required: false });
1366
1410
  async execute() {
1367
1411
  this.preexecute();
1368
1412
  const config = await Config.load(this.cwd);
1369
1413
  const session = await getSession(config);
1370
1414
  await generateDocs({
1371
- session: __spreadProps(__spreadValues({}, session), {
1415
+ session: {
1416
+ ...session,
1372
1417
  variables: []
1373
- }),
1418
+ },
1374
1419
  config
1375
1420
  });
1376
1421
  }
1377
1422
  };
1378
- __publicField(DocsCommand, "paths", [["docs"]]);
1379
- __publicField(DocsCommand, "usage", BaseCommand.Usage({
1380
- description: "Generate markdown documentation for your Clarity contracts"
1381
- }));
1382
1423
 
1383
1424
  // src/commands/init-config-command.ts
1384
1425
  var import_clipanion5 = require("clipanion");
@@ -1419,6 +1460,10 @@ output = "docs"
1419
1460
 
1420
1461
  // src/commands/init-config-command.ts
1421
1462
  var InitConfigCommand = class extends BaseCommand {
1463
+ static paths = [["init-config"], ["init"]];
1464
+ static usage = {
1465
+ description: "Initialize a Clarigen configuration file"
1466
+ };
1422
1467
  cwd = import_clipanion5.Option.String({ required: false });
1423
1468
  overwrite = import_clipanion5.Option.Boolean("--overwrite", false, {
1424
1469
  description: "Overwrite the configuration file if it already exists"
@@ -1435,13 +1480,9 @@ var InitConfigCommand = class extends BaseCommand {
1435
1480
  await (0, import_promises6.writeFile)(path, tomlInit, "utf-8");
1436
1481
  }
1437
1482
  };
1438
- __publicField(InitConfigCommand, "paths", [["init-config"], ["init"]]);
1439
- __publicField(InitConfigCommand, "usage", {
1440
- description: "Initialize a Clarigen configuration file"
1441
- });
1442
1483
 
1443
1484
  // src/generated/version.ts
1444
- var version = "2.1.1";
1485
+ var version = "2.1.3";
1445
1486
 
1446
1487
  // src/run-cli.ts
1447
1488
  var [node, script, ...args] = process.argv;