@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.js CHANGED
@@ -1,39 +1,4 @@
1
1
  #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source)
24
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
- target[prop] = source[prop];
26
- if (source != null && __getOwnPropSymbols)
27
- for (var prop of __getOwnPropSymbols(source)) {
28
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
- target[prop] = source[prop];
30
- }
31
- return target;
32
- };
33
- var __publicField = (obj, key, value) => {
34
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
35
- return value;
36
- };
37
2
 
38
3
  // src/run-cli.ts
39
4
  import { Cli, Builtins } from "clipanion";
@@ -48,12 +13,14 @@ import { z as z2 } from "zod";
48
13
  import { pino } from "pino";
49
14
  import pinoPretty from "pino-pretty";
50
15
  var colorizedClarigen = `\x1B[33m[Clarigen]\x1B[0m`;
51
- var logger = pino(pinoPretty({
52
- colorize: true,
53
- ignore: "pid,hostname,time",
54
- messageFormat: `${colorizedClarigen} {msg}`,
55
- minimumLevel: "debug"
56
- }));
16
+ var logger = pino(
17
+ pinoPretty({
18
+ colorize: true,
19
+ ignore: "pid,hostname,time",
20
+ messageFormat: `${colorizedClarigen} {msg}`,
21
+ minimumLevel: "debug"
22
+ })
23
+ );
57
24
  logger.level = "info";
58
25
  var log = logger;
59
26
 
@@ -62,8 +29,7 @@ import { getContractName, toCamelCase } from "@clarigen/core";
62
29
  import { stat, mkdir, writeFile as fsWriteFile } from "fs/promises";
63
30
  import { dirname, relative } from "path";
64
31
  function encodeVariableName(name) {
65
- if (/^[A-Z\-_]*$/.test(name))
66
- return name.replaceAll("-", "_");
32
+ if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
67
33
  return toCamelCase(name);
68
34
  }
69
35
  async function fileExists(filename) {
@@ -117,7 +83,8 @@ var typesSchema = z2.object({
117
83
  outputs: z2.array(z2.string()).optional(),
118
84
  include_accounts: z2.boolean().optional(),
119
85
  after: z2.string().optional(),
120
- include_boot_contracts: z2.boolean().optional()
86
+ include_boot_contracts: z2.boolean().optional(),
87
+ watch_folders: z2.array(z2.string()).optional()
121
88
  }).optional();
122
89
  var ConfigFileSchema = z2.object({
123
90
  clarinet: z2.string(),
@@ -155,26 +122,25 @@ var Config = class {
155
122
  var _a, _b;
156
123
  const singlePath = (_a = this.configFile[type]) == null ? void 0 : _a.output;
157
124
  const multiPath = ((_b = this.configFile[type]) == null ? void 0 : _b.outputs) || [];
158
- if (singlePath !== void 0)
159
- return [singlePath];
125
+ if (singlePath !== void 0) return [singlePath];
160
126
  return multiPath;
161
127
  }
162
128
  outputResolve(type, filePath) {
163
129
  const outputs = this.getOutputs(type);
164
- if (!this.supports(type))
165
- return null;
130
+ if (!this.supports(type)) return null;
166
131
  return outputs.map((path) => {
167
132
  return resolve2(this.cwd, path, filePath || "");
168
133
  });
169
134
  }
170
135
  async writeOutput(type, contents, filePath) {
171
136
  const paths = this.outputResolve(type, filePath);
172
- if (paths === null)
173
- return null;
174
- await Promise.all(paths.map(async (path) => {
175
- await writeFile(path, contents);
176
- log.debug(`Generated ${type} file at ${relative2(this.cwd, path)}`);
177
- }));
137
+ if (paths === null) return null;
138
+ await Promise.all(
139
+ paths.map(async (path) => {
140
+ await writeFile(path, contents);
141
+ log.debug(`Generated ${type} file at ${relative2(this.cwd, path)}`);
142
+ })
143
+ );
178
144
  return paths;
179
145
  }
180
146
  supports(type) {
@@ -202,8 +168,7 @@ function configFilePath(cwd) {
202
168
  }
203
169
  var sessionConfig;
204
170
  async function getConfig(cwd) {
205
- if (typeof sessionConfig !== "undefined")
206
- return sessionConfig;
171
+ if (typeof sessionConfig !== "undefined") return sessionConfig;
207
172
  const path = configFilePath(cwd);
208
173
  if (await fileExists(path)) {
209
174
  const toml = await readFile2(path, "utf-8");
@@ -236,6 +201,7 @@ var BaseCommand = class extends Command {
236
201
  logger.level = "debug";
237
202
  }
238
203
  }
204
+ // eslint-disable-next-line @typescript-eslint/require-await
239
205
  async catch(error) {
240
206
  if (error instanceof ZodError) {
241
207
  logger.error(error.issues, "Your configuration file is invalid.");
@@ -251,6 +217,10 @@ var BaseCommand = class extends Command {
251
217
 
252
218
  // src/commands/session-info.ts
253
219
  var SessionInfoCommand = class extends BaseCommand {
220
+ static paths = [["session-info"]];
221
+ static usage = Command2.Usage({
222
+ description: "Log info about this project's Clarinet session"
223
+ });
254
224
  cwd = Option2.String({ required: false });
255
225
  async execute() {
256
226
  this.preexecute();
@@ -258,10 +228,6 @@ var SessionInfoCommand = class extends BaseCommand {
258
228
  logger.info(config);
259
229
  }
260
230
  };
261
- __publicField(SessionInfoCommand, "paths", [["session-info"]]);
262
- __publicField(SessionInfoCommand, "usage", Command2.Usage({
263
- description: "Log info about this project's Clarinet session"
264
- }));
265
231
 
266
232
  // src/commands/default-command.ts
267
233
  import { Command as Command3, Option as Option3 } from "clipanion";
@@ -298,12 +264,10 @@ import { toCamelCase as toCamelCase2 } from "@clarigen/core";
298
264
  var jsTypeFromAbiType = (val, isArgument = false) => {
299
265
  if (isClarityAbiPrimitive(val)) {
300
266
  if (val === "uint128") {
301
- if (isArgument)
302
- return "number | bigint";
267
+ if (isArgument) return "number | bigint";
303
268
  return "bigint";
304
269
  } else if (val === "int128") {
305
- if (isArgument)
306
- return "number | bigint";
270
+ if (isArgument) return "number | bigint";
307
271
  return "bigint";
308
272
  } else if (val === "bool") {
309
273
  return "boolean";
@@ -371,7 +335,50 @@ function _hash(...words) {
371
335
  }
372
336
  return h;
373
337
  }
374
- 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");
338
+ var RESERVED = _hash(
339
+ // Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
340
+ "break",
341
+ "do",
342
+ "in",
343
+ "typeof",
344
+ "case",
345
+ "else",
346
+ "instanceof",
347
+ "var",
348
+ "catch",
349
+ "export",
350
+ "new",
351
+ "void",
352
+ "class",
353
+ "extends",
354
+ "return",
355
+ "while",
356
+ "const",
357
+ "finally",
358
+ "super",
359
+ "with",
360
+ "continue",
361
+ "for",
362
+ "switch",
363
+ "yield",
364
+ "debugger",
365
+ "function",
366
+ "this",
367
+ "default",
368
+ "if",
369
+ "throw",
370
+ "delete",
371
+ "import",
372
+ "try",
373
+ // Future Reserved Words, ES6 11.6.2.2
374
+ // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
375
+ "enum",
376
+ "await",
377
+ // NullLiteral & BooleanLiteral
378
+ "null",
379
+ "true",
380
+ "false"
381
+ );
375
382
 
376
383
  // src/files/base.ts
377
384
  import { toCamelCase as toCamelCase3 } from "@clarigen/core";
@@ -379,10 +386,12 @@ import { toCamelCase as toCamelCase3 } from "@clarigen/core";
379
386
  // src/files/accounts.ts
380
387
  function generateAccountsCode(accounts) {
381
388
  const sortedAccounts = sortAccounts(accounts);
382
- const namedAccounts = Object.fromEntries(sortedAccounts.map((a) => {
383
- const _a = a, { name } = _a, rest = __objRest(_a, ["name"]);
384
- return [name, rest];
385
- }));
389
+ const namedAccounts = Object.fromEntries(
390
+ sortedAccounts.map((a) => {
391
+ const { name, ...rest } = a;
392
+ return [name, rest];
393
+ })
394
+ );
386
395
  return JSON.stringify(namedAccounts);
387
396
  }
388
397
  function sortAccounts(accounts) {
@@ -398,10 +407,12 @@ function sortAccounts(accounts) {
398
407
  // src/files/identifiers.ts
399
408
  import { getContractName as getContractName2 } from "@clarigen/core";
400
409
  function generateIdentifiers(session) {
401
- const identifiers = Object.fromEntries(sortContracts(session.contracts).map((c) => {
402
- const contractName = getContractName2(c.contract_id);
403
- return [contractName, c.contract_id];
404
- }));
410
+ const identifiers = Object.fromEntries(
411
+ sortContracts(session.contracts).map((c) => {
412
+ const contractName = getContractName2(c.contract_id);
413
+ return [contractName, c.contract_id];
414
+ })
415
+ );
405
416
  return identifiers;
406
417
  }
407
418
  function generateIdentifiersCode(session) {
@@ -414,7 +425,7 @@ import { inspect } from "util";
414
425
  function generateContractMeta(contract, constants) {
415
426
  const abi = contract.contract_interface;
416
427
  const functionLines = [];
417
- const _a = abi, { functions, maps, variables, non_fungible_tokens } = _a, rest = __objRest(_a, ["functions", "maps", "variables", "non_fungible_tokens"]);
428
+ const { functions, maps, variables, non_fungible_tokens, ...rest } = abi;
418
429
  functions.forEach((func) => {
419
430
  let functionLine = `${toCamelCase3(func.name)}: `;
420
431
  const funcDef = JSON.stringify(func);
@@ -449,7 +460,8 @@ function generateContractMeta(contract, constants) {
449
460
  }
450
461
  var TYPE_IMPORTS = `import type { TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, Response } from '@clarigen/core';`;
451
462
  function generateBaseFile(session) {
452
- const combined = session.contracts.map((c, i) => __spreadProps(__spreadValues({}, c), {
463
+ const combined = session.contracts.map((c, i) => ({
464
+ ...c,
453
465
  constants: session.variables[i]
454
466
  }));
455
467
  const contractDefs = sortContracts(combined).map((contract) => {
@@ -492,14 +504,20 @@ Uint8Array.prototype[inspect.custom] = function(depth, options) {
492
504
  };
493
505
  function serialize(obj) {
494
506
  return inspect(obj, {
507
+ // showHidden: false,
508
+ // depth: 100,
509
+ // colors: false,
495
510
  showHidden: false,
511
+ // iterableLimit: 100000,
496
512
  compact: false,
513
+ // trailingComma: true,
497
514
  depth: 100,
498
515
  colors: false,
499
516
  maxArrayLength: Infinity,
500
517
  maxStringLength: Infinity,
501
518
  breakLength: Infinity,
502
519
  numericSeparator: true
520
+ // strAbbreviateSize: 100000,
503
521
  });
504
522
  }
505
523
  function serializeLines(key, lines) {
@@ -519,7 +537,9 @@ function getVariablesV2(contract, simnet, verbose) {
519
537
  const fakeId = `${getContractName3(contract.contract_id)}-vars`;
520
538
  logger.debug(`Deploying ${contract.contract_id} for variables.`);
521
539
  if (!contract.source) {
522
- logger.debug(`Contract ${getContractName3(contract.contract_id)} has no source. Skipping variables.`);
540
+ logger.debug(
541
+ `Contract ${getContractName3(contract.contract_id)} has no source. Skipping variables.`
542
+ );
523
543
  return {};
524
544
  }
525
545
  if (contract.contract_interface.variables.length === 0) {
@@ -543,9 +563,14 @@ function getVariablesV2(contract, simnet, verbose) {
543
563
 
544
564
  ${varFn}`;
545
565
  try {
546
- const receipt = simnet.deployContract(fakeId, fullSrc, {
547
- clarityVersion: 3
548
- }, deployer);
566
+ const receipt = simnet.deployContract(
567
+ fakeId,
568
+ fullSrc,
569
+ {
570
+ clarityVersion: 3
571
+ },
572
+ deployer
573
+ );
549
574
  const result = receipt.result;
550
575
  const varsAbi = {
551
576
  tuple: []
@@ -562,10 +587,10 @@ ${varFn}`;
562
587
  }
563
588
  return cvToValue(result, true);
564
589
  } catch (error) {
565
- logger.error(`Error getting variables for ${getContractName3(contract.contract_id, false)}`);
566
- logger.error(`Source code: ${contract.source} with type ${String(typeof contract.source)}`);
567
- logger.error(error);
568
- logger.error(fullSrc);
590
+ logger.warn(
591
+ { err: error },
592
+ `Error getting variables for ${getContractName3(contract.contract_id, false)}`
593
+ );
569
594
  return {};
570
595
  }
571
596
  }
@@ -593,24 +618,26 @@ async function getSession(config) {
593
618
  balance: resultCV.toString()
594
619
  };
595
620
  });
596
- const contracts = (await Promise.all([...interfaces.entries()].map(async ([contract_id, contract_interface]) => {
597
- var _a, _b, _c;
598
- if (contract_id.startsWith(MAINNET_BURN_ADDRESS) && ((_a = config.esm) == null ? void 0 : _a.include_boot_contracts) !== true || contract_id.startsWith(TESTNET_BURN_ADDRESS)) {
599
- return void 0;
600
- }
601
- const name = getContractName4(contract_id, false);
602
- const contractPathDef = (_c = (_b = config.clarinet.contracts) == null ? void 0 : _b[name]) == null ? void 0 : _c.path;
603
- let source;
604
- if (contractPathDef) {
605
- const contractPathFull = config.joinFromClarinet(contractPathDef);
606
- source = await readFile3(contractPathFull, "utf-8");
607
- }
608
- return {
609
- contract_id,
610
- contract_interface,
611
- source: source ?? ""
612
- };
613
- }))).filter((x) => x !== void 0);
621
+ const contracts = (await Promise.all(
622
+ [...interfaces.entries()].map(async ([contract_id, contract_interface]) => {
623
+ var _a, _b, _c;
624
+ if (contract_id.startsWith(MAINNET_BURN_ADDRESS) && ((_a = config.esm) == null ? void 0 : _a.include_boot_contracts) !== true || contract_id.startsWith(TESTNET_BURN_ADDRESS)) {
625
+ return void 0;
626
+ }
627
+ const name = getContractName4(contract_id, false);
628
+ const contractPathDef = (_c = (_b = config.clarinet.contracts) == null ? void 0 : _b[name]) == null ? void 0 : _c.path;
629
+ let source;
630
+ if (contractPathDef) {
631
+ const contractPathFull = config.joinFromClarinet(contractPathDef);
632
+ source = await readFile3(contractPathFull, "utf-8");
633
+ }
634
+ return {
635
+ contract_id,
636
+ contract_interface,
637
+ source: source ?? ""
638
+ };
639
+ })
640
+ )).filter((x) => x !== void 0);
614
641
  const session = {
615
642
  session_id: 0,
616
643
  accounts: allAccounts,
@@ -622,6 +649,7 @@ async function getSession(config) {
622
649
  accounts: allAccounts,
623
650
  contracts,
624
651
  variables
652
+ // variables: [],
625
653
  };
626
654
  }
627
655
 
@@ -643,8 +671,7 @@ function getContractTxs(batches) {
643
671
  function getDeploymentContract(contractName, deployment) {
644
672
  const txs = flatBatch(deployment.plan.batches);
645
673
  for (const tx of txs) {
646
- if (!isContractTx(tx))
647
- continue;
674
+ if (!isContractTx(tx)) continue;
648
675
  if ("requirement-publish" in tx) {
649
676
  const [_, name] = tx["requirement-publish"]["contract-id"].split(".");
650
677
  if (name === contractName) {
@@ -696,12 +723,9 @@ function getIdentifier(tx) {
696
723
  throw new Error(`Unable to find ID for contract.`);
697
724
  }
698
725
  function isContractTx(tx) {
699
- if ("contract-call" in tx)
700
- return false;
701
- if ("btc-transfer" in tx)
702
- return false;
703
- if ("emulated-contract-call" in tx)
704
- return false;
726
+ if ("contract-call" in tx) return false;
727
+ if ("btc-transfer" in tx) return false;
728
+ if ("emulated-contract-call" in tx) return false;
705
729
  return true;
706
730
  }
707
731
 
@@ -715,16 +739,18 @@ async function parseDeployment(path) {
715
739
  }
716
740
  var DEPLOYMENT_NETWORKS = ["devnet", "simnet", "testnet", "mainnet"];
717
741
  async function getDeployments(config) {
718
- const entries = await Promise.all(DEPLOYMENT_NETWORKS.map(async (network) => {
719
- const file = `default.${network}-plan.yaml`;
720
- const path = join2(dirname3(config.clarinetFile()), "deployments", file);
721
- let plan;
722
- try {
723
- plan = await parseDeployment(path);
724
- } catch (_) {
725
- }
726
- return [network, plan];
727
- }));
742
+ const entries = await Promise.all(
743
+ DEPLOYMENT_NETWORKS.map(async (network) => {
744
+ const file = `default.${network}-plan.yaml`;
745
+ const path = join2(dirname3(config.clarinetFile()), "deployments", file);
746
+ let plan;
747
+ try {
748
+ plan = await parseDeployment(path);
749
+ } catch (_) {
750
+ }
751
+ return [network, plan];
752
+ })
753
+ );
728
754
  return Object.fromEntries(entries);
729
755
  }
730
756
  async function generateESMFile({
@@ -755,24 +781,28 @@ function insertNetworkId(deployments, identifier, network) {
755
781
  }
756
782
  function collectContractDeployments(session, deployments, config) {
757
783
  var _a;
758
- const full = Object.fromEntries(sortContracts(session.contracts).map((contract) => {
759
- const contractName = getContractName5(contract.contract_id);
760
- const contractDeployments = Object.fromEntries(DEPLOYMENT_NETWORKS.map((network) => {
761
- const deployment = deployments[network];
762
- if (typeof deployment === "undefined") {
763
- return [network, null];
764
- }
765
- try {
766
- const contractName2 = contract.contract_id.split(".")[1];
767
- const tx = getDeploymentContract(contractName2, deployment);
768
- const id = getIdentifier(tx);
769
- return [network, id];
770
- } catch (_) {
771
- return [network, null];
772
- }
773
- }));
774
- return [contractName, contractDeployments];
775
- }));
784
+ const full = Object.fromEntries(
785
+ sortContracts(session.contracts).map((contract) => {
786
+ const contractName = getContractName5(contract.contract_id);
787
+ const contractDeployments = Object.fromEntries(
788
+ DEPLOYMENT_NETWORKS.map((network) => {
789
+ const deployment = deployments[network];
790
+ if (typeof deployment === "undefined") {
791
+ return [network, null];
792
+ }
793
+ try {
794
+ const contractName2 = contract.contract_id.split(".")[1];
795
+ const tx = getDeploymentContract(contractName2, deployment);
796
+ const id = getIdentifier(tx);
797
+ return [network, id];
798
+ } catch (_) {
799
+ return [network, null];
800
+ }
801
+ })
802
+ );
803
+ return [contractName, contractDeployments];
804
+ })
805
+ );
776
806
  const deployer = session.accounts.find((a) => a.name === "deployer");
777
807
  (_a = config.clarinet.project.requirements) == null ? void 0 : _a.forEach(({ contract_id }) => {
778
808
  insertNetworkId(full, contract_id, "mainnet");
@@ -789,8 +819,7 @@ function collectContractDeployments(session, deployments, config) {
789
819
  return full;
790
820
  }
791
821
  function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
792
- if (!deployments.simnet)
793
- return [];
822
+ if (!deployments.simnet) return [];
794
823
  const simnet = deployments.simnet;
795
824
  const txs = getContractTxs(simnet.plan.batches);
796
825
  const entries = txs.map((tx) => {
@@ -805,8 +834,7 @@ function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
805
834
  }
806
835
  function generateSimnetCode(config, deployments, _session) {
807
836
  var _a;
808
- if (!((_a = config.esm) == null ? void 0 : _a.include_accounts))
809
- return "";
837
+ if (!((_a = config.esm) == null ? void 0 : _a.include_accounts)) return "";
810
838
  const clarinetFolder = dirname3(config.clarinetFile());
811
839
  const files = collectDeploymentFiles(deployments, clarinetFolder, config.cwd);
812
840
  return `
@@ -816,8 +844,7 @@ export const simnetDeployment = ${JSON.stringify(files)};
816
844
  async function afterESM(config) {
817
845
  var _a;
818
846
  const command = (_a = config.esm) == null ? void 0 : _a.after;
819
- if (!command)
820
- return;
847
+ if (!command) return;
821
848
  logger.debug(`Running after ESM command: ${command}`);
822
849
  const parts = command.split(" ");
823
850
  const [cmd, ...args2] = parts;
@@ -859,16 +886,19 @@ async function generate(config) {
859
886
  }
860
887
  async function watch(config, cwd) {
861
888
  return new Promise(async (resolve3, reject) => {
862
- const clarinetFolder = dirname4(config.clarinetFile());
863
- const contractsFolder = join3(clarinetFolder, "/contracts/**/*.clar");
889
+ var _a;
864
890
  try {
865
891
  await generate(config);
866
892
  } catch (error) {
867
893
  logger.error({ error }, "Error generating types");
868
894
  }
895
+ const clarinetFolder = dirname4(config.clarinetFile());
896
+ const contractsFolder = join3(clarinetFolder, "/contracts/**/*.clar");
869
897
  const relativeFolder = relative4(cwd || process.cwd(), contractsFolder);
870
- logger.info(`Watching for changes in ${relativeFolder}`);
871
- const watcher = chokidar.watch(contractsFolder, { persistent: true, cwd: clarinetFolder });
898
+ const watchFolders = ((_a = config.esm) == null ? void 0 : _a.watch_folders) ?? [];
899
+ watchFolders.push(relativeFolder);
900
+ logger.info(`Watching for changes in ${watchFolders}`);
901
+ const watcher = chokidar.watch(watchFolders, { persistent: true, cwd: clarinetFolder });
872
902
  let running = false;
873
903
  let start = 0;
874
904
  const isVerbose = logger.level !== "info";
@@ -884,7 +914,9 @@ async function watch(config, cwd) {
884
914
  process.stdout.moveCursor(0, -1);
885
915
  process.stdout.clearLine(1);
886
916
  const elapsed = Date.now() - start;
887
- logger.info(`Types generated (${(elapsed / 1e3).toFixed(2)}s). Watching for changes...`);
917
+ logger.info(
918
+ `Types generated (${(elapsed / 1e3).toFixed(2)}s). Watching for changes...`
919
+ );
888
920
  running = false;
889
921
  });
890
922
  });
@@ -893,6 +925,16 @@ async function watch(config, cwd) {
893
925
  });
894
926
  }
895
927
  var DefaultCommand = class extends BaseCommand {
928
+ static paths = [Command3.Default, ["generate"]];
929
+ // static description = 'Generate types for your Clarity contracts';
930
+ static usage = Command3.Usage({
931
+ description: "Generate types for your Clarity contracts",
932
+ examples: [
933
+ ["Basic usage:", "clarigen"],
934
+ ["When your `Clarigen.toml` is in a different directory:", "clarigen /path/to/your/project"],
935
+ ["Watch for changes and regenerate types:", "clarigen --watch"]
936
+ ]
937
+ });
896
938
  cwd = Option3.String({
897
939
  required: false
898
940
  });
@@ -910,15 +952,6 @@ var DefaultCommand = class extends BaseCommand {
910
952
  }
911
953
  }
912
954
  };
913
- __publicField(DefaultCommand, "paths", [Command3.Default, ["generate"]]);
914
- __publicField(DefaultCommand, "usage", Command3.Usage({
915
- description: "Generate types for your Clarity contracts",
916
- examples: [
917
- ["Basic usage:", "clarigen"],
918
- ["When your `Clarigen.toml` is in a different directory:", "clarigen /path/to/your/project"],
919
- ["Watch for changes and regenerate types:", "clarigen --watch"]
920
- ]
921
- }));
922
955
 
923
956
  // src/commands/docs-command.ts
924
957
  import { Option as Option4 } from "clipanion";
@@ -1022,8 +1055,7 @@ function findItemNameFromLine(line) {
1022
1055
  }
1023
1056
  for (const type of VAR_TYPES) {
1024
1057
  const prefix = `(define-${type} `;
1025
- if (!line.startsWith(prefix))
1026
- continue;
1058
+ if (!line.startsWith(prefix)) continue;
1027
1059
  const startString = line.slice(prefix.length);
1028
1060
  const match = clarityNameMatcher(startString);
1029
1061
  if (!match) {
@@ -1039,11 +1071,9 @@ function findAbiItemByName(abi, name) {
1039
1071
  const fn = abi.functions.find((fn2) => {
1040
1072
  return fn2.name === name;
1041
1073
  });
1042
- if (fn)
1043
- return fn;
1074
+ if (fn) return fn;
1044
1075
  const map = abi.maps.find((m) => m.name === name);
1045
- if (map)
1046
- return map;
1076
+ if (map) return map;
1047
1077
  const v = abi.variables.find((v2) => v2.name === name);
1048
1078
  return v;
1049
1079
  }
@@ -1053,10 +1083,8 @@ function isComment(line) {
1053
1083
  function traceParens(line, count) {
1054
1084
  let newCount = count;
1055
1085
  line.split("").forEach((char) => {
1056
- if (char === "(")
1057
- newCount++;
1058
- if (char === ")")
1059
- newCount--;
1086
+ if (char === "(") newCount++;
1087
+ if (char === ")") newCount--;
1060
1088
  });
1061
1089
  return newCount;
1062
1090
  }
@@ -1077,8 +1105,7 @@ function parseComments(comments, abi) {
1077
1105
  }
1078
1106
  return;
1079
1107
  }
1080
- if (!("args" in abi))
1081
- return;
1108
+ if (!("args" in abi)) return;
1082
1109
  const [_full, name, _separator, rest] = paramMatches;
1083
1110
  const arg = abi.args.find((arg2) => arg2.name === name);
1084
1111
  if (!arg) {
@@ -1106,8 +1133,7 @@ function parseComments(comments, abi) {
1106
1133
  async function afterDocs(config) {
1107
1134
  var _a;
1108
1135
  const command = (_a = config.docs) == null ? void 0 : _a.after;
1109
- if (!command)
1110
- return;
1136
+ if (!command) return;
1111
1137
  logger.debug(`Running after docs command: ${command}`);
1112
1138
  const parts = command.split(" ");
1113
1139
  const [cmd, ...args2] = parts;
@@ -1193,7 +1219,9 @@ ${fn.source.join("\n")}
1193
1219
  \`\`\`
1194
1220
  </details>
1195
1221
  `;
1196
- const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(" ")}) ${returnType})`;
1222
+ const sig = `(define-${fn.abi.access.replace("_", "-")} (${fn.abi.name} (${paramSigs.join(
1223
+ " "
1224
+ )}) ${returnType})`;
1197
1225
  return `### ${fn.abi.name}
1198
1226
 
1199
1227
  ${link}
@@ -1207,8 +1235,7 @@ ${source}
1207
1235
  ${params}`;
1208
1236
  }
1209
1237
  function mdParams(fn) {
1210
- if (fn.abi.args.length === 0)
1211
- return "";
1238
+ if (fn.abi.args.length === 0) return "";
1212
1239
  const hasDescription = Object.values(fn.comments.params).some((p) => p.comments.length > 0);
1213
1240
  const params = Object.values(fn.comments.params).map((p) => markdownParam(p, hasDescription));
1214
1241
  return `**Parameters:**
@@ -1220,8 +1247,7 @@ ${params.join("\n")}`;
1220
1247
  function markdownParam(param, withDescription) {
1221
1248
  const typeString = getTypeString(param.abi.type);
1222
1249
  const base = `| ${param.abi.name} | ${typeString} |`;
1223
- if (!withDescription)
1224
- return base;
1250
+ if (!withDescription) return base;
1225
1251
  return `${base} ${param.comments.join(" ")} |`;
1226
1252
  }
1227
1253
  function markdownMap(map, contractFile) {
@@ -1299,8 +1325,7 @@ function generateReadme(session, excluded) {
1299
1325
  const contractLines = [];
1300
1326
  sortContracts(session.contracts).forEach((contract) => {
1301
1327
  const name = getContractName6(contract.contract_id, false);
1302
- if (excluded[name])
1303
- return;
1328
+ if (excluded[name]) return;
1304
1329
  const fileName = `${name}.md`;
1305
1330
  const line = `- [\`${name}\`](${fileName})`;
1306
1331
  contractLines.push(line);
@@ -1327,63 +1352,69 @@ async function generateDocs({
1327
1352
  if (docsPathExt) {
1328
1353
  log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
1329
1354
  }
1330
- const excluded = Object.fromEntries((docs.exclude || []).map((e) => {
1331
- return [e, true];
1332
- }));
1355
+ const excluded = Object.fromEntries(
1356
+ (docs.exclude || []).map((e) => {
1357
+ return [e, true];
1358
+ })
1359
+ );
1333
1360
  log.debug(`Generating docs at path \`${docsBase}\``);
1334
1361
  const docsBaseFolder = config.outputResolve("docs" /* Docs */, "./")[0];
1335
- const paths = await Promise.all(session.contracts.map(async (contract) => {
1336
- var _a, _b;
1337
- const name = getContractName7(contract.contract_id, false);
1338
- if (excluded[name])
1339
- return null;
1340
- const docFile = `${name}.md`;
1341
- const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
1342
- let contractFile;
1343
- if (contractPathDef) {
1344
- const contractPathFull = config.joinFromClarinet(contractPathDef);
1345
- contractFile = relative5(docsBaseFolder, contractPathFull);
1346
- } else {
1347
- log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
1348
- }
1349
- const md = generateMarkdown({ contract, contractFile });
1350
- const path = await config.writeOutput("docs" /* Docs */, md, docFile);
1351
- return path[0];
1352
- }));
1362
+ const paths = await Promise.all(
1363
+ session.contracts.map(async (contract) => {
1364
+ var _a, _b;
1365
+ const name = getContractName7(contract.contract_id, false);
1366
+ if (excluded[name]) return null;
1367
+ const docFile = `${name}.md`;
1368
+ const contractPathDef = (_b = (_a = config.clarinet.contracts) == null ? void 0 : _a[name]) == null ? void 0 : _b.path;
1369
+ let contractFile;
1370
+ if (contractPathDef) {
1371
+ const contractPathFull = config.joinFromClarinet(contractPathDef);
1372
+ contractFile = relative5(docsBaseFolder, contractPathFull);
1373
+ } else {
1374
+ log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
1375
+ }
1376
+ const md = generateMarkdown({ contract, contractFile });
1377
+ const path = await config.writeOutput("docs" /* Docs */, md, docFile);
1378
+ return path[0];
1379
+ })
1380
+ );
1353
1381
  const readme = generateReadme(session, excluded);
1354
1382
  paths.push((await config.writeOutput("docs" /* Docs */, readme, "README.md"))[0]);
1355
1383
  await afterDocs(config);
1356
1384
  }
1357
1385
  function warnNoDocs() {
1358
- log.warn(`
1386
+ log.warn(
1387
+ `
1359
1388
  Clarigen config file doesn't include an output directory for docs.
1360
1389
 
1361
1390
  To generate docs, specify 'docs.output' in your config file:
1362
1391
 
1363
1392
  [docs]
1364
1393
  output = "docs/"
1365
- `.trimEnd());
1394
+ `.trimEnd()
1395
+ );
1366
1396
  }
1367
1397
 
1368
1398
  // src/commands/docs-command.ts
1369
1399
  var DocsCommand = class extends BaseCommand {
1400
+ static paths = [["docs"]];
1401
+ static usage = BaseCommand.Usage({
1402
+ description: "Generate markdown documentation for your Clarity contracts"
1403
+ });
1370
1404
  cwd = Option4.String({ required: false });
1371
1405
  async execute() {
1372
1406
  this.preexecute();
1373
1407
  const config = await Config.load(this.cwd);
1374
1408
  const session = await getSession(config);
1375
1409
  await generateDocs({
1376
- session: __spreadProps(__spreadValues({}, session), {
1410
+ session: {
1411
+ ...session,
1377
1412
  variables: []
1378
- }),
1413
+ },
1379
1414
  config
1380
1415
  });
1381
1416
  }
1382
1417
  };
1383
- __publicField(DocsCommand, "paths", [["docs"]]);
1384
- __publicField(DocsCommand, "usage", BaseCommand.Usage({
1385
- description: "Generate markdown documentation for your Clarity contracts"
1386
- }));
1387
1418
 
1388
1419
  // src/commands/init-config-command.ts
1389
1420
  import { Option as Option5 } from "clipanion";
@@ -1424,6 +1455,10 @@ output = "docs"
1424
1455
 
1425
1456
  // src/commands/init-config-command.ts
1426
1457
  var InitConfigCommand = class extends BaseCommand {
1458
+ static paths = [["init-config"], ["init"]];
1459
+ static usage = {
1460
+ description: "Initialize a Clarigen configuration file"
1461
+ };
1427
1462
  cwd = Option5.String({ required: false });
1428
1463
  overwrite = Option5.Boolean("--overwrite", false, {
1429
1464
  description: "Overwrite the configuration file if it already exists"
@@ -1440,13 +1475,9 @@ var InitConfigCommand = class extends BaseCommand {
1440
1475
  await writeFile2(path, tomlInit, "utf-8");
1441
1476
  }
1442
1477
  };
1443
- __publicField(InitConfigCommand, "paths", [["init-config"], ["init"]]);
1444
- __publicField(InitConfigCommand, "usage", {
1445
- description: "Initialize a Clarigen configuration file"
1446
- });
1447
1478
 
1448
1479
  // src/generated/version.ts
1449
- var version = "2.1.1";
1480
+ var version = "2.1.3";
1450
1481
 
1451
1482
  // src/run-cli.ts
1452
1483
  var [node, script, ...args] = process.argv;