@clarigen/cli 1.0.0-next.21 → 1.0.0-next.25
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 +187 -157
- package/dist/index.js +187 -157
- package/package.json +13 -9
- package/src/clarinet-config.ts +29 -13
- package/src/commands/index.ts +5 -1
- package/src/config.ts +8 -1
- package/src/contract.ts +65 -0
- package/src/deno-run.ts +35 -0
- package/src/generate/deployment.ts +45 -0
- package/src/generate/files.ts +1 -1
- package/src/utils.ts +23 -10
package/dist/commands/index.js
CHANGED
|
@@ -58,37 +58,118 @@ var import_command2 = require("@oclif/command");
|
|
|
58
58
|
|
|
59
59
|
// src/generate/files.ts
|
|
60
60
|
var import_core2 = require("@clarigen/core");
|
|
61
|
-
var
|
|
61
|
+
var import_path5 = require("path");
|
|
62
62
|
|
|
63
63
|
// src/index.ts
|
|
64
64
|
var import_command = require("@oclif/command");
|
|
65
65
|
|
|
66
66
|
// src/config.ts
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
var
|
|
67
|
+
var import_path4 = require("path");
|
|
68
|
+
var import_promises4 = require("fs/promises");
|
|
69
|
+
var import_fs2 = require("fs");
|
|
70
70
|
|
|
71
71
|
// src/clarinet-config.ts
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
72
|
+
var import_toml = require("@iarna/toml");
|
|
73
|
+
var import_path3 = require("path");
|
|
74
|
+
var import_promises3 = require("fs/promises");
|
|
75
75
|
var import_wallet_sdk = require("micro-stacks/wallet-sdk");
|
|
76
76
|
var import_toposort = require("toposort");
|
|
77
77
|
var import_crypto = require("micro-stacks/crypto");
|
|
78
|
+
|
|
79
|
+
// src/generate/deployment.ts
|
|
80
|
+
var import_js_yaml = require("js-yaml");
|
|
81
|
+
var import_promises2 = require("fs/promises");
|
|
82
|
+
var import_path2 = require("path");
|
|
83
|
+
var import_fs = require("fs");
|
|
84
|
+
|
|
85
|
+
// src/writer.ts
|
|
86
|
+
var import_promises = require("fs/promises");
|
|
87
|
+
var import_path = require("path");
|
|
88
|
+
var import_prettier = require("prettier");
|
|
89
|
+
var defaultPrettierConfig = {
|
|
90
|
+
printWidth: 80,
|
|
91
|
+
semi: true,
|
|
92
|
+
singleQuote: true,
|
|
93
|
+
trailingComma: "es5"
|
|
94
|
+
};
|
|
95
|
+
async function resolvePrettierConfig() {
|
|
96
|
+
try {
|
|
97
|
+
const local = await (0, import_prettier.resolveConfig)(process.cwd());
|
|
98
|
+
if (local)
|
|
99
|
+
return local;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
}
|
|
102
|
+
return defaultPrettierConfig;
|
|
103
|
+
}
|
|
104
|
+
async function formatFile(contents, path) {
|
|
105
|
+
try {
|
|
106
|
+
const fileName = (0, import_path.basename)(path);
|
|
107
|
+
const config = await resolvePrettierConfig();
|
|
108
|
+
const formatted = (0, import_prettier.format)(contents, __spreadProps(__spreadValues({}, config), {
|
|
109
|
+
filepath: fileName
|
|
110
|
+
}));
|
|
111
|
+
return formatted;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
}
|
|
114
|
+
return contents;
|
|
115
|
+
}
|
|
116
|
+
async function writeFile(path, contents) {
|
|
117
|
+
const formatted = await formatFile(contents, path);
|
|
118
|
+
await (0, import_promises.writeFile)(path, formatted);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/generate/deployment.ts
|
|
122
|
+
async function parseDeployment(path) {
|
|
123
|
+
const contents = await (0, import_promises2.readFile)(path, { encoding: "utf-8" });
|
|
124
|
+
const parsed = (0, import_js_yaml.load)(contents);
|
|
125
|
+
return parsed;
|
|
126
|
+
}
|
|
127
|
+
async function generateDeployment(network, config) {
|
|
128
|
+
const file = `default.${network}-plan.yaml`;
|
|
129
|
+
const deploymentPath = (0, import_path2.resolve)(process.cwd(), config.clarinet, "deployments", file);
|
|
130
|
+
if ((0, import_fs.existsSync)(deploymentPath)) {
|
|
131
|
+
const plan = await parseDeployment(deploymentPath);
|
|
132
|
+
const varName = `${network}Deployment`;
|
|
133
|
+
const contents = `export const ${varName} = ${JSON.stringify(plan)} as const;
|
|
134
|
+
`;
|
|
135
|
+
const outputFile = (0, import_path2.resolve)(config.outputDir, "deployments", `${network}.ts`);
|
|
136
|
+
await writeFile(outputFile, contents);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function generateDeployments(config) {
|
|
140
|
+
const networks = ["devnet", "simnet", "testnet", "mainnet"];
|
|
141
|
+
const folder = (0, import_path2.resolve)(process.cwd(), config.outputDir, "deployments");
|
|
142
|
+
await (0, import_promises2.mkdir)(folder, { recursive: true });
|
|
143
|
+
const generates = networks.map((n) => generateDeployment(n, config));
|
|
144
|
+
await Promise.all(generates);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/clarinet-config.ts
|
|
78
148
|
async function getClarinetDevConfig(folder) {
|
|
79
|
-
const baseConfigPath = (0,
|
|
80
|
-
const configContents = await (0,
|
|
81
|
-
const config = (0,
|
|
82
|
-
longer: true
|
|
83
|
-
});
|
|
149
|
+
const baseConfigPath = (0, import_path3.resolve)(folder, "settings", "Devnet.toml");
|
|
150
|
+
const configContents = await (0, import_promises3.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
151
|
+
const config = (0, import_toml.parse)(configContents);
|
|
84
152
|
return config;
|
|
85
153
|
}
|
|
86
154
|
async function getClarinetConfig(folder) {
|
|
87
|
-
const baseConfigPath = (0,
|
|
88
|
-
const configContents = await (0,
|
|
89
|
-
const config = (0,
|
|
155
|
+
const baseConfigPath = (0, import_path3.resolve)(folder, "Clarinet.toml");
|
|
156
|
+
const configContents = await (0, import_promises3.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
157
|
+
const config = (0, import_toml.parse)(configContents);
|
|
90
158
|
return config;
|
|
91
159
|
}
|
|
160
|
+
async function getContractsFromDeployment(clarinetPath) {
|
|
161
|
+
const simnetPath = (0, import_path3.resolve)(clarinetPath || process.cwd(), "deployments/default.simnet-plan.yaml");
|
|
162
|
+
const deployment = await parseDeployment(simnetPath);
|
|
163
|
+
const txs = deployment.plan.batches[0].transactions;
|
|
164
|
+
return txs.map((_tx) => {
|
|
165
|
+
const tx = _tx["emulated-contract-publish"];
|
|
166
|
+
return {
|
|
167
|
+
file: tx.path,
|
|
168
|
+
name: tx["contract-name"],
|
|
169
|
+
address: tx["emulated-sender"]
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
}
|
|
92
173
|
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
93
174
|
const deployerAddress = accounts.deployer.address;
|
|
94
175
|
const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
|
|
@@ -107,8 +188,9 @@ function sortClarinetContracts(contractsConfig) {
|
|
|
107
188
|
const edges = [];
|
|
108
189
|
const nodes = [];
|
|
109
190
|
Object.entries(contractsConfig).forEach(([contractName, info]) => {
|
|
191
|
+
var _a;
|
|
110
192
|
nodes.push(contractName);
|
|
111
|
-
info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
|
|
193
|
+
(_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
|
|
112
194
|
});
|
|
113
195
|
const sorted = (0, import_toposort.array)(nodes, edges).reverse();
|
|
114
196
|
return sorted;
|
|
@@ -136,11 +218,11 @@ var defaultConfigFile = {
|
|
|
136
218
|
clarinet: "."
|
|
137
219
|
};
|
|
138
220
|
function configFilePath(rootPath) {
|
|
139
|
-
return (0,
|
|
221
|
+
return (0, import_path4.resolve)(rootPath, "clarigen.config.json");
|
|
140
222
|
}
|
|
141
223
|
async function configFileExists(configPath) {
|
|
142
224
|
try {
|
|
143
|
-
await (0,
|
|
225
|
+
await (0, import_promises4.access)(configPath, import_fs2.constants.R_OK);
|
|
144
226
|
return true;
|
|
145
227
|
} catch (error) {
|
|
146
228
|
return false;
|
|
@@ -150,7 +232,7 @@ async function getConfigFile(rootPath) {
|
|
|
150
232
|
const fullPath = configFilePath(rootPath);
|
|
151
233
|
const exists = await configFileExists(fullPath);
|
|
152
234
|
if (exists) {
|
|
153
|
-
const configContents = await (0,
|
|
235
|
+
const configContents = await (0, import_promises4.readFile)(fullPath, { encoding: "utf-8" });
|
|
154
236
|
const configFile = JSON.parse(configContents);
|
|
155
237
|
return __spreadValues(__spreadValues({}, defaultConfigFile), configFile);
|
|
156
238
|
}
|
|
@@ -159,11 +241,16 @@ async function getConfigFile(rootPath) {
|
|
|
159
241
|
async function getProjectConfig(rootPath) {
|
|
160
242
|
var _a, _b;
|
|
161
243
|
const configFile = await getConfigFile(rootPath);
|
|
162
|
-
const clarinetPath = (0,
|
|
244
|
+
const clarinetPath = (0, import_path4.resolve)(rootPath, configFile.clarinet);
|
|
163
245
|
const clarinet = await getClarinetConfig(clarinetPath);
|
|
164
246
|
const accounts = await getClarinetAccounts(clarinetPath);
|
|
165
|
-
|
|
166
|
-
|
|
247
|
+
let contracts;
|
|
248
|
+
try {
|
|
249
|
+
contracts = await getContractsFromDeployment(clarinetPath);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
contracts = getContractsFromClarinet(clarinet, accounts);
|
|
252
|
+
}
|
|
253
|
+
const contractsDir = (0, import_path4.relative)(process.cwd(), (0, import_path4.join)(configFile.clarinet, "contracts"));
|
|
167
254
|
return __spreadProps(__spreadValues({}, configFile), {
|
|
168
255
|
outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
|
|
169
256
|
docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
|
|
@@ -362,8 +449,8 @@ export const accounts = {
|
|
|
362
449
|
const contractVar = (0, import_core2.toCamelCase)(contractName);
|
|
363
450
|
const contractInfo = `${contractVar}Info`;
|
|
364
451
|
const contractInterface = `${(0, import_core2.toCamelCase)(contractName, true)}Contract`;
|
|
365
|
-
const dirName = (0,
|
|
366
|
-
const importPath = `'./${
|
|
452
|
+
const dirName = (0, import_path5.dirname)(contract.file);
|
|
453
|
+
const importPath = `'./${contractName}'`;
|
|
367
454
|
const _import = `import { ${contractInfo} } from ${importPath};`;
|
|
368
455
|
imports.push(_import);
|
|
369
456
|
const _export = `export type { ${contractInterface} } from ${importPath};`;
|
|
@@ -386,13 +473,13 @@ export const contracts = {
|
|
|
386
473
|
|
|
387
474
|
// src/utils.ts
|
|
388
475
|
var import_native_bin2 = require("@clarigen/native-bin");
|
|
389
|
-
var
|
|
390
|
-
var
|
|
476
|
+
var import_path9 = require("path");
|
|
477
|
+
var import_promises8 = require("fs/promises");
|
|
391
478
|
|
|
392
479
|
// src/docs.ts
|
|
393
480
|
var import_claridocs = require("@clarigen/claridocs");
|
|
394
|
-
var
|
|
395
|
-
var
|
|
481
|
+
var import_promises5 = require("fs/promises");
|
|
482
|
+
var import_path6 = require("path");
|
|
396
483
|
async function generateMarkdownDoc({
|
|
397
484
|
contractFile,
|
|
398
485
|
contractName,
|
|
@@ -400,18 +487,18 @@ async function generateMarkdownDoc({
|
|
|
400
487
|
abi,
|
|
401
488
|
dirName
|
|
402
489
|
}) {
|
|
403
|
-
const contractSrc = await (0,
|
|
490
|
+
const contractSrc = await (0, import_promises5.readFile)(contractFile, { encoding: "utf-8" });
|
|
404
491
|
const docs = (0, import_claridocs.createContractDocInfo)({ contractSrc, abi });
|
|
405
|
-
const folder = (0,
|
|
406
|
-
const filePath = (0,
|
|
492
|
+
const folder = (0, import_path6.resolve)(process.cwd(), docsPath, dirName || ".");
|
|
493
|
+
const filePath = (0, import_path6.resolve)(folder, `${contractName}.md`);
|
|
407
494
|
const md = (0, import_claridocs.generateMarkdown)({
|
|
408
495
|
contract: docs,
|
|
409
|
-
contractFile: (0,
|
|
496
|
+
contractFile: (0, import_path6.relative)(folder, contractFile),
|
|
410
497
|
contractName,
|
|
411
498
|
abi
|
|
412
499
|
});
|
|
413
|
-
await (0,
|
|
414
|
-
await (0,
|
|
500
|
+
await (0, import_promises5.mkdir)(folder, { recursive: true });
|
|
501
|
+
await (0, import_promises5.writeFile)(filePath, md);
|
|
415
502
|
}
|
|
416
503
|
async function generateDocsIndex(configFile) {
|
|
417
504
|
if (!configFile.docs)
|
|
@@ -424,14 +511,14 @@ async function generateDocsIndex(configFile) {
|
|
|
424
511
|
|
|
425
512
|
${contractLines.join("\n")}
|
|
426
513
|
`;
|
|
427
|
-
const filepath = (0,
|
|
428
|
-
await (0,
|
|
514
|
+
const filepath = (0, import_path6.resolve)(process.cwd(), configFile.docs, "README.md");
|
|
515
|
+
await (0, import_promises5.writeFile)(filepath, fileContents);
|
|
429
516
|
}
|
|
430
517
|
|
|
431
518
|
// src/generate/single.ts
|
|
432
519
|
var import_core3 = require("@clarigen/core");
|
|
433
|
-
var
|
|
434
|
-
var
|
|
520
|
+
var import_path7 = require("path");
|
|
521
|
+
var import_promises6 = require("fs/promises");
|
|
435
522
|
var import_util = require("util");
|
|
436
523
|
function generateContractMeta(contract) {
|
|
437
524
|
const { abi } = contract;
|
|
@@ -469,7 +556,7 @@ function generateContractMeta(contract) {
|
|
|
469
556
|
return mapLine;
|
|
470
557
|
});
|
|
471
558
|
const otherAbi = JSON.stringify(rest);
|
|
472
|
-
const contractFile = (0,
|
|
559
|
+
const contractFile = (0, import_path7.relative)(process.cwd(), contract.contractFile);
|
|
473
560
|
return `{
|
|
474
561
|
${serializeLines("functions", functionLines)}
|
|
475
562
|
${serializeLines("variables", variableLines)}
|
|
@@ -534,116 +621,51 @@ function serializeLines(key, lines) {
|
|
|
534
621
|
},`;
|
|
535
622
|
}
|
|
536
623
|
async function getSingleTypes() {
|
|
537
|
-
const typesPath = (0,
|
|
538
|
-
const typesFile = await (0,
|
|
624
|
+
const typesPath = (0, import_path7.resolve)(__dirname, "../../dist/abi-types.ts.txt");
|
|
625
|
+
const typesFile = await (0, import_promises6.readFile)(typesPath, { encoding: "utf-8" });
|
|
539
626
|
return typesFile;
|
|
540
627
|
}
|
|
541
628
|
|
|
542
|
-
// src/writer.ts
|
|
543
|
-
var import_promises5 = require("fs/promises");
|
|
544
|
-
var import_path6 = require("path");
|
|
545
|
-
var import_prettier = require("prettier");
|
|
546
|
-
var defaultPrettierConfig = {
|
|
547
|
-
printWidth: 80,
|
|
548
|
-
semi: true,
|
|
549
|
-
singleQuote: true,
|
|
550
|
-
trailingComma: "es5"
|
|
551
|
-
};
|
|
552
|
-
async function resolvePrettierConfig() {
|
|
553
|
-
try {
|
|
554
|
-
const local = await (0, import_prettier.resolveConfig)(process.cwd());
|
|
555
|
-
if (local)
|
|
556
|
-
return local;
|
|
557
|
-
} catch (error) {
|
|
558
|
-
}
|
|
559
|
-
return defaultPrettierConfig;
|
|
560
|
-
}
|
|
561
|
-
async function formatFile(contents, path) {
|
|
562
|
-
try {
|
|
563
|
-
const fileName = (0, import_path6.basename)(path);
|
|
564
|
-
const config = await resolvePrettierConfig();
|
|
565
|
-
const formatted = (0, import_prettier.format)(contents, __spreadProps(__spreadValues({}, config), {
|
|
566
|
-
filepath: fileName
|
|
567
|
-
}));
|
|
568
|
-
return formatted;
|
|
569
|
-
} catch (error) {
|
|
570
|
-
}
|
|
571
|
-
return contents;
|
|
572
|
-
}
|
|
573
|
-
async function writeFile2(path, contents) {
|
|
574
|
-
const formatted = await formatFile(contents, path);
|
|
575
|
-
await (0, import_promises5.writeFile)(path, formatted);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
629
|
// src/generate/vars.ts
|
|
579
630
|
var import_core4 = require("@clarigen/core");
|
|
580
631
|
var import_native_bin = require("@clarigen/native-bin");
|
|
581
632
|
var import_clarity = require("micro-stacks/clarity");
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
contractIdentifier,
|
|
599
|
-
variable,
|
|
600
|
-
provider
|
|
601
|
-
}) {
|
|
602
|
-
const code = getEvalCode(variable);
|
|
603
|
-
const result = await (0, import_native_bin.evalRaw)({
|
|
604
|
-
contractAddress: contractIdentifier,
|
|
605
|
-
code,
|
|
606
|
-
provider
|
|
607
|
-
});
|
|
608
|
-
const resultCV = (0, import_clarity.hexToCV)(result.output_serialized);
|
|
609
|
-
const value = (0, import_core4.cvToValue)(resultCV, true);
|
|
610
|
-
return __spreadProps(__spreadValues({}, variable), {
|
|
611
|
-
defaultValue: value
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
function getEvalCode(variable) {
|
|
615
|
-
const { access: access2 } = variable;
|
|
616
|
-
if (access2 === "variable") {
|
|
617
|
-
return `(var-get ${variable.name})`;
|
|
633
|
+
|
|
634
|
+
// src/deno-run.ts
|
|
635
|
+
var import_child_process = require("child_process");
|
|
636
|
+
var import_util2 = require("util");
|
|
637
|
+
var exec = (0, import_util2.promisify)(import_child_process.exec);
|
|
638
|
+
async function getClarinetSession(cwd) {
|
|
639
|
+
const scriptPath = "https://raw.githubusercontent.com/mechanismHQ/clarigen-deno/main/src/cli/print.ts";
|
|
640
|
+
const command = `clarinet run ${scriptPath}`;
|
|
641
|
+
try {
|
|
642
|
+
const result = await exec(command, { cwd });
|
|
643
|
+
const sessionJSON = result.stdout.split("\n")[1];
|
|
644
|
+
const session = JSON.parse(sessionJSON);
|
|
645
|
+
return session;
|
|
646
|
+
} catch (error) {
|
|
647
|
+
console.error(`Error getting clarinet session`);
|
|
648
|
+
throw error;
|
|
618
649
|
}
|
|
619
|
-
return variable.name;
|
|
620
650
|
}
|
|
621
651
|
|
|
622
|
-
// src/
|
|
623
|
-
var
|
|
624
|
-
|
|
652
|
+
// src/contract.ts
|
|
653
|
+
var import_promises7 = require("fs/promises");
|
|
654
|
+
var import_path8 = require("path");
|
|
655
|
+
var generateFilesForContractWithSession = async ({
|
|
625
656
|
outputFolder,
|
|
626
|
-
|
|
627
|
-
contractAddress,
|
|
657
|
+
sessionContract,
|
|
628
658
|
dirName,
|
|
629
|
-
|
|
630
|
-
|
|
659
|
+
docsPath,
|
|
660
|
+
contractFile
|
|
631
661
|
}) => {
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
const abi =
|
|
635
|
-
|
|
636
|
-
contractFilePath: contractFile,
|
|
637
|
-
provider
|
|
638
|
-
});
|
|
639
|
-
const variables = await getVariables({
|
|
640
|
-
abi,
|
|
641
|
-
contractIdentifier,
|
|
642
|
-
provider
|
|
643
|
-
});
|
|
662
|
+
const contractIdentifier = sessionContract.contract_id;
|
|
663
|
+
const [contractAddress, contractName] = contractIdentifier.split(".");
|
|
664
|
+
const abi = sessionContract.contract_interface;
|
|
665
|
+
const variables = [];
|
|
644
666
|
const typesFile = generateTypesFile(abi, contractName);
|
|
645
667
|
const indexFile = generateIndexFile({
|
|
646
|
-
contractFile: (0,
|
|
668
|
+
contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
|
|
647
669
|
contractAddress,
|
|
648
670
|
contractName
|
|
649
671
|
});
|
|
@@ -657,11 +679,11 @@ var generateFilesForContract = async ({
|
|
|
657
679
|
dirName
|
|
658
680
|
});
|
|
659
681
|
}
|
|
660
|
-
const outputPath = (0,
|
|
661
|
-
await (0,
|
|
662
|
-
await
|
|
663
|
-
await
|
|
664
|
-
await
|
|
682
|
+
const outputPath = (0, import_path8.resolve)(outputFolder, dirName || ".", contractName);
|
|
683
|
+
await (0, import_promises7.mkdir)(outputPath, { recursive: true });
|
|
684
|
+
await writeFile((0, import_path8.resolve)(outputPath, "abi.ts"), abiFile);
|
|
685
|
+
await writeFile((0, import_path8.resolve)(outputPath, "index.ts"), indexFile);
|
|
686
|
+
await writeFile((0, import_path8.resolve)(outputPath, "types.ts"), typesFile);
|
|
665
687
|
return {
|
|
666
688
|
abi,
|
|
667
689
|
contractFile,
|
|
@@ -671,38 +693,42 @@ var generateFilesForContract = async ({
|
|
|
671
693
|
variables
|
|
672
694
|
};
|
|
673
695
|
};
|
|
696
|
+
|
|
697
|
+
// src/utils.ts
|
|
674
698
|
var generateProject = async (projectPath) => {
|
|
675
699
|
const configFile = await getProjectConfig(projectPath);
|
|
676
700
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
677
|
-
const outputFolder = (0,
|
|
701
|
+
const outputFolder = (0, import_path9.resolve)(projectPath, outputDir);
|
|
678
702
|
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
679
703
|
const metas = [];
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
704
|
+
const session = await getClarinetSession((0, import_path9.resolve)(projectPath, configFile.clarinet));
|
|
705
|
+
for (const contract of session.contracts) {
|
|
706
|
+
const configContract = contracts.find((c) => c.name === contract.contract_id.split(".")[1]);
|
|
707
|
+
if (typeof configContract === "undefined") {
|
|
708
|
+
throw new Error(`No config contract found for ${contract.contract_id}`);
|
|
709
|
+
}
|
|
710
|
+
const contractFile = (0, import_path9.resolve)(projectPath, configFile.clarinet, configContract.file);
|
|
711
|
+
const meta = await generateFilesForContractWithSession({
|
|
712
|
+
sessionContract: contract,
|
|
685
713
|
outputFolder,
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
dirName,
|
|
689
|
-
contractName: contract.name,
|
|
690
|
-
docsPath: configFile.docs
|
|
714
|
+
docsPath: configFile.docs,
|
|
715
|
+
contractFile
|
|
691
716
|
});
|
|
692
717
|
metas.push(meta);
|
|
693
718
|
}
|
|
694
719
|
const indexFile = generateProjectIndexFile(configFile);
|
|
695
720
|
await generateDocsIndex(configFile);
|
|
696
|
-
const indexPath = (0,
|
|
697
|
-
await
|
|
721
|
+
const indexPath = (0, import_path9.resolve)(outputFolder, "index.ts");
|
|
722
|
+
await writeFile(indexPath, indexFile);
|
|
698
723
|
const singleFile = await generateSingleFile(configFile, metas);
|
|
699
|
-
const singlePath = (0,
|
|
700
|
-
await
|
|
724
|
+
const singlePath = (0, import_path9.resolve)(outputFolder, "single.ts");
|
|
725
|
+
await writeFile(singlePath, singleFile);
|
|
726
|
+
await generateDeployments(configFile);
|
|
701
727
|
};
|
|
702
728
|
|
|
703
729
|
// src/commands/index.ts
|
|
704
730
|
var import_chokidar = require("chokidar");
|
|
705
|
-
var
|
|
731
|
+
var import_path10 = require("path");
|
|
706
732
|
var import_chalk = require("chalk");
|
|
707
733
|
var import_ora = __toESM(require("ora"));
|
|
708
734
|
var _Generate = class extends import_command2.Command {
|
|
@@ -724,7 +750,7 @@ ${String(error.message)}`);
|
|
|
724
750
|
}
|
|
725
751
|
watcher.on("change", (path) => {
|
|
726
752
|
const cb = async () => {
|
|
727
|
-
const file = (0,
|
|
753
|
+
const file = (0, import_path10.basename)(path);
|
|
728
754
|
spinner.clear();
|
|
729
755
|
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
730
756
|
try {
|
|
@@ -746,7 +772,11 @@ ${msg}`);
|
|
|
746
772
|
void cb();
|
|
747
773
|
});
|
|
748
774
|
} else {
|
|
749
|
-
|
|
775
|
+
try {
|
|
776
|
+
await generateProject(cwd);
|
|
777
|
+
} catch (error) {
|
|
778
|
+
console.log(error);
|
|
779
|
+
}
|
|
750
780
|
}
|
|
751
781
|
}
|
|
752
782
|
};
|