@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/index.js CHANGED
@@ -70,31 +70,112 @@ module.exports = __toCommonJS(src_exports);
70
70
  var import_command2 = require("@oclif/command");
71
71
 
72
72
  // src/config.ts
73
- var import_path2 = require("path");
74
- var import_promises2 = require("fs/promises");
75
- var import_fs = require("fs");
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
- var import_j_toml = require("@ltd/j-toml");
79
- var import_path = require("path");
80
- var import_promises = require("fs/promises");
78
+ var import_toml = require("@iarna/toml");
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, import_path.resolve)(folder, "settings", "Devnet.toml");
86
- const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
87
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true, {
88
- longer: true
89
- });
155
+ const baseConfigPath = (0, import_path3.resolve)(folder, "settings", "Devnet.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
  }
92
160
  async function getClarinetConfig(folder) {
93
- const baseConfigPath = (0, import_path.resolve)(folder, "Clarinet.toml");
94
- const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
95
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true);
161
+ const baseConfigPath = (0, import_path3.resolve)(folder, "Clarinet.toml");
162
+ const configContents = await (0, import_promises3.readFile)(baseConfigPath, { encoding: "utf-8" });
163
+ const config = (0, import_toml.parse)(configContents);
96
164
  return config;
97
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
+ }
98
179
  function getContractsFromClarinet(clarinetConfig, accounts) {
99
180
  const deployerAddress = accounts.deployer.address;
100
181
  const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
@@ -113,8 +194,9 @@ function sortClarinetContracts(contractsConfig) {
113
194
  const edges = [];
114
195
  const nodes = [];
115
196
  Object.entries(contractsConfig).forEach(([contractName, info]) => {
197
+ var _a;
116
198
  nodes.push(contractName);
117
- info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
199
+ (_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
118
200
  });
119
201
  const sorted = (0, import_toposort.array)(nodes, edges).reverse();
120
202
  return sorted;
@@ -142,11 +224,11 @@ var defaultConfigFile = {
142
224
  clarinet: "."
143
225
  };
144
226
  function configFilePath(rootPath) {
145
- return (0, import_path2.resolve)(rootPath, "clarigen.config.json");
227
+ return (0, import_path4.resolve)(rootPath, "clarigen.config.json");
146
228
  }
147
229
  async function configFileExists(configPath) {
148
230
  try {
149
- await (0, import_promises2.access)(configPath, import_fs.constants.R_OK);
231
+ await (0, import_promises4.access)(configPath, import_fs2.constants.R_OK);
150
232
  return true;
151
233
  } catch (error) {
152
234
  return false;
@@ -156,7 +238,7 @@ async function getConfigFile(rootPath) {
156
238
  const fullPath = configFilePath(rootPath);
157
239
  const exists = await configFileExists(fullPath);
158
240
  if (exists) {
159
- const configContents = await (0, import_promises2.readFile)(fullPath, { encoding: "utf-8" });
241
+ const configContents = await (0, import_promises4.readFile)(fullPath, { encoding: "utf-8" });
160
242
  const configFile = JSON.parse(configContents);
161
243
  return __spreadValues(__spreadValues({}, defaultConfigFile), configFile);
162
244
  }
@@ -165,11 +247,16 @@ async function getConfigFile(rootPath) {
165
247
  async function getProjectConfig(rootPath) {
166
248
  var _a, _b;
167
249
  const configFile = await getConfigFile(rootPath);
168
- const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet);
250
+ const clarinetPath = (0, import_path4.resolve)(rootPath, configFile.clarinet);
169
251
  const clarinet = await getClarinetConfig(clarinetPath);
170
252
  const accounts = await getClarinetAccounts(clarinetPath);
171
- const contracts = getContractsFromClarinet(clarinet, accounts);
172
- const contractsDir = (0, import_path2.relative)(process.cwd(), (0, import_path2.join)(configFile.clarinet, "contracts"));
253
+ let contracts;
254
+ try {
255
+ contracts = await getContractsFromDeployment(clarinetPath);
256
+ } catch (error) {
257
+ contracts = getContractsFromClarinet(clarinet, accounts);
258
+ }
259
+ const contractsDir = (0, import_path4.relative)(process.cwd(), (0, import_path4.join)(configFile.clarinet, "contracts"));
173
260
  return __spreadProps(__spreadValues({}, configFile), {
174
261
  outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
175
262
  docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
@@ -283,7 +370,7 @@ function makePureTypes(abi) {
283
370
 
284
371
  // src/generate/files.ts
285
372
  var import_core2 = require("@clarigen/core");
286
- var import_path3 = require("path");
373
+ var import_path5 = require("path");
287
374
  var generateInterfaceFile = ({
288
375
  contractName,
289
376
  abi
@@ -370,8 +457,8 @@ export const accounts = {
370
457
  const contractVar = (0, import_core2.toCamelCase)(contractName);
371
458
  const contractInfo = `${contractVar}Info`;
372
459
  const contractInterface = `${(0, import_core2.toCamelCase)(contractName, true)}Contract`;
373
- const dirName = (0, import_path3.dirname)(contract.file);
374
- const importPath = `'./${(0, import_path3.join)(dirName || ".", contractName)}'`;
460
+ const dirName = (0, import_path5.dirname)(contract.file);
461
+ const importPath = `'./${contractName}'`;
375
462
  const _import = `import { ${contractInfo} } from ${importPath};`;
376
463
  imports.push(_import);
377
464
  const _export = `export type { ${contractInterface} } from ${importPath};`;
@@ -397,13 +484,13 @@ var import_command = require("@oclif/command");
397
484
 
398
485
  // src/utils.ts
399
486
  var import_native_bin2 = require("@clarigen/native-bin");
400
- var import_path7 = require("path");
401
- var import_promises6 = require("fs/promises");
487
+ var import_path9 = require("path");
488
+ var import_promises8 = require("fs/promises");
402
489
 
403
490
  // src/docs.ts
404
491
  var import_claridocs = require("@clarigen/claridocs");
405
- var import_promises3 = require("fs/promises");
406
- var import_path4 = require("path");
492
+ var import_promises5 = require("fs/promises");
493
+ var import_path6 = require("path");
407
494
  async function generateMarkdownDoc({
408
495
  contractFile,
409
496
  contractName,
@@ -411,18 +498,18 @@ async function generateMarkdownDoc({
411
498
  abi,
412
499
  dirName
413
500
  }) {
414
- const contractSrc = await (0, import_promises3.readFile)(contractFile, { encoding: "utf-8" });
501
+ const contractSrc = await (0, import_promises5.readFile)(contractFile, { encoding: "utf-8" });
415
502
  const docs = (0, import_claridocs.createContractDocInfo)({ contractSrc, abi });
416
- const folder = (0, import_path4.resolve)(process.cwd(), docsPath, dirName || ".");
417
- const filePath = (0, import_path4.resolve)(folder, `${contractName}.md`);
503
+ const folder = (0, import_path6.resolve)(process.cwd(), docsPath, dirName || ".");
504
+ const filePath = (0, import_path6.resolve)(folder, `${contractName}.md`);
418
505
  const md = (0, import_claridocs.generateMarkdown)({
419
506
  contract: docs,
420
- contractFile: (0, import_path4.relative)(folder, contractFile),
507
+ contractFile: (0, import_path6.relative)(folder, contractFile),
421
508
  contractName,
422
509
  abi
423
510
  });
424
- await (0, import_promises3.mkdir)(folder, { recursive: true });
425
- await (0, import_promises3.writeFile)(filePath, md);
511
+ await (0, import_promises5.mkdir)(folder, { recursive: true });
512
+ await (0, import_promises5.writeFile)(filePath, md);
426
513
  }
427
514
  async function generateDocsIndex(configFile) {
428
515
  if (!configFile.docs)
@@ -435,14 +522,14 @@ async function generateDocsIndex(configFile) {
435
522
 
436
523
  ${contractLines.join("\n")}
437
524
  `;
438
- const filepath = (0, import_path4.resolve)(process.cwd(), configFile.docs, "README.md");
439
- await (0, import_promises3.writeFile)(filepath, fileContents);
525
+ const filepath = (0, import_path6.resolve)(process.cwd(), configFile.docs, "README.md");
526
+ await (0, import_promises5.writeFile)(filepath, fileContents);
440
527
  }
441
528
 
442
529
  // src/generate/single.ts
443
530
  var import_core3 = require("@clarigen/core");
444
- var import_path5 = require("path");
445
- var import_promises4 = require("fs/promises");
531
+ var import_path7 = require("path");
532
+ var import_promises6 = require("fs/promises");
446
533
  var import_util = require("util");
447
534
  function generateContractMeta(contract) {
448
535
  const { abi } = contract;
@@ -480,7 +567,7 @@ function generateContractMeta(contract) {
480
567
  return mapLine;
481
568
  });
482
569
  const otherAbi = JSON.stringify(rest);
483
- const contractFile = (0, import_path5.relative)(process.cwd(), contract.contractFile);
570
+ const contractFile = (0, import_path7.relative)(process.cwd(), contract.contractFile);
484
571
  return `{
485
572
  ${serializeLines("functions", functionLines)}
486
573
  ${serializeLines("variables", variableLines)}
@@ -545,116 +632,51 @@ function serializeLines(key, lines) {
545
632
  },`;
546
633
  }
547
634
  async function getSingleTypes() {
548
- const typesPath = (0, import_path5.resolve)(__dirname, "../../dist/abi-types.ts.txt");
549
- const typesFile = await (0, import_promises4.readFile)(typesPath, { encoding: "utf-8" });
635
+ const typesPath = (0, import_path7.resolve)(__dirname, "../../dist/abi-types.ts.txt");
636
+ const typesFile = await (0, import_promises6.readFile)(typesPath, { encoding: "utf-8" });
550
637
  return typesFile;
551
638
  }
552
639
 
553
- // src/writer.ts
554
- var import_promises5 = require("fs/promises");
555
- var import_path6 = require("path");
556
- var import_prettier = require("prettier");
557
- var defaultPrettierConfig = {
558
- printWidth: 80,
559
- semi: true,
560
- singleQuote: true,
561
- trailingComma: "es5"
562
- };
563
- async function resolvePrettierConfig() {
564
- try {
565
- const local = await (0, import_prettier.resolveConfig)(process.cwd());
566
- if (local)
567
- return local;
568
- } catch (error) {
569
- }
570
- return defaultPrettierConfig;
571
- }
572
- async function formatFile(contents, path) {
573
- try {
574
- const fileName = (0, import_path6.basename)(path);
575
- const config = await resolvePrettierConfig();
576
- const formatted = (0, import_prettier.format)(contents, __spreadProps(__spreadValues({}, config), {
577
- filepath: fileName
578
- }));
579
- return formatted;
580
- } catch (error) {
581
- }
582
- return contents;
583
- }
584
- async function writeFile2(path, contents) {
585
- const formatted = await formatFile(contents, path);
586
- await (0, import_promises5.writeFile)(path, formatted);
587
- }
588
-
589
640
  // src/generate/vars.ts
590
641
  var import_core4 = require("@clarigen/core");
591
642
  var import_native_bin = require("@clarigen/native-bin");
592
643
  var import_clarity = require("micro-stacks/clarity");
593
- async function getVariables({
594
- abi,
595
- contractIdentifier,
596
- provider
597
- }) {
598
- const variableTransforms = abi.variables.map((variable) => {
599
- return evalVariable({
600
- variable,
601
- provider,
602
- contractIdentifier
603
- });
604
- });
605
- const variables = await Promise.all(variableTransforms);
606
- return variables;
607
- }
608
- async function evalVariable({
609
- contractIdentifier,
610
- variable,
611
- provider
612
- }) {
613
- const code = getEvalCode(variable);
614
- const result = await (0, import_native_bin.evalRaw)({
615
- contractAddress: contractIdentifier,
616
- code,
617
- provider
618
- });
619
- const resultCV = (0, import_clarity.hexToCV)(result.output_serialized);
620
- const value = (0, import_core4.cvToValue)(resultCV, true);
621
- return __spreadProps(__spreadValues({}, variable), {
622
- defaultValue: value
623
- });
624
- }
625
- function getEvalCode(variable) {
626
- const { access: access2 } = variable;
627
- if (access2 === "variable") {
628
- return `(var-get ${variable.name})`;
644
+
645
+ // src/deno-run.ts
646
+ var import_child_process = require("child_process");
647
+ var import_util2 = require("util");
648
+ var exec = (0, import_util2.promisify)(import_child_process.exec);
649
+ async function getClarinetSession(cwd) {
650
+ const scriptPath = "https://raw.githubusercontent.com/mechanismHQ/clarigen-deno/main/src/cli/print.ts";
651
+ const command = `clarinet run ${scriptPath}`;
652
+ try {
653
+ const result = await exec(command, { cwd });
654
+ const sessionJSON = result.stdout.split("\n")[1];
655
+ const session = JSON.parse(sessionJSON);
656
+ return session;
657
+ } catch (error) {
658
+ console.error(`Error getting clarinet session`);
659
+ throw error;
629
660
  }
630
- return variable.name;
631
661
  }
632
662
 
633
- // src/utils.ts
634
- var generateFilesForContract = async ({
635
- contractFile: _contractFile,
663
+ // src/contract.ts
664
+ var import_promises7 = require("fs/promises");
665
+ var import_path8 = require("path");
666
+ var generateFilesForContractWithSession = async ({
636
667
  outputFolder,
637
- provider,
638
- contractAddress,
668
+ sessionContract,
639
669
  dirName,
640
- contractName,
641
- docsPath
670
+ docsPath,
671
+ contractFile
642
672
  }) => {
643
- const contractFile = (0, import_path7.resolve)(process.cwd(), _contractFile);
644
- const contractIdentifier = `${contractAddress}.${contractName}`;
645
- const abi = await (0, import_native_bin2.deployContract)({
646
- contractIdentifier,
647
- contractFilePath: contractFile,
648
- provider
649
- });
650
- const variables = await getVariables({
651
- abi,
652
- contractIdentifier,
653
- provider
654
- });
673
+ const contractIdentifier = sessionContract.contract_id;
674
+ const [contractAddress, contractName] = contractIdentifier.split(".");
675
+ const abi = sessionContract.contract_interface;
676
+ const variables = [];
655
677
  const typesFile = generateTypesFile(abi, contractName);
656
678
  const indexFile = generateIndexFile({
657
- contractFile: (0, import_path7.relative)(process.cwd(), contractFile),
679
+ contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
658
680
  contractAddress,
659
681
  contractName
660
682
  });
@@ -668,11 +690,11 @@ var generateFilesForContract = async ({
668
690
  dirName
669
691
  });
670
692
  }
671
- const outputPath = (0, import_path7.resolve)(outputFolder, dirName || ".", contractName);
672
- await (0, import_promises6.mkdir)(outputPath, { recursive: true });
673
- await writeFile2((0, import_path7.resolve)(outputPath, "abi.ts"), abiFile);
674
- await writeFile2((0, import_path7.resolve)(outputPath, "index.ts"), indexFile);
675
- await writeFile2((0, import_path7.resolve)(outputPath, "types.ts"), typesFile);
693
+ const outputPath = (0, import_path8.resolve)(outputFolder, dirName || ".", contractName);
694
+ await (0, import_promises7.mkdir)(outputPath, { recursive: true });
695
+ await writeFile((0, import_path8.resolve)(outputPath, "abi.ts"), abiFile);
696
+ await writeFile((0, import_path8.resolve)(outputPath, "index.ts"), indexFile);
697
+ await writeFile((0, import_path8.resolve)(outputPath, "types.ts"), typesFile);
676
698
  return {
677
699
  abi,
678
700
  contractFile,
@@ -682,38 +704,42 @@ var generateFilesForContract = async ({
682
704
  variables
683
705
  };
684
706
  };
707
+
708
+ // src/utils.ts
685
709
  var generateProject = async (projectPath) => {
686
710
  const configFile = await getProjectConfig(projectPath);
687
711
  const { contractsDir, outputDir, contracts } = configFile;
688
- const outputFolder = (0, import_path7.resolve)(projectPath, outputDir);
712
+ const outputFolder = (0, import_path9.resolve)(projectPath, outputDir);
689
713
  const provider = await (0, import_native_bin2.createClarityBin)();
690
714
  const metas = [];
691
- for (const contract of contracts) {
692
- const contractFile = (0, import_path7.resolve)(projectPath, contractsDir, contract.file);
693
- const dirName = (0, import_path7.dirname)(contract.file);
694
- const meta = await generateFilesForContract({
695
- contractFile,
715
+ const session = await getClarinetSession((0, import_path9.resolve)(projectPath, configFile.clarinet));
716
+ for (const contract of session.contracts) {
717
+ const configContract = contracts.find((c) => c.name === contract.contract_id.split(".")[1]);
718
+ if (typeof configContract === "undefined") {
719
+ throw new Error(`No config contract found for ${contract.contract_id}`);
720
+ }
721
+ const contractFile = (0, import_path9.resolve)(projectPath, configFile.clarinet, configContract.file);
722
+ const meta = await generateFilesForContractWithSession({
723
+ sessionContract: contract,
696
724
  outputFolder,
697
- provider,
698
- contractAddress: contract.address,
699
- dirName,
700
- contractName: contract.name,
701
- docsPath: configFile.docs
725
+ docsPath: configFile.docs,
726
+ contractFile
702
727
  });
703
728
  metas.push(meta);
704
729
  }
705
730
  const indexFile = generateProjectIndexFile(configFile);
706
731
  await generateDocsIndex(configFile);
707
- const indexPath = (0, import_path7.resolve)(outputFolder, "index.ts");
708
- await writeFile2(indexPath, indexFile);
732
+ const indexPath = (0, import_path9.resolve)(outputFolder, "index.ts");
733
+ await writeFile(indexPath, indexFile);
709
734
  const singleFile = await generateSingleFile(configFile, metas);
710
- const singlePath = (0, import_path7.resolve)(outputFolder, "single.ts");
711
- await writeFile2(singlePath, singleFile);
735
+ const singlePath = (0, import_path9.resolve)(outputFolder, "single.ts");
736
+ await writeFile(singlePath, singleFile);
737
+ await generateDeployments(configFile);
712
738
  };
713
739
 
714
740
  // src/commands/index.ts
715
741
  var import_chokidar = require("chokidar");
716
- var import_path8 = require("path");
742
+ var import_path10 = require("path");
717
743
  var import_chalk = require("chalk");
718
744
  var import_ora = __toESM(require("ora"));
719
745
  var _Generate = class extends import_command.Command {
@@ -735,7 +761,7 @@ ${String(error.message)}`);
735
761
  }
736
762
  watcher.on("change", (path) => {
737
763
  const cb = async () => {
738
- const file = (0, import_path8.basename)(path);
764
+ const file = (0, import_path10.basename)(path);
739
765
  spinner.clear();
740
766
  spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
741
767
  try {
@@ -757,7 +783,11 @@ ${msg}`);
757
783
  void cb();
758
784
  });
759
785
  } else {
760
- await generateProject(cwd);
786
+ try {
787
+ await generateProject(cwd);
788
+ } catch (error) {
789
+ console.log(error);
790
+ }
761
791
  }
762
792
  }
763
793
  };
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.21",
5
+ "version": "1.0.0-next.25",
6
6
  "license": "MIT",
7
7
  "types": "./dist/index.d.ts",
8
8
  "main": "./dist/index.js",
@@ -30,6 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@oclif/dev-cli": "^1.26.0",
32
32
  "@oclif/errors": "^1.3.4",
33
+ "@types/js-yaml": "^4.0.5",
33
34
  "@types/reserved-words": "0.1.0",
34
35
  "@types/toposort": "2.0.3",
35
36
  "@vercel/ncc": "0.27.0",
@@ -37,20 +38,23 @@
37
38
  "ts-node": "^9.1.1"
38
39
  },
39
40
  "dependencies": {
40
- "@clarigen/core": "1.0.0-next.21",
41
- "@clarigen/native-bin": "1.0.0-next.21",
42
- "@clarigen/claridocs": "1.0.0-next.21",
43
- "@ltd/j-toml": "1.12.2",
41
+ "@clarigen/claridocs": "1.0.0-next.25",
42
+ "@clarigen/core": "1.0.0-next.25",
43
+ "@clarigen/native-bin": "1.0.0-next.25",
44
+ "@iarna/toml": "^2.2.5",
44
45
  "@oclif/command": "^1.8.0",
45
46
  "@oclif/config": "^1.17.0",
46
47
  "@oclif/plugin-help": "3.2.3",
48
+ "@scure/bip32": "^1.1.0",
49
+ "@scure/bip39": "^1.1.0",
47
50
  "chalk": "4.1.0",
48
51
  "chokidar": "3.5.1",
49
- "micro-stacks": "^0.2.0",
52
+ "js-yaml": "^4.1.0",
53
+ "micro-stacks": "^0.5.2",
50
54
  "ora": "5.4.0",
51
55
  "prettier": "2.6.2",
52
- "toposort": "2.0.2",
53
- "reserved-words": "0.1.2"
56
+ "reserved-words": "0.1.2",
57
+ "toposort": "2.0.2"
54
58
  },
55
59
  "publishConfig": {
56
60
  "access": "public"
@@ -65,6 +69,6 @@
65
69
  "lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
66
70
  "typecheck": "tsc --noEmit -p tsconfig-test.json",
67
71
  "demo": "pnpm build && node bin/run",
68
- "publish:dev": "yalc publish --push"
72
+ "publish:dev": "pnpm build && yalc publish --push"
69
73
  }
70
74
  }
@@ -1,4 +1,4 @@
1
- import { parse } from '@ltd/j-toml';
1
+ import { parse } from '@iarna/toml';
2
2
  import { resolve } from 'path';
3
3
  import { readFile } from 'fs/promises';
4
4
  import { ConfigContract } from './config';
@@ -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;
@@ -29,15 +31,13 @@ export async function getClarinetDevConfig(
29
31
  ): Promise<ClarinetDevConfig> {
30
32
  const baseConfigPath = resolve(folder, 'settings', 'Devnet.toml');
31
33
  const configContents = await readFile(baseConfigPath, { encoding: 'utf-8' });
32
- const config = parse(configContents, 1.0, '\n', true, {
33
- longer: true,
34
- }) as unknown as ClarinetDevConfig;
35
- return config;
34
+ const config = parse(configContents);
35
+ return config as unknown as ClarinetDevConfig;
36
36
  }
37
37
 
38
38
  export interface ClarinetContract {
39
39
  path: string;
40
- depends_on: string[];
40
+ depends_on?: string[];
41
41
  }
42
42
 
43
43
  export interface ClarinetContracts {
@@ -61,15 +61,31 @@ export const CLARINET_SETTINGS = [
61
61
  export async function getClarinetConfig(folder: string) {
62
62
  const baseConfigPath = resolve(folder, 'Clarinet.toml');
63
63
  const configContents = await readFile(baseConfigPath, { encoding: 'utf-8' });
64
- const config = parse(
65
- configContents,
66
- 1.0,
67
- '\n',
68
- true
69
- ) as unknown as ClarinetConfig;
64
+ const config = parse(configContents) as unknown as ClarinetConfig;
70
65
  return config;
71
66
  }
72
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
+
73
89
  export function getContractsFromClarinet(
74
90
  clarinetConfig: ClarinetConfig,
75
91
  accounts: ClarinetAccounts
@@ -93,7 +109,7 @@ export function sortClarinetContracts(contractsConfig: ClarinetContracts) {
93
109
  const nodes: string[] = [];
94
110
  Object.entries(contractsConfig).forEach(([contractName, info]) => {
95
111
  nodes.push(contractName);
96
- info.depends_on.forEach((dependency) =>
112
+ info.depends_on?.forEach((dependency) =>
97
113
  edges.push([contractName, dependency])
98
114
  );
99
115
  });
@@ -66,7 +66,11 @@ export class Generate extends Command {
66
66
  void cb();
67
67
  });
68
68
  } else {
69
- await generateProject(cwd);
69
+ try {
70
+ await generateProject(cwd);
71
+ } catch (error) {
72
+ console.log(error);
73
+ }
70
74
  }
71
75
  }
72
76
  }