@clarigen/cli 4.0.2-alpha.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm-CO92uOgU.mjs → esm-BjGH_MkS.mjs} +85 -245
- package/dist/esm-BjGH_MkS.mjs.map +1 -0
- package/dist/{esm-CRbGFHSR.cjs → esm-DPOm6Bdw.cjs} +114 -316
- package/dist/esm-DPOm6Bdw.cjs.map +1 -0
- package/dist/index.cjs +1 -8
- package/dist/index.d.cts +21 -64
- package/dist/index.d.mts +21 -64
- package/dist/index.mjs +2 -2
- package/dist/run-cli.cjs +53 -50
- package/dist/run-cli.cjs.map +1 -1
- package/dist/run-cli.mjs +51 -48
- package/dist/run-cli.mjs.map +1 -1
- package/package.json +17 -15
- package/dist/esm-CO92uOgU.mjs.map +0 -1
- package/dist/esm-CRbGFHSR.cjs.map +0 -1
|
@@ -26,233 +26,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let __clarigen_core = require("@clarigen/core");
|
|
29
|
+
let __clarigen_docs = require("@clarigen/docs");
|
|
30
|
+
let node_path = require("node:path");
|
|
31
|
+
let node_fs_promises = require("node:fs/promises");
|
|
29
32
|
let pino = require("pino");
|
|
30
33
|
let pino_pretty = require("pino-pretty");
|
|
31
34
|
pino_pretty = __toESM(pino_pretty);
|
|
32
|
-
let
|
|
33
|
-
let path = require("path");
|
|
34
|
-
let fs_promises = require("fs/promises");
|
|
35
|
+
let node_child_process = require("node:child_process");
|
|
35
36
|
let arktype = require("arktype");
|
|
36
37
|
let __iarna_toml = require("@iarna/toml");
|
|
37
|
-
let
|
|
38
|
+
let node_util = require("node:util");
|
|
38
39
|
let yaml = require("yaml");
|
|
39
40
|
let __clarigen_core_deployment = require("@clarigen/core/deployment");
|
|
40
41
|
|
|
41
|
-
//#region src/logger.ts
|
|
42
|
-
const colorizedClarigen = `\x1b[33m[Clarigen]\x1b[0m`;
|
|
43
|
-
const logger = (0, pino.pino)((0, pino_pretty.default)({
|
|
44
|
-
colorize: true,
|
|
45
|
-
ignore: "pid,hostname,time",
|
|
46
|
-
messageFormat: `${colorizedClarigen} {msg}`,
|
|
47
|
-
minimumLevel: "debug"
|
|
48
|
-
}));
|
|
49
|
-
logger.level = "info";
|
|
50
|
-
const log = logger;
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/docs/index.ts
|
|
54
|
-
const FN_TYPES = [
|
|
55
|
-
"read-only",
|
|
56
|
-
"public",
|
|
57
|
-
"private"
|
|
58
|
-
];
|
|
59
|
-
const VAR_TYPES = [
|
|
60
|
-
"map",
|
|
61
|
-
"data-var",
|
|
62
|
-
"constant"
|
|
63
|
-
];
|
|
64
|
-
function createContractDocInfo({ contractSrc, abi }) {
|
|
65
|
-
const lines = contractSrc.split("\n");
|
|
66
|
-
let comments = [];
|
|
67
|
-
let parensCount = 0;
|
|
68
|
-
let currentFn;
|
|
69
|
-
const contract = {
|
|
70
|
-
comments: [],
|
|
71
|
-
functions: [],
|
|
72
|
-
variables: [],
|
|
73
|
-
maps: []
|
|
74
|
-
};
|
|
75
|
-
lines.forEach((line, lineNumber) => {
|
|
76
|
-
if (currentFn) {
|
|
77
|
-
currentFn.source.push(line);
|
|
78
|
-
parensCount = traceParens(line, parensCount);
|
|
79
|
-
if (parensCount === 0) {
|
|
80
|
-
pushItem(contract, currentFn);
|
|
81
|
-
currentFn = void 0;
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (isComment(line)) {
|
|
86
|
-
const comment = line.replace(/^\s*;;\s*/g, "");
|
|
87
|
-
if (contract.comments.length === lineNumber) contract.comments.push(comment);
|
|
88
|
-
else comments.push(comment);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const name = findItemNameFromLine(line);
|
|
92
|
-
if (typeof name === "undefined") comments = [];
|
|
93
|
-
else {
|
|
94
|
-
const abiFn = findAbiItemByName(abi, name);
|
|
95
|
-
if (!abiFn) {
|
|
96
|
-
console.debug(`[claridoc]: Unable to find ABI for function \`${name}\`. Probably a bug.`);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
parensCount = traceParens(line, 0);
|
|
100
|
-
currentFn = {
|
|
101
|
-
abi: abiFn,
|
|
102
|
-
comments: parseComments(comments, abiFn),
|
|
103
|
-
startLine: lineNumber,
|
|
104
|
-
source: [line]
|
|
105
|
-
};
|
|
106
|
-
if (parensCount === 0) {
|
|
107
|
-
pushItem(contract, currentFn);
|
|
108
|
-
currentFn = void 0;
|
|
109
|
-
}
|
|
110
|
-
comments = [];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
return contract;
|
|
114
|
-
}
|
|
115
|
-
function pushItem(contract, item) {
|
|
116
|
-
if ("args" in item.abi) contract.functions.push(item);
|
|
117
|
-
else if ("key" in item.abi) contract.maps.push(item);
|
|
118
|
-
else if ("access" in item.abi) contract.variables.push(item);
|
|
119
|
-
}
|
|
120
|
-
function clarityNameMatcher(line) {
|
|
121
|
-
return /[\w|\-|\?|\!]+/.exec(line);
|
|
122
|
-
}
|
|
123
|
-
function findItemNameFromLine(line) {
|
|
124
|
-
const fnType = FN_TYPES.find((type$2) => {
|
|
125
|
-
return line.startsWith(`(define-${type$2}`);
|
|
126
|
-
});
|
|
127
|
-
if (fnType) {
|
|
128
|
-
const prefix = `(define-${fnType} (`;
|
|
129
|
-
const match = clarityNameMatcher(line.slice(prefix.length));
|
|
130
|
-
if (!match) {
|
|
131
|
-
console.debug(`[claridocs]: Unable to determine function name from line:\n \`${line}\``);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
return match[0];
|
|
135
|
-
}
|
|
136
|
-
for (const type$2 of VAR_TYPES) {
|
|
137
|
-
const prefix = `(define-${type$2} `;
|
|
138
|
-
if (!line.startsWith(prefix)) continue;
|
|
139
|
-
const match = clarityNameMatcher(line.slice(prefix.length));
|
|
140
|
-
if (!match) {
|
|
141
|
-
console.debug(`[claridocs]: Unable to determine ${type$2} name from line:\n \`${line}\``);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
return match[0];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function findAbiItemByName(abi, name) {
|
|
148
|
-
const fn = abi.functions.find((fn$1) => {
|
|
149
|
-
return fn$1.name === name;
|
|
150
|
-
});
|
|
151
|
-
if (fn) return fn;
|
|
152
|
-
const map = abi.maps.find((m) => m.name === name);
|
|
153
|
-
if (map) return map;
|
|
154
|
-
return abi.variables.find((v) => v.name === name);
|
|
155
|
-
}
|
|
156
|
-
function isComment(line) {
|
|
157
|
-
return line.startsWith(";;");
|
|
158
|
-
}
|
|
159
|
-
function getFnName(line) {
|
|
160
|
-
const fnType = FN_TYPES.find((type$2) => {
|
|
161
|
-
return line.startsWith(`(define-${type$2}`);
|
|
162
|
-
});
|
|
163
|
-
if (typeof fnType === "undefined") return;
|
|
164
|
-
const prefix = `(define-${fnType} (`;
|
|
165
|
-
const match = clarityNameMatcher(line.slice(prefix.length));
|
|
166
|
-
if (!match) {
|
|
167
|
-
console.debug(`[claridocs]: Unable to determine function name from line:\n \`${line}\``);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
return match[0];
|
|
171
|
-
}
|
|
172
|
-
function traceParens(line, count) {
|
|
173
|
-
let newCount = count;
|
|
174
|
-
line.split("").forEach((char) => {
|
|
175
|
-
if (char === "(") newCount++;
|
|
176
|
-
if (char === ")") newCount--;
|
|
177
|
-
});
|
|
178
|
-
return newCount;
|
|
179
|
-
}
|
|
180
|
-
function parseComments(comments, abi) {
|
|
181
|
-
let curParam;
|
|
182
|
-
const parsed = {
|
|
183
|
-
text: [],
|
|
184
|
-
params: {}
|
|
185
|
-
};
|
|
186
|
-
comments.forEach((line) => {
|
|
187
|
-
const paramMatches = /\s*@param\s([\w|\-]+)([;|-|\s]*)(.*)/.exec(line);
|
|
188
|
-
if (paramMatches === null) {
|
|
189
|
-
if (!curParam || line.trim() === "") {
|
|
190
|
-
curParam = void 0;
|
|
191
|
-
parsed.text.push(line);
|
|
192
|
-
} else parsed.params[curParam].comments.push(line);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (!("args" in abi)) return;
|
|
196
|
-
const [_full, name, _separator, rest] = paramMatches;
|
|
197
|
-
const arg = abi.args.find((arg$1) => arg$1.name === name);
|
|
198
|
-
if (!arg) {
|
|
199
|
-
console.debug(`[claridocs]: Unable to find ABI for @param ${name}`);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
curParam = name;
|
|
203
|
-
parsed.params[curParam] = {
|
|
204
|
-
abi: arg,
|
|
205
|
-
comments: [rest]
|
|
206
|
-
};
|
|
207
|
-
});
|
|
208
|
-
if ("args" in abi) abi.args.forEach((arg) => {
|
|
209
|
-
if (!parsed.params[arg.name]) parsed.params[arg.name] = {
|
|
210
|
-
abi: arg,
|
|
211
|
-
comments: []
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
return parsed;
|
|
215
|
-
}
|
|
216
|
-
async function afterDocs(config) {
|
|
217
|
-
var _config$docs;
|
|
218
|
-
const command = (_config$docs = config.docs) === null || _config$docs === void 0 ? void 0 : _config$docs.after;
|
|
219
|
-
if (!command) return;
|
|
220
|
-
logger.debug(`Running after docs command: ${command}`);
|
|
221
|
-
const [cmd, ...args] = command.split(" ");
|
|
222
|
-
return new Promise((resolve$1, reject) => {
|
|
223
|
-
const child = (0, child_process.spawn)(cmd, args, {
|
|
224
|
-
cwd: config.cwd,
|
|
225
|
-
stdio: "inherit"
|
|
226
|
-
});
|
|
227
|
-
child.on("error", reject);
|
|
228
|
-
child.on("exit", (code) => {
|
|
229
|
-
if (code === 0) resolve$1();
|
|
230
|
-
else reject(/* @__PURE__ */ new Error(`Command failed with code ${code ?? "unknown"}`));
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
//#endregion
|
|
236
42
|
//#region src/utils.ts
|
|
43
|
+
/** biome-ignore-all lint/style/useTrimStartEnd: suppressed */
|
|
237
44
|
function encodeVariableName(name) {
|
|
238
45
|
if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll("-", "_");
|
|
239
46
|
return (0, __clarigen_core.toCamelCase)(name);
|
|
240
47
|
}
|
|
241
48
|
async function fileExists(filename) {
|
|
242
49
|
try {
|
|
243
|
-
await (0,
|
|
50
|
+
await (0, node_fs_promises.stat)(filename);
|
|
244
51
|
return true;
|
|
245
|
-
} catch (
|
|
52
|
+
} catch (_error) {
|
|
246
53
|
return false;
|
|
247
54
|
}
|
|
248
55
|
}
|
|
249
|
-
async function writeFile(path
|
|
250
|
-
await (0,
|
|
251
|
-
await (0,
|
|
252
|
-
return path
|
|
56
|
+
async function writeFile(path, contents) {
|
|
57
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
58
|
+
await (0, node_fs_promises.writeFile)(path, contents, "utf-8");
|
|
59
|
+
return path;
|
|
253
60
|
}
|
|
254
|
-
function cwdRelative(path
|
|
255
|
-
return (0,
|
|
61
|
+
function cwdRelative(path) {
|
|
62
|
+
return (0, node_path.relative)(process.cwd(), path);
|
|
256
63
|
}
|
|
257
64
|
function sortContracts(contracts) {
|
|
258
65
|
return [...contracts].sort((a, b) => {
|
|
@@ -265,7 +72,7 @@ function sortContracts(contracts) {
|
|
|
265
72
|
//#region src/docs/markdown.ts
|
|
266
73
|
function generateMarkdown({ contract, contractFile, withToc = true }) {
|
|
267
74
|
const contractName = (0, __clarigen_core.getContractName)(contract.contract_id, false);
|
|
268
|
-
const doc = createContractDocInfo({
|
|
75
|
+
const doc = (0, __clarigen_docs.createContractDocInfo)({
|
|
269
76
|
contractSrc: contract.source,
|
|
270
77
|
abi: contract.contract_interface
|
|
271
78
|
});
|
|
@@ -274,7 +81,7 @@ function generateMarkdown({ contract, contractFile, withToc = true }) {
|
|
|
274
81
|
const vars = doc.variables.filter((v) => v.abi.access === "variable").map((v) => markdownVar(v, contractFile));
|
|
275
82
|
const constants = doc.variables.filter((v) => v.abi.access === "constant").map((v) => markdownVar(v, contractFile));
|
|
276
83
|
let fileLine = "";
|
|
277
|
-
if (contractFile) fileLine = `\n[\`${(0,
|
|
84
|
+
if (contractFile) fileLine = `\n[\`${(0, node_path.basename)(contractFile)}\`](${contractFile})`;
|
|
278
85
|
return `
|
|
279
86
|
# ${contractName}
|
|
280
87
|
${fileLine}
|
|
@@ -303,9 +110,7 @@ ${constants.join("\n\n")}
|
|
|
303
110
|
function markdownFunction(fn, contractFile) {
|
|
304
111
|
const params = mdParams(fn);
|
|
305
112
|
const returnType = (0, __clarigen_core.getTypeString)(fn.abi.outputs.type);
|
|
306
|
-
const paramSigs = fn.abi.args.map((arg) => {
|
|
307
|
-
return `(${arg.name} ${(0, __clarigen_core.getTypeString)(arg.type)})`;
|
|
308
|
-
});
|
|
113
|
+
const paramSigs = fn.abi.args.map((arg) => `(${arg.name} ${(0, __clarigen_core.getTypeString)(arg.type)})`);
|
|
309
114
|
const startLine = fn.startLine + 1;
|
|
310
115
|
let link = "";
|
|
311
116
|
if (contractFile) link = `[View in file](${contractFile}#L${startLine})`;
|
|
@@ -427,8 +232,42 @@ ${contractLines.join("\n")}
|
|
|
427
232
|
`;
|
|
428
233
|
}
|
|
429
234
|
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/logger.ts
|
|
237
|
+
const colorizedClarigen = "\x1B[33m[Clarigen]\x1B[0m";
|
|
238
|
+
const logger = (0, pino.pino)((0, pino_pretty.default)({
|
|
239
|
+
colorize: true,
|
|
240
|
+
ignore: "pid,hostname,time",
|
|
241
|
+
messageFormat: `${colorizedClarigen} {msg}`,
|
|
242
|
+
minimumLevel: "debug"
|
|
243
|
+
}));
|
|
244
|
+
logger.level = "info";
|
|
245
|
+
const log = logger;
|
|
246
|
+
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/docs/index.ts
|
|
249
|
+
async function afterDocs(config) {
|
|
250
|
+
var _config$docs;
|
|
251
|
+
const command = (_config$docs = config.docs) === null || _config$docs === void 0 ? void 0 : _config$docs.after;
|
|
252
|
+
if (!command) return;
|
|
253
|
+
logger.debug(`Running after docs command: ${command}`);
|
|
254
|
+
const [cmd, ...args] = command.split(" ");
|
|
255
|
+
return new Promise((resolve$1, reject) => {
|
|
256
|
+
const child = (0, node_child_process.spawn)(cmd, args, {
|
|
257
|
+
cwd: config.cwd,
|
|
258
|
+
stdio: "inherit"
|
|
259
|
+
});
|
|
260
|
+
child.on("error", reject);
|
|
261
|
+
child.on("exit", (code) => {
|
|
262
|
+
if (code === 0) resolve$1();
|
|
263
|
+
else reject(/* @__PURE__ */ new Error(`Command failed with code ${code ?? "unknown"}`));
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
430
268
|
//#endregion
|
|
431
269
|
//#region src/clarinet-config.ts
|
|
270
|
+
/** biome-ignore-all lint/style/useTrimStartEnd: suppressed */
|
|
432
271
|
const ClarinetConfig = (0, arktype.type)({
|
|
433
272
|
project: (0, arktype.type)({
|
|
434
273
|
requirements: (0, arktype.type)({ contract_id: (0, arktype.type)("string").describe("Contract ID") }).array().describe("Project requirements").optional(),
|
|
@@ -436,13 +275,14 @@ const ClarinetConfig = (0, arktype.type)({
|
|
|
436
275
|
}),
|
|
437
276
|
contracts: (0, arktype.type)({ "[string]": (0, arktype.type)({ path: (0, arktype.type)("string").describe("Contract path") }) }).optional()
|
|
438
277
|
});
|
|
439
|
-
async function getClarinetConfig(path
|
|
440
|
-
const file = await (0,
|
|
278
|
+
async function getClarinetConfig(path) {
|
|
279
|
+
const file = await (0, node_fs_promises.readFile)(path, "utf-8");
|
|
441
280
|
return ClarinetConfig.assert((0, __iarna_toml.parse)(file));
|
|
442
281
|
}
|
|
443
282
|
|
|
444
283
|
//#endregion
|
|
445
284
|
//#region src/config.ts
|
|
285
|
+
/** biome-ignore-all lint/style/useTrimStartEnd: suppressed */
|
|
446
286
|
const CONFIG_FILE = "Clarigen.toml";
|
|
447
287
|
let OutputType = /* @__PURE__ */ function(OutputType$1) {
|
|
448
288
|
OutputType$1["ESM"] = "types";
|
|
@@ -470,7 +310,7 @@ const ConfigFile = (0, arktype.type)({
|
|
|
470
310
|
}).optional()
|
|
471
311
|
});
|
|
472
312
|
const defaultConfigFile = { clarinet: "./Clarinet.toml" };
|
|
473
|
-
var Config = class {
|
|
313
|
+
var Config = class Config {
|
|
474
314
|
configFile;
|
|
475
315
|
clarinet;
|
|
476
316
|
cwd;
|
|
@@ -485,8 +325,7 @@ var Config = class {
|
|
|
485
325
|
config[OutputType.ESM] = config[OutputType.ESM_OLD];
|
|
486
326
|
delete config[OutputType.ESM_OLD];
|
|
487
327
|
}
|
|
488
|
-
|
|
489
|
-
return new this(config, clarinet, cwd);
|
|
328
|
+
return new Config(config, await getClarinetConfig((0, node_path.resolve)(cwd ?? "", config.clarinet)), cwd);
|
|
490
329
|
}
|
|
491
330
|
getOutputs(type$2) {
|
|
492
331
|
var _this$configFile$type, _this$configFile$type2;
|
|
@@ -498,16 +337,14 @@ var Config = class {
|
|
|
498
337
|
outputResolve(type$2, filePath) {
|
|
499
338
|
const outputs = this.getOutputs(type$2);
|
|
500
339
|
if (!this.supports(type$2)) return null;
|
|
501
|
-
return outputs.map((path
|
|
502
|
-
return (0, path.resolve)(this.cwd, path$1, filePath || "");
|
|
503
|
-
});
|
|
340
|
+
return outputs.map((path) => (0, node_path.resolve)(this.cwd, path, filePath || ""));
|
|
504
341
|
}
|
|
505
342
|
async writeOutput(type$2, contents, filePath) {
|
|
506
343
|
const paths = this.outputResolve(type$2, filePath);
|
|
507
344
|
if (paths === null) return null;
|
|
508
|
-
await Promise.all(paths.map(async (path
|
|
509
|
-
await writeFile(path
|
|
510
|
-
log.debug(`Generated ${type$2} file at ${(0,
|
|
345
|
+
await Promise.all(paths.map(async (path) => {
|
|
346
|
+
await writeFile(path, contents);
|
|
347
|
+
log.debug(`Generated ${type$2} file at ${(0, node_path.relative)(this.cwd, path)}`);
|
|
511
348
|
}));
|
|
512
349
|
return paths;
|
|
513
350
|
}
|
|
@@ -524,14 +361,14 @@ var Config = class {
|
|
|
524
361
|
return this.configFile[OutputType.Docs];
|
|
525
362
|
}
|
|
526
363
|
clarinetFile() {
|
|
527
|
-
return (0,
|
|
364
|
+
return (0, node_path.resolve)(this.cwd, this.configFile.clarinet);
|
|
528
365
|
}
|
|
529
366
|
joinFromClarinet(filePath) {
|
|
530
|
-
return (0,
|
|
367
|
+
return (0, node_path.join)((0, node_path.dirname)(this.clarinetFile()), filePath);
|
|
531
368
|
}
|
|
532
369
|
};
|
|
533
370
|
function configFilePath(cwd) {
|
|
534
|
-
return (0,
|
|
371
|
+
return (0, node_path.resolve)(cwd ?? process.cwd(), CONFIG_FILE);
|
|
535
372
|
}
|
|
536
373
|
async function saveConfig(config) {
|
|
537
374
|
const configToml = (0, __iarna_toml.stringify)({ ...config });
|
|
@@ -540,9 +377,9 @@ async function saveConfig(config) {
|
|
|
540
377
|
let sessionConfig;
|
|
541
378
|
async function getConfig(cwd) {
|
|
542
379
|
if (typeof sessionConfig !== "undefined") return sessionConfig;
|
|
543
|
-
const path
|
|
544
|
-
if (await fileExists(path
|
|
545
|
-
const parsed = ConfigFile((0, __iarna_toml.parse)(await (0,
|
|
380
|
+
const path = configFilePath(cwd);
|
|
381
|
+
if (await fileExists(path)) {
|
|
382
|
+
const parsed = ConfigFile((0, __iarna_toml.parse)(await (0, node_fs_promises.readFile)(path, "utf-8")));
|
|
546
383
|
if (parsed instanceof arktype.type.errors) {
|
|
547
384
|
logger.error(`Error parsing Clarigen config: ${parsed.summary}`);
|
|
548
385
|
throw new Error(`Error parsing Clarigen config: ${parsed.summary}`);
|
|
@@ -555,18 +392,17 @@ async function getConfig(cwd) {
|
|
|
555
392
|
//#endregion
|
|
556
393
|
//#region src/files/docs.ts
|
|
557
394
|
async function generateDocs({ session, config }) {
|
|
395
|
+
var _config$outputResolve, _await$config$writeOu;
|
|
558
396
|
const docs = config.configFile[OutputType.Docs];
|
|
559
397
|
const docsBase = docs === null || docs === void 0 ? void 0 : docs.output;
|
|
560
398
|
if (!docsBase) {
|
|
561
399
|
warnNoDocs();
|
|
562
400
|
return;
|
|
563
401
|
}
|
|
564
|
-
if ((0,
|
|
565
|
-
const excluded = Object.fromEntries((docs.exclude || []).map((e) =>
|
|
566
|
-
return [e, true];
|
|
567
|
-
}));
|
|
402
|
+
if ((0, node_path.extname)(docsBase)) log.warn(`Docs output path ('${docsBase}') looks like a file - it needs to be a directory.`);
|
|
403
|
+
const excluded = Object.fromEntries((docs.exclude || []).map((e) => [e, true]));
|
|
568
404
|
log.debug(`Generating docs at path \`${docsBase}\``);
|
|
569
|
-
const docsBaseFolder = config.outputResolve(OutputType.Docs, "./")[0];
|
|
405
|
+
const docsBaseFolder = (_config$outputResolve = config.outputResolve(OutputType.Docs, "./")) === null || _config$outputResolve === void 0 ? void 0 : _config$outputResolve[0];
|
|
570
406
|
const paths = await Promise.all(session.contracts.map(async (contract) => {
|
|
571
407
|
var _config$clarinet$cont;
|
|
572
408
|
const name = (0, __clarigen_core.getContractName)(contract.contract_id, false);
|
|
@@ -574,7 +410,7 @@ async function generateDocs({ session, config }) {
|
|
|
574
410
|
const docFile = `${name}.md`;
|
|
575
411
|
const contractPathDef = (_config$clarinet$cont = config.clarinet.contracts) === null || _config$clarinet$cont === void 0 || (_config$clarinet$cont = _config$clarinet$cont[name]) === null || _config$clarinet$cont === void 0 ? void 0 : _config$clarinet$cont.path;
|
|
576
412
|
let contractFile;
|
|
577
|
-
if (contractPathDef) contractFile = (0,
|
|
413
|
+
if (contractPathDef) contractFile = (0, node_path.relative)(docsBaseFolder, config.joinFromClarinet(contractPathDef));
|
|
578
414
|
else log.debug(`Couldn't find contract file from Clarinet.toml for contract ${name}`);
|
|
579
415
|
const md = generateMarkdown({
|
|
580
416
|
contract,
|
|
@@ -583,7 +419,7 @@ async function generateDocs({ session, config }) {
|
|
|
583
419
|
return (await config.writeOutput(OutputType.Docs, md, docFile))[0];
|
|
584
420
|
}));
|
|
585
421
|
const readme = generateReadme(session, excluded);
|
|
586
|
-
paths.push((await config.writeOutput(OutputType.Docs, readme, "README.md"))[0]);
|
|
422
|
+
paths.push((_await$config$writeOu = await config.writeOutput(OutputType.Docs, readme, "README.md")) === null || _await$config$writeOu === void 0 ? void 0 : _await$config$writeOu[0]);
|
|
587
423
|
await afterDocs(config);
|
|
588
424
|
}
|
|
589
425
|
function warnNoDocs() {
|
|
@@ -599,21 +435,25 @@ output = "docs/"
|
|
|
599
435
|
//#endregion
|
|
600
436
|
//#region src/declaration.ts
|
|
601
437
|
const jsTypeFromAbiType = (val, isArgument = false) => {
|
|
602
|
-
if ((0, __clarigen_core.isClarityAbiPrimitive)(val))
|
|
603
|
-
if (
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
438
|
+
if ((0, __clarigen_core.isClarityAbiPrimitive)(val)) {
|
|
439
|
+
if (val === "uint128") {
|
|
440
|
+
if (isArgument) return "number | bigint";
|
|
441
|
+
return "bigint";
|
|
442
|
+
}
|
|
443
|
+
if (val === "int128") {
|
|
444
|
+
if (isArgument) return "number | bigint";
|
|
445
|
+
return "bigint";
|
|
446
|
+
}
|
|
447
|
+
if (val === "bool") return "boolean";
|
|
448
|
+
if (val === "principal") return "string";
|
|
449
|
+
if (val === "none") return "null";
|
|
450
|
+
if (val === "trait_reference") return "string";
|
|
451
|
+
throw new Error(`Unexpected Clarity ABI type primitive: ${JSON.stringify(val)}`);
|
|
452
|
+
}
|
|
453
|
+
if ((0, __clarigen_core.isClarityAbiBuffer)(val)) return "Uint8Array";
|
|
454
|
+
if ((0, __clarigen_core.isClarityAbiResponse)(val)) return `Response<${jsTypeFromAbiType(val.response.ok, isArgument)}, ${jsTypeFromAbiType(val.response.error, isArgument)}>`;
|
|
455
|
+
if ((0, __clarigen_core.isClarityAbiOptional)(val)) return `${jsTypeFromAbiType(val.optional, isArgument)} | null`;
|
|
456
|
+
if ((0, __clarigen_core.isClarityAbiTuple)(val)) {
|
|
617
457
|
const tupleDefs = [];
|
|
618
458
|
val.tuple.forEach(({ name, type: type$2 }) => {
|
|
619
459
|
const camelName = (0, __clarigen_core.toCamelCase)(name);
|
|
@@ -623,11 +463,12 @@ const jsTypeFromAbiType = (val, isArgument = false) => {
|
|
|
623
463
|
return `{
|
|
624
464
|
${tupleDefs.join("\n ")}
|
|
625
465
|
}`;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
466
|
+
}
|
|
467
|
+
if ((0, __clarigen_core.isClarityAbiList)(val)) return `${jsTypeFromAbiType(val.list.type, isArgument)}[]`;
|
|
468
|
+
if ((0, __clarigen_core.isClarityAbiStringAscii)(val)) return "string";
|
|
469
|
+
if ((0, __clarigen_core.isClarityAbiStringUtf8)(val)) return "string";
|
|
470
|
+
if ((0, __clarigen_core.isClarityAbiTraitReference)(val)) return "string";
|
|
471
|
+
throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(val)}`);
|
|
631
472
|
};
|
|
632
473
|
function abiArgType(arg) {
|
|
633
474
|
const nativeType = jsTypeFromAbiType(arg.type, true);
|
|
@@ -704,9 +545,7 @@ function generateContractMeta(contract, constants) {
|
|
|
704
545
|
const otherAbi = JSON.stringify(rest);
|
|
705
546
|
const contractName = contract.contract_id.split(".")[1];
|
|
706
547
|
const variableLines = encodeVariables(variables);
|
|
707
|
-
const nftLines = non_fungible_tokens.map((nft) =>
|
|
708
|
-
return JSON.stringify(nft);
|
|
709
|
-
});
|
|
548
|
+
const nftLines = non_fungible_tokens.map((nft) => JSON.stringify(nft));
|
|
710
549
|
return `{
|
|
711
550
|
${serializeLines("functions", functionLines)}
|
|
712
551
|
${serializeLines("maps", mapLines)}
|
|
@@ -754,18 +593,18 @@ function encodeVariables(variables) {
|
|
|
754
593
|
return varLine;
|
|
755
594
|
});
|
|
756
595
|
}
|
|
757
|
-
Uint8Array.prototype[
|
|
596
|
+
Uint8Array.prototype[node_util.inspect.custom] = function(_depth, _options) {
|
|
758
597
|
return `Uint8Array.from([${this.join(",")}])`;
|
|
759
598
|
};
|
|
760
599
|
function serialize(obj) {
|
|
761
|
-
return (0,
|
|
600
|
+
return (0, node_util.inspect)(obj, {
|
|
762
601
|
showHidden: false,
|
|
763
602
|
compact: false,
|
|
764
603
|
depth: 100,
|
|
765
604
|
colors: false,
|
|
766
|
-
maxArrayLength:
|
|
767
|
-
maxStringLength:
|
|
768
|
-
breakLength:
|
|
605
|
+
maxArrayLength: Number.POSITIVE_INFINITY,
|
|
606
|
+
maxStringLength: Number.POSITIVE_INFINITY,
|
|
607
|
+
breakLength: Number.POSITIVE_INFINITY,
|
|
769
608
|
numericSeparator: true
|
|
770
609
|
});
|
|
771
610
|
}
|
|
@@ -803,7 +642,7 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
803
642
|
logger.info(`Contract ${(0, __clarigen_core.getContractName)(contract.contract_id, false)} has no variables`);
|
|
804
643
|
return {};
|
|
805
644
|
}
|
|
806
|
-
let varFn =
|
|
645
|
+
let varFn = "{\n";
|
|
807
646
|
const varLines = contract.contract_interface.variables.map((variable) => {
|
|
808
647
|
let varLine = `${variable.name}: `;
|
|
809
648
|
if (variable.access === "constant") varLine += `${variable.name}`;
|
|
@@ -812,7 +651,7 @@ function getVariablesV2(contract, simnet, verbose) {
|
|
|
812
651
|
});
|
|
813
652
|
varFn += varLines.map((l) => ` ${l},`).join("\n");
|
|
814
653
|
varFn += "\n}";
|
|
815
|
-
const fullSrc = contract.source
|
|
654
|
+
const fullSrc = `${contract.source}\n\n${varFn}`;
|
|
816
655
|
try {
|
|
817
656
|
const result = simnet.deployContract(fakeId, fullSrc, { clarityVersion: clarityVersionForContract(contract) }, deployer).result;
|
|
818
657
|
const varsAbi = { tuple: [] };
|
|
@@ -838,8 +677,9 @@ function mapVariables(session, simnet) {
|
|
|
838
677
|
|
|
839
678
|
//#endregion
|
|
840
679
|
//#region src/files/esm.ts
|
|
841
|
-
|
|
842
|
-
|
|
680
|
+
/** biome-ignore-all lint/style/useTrimStartEnd: suppressed */
|
|
681
|
+
async function parseDeployment(path) {
|
|
682
|
+
return (0, yaml.parse)(await (0, node_fs_promises.readFile)(path, "utf-8"));
|
|
843
683
|
}
|
|
844
684
|
const DEPLOYMENT_NETWORKS = [
|
|
845
685
|
"devnet",
|
|
@@ -850,10 +690,10 @@ const DEPLOYMENT_NETWORKS = [
|
|
|
850
690
|
async function getDeployments(config) {
|
|
851
691
|
const entries = await Promise.all(DEPLOYMENT_NETWORKS.map(async (network) => {
|
|
852
692
|
const file = `default.${network}-plan.yaml`;
|
|
853
|
-
const path
|
|
693
|
+
const path = (0, node_path.join)((0, node_path.dirname)(config.clarinetFile()), "deployments", file);
|
|
854
694
|
let plan;
|
|
855
695
|
try {
|
|
856
|
-
plan = await parseDeployment(path
|
|
696
|
+
plan = await parseDeployment(path);
|
|
857
697
|
} catch (_) {}
|
|
858
698
|
return [network, plan];
|
|
859
699
|
}));
|
|
@@ -909,14 +749,14 @@ function collectDeploymentFiles(deployments, clarinetFolder, cwd) {
|
|
|
909
749
|
return (0, __clarigen_core_deployment.getContractTxs)(simnet.plan.batches).map((tx) => {
|
|
910
750
|
return {
|
|
911
751
|
identifier: (0, __clarigen_core_deployment.getIdentifierForDeploymentTx)(tx),
|
|
912
|
-
file: (0,
|
|
752
|
+
file: (0, node_path.relative)(cwd, (0, node_path.join)(clarinetFolder, (0, __clarigen_core_deployment.getDeploymentTxPath)(tx)))
|
|
913
753
|
};
|
|
914
754
|
});
|
|
915
755
|
}
|
|
916
756
|
function generateSimnetCode(config, deployments, _session) {
|
|
917
757
|
var _config$esm;
|
|
918
758
|
if (!((_config$esm = config.esm) === null || _config$esm === void 0 ? void 0 : _config$esm.include_accounts)) return "";
|
|
919
|
-
const files = collectDeploymentFiles(deployments, (0,
|
|
759
|
+
const files = collectDeploymentFiles(deployments, (0, node_path.dirname)(config.clarinetFile()), config.cwd);
|
|
920
760
|
return `
|
|
921
761
|
export const simnetDeployment = ${JSON.stringify(files)};
|
|
922
762
|
`;
|
|
@@ -928,7 +768,7 @@ async function afterESM(config) {
|
|
|
928
768
|
logger.debug(`Running after ESM command: ${command}`);
|
|
929
769
|
const [cmd, ...args] = command.split(" ");
|
|
930
770
|
return new Promise((resolve$1, reject) => {
|
|
931
|
-
const child = (0,
|
|
771
|
+
const child = (0, node_child_process.spawn)(cmd, args, {
|
|
932
772
|
cwd: config.cwd,
|
|
933
773
|
stdio: "inherit"
|
|
934
774
|
});
|
|
@@ -971,12 +811,6 @@ Object.defineProperty(exports, 'DEPLOYMENT_NETWORKS', {
|
|
|
971
811
|
return DEPLOYMENT_NETWORKS;
|
|
972
812
|
}
|
|
973
813
|
});
|
|
974
|
-
Object.defineProperty(exports, 'FN_TYPES', {
|
|
975
|
-
enumerable: true,
|
|
976
|
-
get: function () {
|
|
977
|
-
return FN_TYPES;
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
814
|
Object.defineProperty(exports, 'OutputType', {
|
|
981
815
|
enumerable: true,
|
|
982
816
|
get: function () {
|
|
@@ -989,12 +823,6 @@ Object.defineProperty(exports, 'TYPE_IMPORTS', {
|
|
|
989
823
|
return TYPE_IMPORTS;
|
|
990
824
|
}
|
|
991
825
|
});
|
|
992
|
-
Object.defineProperty(exports, 'VAR_TYPES', {
|
|
993
|
-
enumerable: true,
|
|
994
|
-
get: function () {
|
|
995
|
-
return VAR_TYPES;
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
826
|
Object.defineProperty(exports, '__toESM', {
|
|
999
827
|
enumerable: true,
|
|
1000
828
|
get: function () {
|
|
@@ -1043,12 +871,6 @@ Object.defineProperty(exports, 'configFilePath', {
|
|
|
1043
871
|
return configFilePath;
|
|
1044
872
|
}
|
|
1045
873
|
});
|
|
1046
|
-
Object.defineProperty(exports, 'createContractDocInfo', {
|
|
1047
|
-
enumerable: true,
|
|
1048
|
-
get: function () {
|
|
1049
|
-
return createContractDocInfo;
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
874
|
Object.defineProperty(exports, 'cwdRelative', {
|
|
1053
875
|
enumerable: true,
|
|
1054
876
|
get: function () {
|
|
@@ -1139,24 +961,12 @@ Object.defineProperty(exports, 'getDeployments', {
|
|
|
1139
961
|
return getDeployments;
|
|
1140
962
|
}
|
|
1141
963
|
});
|
|
1142
|
-
Object.defineProperty(exports, 'getFnName', {
|
|
1143
|
-
enumerable: true,
|
|
1144
|
-
get: function () {
|
|
1145
|
-
return getFnName;
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
964
|
Object.defineProperty(exports, 'getVariablesV2', {
|
|
1149
965
|
enumerable: true,
|
|
1150
966
|
get: function () {
|
|
1151
967
|
return getVariablesV2;
|
|
1152
968
|
}
|
|
1153
969
|
});
|
|
1154
|
-
Object.defineProperty(exports, 'isComment', {
|
|
1155
|
-
enumerable: true,
|
|
1156
|
-
get: function () {
|
|
1157
|
-
return isComment;
|
|
1158
|
-
}
|
|
1159
|
-
});
|
|
1160
970
|
Object.defineProperty(exports, 'jsTypeFromAbiType', {
|
|
1161
971
|
enumerable: true,
|
|
1162
972
|
get: function () {
|
|
@@ -1181,12 +991,6 @@ Object.defineProperty(exports, 'markdownFunction', {
|
|
|
1181
991
|
return markdownFunction;
|
|
1182
992
|
}
|
|
1183
993
|
});
|
|
1184
|
-
Object.defineProperty(exports, 'parseComments', {
|
|
1185
|
-
enumerable: true,
|
|
1186
|
-
get: function () {
|
|
1187
|
-
return parseComments;
|
|
1188
|
-
}
|
|
1189
|
-
});
|
|
1190
994
|
Object.defineProperty(exports, 'parseDeployment', {
|
|
1191
995
|
enumerable: true,
|
|
1192
996
|
get: function () {
|
|
@@ -1211,16 +1015,10 @@ Object.defineProperty(exports, 'sortContracts', {
|
|
|
1211
1015
|
return sortContracts;
|
|
1212
1016
|
}
|
|
1213
1017
|
});
|
|
1214
|
-
Object.defineProperty(exports, 'traceParens', {
|
|
1215
|
-
enumerable: true,
|
|
1216
|
-
get: function () {
|
|
1217
|
-
return traceParens;
|
|
1218
|
-
}
|
|
1219
|
-
});
|
|
1220
1018
|
Object.defineProperty(exports, 'writeFile', {
|
|
1221
1019
|
enumerable: true,
|
|
1222
1020
|
get: function () {
|
|
1223
1021
|
return writeFile;
|
|
1224
1022
|
}
|
|
1225
1023
|
});
|
|
1226
|
-
//# sourceMappingURL=esm-
|
|
1024
|
+
//# sourceMappingURL=esm-DPOm6Bdw.cjs.map
|