@clarigen/cli 1.0.0-next.22 → 1.0.0-next.26
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/commands/index.js +190 -182
- package/dist/index.js +190 -182
- package/package.json +5 -5
- package/src/clarinet-config.ts +23 -0
- package/src/commands/index.ts +5 -1
- package/src/config.ts +10 -1
- package/src/contract.ts +69 -0
- package/src/deno-run.ts +35 -0
- package/src/generate/files.ts +1 -1
- package/src/utils.ts +31 -16
package/dist/index.js
CHANGED
|
@@ -70,29 +70,112 @@ module.exports = __toCommonJS(src_exports);
|
|
|
70
70
|
var import_command2 = require("@oclif/command");
|
|
71
71
|
|
|
72
72
|
// src/config.ts
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
73
|
+
var import_path4 = require("path");
|
|
74
|
+
var import_promises4 = require("fs/promises");
|
|
75
|
+
var import_fs2 = require("fs");
|
|
76
76
|
|
|
77
77
|
// src/clarinet-config.ts
|
|
78
78
|
var import_toml = require("@iarna/toml");
|
|
79
|
-
var
|
|
80
|
-
var
|
|
79
|
+
var import_path3 = require("path");
|
|
80
|
+
var import_promises3 = require("fs/promises");
|
|
81
81
|
var import_wallet_sdk = require("micro-stacks/wallet-sdk");
|
|
82
82
|
var import_toposort = require("toposort");
|
|
83
83
|
var import_crypto = require("micro-stacks/crypto");
|
|
84
|
+
|
|
85
|
+
// src/generate/deployment.ts
|
|
86
|
+
var import_js_yaml = require("js-yaml");
|
|
87
|
+
var import_promises2 = require("fs/promises");
|
|
88
|
+
var import_path2 = require("path");
|
|
89
|
+
var import_fs = require("fs");
|
|
90
|
+
|
|
91
|
+
// src/writer.ts
|
|
92
|
+
var import_promises = require("fs/promises");
|
|
93
|
+
var import_path = require("path");
|
|
94
|
+
var import_prettier = require("prettier");
|
|
95
|
+
var defaultPrettierConfig = {
|
|
96
|
+
printWidth: 80,
|
|
97
|
+
semi: true,
|
|
98
|
+
singleQuote: true,
|
|
99
|
+
trailingComma: "es5"
|
|
100
|
+
};
|
|
101
|
+
async function resolvePrettierConfig() {
|
|
102
|
+
try {
|
|
103
|
+
const local = await (0, import_prettier.resolveConfig)(process.cwd());
|
|
104
|
+
if (local)
|
|
105
|
+
return local;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
}
|
|
108
|
+
return defaultPrettierConfig;
|
|
109
|
+
}
|
|
110
|
+
async function formatFile(contents, path) {
|
|
111
|
+
try {
|
|
112
|
+
const fileName = (0, import_path.basename)(path);
|
|
113
|
+
const config = await resolvePrettierConfig();
|
|
114
|
+
const formatted = (0, import_prettier.format)(contents, __spreadProps(__spreadValues({}, config), {
|
|
115
|
+
filepath: fileName
|
|
116
|
+
}));
|
|
117
|
+
return formatted;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
}
|
|
120
|
+
return contents;
|
|
121
|
+
}
|
|
122
|
+
async function writeFile(path, contents) {
|
|
123
|
+
const formatted = await formatFile(contents, path);
|
|
124
|
+
await (0, import_promises.writeFile)(path, formatted);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/generate/deployment.ts
|
|
128
|
+
async function parseDeployment(path) {
|
|
129
|
+
const contents = await (0, import_promises2.readFile)(path, { encoding: "utf-8" });
|
|
130
|
+
const parsed = (0, import_js_yaml.load)(contents);
|
|
131
|
+
return parsed;
|
|
132
|
+
}
|
|
133
|
+
async function generateDeployment(network, config) {
|
|
134
|
+
const file = `default.${network}-plan.yaml`;
|
|
135
|
+
const deploymentPath = (0, import_path2.resolve)(process.cwd(), config.clarinet, "deployments", file);
|
|
136
|
+
if ((0, import_fs.existsSync)(deploymentPath)) {
|
|
137
|
+
const plan = await parseDeployment(deploymentPath);
|
|
138
|
+
const varName = `${network}Deployment`;
|
|
139
|
+
const contents = `export const ${varName} = ${JSON.stringify(plan)} as const;
|
|
140
|
+
`;
|
|
141
|
+
const outputFile = (0, import_path2.resolve)(config.outputDir, "deployments", `${network}.ts`);
|
|
142
|
+
await writeFile(outputFile, contents);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function generateDeployments(config) {
|
|
146
|
+
const networks = ["devnet", "simnet", "testnet", "mainnet"];
|
|
147
|
+
const folder = (0, import_path2.resolve)(process.cwd(), config.outputDir, "deployments");
|
|
148
|
+
await (0, import_promises2.mkdir)(folder, { recursive: true });
|
|
149
|
+
const generates = networks.map((n) => generateDeployment(n, config));
|
|
150
|
+
await Promise.all(generates);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/clarinet-config.ts
|
|
84
154
|
async function getClarinetDevConfig(folder) {
|
|
85
|
-
const baseConfigPath = (0,
|
|
86
|
-
const configContents = await (0,
|
|
155
|
+
const baseConfigPath = (0, import_path3.resolve)(folder, "settings", "Devnet.toml");
|
|
156
|
+
const configContents = await (0, import_promises3.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
87
157
|
const config = (0, import_toml.parse)(configContents);
|
|
88
158
|
return config;
|
|
89
159
|
}
|
|
90
160
|
async function getClarinetConfig(folder) {
|
|
91
|
-
const baseConfigPath = (0,
|
|
92
|
-
const configContents = await (0,
|
|
161
|
+
const baseConfigPath = (0, import_path3.resolve)(folder, "Clarinet.toml");
|
|
162
|
+
const configContents = await (0, import_promises3.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
93
163
|
const config = (0, import_toml.parse)(configContents);
|
|
94
164
|
return config;
|
|
95
165
|
}
|
|
166
|
+
async function getContractsFromDeployment(clarinetPath) {
|
|
167
|
+
const simnetPath = (0, import_path3.resolve)(clarinetPath || process.cwd(), "deployments/default.simnet-plan.yaml");
|
|
168
|
+
const deployment = await parseDeployment(simnetPath);
|
|
169
|
+
const txs = deployment.plan.batches[0].transactions;
|
|
170
|
+
return txs.map((_tx) => {
|
|
171
|
+
const tx = _tx["emulated-contract-publish"];
|
|
172
|
+
return {
|
|
173
|
+
file: tx.path,
|
|
174
|
+
name: tx["contract-name"],
|
|
175
|
+
address: tx["emulated-sender"]
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
96
179
|
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
97
180
|
const deployerAddress = accounts.deployer.address;
|
|
98
181
|
const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
|
|
@@ -138,14 +221,15 @@ async function getClarinetAccounts(folder) {
|
|
|
138
221
|
// src/config.ts
|
|
139
222
|
var defaultConfigFile = {
|
|
140
223
|
outputDir: "src/clarigen",
|
|
141
|
-
clarinet: "."
|
|
224
|
+
clarinet: ".",
|
|
225
|
+
legacy: false
|
|
142
226
|
};
|
|
143
227
|
function configFilePath(rootPath) {
|
|
144
|
-
return (0,
|
|
228
|
+
return (0, import_path4.resolve)(rootPath, "clarigen.config.json");
|
|
145
229
|
}
|
|
146
230
|
async function configFileExists(configPath) {
|
|
147
231
|
try {
|
|
148
|
-
await (0,
|
|
232
|
+
await (0, import_promises4.access)(configPath, import_fs2.constants.R_OK);
|
|
149
233
|
return true;
|
|
150
234
|
} catch (error) {
|
|
151
235
|
return false;
|
|
@@ -155,7 +239,7 @@ async function getConfigFile(rootPath) {
|
|
|
155
239
|
const fullPath = configFilePath(rootPath);
|
|
156
240
|
const exists = await configFileExists(fullPath);
|
|
157
241
|
if (exists) {
|
|
158
|
-
const configContents = await (0,
|
|
242
|
+
const configContents = await (0, import_promises4.readFile)(fullPath, { encoding: "utf-8" });
|
|
159
243
|
const configFile = JSON.parse(configContents);
|
|
160
244
|
return __spreadValues(__spreadValues({}, defaultConfigFile), configFile);
|
|
161
245
|
}
|
|
@@ -164,11 +248,16 @@ async function getConfigFile(rootPath) {
|
|
|
164
248
|
async function getProjectConfig(rootPath) {
|
|
165
249
|
var _a, _b;
|
|
166
250
|
const configFile = await getConfigFile(rootPath);
|
|
167
|
-
const clarinetPath = (0,
|
|
251
|
+
const clarinetPath = (0, import_path4.resolve)(rootPath, configFile.clarinet);
|
|
168
252
|
const clarinet = await getClarinetConfig(clarinetPath);
|
|
169
253
|
const accounts = await getClarinetAccounts(clarinetPath);
|
|
170
|
-
|
|
171
|
-
|
|
254
|
+
let contracts;
|
|
255
|
+
try {
|
|
256
|
+
contracts = await getContractsFromDeployment(clarinetPath);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
contracts = getContractsFromClarinet(clarinet, accounts);
|
|
259
|
+
}
|
|
260
|
+
const contractsDir = (0, import_path4.relative)(process.cwd(), (0, import_path4.join)(configFile.clarinet, "contracts"));
|
|
172
261
|
return __spreadProps(__spreadValues({}, configFile), {
|
|
173
262
|
outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
|
|
174
263
|
docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
|
|
@@ -282,7 +371,7 @@ function makePureTypes(abi) {
|
|
|
282
371
|
|
|
283
372
|
// src/generate/files.ts
|
|
284
373
|
var import_core2 = require("@clarigen/core");
|
|
285
|
-
var
|
|
374
|
+
var import_path5 = require("path");
|
|
286
375
|
var generateInterfaceFile = ({
|
|
287
376
|
contractName,
|
|
288
377
|
abi
|
|
@@ -369,8 +458,8 @@ export const accounts = {
|
|
|
369
458
|
const contractVar = (0, import_core2.toCamelCase)(contractName);
|
|
370
459
|
const contractInfo = `${contractVar}Info`;
|
|
371
460
|
const contractInterface = `${(0, import_core2.toCamelCase)(contractName, true)}Contract`;
|
|
372
|
-
const dirName = (0,
|
|
373
|
-
const importPath = `'./${
|
|
461
|
+
const dirName = (0, import_path5.dirname)(contract.file);
|
|
462
|
+
const importPath = `'./${contractName}'`;
|
|
374
463
|
const _import = `import { ${contractInfo} } from ${importPath};`;
|
|
375
464
|
imports.push(_import);
|
|
376
465
|
const _export = `export type { ${contractInterface} } from ${importPath};`;
|
|
@@ -396,13 +485,13 @@ var import_command = require("@oclif/command");
|
|
|
396
485
|
|
|
397
486
|
// src/utils.ts
|
|
398
487
|
var import_native_bin2 = require("@clarigen/native-bin");
|
|
399
|
-
var
|
|
400
|
-
var
|
|
488
|
+
var import_path9 = require("path");
|
|
489
|
+
var import_promises8 = require("fs/promises");
|
|
401
490
|
|
|
402
491
|
// src/docs.ts
|
|
403
492
|
var import_claridocs = require("@clarigen/claridocs");
|
|
404
|
-
var
|
|
405
|
-
var
|
|
493
|
+
var import_promises5 = require("fs/promises");
|
|
494
|
+
var import_path6 = require("path");
|
|
406
495
|
async function generateMarkdownDoc({
|
|
407
496
|
contractFile,
|
|
408
497
|
contractName,
|
|
@@ -410,18 +499,18 @@ async function generateMarkdownDoc({
|
|
|
410
499
|
abi,
|
|
411
500
|
dirName
|
|
412
501
|
}) {
|
|
413
|
-
const contractSrc = await (0,
|
|
502
|
+
const contractSrc = await (0, import_promises5.readFile)(contractFile, { encoding: "utf-8" });
|
|
414
503
|
const docs = (0, import_claridocs.createContractDocInfo)({ contractSrc, abi });
|
|
415
|
-
const folder = (0,
|
|
416
|
-
const filePath = (0,
|
|
504
|
+
const folder = (0, import_path6.resolve)(process.cwd(), docsPath, dirName || ".");
|
|
505
|
+
const filePath = (0, import_path6.resolve)(folder, `${contractName}.md`);
|
|
417
506
|
const md = (0, import_claridocs.generateMarkdown)({
|
|
418
507
|
contract: docs,
|
|
419
|
-
contractFile: (0,
|
|
508
|
+
contractFile: (0, import_path6.relative)(folder, contractFile),
|
|
420
509
|
contractName,
|
|
421
510
|
abi
|
|
422
511
|
});
|
|
423
|
-
await (0,
|
|
424
|
-
await (0,
|
|
512
|
+
await (0, import_promises5.mkdir)(folder, { recursive: true });
|
|
513
|
+
await (0, import_promises5.writeFile)(filePath, md);
|
|
425
514
|
}
|
|
426
515
|
async function generateDocsIndex(configFile) {
|
|
427
516
|
if (!configFile.docs)
|
|
@@ -434,14 +523,14 @@ async function generateDocsIndex(configFile) {
|
|
|
434
523
|
|
|
435
524
|
${contractLines.join("\n")}
|
|
436
525
|
`;
|
|
437
|
-
const filepath = (0,
|
|
438
|
-
await (0,
|
|
526
|
+
const filepath = (0, import_path6.resolve)(process.cwd(), configFile.docs, "README.md");
|
|
527
|
+
await (0, import_promises5.writeFile)(filepath, fileContents);
|
|
439
528
|
}
|
|
440
529
|
|
|
441
530
|
// src/generate/single.ts
|
|
442
531
|
var import_core3 = require("@clarigen/core");
|
|
443
|
-
var
|
|
444
|
-
var
|
|
532
|
+
var import_path7 = require("path");
|
|
533
|
+
var import_promises6 = require("fs/promises");
|
|
445
534
|
var import_util = require("util");
|
|
446
535
|
function generateContractMeta(contract) {
|
|
447
536
|
const { abi } = contract;
|
|
@@ -479,7 +568,7 @@ function generateContractMeta(contract) {
|
|
|
479
568
|
return mapLine;
|
|
480
569
|
});
|
|
481
570
|
const otherAbi = JSON.stringify(rest);
|
|
482
|
-
const contractFile = (0,
|
|
571
|
+
const contractFile = (0, import_path7.relative)(process.cwd(), contract.contractFile);
|
|
483
572
|
return `{
|
|
484
573
|
${serializeLines("functions", functionLines)}
|
|
485
574
|
${serializeLines("variables", variableLines)}
|
|
@@ -544,143 +633,49 @@ function serializeLines(key, lines) {
|
|
|
544
633
|
},`;
|
|
545
634
|
}
|
|
546
635
|
async function getSingleTypes() {
|
|
547
|
-
const typesPath = (0,
|
|
548
|
-
const typesFile = await (0,
|
|
636
|
+
const typesPath = (0, import_path7.resolve)(__dirname, "../../dist/abi-types.ts.txt");
|
|
637
|
+
const typesFile = await (0, import_promises6.readFile)(typesPath, { encoding: "utf-8" });
|
|
549
638
|
return typesFile;
|
|
550
639
|
}
|
|
551
640
|
|
|
552
|
-
// src/writer.ts
|
|
553
|
-
var import_promises5 = require("fs/promises");
|
|
554
|
-
var import_path6 = require("path");
|
|
555
|
-
var import_prettier = require("prettier");
|
|
556
|
-
var defaultPrettierConfig = {
|
|
557
|
-
printWidth: 80,
|
|
558
|
-
semi: true,
|
|
559
|
-
singleQuote: true,
|
|
560
|
-
trailingComma: "es5"
|
|
561
|
-
};
|
|
562
|
-
async function resolvePrettierConfig() {
|
|
563
|
-
try {
|
|
564
|
-
const local = await (0, import_prettier.resolveConfig)(process.cwd());
|
|
565
|
-
if (local)
|
|
566
|
-
return local;
|
|
567
|
-
} catch (error) {
|
|
568
|
-
}
|
|
569
|
-
return defaultPrettierConfig;
|
|
570
|
-
}
|
|
571
|
-
async function formatFile(contents, path) {
|
|
572
|
-
try {
|
|
573
|
-
const fileName = (0, import_path6.basename)(path);
|
|
574
|
-
const config = await resolvePrettierConfig();
|
|
575
|
-
const formatted = (0, import_prettier.format)(contents, __spreadProps(__spreadValues({}, config), {
|
|
576
|
-
filepath: fileName
|
|
577
|
-
}));
|
|
578
|
-
return formatted;
|
|
579
|
-
} catch (error) {
|
|
580
|
-
}
|
|
581
|
-
return contents;
|
|
582
|
-
}
|
|
583
|
-
async function writeFile2(path, contents) {
|
|
584
|
-
const formatted = await formatFile(contents, path);
|
|
585
|
-
await (0, import_promises5.writeFile)(path, formatted);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
641
|
// src/generate/vars.ts
|
|
589
642
|
var import_core4 = require("@clarigen/core");
|
|
590
643
|
var import_native_bin = require("@clarigen/native-bin");
|
|
591
644
|
var import_clarity = require("micro-stacks/clarity");
|
|
592
|
-
async function getVariables({
|
|
593
|
-
abi,
|
|
594
|
-
contractIdentifier,
|
|
595
|
-
provider
|
|
596
|
-
}) {
|
|
597
|
-
const variableTransforms = abi.variables.map((variable) => {
|
|
598
|
-
return evalVariable({
|
|
599
|
-
variable,
|
|
600
|
-
provider,
|
|
601
|
-
contractIdentifier
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
const variables = await Promise.all(variableTransforms);
|
|
605
|
-
return variables;
|
|
606
|
-
}
|
|
607
|
-
async function evalVariable({
|
|
608
|
-
contractIdentifier,
|
|
609
|
-
variable,
|
|
610
|
-
provider
|
|
611
|
-
}) {
|
|
612
|
-
const code = getEvalCode(variable);
|
|
613
|
-
const result = await (0, import_native_bin.evalRaw)({
|
|
614
|
-
contractAddress: contractIdentifier,
|
|
615
|
-
code,
|
|
616
|
-
provider
|
|
617
|
-
});
|
|
618
|
-
const resultCV = (0, import_clarity.hexToCV)(result.output_serialized);
|
|
619
|
-
const value = (0, import_core4.cvToValue)(resultCV, true);
|
|
620
|
-
return __spreadProps(__spreadValues({}, variable), {
|
|
621
|
-
defaultValue: value
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function getEvalCode(variable) {
|
|
625
|
-
const { access: access2 } = variable;
|
|
626
|
-
if (access2 === "variable") {
|
|
627
|
-
return `(var-get ${variable.name})`;
|
|
628
|
-
}
|
|
629
|
-
return variable.name;
|
|
630
|
-
}
|
|
631
645
|
|
|
632
|
-
// src/
|
|
633
|
-
var
|
|
634
|
-
var
|
|
635
|
-
var
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const varName = `${network}Deployment`;
|
|
648
|
-
const contents = `export const ${varName} = ${JSON.stringify(plan)} as const;
|
|
649
|
-
`;
|
|
650
|
-
const outputFile = (0, import_path7.resolve)(config.outputDir, "deployments", `${network}.ts`);
|
|
651
|
-
await writeFile2(outputFile, contents);
|
|
646
|
+
// src/deno-run.ts
|
|
647
|
+
var import_child_process = require("child_process");
|
|
648
|
+
var import_util2 = require("util");
|
|
649
|
+
var exec = (0, import_util2.promisify)(import_child_process.exec);
|
|
650
|
+
async function getClarinetSession(cwd) {
|
|
651
|
+
const scriptPath = "https://raw.githubusercontent.com/mechanismHQ/clarigen-deno/main/src/cli/print.ts";
|
|
652
|
+
const command = `clarinet run ${scriptPath}`;
|
|
653
|
+
try {
|
|
654
|
+
const result = await exec(command, { cwd });
|
|
655
|
+
const sessionJSON = result.stdout.split("\n")[1];
|
|
656
|
+
const session = JSON.parse(sessionJSON);
|
|
657
|
+
return session;
|
|
658
|
+
} catch (error) {
|
|
659
|
+
console.error(`Error getting clarinet session`);
|
|
660
|
+
throw error;
|
|
652
661
|
}
|
|
653
662
|
}
|
|
654
|
-
async function generateDeployments(config) {
|
|
655
|
-
const networks = ["devnet", "simnet", "testnet", "mainnet"];
|
|
656
|
-
const folder = (0, import_path7.resolve)(process.cwd(), config.outputDir, "deployments");
|
|
657
|
-
await (0, import_promises6.mkdir)(folder, { recursive: true });
|
|
658
|
-
const generates = networks.map((n) => generateDeployment(n, config));
|
|
659
|
-
await Promise.all(generates);
|
|
660
|
-
}
|
|
661
663
|
|
|
662
|
-
// src/
|
|
663
|
-
var
|
|
664
|
-
|
|
664
|
+
// src/contract.ts
|
|
665
|
+
var import_promises7 = require("fs/promises");
|
|
666
|
+
var import_path8 = require("path");
|
|
667
|
+
var generateFilesForContractWithSession = async ({
|
|
665
668
|
outputFolder,
|
|
666
|
-
|
|
667
|
-
contractAddress,
|
|
669
|
+
sessionContract,
|
|
668
670
|
dirName,
|
|
669
|
-
|
|
670
|
-
|
|
671
|
+
docsPath,
|
|
672
|
+
contractFile,
|
|
673
|
+
legacy = false
|
|
671
674
|
}) => {
|
|
672
|
-
const
|
|
673
|
-
const
|
|
674
|
-
const abi =
|
|
675
|
-
|
|
676
|
-
contractFilePath: contractFile,
|
|
677
|
-
provider
|
|
678
|
-
});
|
|
679
|
-
const variables = await getVariables({
|
|
680
|
-
abi,
|
|
681
|
-
contractIdentifier,
|
|
682
|
-
provider
|
|
683
|
-
});
|
|
675
|
+
const contractIdentifier = sessionContract.contract_id;
|
|
676
|
+
const [contractAddress, contractName] = contractIdentifier.split(".");
|
|
677
|
+
const abi = sessionContract.contract_interface;
|
|
678
|
+
const variables = [];
|
|
684
679
|
const typesFile = generateTypesFile(abi, contractName);
|
|
685
680
|
const indexFile = generateIndexFile({
|
|
686
681
|
contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
|
|
@@ -697,11 +692,13 @@ var generateFilesForContract = async ({
|
|
|
697
692
|
dirName
|
|
698
693
|
});
|
|
699
694
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
695
|
+
if (legacy) {
|
|
696
|
+
const outputPath = (0, import_path8.resolve)(outputFolder, dirName || ".", contractName);
|
|
697
|
+
await (0, import_promises7.mkdir)(outputPath, { recursive: true });
|
|
698
|
+
await writeFile((0, import_path8.resolve)(outputPath, "abi.ts"), abiFile);
|
|
699
|
+
await writeFile((0, import_path8.resolve)(outputPath, "index.ts"), indexFile);
|
|
700
|
+
await writeFile((0, import_path8.resolve)(outputPath, "types.ts"), typesFile);
|
|
701
|
+
}
|
|
705
702
|
return {
|
|
706
703
|
abi,
|
|
707
704
|
contractFile,
|
|
@@ -711,39 +708,46 @@ var generateFilesForContract = async ({
|
|
|
711
708
|
variables
|
|
712
709
|
};
|
|
713
710
|
};
|
|
711
|
+
|
|
712
|
+
// src/utils.ts
|
|
714
713
|
var generateProject = async (projectPath) => {
|
|
715
714
|
const configFile = await getProjectConfig(projectPath);
|
|
716
715
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
717
|
-
const outputFolder = (0,
|
|
716
|
+
const outputFolder = (0, import_path9.resolve)(projectPath, outputDir);
|
|
718
717
|
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
719
718
|
const metas = [];
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
719
|
+
const session = await getClarinetSession((0, import_path9.resolve)(projectPath, configFile.clarinet));
|
|
720
|
+
for (const contract of session.contracts) {
|
|
721
|
+
const configContract = contracts.find((c) => c.name === contract.contract_id.split(".")[1]);
|
|
722
|
+
if (typeof configContract === "undefined") {
|
|
723
|
+
throw new Error(`No config contract found for ${contract.contract_id}`);
|
|
724
|
+
}
|
|
725
|
+
const contractFile = (0, import_path9.resolve)(projectPath, configFile.clarinet, configContract.file);
|
|
726
|
+
const meta = await generateFilesForContractWithSession({
|
|
727
|
+
sessionContract: contract,
|
|
725
728
|
outputFolder,
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
contractName: contract.name,
|
|
730
|
-
docsPath: configFile.docs
|
|
729
|
+
docsPath: configFile.docs,
|
|
730
|
+
contractFile,
|
|
731
|
+
legacy: configFile.legacy
|
|
731
732
|
});
|
|
732
733
|
metas.push(meta);
|
|
733
734
|
}
|
|
734
|
-
const indexFile = generateProjectIndexFile(configFile);
|
|
735
735
|
await generateDocsIndex(configFile);
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
736
|
+
if (configFile.legacy) {
|
|
737
|
+
const indexFile = generateProjectIndexFile(configFile);
|
|
738
|
+
const indexPath = (0, import_path9.resolve)(outputFolder, "index.ts");
|
|
739
|
+
await writeFile(indexPath, indexFile);
|
|
740
|
+
}
|
|
741
|
+
const singleFileContents = await generateSingleFile(configFile, metas);
|
|
742
|
+
const singleFile = configFile.legacy ? "single.ts" : "index.ts";
|
|
743
|
+
const singlePath = (0, import_path9.resolve)(outputFolder, singleFile);
|
|
744
|
+
await writeFile(singlePath, singleFileContents);
|
|
741
745
|
await generateDeployments(configFile);
|
|
742
746
|
};
|
|
743
747
|
|
|
744
748
|
// src/commands/index.ts
|
|
745
749
|
var import_chokidar = require("chokidar");
|
|
746
|
-
var
|
|
750
|
+
var import_path10 = require("path");
|
|
747
751
|
var import_chalk = require("chalk");
|
|
748
752
|
var import_ora = __toESM(require("ora"));
|
|
749
753
|
var _Generate = class extends import_command.Command {
|
|
@@ -765,7 +769,7 @@ ${String(error.message)}`);
|
|
|
765
769
|
}
|
|
766
770
|
watcher.on("change", (path) => {
|
|
767
771
|
const cb = async () => {
|
|
768
|
-
const file = (0,
|
|
772
|
+
const file = (0, import_path10.basename)(path);
|
|
769
773
|
spinner.clear();
|
|
770
774
|
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
771
775
|
try {
|
|
@@ -787,7 +791,11 @@ ${msg}`);
|
|
|
787
791
|
void cb();
|
|
788
792
|
});
|
|
789
793
|
} else {
|
|
790
|
-
|
|
794
|
+
try {
|
|
795
|
+
await generateProject(cwd);
|
|
796
|
+
} catch (error) {
|
|
797
|
+
console.log(error);
|
|
798
|
+
}
|
|
791
799
|
}
|
|
792
800
|
}
|
|
793
801
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@clarigen/cli",
|
|
3
3
|
"description": "A CLI for generating a Typescript interface for a Clarity contract.",
|
|
4
4
|
"author": "Hank Stoever",
|
|
5
|
-
"version": "1.0.0-next.
|
|
5
|
+
"version": "1.0.0-next.26",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"main": "./dist/index.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"ts-node": "^9.1.1"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@clarigen/claridocs": "1.0.0-next.
|
|
42
|
-
"@clarigen/core": "1.0.0-next.
|
|
43
|
-
"@clarigen/native-bin": "1.0.0-next.
|
|
41
|
+
"@clarigen/claridocs": "1.0.0-next.25",
|
|
42
|
+
"@clarigen/core": "1.0.0-next.26",
|
|
43
|
+
"@clarigen/native-bin": "1.0.0-next.25",
|
|
44
44
|
"@iarna/toml": "^2.2.5",
|
|
45
45
|
"@oclif/command": "^1.8.0",
|
|
46
46
|
"@oclif/config": "^1.17.0",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
|
|
70
70
|
"typecheck": "tsc --noEmit -p tsconfig-test.json",
|
|
71
71
|
"demo": "pnpm build && node bin/run",
|
|
72
|
-
"publish:dev": "yalc publish --push"
|
|
72
|
+
"publish:dev": "pnpm build && yalc publish --push"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/clarinet-config.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
} from 'micro-stacks/wallet-sdk';
|
|
9
9
|
import { array as toposort } from 'toposort';
|
|
10
10
|
import { StacksNetworkVersion } from 'micro-stacks/crypto';
|
|
11
|
+
import { parseDeployment } from './generate/deployment';
|
|
12
|
+
import { SimnetDeploymentPlan } from '@clarigen/core';
|
|
11
13
|
|
|
12
14
|
interface ClarinetConfigAccount {
|
|
13
15
|
mnemonic: string;
|
|
@@ -63,6 +65,27 @@ export async function getClarinetConfig(folder: string) {
|
|
|
63
65
|
return config;
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
export async function getContractsFromDeployment(
|
|
69
|
+
clarinetPath?: string
|
|
70
|
+
): Promise<ConfigContract[]> {
|
|
71
|
+
const simnetPath = resolve(
|
|
72
|
+
clarinetPath || process.cwd(),
|
|
73
|
+
'deployments/default.simnet-plan.yaml'
|
|
74
|
+
);
|
|
75
|
+
const deployment = (await parseDeployment(
|
|
76
|
+
simnetPath
|
|
77
|
+
)) as SimnetDeploymentPlan;
|
|
78
|
+
const txs = deployment.plan.batches[0].transactions;
|
|
79
|
+
return txs.map((_tx) => {
|
|
80
|
+
const tx = _tx['emulated-contract-publish'];
|
|
81
|
+
return {
|
|
82
|
+
file: tx.path,
|
|
83
|
+
name: tx['contract-name'],
|
|
84
|
+
address: tx['emulated-sender'],
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
66
89
|
export function getContractsFromClarinet(
|
|
67
90
|
clarinetConfig: ClarinetConfig,
|
|
68
91
|
accounts: ClarinetAccounts
|
package/src/commands/index.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { readFile, access } from 'fs/promises';
|
|
|
3
3
|
import { constants } from 'fs';
|
|
4
4
|
import {
|
|
5
5
|
ClarinetAccounts,
|
|
6
|
+
ClarinetConfig,
|
|
6
7
|
getClarinetAccounts,
|
|
7
8
|
getClarinetConfig,
|
|
8
9
|
getContractsFromClarinet,
|
|
10
|
+
getContractsFromDeployment,
|
|
9
11
|
} from './clarinet-config';
|
|
10
12
|
|
|
11
13
|
export interface ConfigContract {
|
|
@@ -18,6 +20,7 @@ export interface ConfigFileContents {
|
|
|
18
20
|
outputDir: string;
|
|
19
21
|
clarinet: string;
|
|
20
22
|
docs?: string;
|
|
23
|
+
legacy?: boolean;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export interface ConfigFile extends ConfigFileContents {
|
|
@@ -30,6 +33,7 @@ export interface ConfigFile extends ConfigFileContents {
|
|
|
30
33
|
export const defaultConfigFile: ConfigFileContents = {
|
|
31
34
|
outputDir: 'src/clarigen',
|
|
32
35
|
clarinet: '.',
|
|
36
|
+
legacy: false,
|
|
33
37
|
};
|
|
34
38
|
|
|
35
39
|
export function configFilePath(rootPath: string) {
|
|
@@ -66,7 +70,12 @@ export async function getProjectConfig(rootPath: string): Promise<ConfigFile> {
|
|
|
66
70
|
const clarinetPath = resolve(rootPath, configFile.clarinet);
|
|
67
71
|
const clarinet = await getClarinetConfig(clarinetPath);
|
|
68
72
|
const accounts = await getClarinetAccounts(clarinetPath);
|
|
69
|
-
|
|
73
|
+
let contracts: ConfigContract[];
|
|
74
|
+
try {
|
|
75
|
+
contracts = await getContractsFromDeployment(clarinetPath);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
contracts = getContractsFromClarinet(clarinet, accounts);
|
|
78
|
+
}
|
|
70
79
|
const contractsDir = relative(
|
|
71
80
|
process.cwd(),
|
|
72
81
|
join(configFile.clarinet, 'contracts')
|