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