@clarigen/cli 1.0.0-next.19 → 1.0.0-next.22

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.
@@ -1,9 +1,11 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -43,6 +45,7 @@ var __copyProps = (to, from, except, desc) => {
43
45
  }
44
46
  return to;
45
47
  };
48
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
46
49
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
50
 
48
51
  // src/commands/index.ts
@@ -54,7 +57,6 @@ module.exports = __toCommonJS(commands_exports);
54
57
  var import_command2 = require("@oclif/command");
55
58
 
56
59
  // src/generate/files.ts
57
- var import_native_bin = require("@clarigen/native-bin");
58
60
  var import_core2 = require("@clarigen/core");
59
61
  var import_path3 = require("path");
60
62
 
@@ -67,7 +69,7 @@ var import_promises2 = require("fs/promises");
67
69
  var import_fs = require("fs");
68
70
 
69
71
  // src/clarinet-config.ts
70
- var import_j_toml = require("@ltd/j-toml");
72
+ var import_toml = require("@iarna/toml");
71
73
  var import_path = require("path");
72
74
  var import_promises = require("fs/promises");
73
75
  var import_wallet_sdk = require("micro-stacks/wallet-sdk");
@@ -76,19 +78,16 @@ var import_crypto = require("micro-stacks/crypto");
76
78
  async function getClarinetDevConfig(folder) {
77
79
  const baseConfigPath = (0, import_path.resolve)(folder, "settings", "Devnet.toml");
78
80
  const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
79
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true, {
80
- longer: true
81
- });
81
+ const config = (0, import_toml.parse)(configContents);
82
82
  return config;
83
83
  }
84
84
  async function getClarinetConfig(folder) {
85
85
  const baseConfigPath = (0, import_path.resolve)(folder, "Clarinet.toml");
86
86
  const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
87
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true);
87
+ const config = (0, import_toml.parse)(configContents);
88
88
  return config;
89
89
  }
90
- async function getContractsFromClarinet(folder, accounts) {
91
- const clarinetConfig = await getClarinetConfig(folder);
90
+ function getContractsFromClarinet(clarinetConfig, accounts) {
92
91
  const deployerAddress = accounts.deployer.address;
93
92
  const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
94
93
  const contracts = sortedContracts.map((contractName) => {
@@ -106,8 +105,9 @@ function sortClarinetContracts(contractsConfig) {
106
105
  const edges = [];
107
106
  const nodes = [];
108
107
  Object.entries(contractsConfig).forEach(([contractName, info]) => {
108
+ var _a;
109
109
  nodes.push(contractName);
110
- info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
110
+ (_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
111
111
  });
112
112
  const sorted = (0, import_toposort.array)(nodes, edges).reverse();
113
113
  return sorted;
@@ -156,16 +156,20 @@ async function getConfigFile(rootPath) {
156
156
  return defaultConfigFile;
157
157
  }
158
158
  async function getProjectConfig(rootPath) {
159
+ var _a, _b;
159
160
  const configFile = await getConfigFile(rootPath);
160
- const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet || ".");
161
+ const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet);
162
+ const clarinet = await getClarinetConfig(clarinetPath);
161
163
  const accounts = await getClarinetAccounts(clarinetPath);
162
- const contracts = await getContractsFromClarinet(clarinetPath, accounts);
164
+ const contracts = getContractsFromClarinet(clarinet, accounts);
163
165
  const contractsDir = (0, import_path2.relative)(process.cwd(), (0, import_path2.join)(configFile.clarinet, "contracts"));
164
166
  return __spreadProps(__spreadValues({}, configFile), {
167
+ outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
168
+ docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
165
169
  contracts,
166
170
  contractsDir,
167
171
  accounts,
168
- clarinet: configFile.clarinet || "."
172
+ clarinet: configFile.clarinet
169
173
  });
170
174
  }
171
175
 
@@ -380,9 +384,9 @@ export const contracts = {
380
384
  };
381
385
 
382
386
  // src/utils.ts
383
- var import_native_bin3 = require("@clarigen/native-bin");
384
- var import_path7 = require("path");
385
- var import_promises6 = require("fs/promises");
387
+ var import_native_bin2 = require("@clarigen/native-bin");
388
+ var import_path8 = require("path");
389
+ var import_promises7 = require("fs/promises");
386
390
 
387
391
  // src/docs.ts
388
392
  var import_claridocs = require("@clarigen/claridocs");
@@ -447,7 +451,7 @@ function generateContractMeta(contract) {
447
451
  const variableLines = contract.variables.map((v) => {
448
452
  let varLine = `${(0, import_core3.toCamelCase)(v.name)}: `;
449
453
  const type = jsTypeFromAbiType(v.type);
450
- const varJSON = (0, import_util.inspect)(v, false, null, false);
454
+ const varJSON = serialize(v);
451
455
  varLine += `${varJSON} as TypedAbiVariable<${type}>`;
452
456
  return varLine;
453
457
  });
@@ -572,7 +576,7 @@ async function writeFile2(path, contents) {
572
576
 
573
577
  // src/generate/vars.ts
574
578
  var import_core4 = require("@clarigen/core");
575
- var import_native_bin2 = require("@clarigen/native-bin");
579
+ var import_native_bin = require("@clarigen/native-bin");
576
580
  var import_clarity = require("micro-stacks/clarity");
577
581
  async function getVariables({
578
582
  abi,
@@ -595,7 +599,7 @@ async function evalVariable({
595
599
  provider
596
600
  }) {
597
601
  const code = getEvalCode(variable);
598
- const result = await (0, import_native_bin2.evalRaw)({
602
+ const result = await (0, import_native_bin.evalRaw)({
599
603
  contractAddress: contractIdentifier,
600
604
  code,
601
605
  provider
@@ -614,6 +618,36 @@ function getEvalCode(variable) {
614
618
  return variable.name;
615
619
  }
616
620
 
621
+ // src/generate/deployment.ts
622
+ var import_js_yaml = require("js-yaml");
623
+ var import_promises6 = require("fs/promises");
624
+ var import_path7 = require("path");
625
+ var import_fs2 = require("fs");
626
+ async function parseDeployment(path) {
627
+ const contents = await (0, import_promises6.readFile)(path, { encoding: "utf-8" });
628
+ const parsed = (0, import_js_yaml.load)(contents);
629
+ return parsed;
630
+ }
631
+ async function generateDeployment(network, config) {
632
+ const file = `default.${network}-plan.yaml`;
633
+ const deploymentPath = (0, import_path7.resolve)(process.cwd(), config.clarinet, "deployments", file);
634
+ if ((0, import_fs2.existsSync)(deploymentPath)) {
635
+ const plan = await parseDeployment(deploymentPath);
636
+ const varName = `${network}Deployment`;
637
+ const contents = `export const ${varName} = ${JSON.stringify(plan)} as const;
638
+ `;
639
+ const outputFile = (0, import_path7.resolve)(config.outputDir, "deployments", `${network}.ts`);
640
+ await writeFile2(outputFile, contents);
641
+ }
642
+ }
643
+ async function generateDeployments(config) {
644
+ const networks = ["devnet", "simnet", "testnet", "mainnet"];
645
+ const folder = (0, import_path7.resolve)(process.cwd(), config.outputDir, "deployments");
646
+ await (0, import_promises6.mkdir)(folder, { recursive: true });
647
+ const generates = networks.map((n) => generateDeployment(n, config));
648
+ await Promise.all(generates);
649
+ }
650
+
617
651
  // src/utils.ts
618
652
  var generateFilesForContract = async ({
619
653
  contractFile: _contractFile,
@@ -624,9 +658,9 @@ var generateFilesForContract = async ({
624
658
  contractName,
625
659
  docsPath
626
660
  }) => {
627
- const contractFile = (0, import_path7.resolve)(process.cwd(), _contractFile);
661
+ const contractFile = (0, import_path8.resolve)(process.cwd(), _contractFile);
628
662
  const contractIdentifier = `${contractAddress}.${contractName}`;
629
- const abi = await (0, import_native_bin3.deployContract)({
663
+ const abi = await (0, import_native_bin2.deployContract)({
630
664
  contractIdentifier,
631
665
  contractFilePath: contractFile,
632
666
  provider
@@ -638,7 +672,7 @@ var generateFilesForContract = async ({
638
672
  });
639
673
  const typesFile = generateTypesFile(abi, contractName);
640
674
  const indexFile = generateIndexFile({
641
- contractFile: (0, import_path7.relative)(process.cwd(), contractFile),
675
+ contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
642
676
  contractAddress,
643
677
  contractName
644
678
  });
@@ -652,11 +686,11 @@ var generateFilesForContract = async ({
652
686
  dirName
653
687
  });
654
688
  }
655
- const outputPath = (0, import_path7.resolve)(outputFolder, dirName || ".", contractName);
656
- await (0, import_promises6.mkdir)(outputPath, { recursive: true });
657
- await writeFile2((0, import_path7.resolve)(outputPath, "abi.ts"), abiFile);
658
- await writeFile2((0, import_path7.resolve)(outputPath, "index.ts"), indexFile);
659
- await writeFile2((0, import_path7.resolve)(outputPath, "types.ts"), typesFile);
689
+ const outputPath = (0, import_path8.resolve)(outputFolder, dirName || ".", contractName);
690
+ await (0, import_promises7.mkdir)(outputPath, { recursive: true });
691
+ await writeFile2((0, import_path8.resolve)(outputPath, "abi.ts"), abiFile);
692
+ await writeFile2((0, import_path8.resolve)(outputPath, "index.ts"), indexFile);
693
+ await writeFile2((0, import_path8.resolve)(outputPath, "types.ts"), typesFile);
660
694
  return {
661
695
  abi,
662
696
  contractFile,
@@ -669,12 +703,12 @@ var generateFilesForContract = async ({
669
703
  var generateProject = async (projectPath) => {
670
704
  const configFile = await getProjectConfig(projectPath);
671
705
  const { contractsDir, outputDir, contracts } = configFile;
672
- const outputFolder = (0, import_path7.resolve)(projectPath, outputDir);
673
- const provider = await (0, import_native_bin3.createClarityBin)();
706
+ const outputFolder = (0, import_path8.resolve)(projectPath, outputDir);
707
+ const provider = await (0, import_native_bin2.createClarityBin)();
674
708
  const metas = [];
675
709
  for (const contract of contracts) {
676
- const contractFile = (0, import_path7.resolve)(projectPath, contractsDir, contract.file);
677
- const dirName = (0, import_path7.dirname)(contract.file);
710
+ const contractFile = (0, import_path8.resolve)(projectPath, contractsDir, contract.file);
711
+ const dirName = (0, import_path8.dirname)(contract.file);
678
712
  const meta = await generateFilesForContract({
679
713
  contractFile,
680
714
  outputFolder,
@@ -688,24 +722,25 @@ var generateProject = async (projectPath) => {
688
722
  }
689
723
  const indexFile = generateProjectIndexFile(configFile);
690
724
  await generateDocsIndex(configFile);
691
- const indexPath = (0, import_path7.resolve)(outputFolder, "index.ts");
725
+ const indexPath = (0, import_path8.resolve)(outputFolder, "index.ts");
692
726
  await writeFile2(indexPath, indexFile);
693
727
  const singleFile = await generateSingleFile(configFile, metas);
694
- const singlePath = (0, import_path7.resolve)(outputFolder, "single.ts");
728
+ const singlePath = (0, import_path8.resolve)(outputFolder, "single.ts");
695
729
  await writeFile2(singlePath, singleFile);
730
+ await generateDeployments(configFile);
696
731
  };
697
732
 
698
733
  // src/commands/index.ts
699
734
  var import_chokidar = require("chokidar");
700
- var import_path8 = require("path");
735
+ var import_path9 = require("path");
701
736
  var import_chalk = require("chalk");
702
- var ora = require("ora");
737
+ var import_ora = __toESM(require("ora"));
703
738
  var _Generate = class extends import_command2.Command {
704
739
  async run() {
705
740
  const { flags: flags2 } = this.parse(_Generate);
706
741
  const cwd = process.cwd();
707
742
  if (flags2.watch) {
708
- const spinner = ora("Generating files").start();
743
+ const spinner = (0, import_ora.default)("Generating files").start();
709
744
  const { contractsDir } = await getProjectConfig(cwd);
710
745
  const watcher = (0, import_chokidar.watch)([contractsDir], {
711
746
  cwd
@@ -715,24 +750,30 @@ var _Generate = class extends import_command2.Command {
715
750
  spinner.succeed(`Finished generating files. Watching for changes.`);
716
751
  } catch (error) {
717
752
  spinner.fail(`Error generating files.
718
- ${error.message}`);
753
+ ${String(error.message)}`);
719
754
  }
720
- watcher.on("change", async (path) => {
721
- const file = (0, import_path8.basename)(path);
722
- spinner.clear();
723
- spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
724
- try {
725
- await generateProject(cwd);
726
- spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
727
- } catch (error) {
728
- const msg = error.message;
729
- spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
755
+ watcher.on("change", (path) => {
756
+ const cb = async () => {
757
+ const file = (0, import_path9.basename)(path);
758
+ spinner.clear();
759
+ spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
760
+ try {
761
+ await generateProject(cwd);
762
+ spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
763
+ } catch (error) {
764
+ const msg = error.message;
765
+ spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
730
766
  ${msg}`);
731
- }
767
+ }
768
+ };
769
+ void cb();
732
770
  });
733
- process.on("SIGINT", async () => {
734
- await watcher.close();
735
- process.exit();
771
+ process.on("SIGINT", () => {
772
+ async function cb() {
773
+ await watcher.close();
774
+ process.exit();
775
+ }
776
+ void cb();
736
777
  });
737
778
  } else {
738
779
  await generateProject(cwd);
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -43,6 +45,7 @@ var __copyProps = (to, from, except, desc) => {
43
45
  }
44
46
  return to;
45
47
  };
48
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
46
49
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
50
 
48
51
  // src/index.ts
@@ -53,7 +56,6 @@ __export(src_exports, {
53
56
  configFilePath: () => configFilePath,
54
57
  defaultConfigFile: () => defaultConfigFile,
55
58
  generateIndexFile: () => generateIndexFile,
56
- generateInterface: () => generateInterface,
57
59
  generateInterfaceFile: () => generateInterfaceFile,
58
60
  generateProjectIndexFile: () => generateProjectIndexFile,
59
61
  generateTypesFile: () => generateTypesFile,
@@ -73,7 +75,7 @@ var import_promises2 = require("fs/promises");
73
75
  var import_fs = require("fs");
74
76
 
75
77
  // src/clarinet-config.ts
76
- var import_j_toml = require("@ltd/j-toml");
78
+ var import_toml = require("@iarna/toml");
77
79
  var import_path = require("path");
78
80
  var import_promises = require("fs/promises");
79
81
  var import_wallet_sdk = require("micro-stacks/wallet-sdk");
@@ -82,19 +84,16 @@ var import_crypto = require("micro-stacks/crypto");
82
84
  async function getClarinetDevConfig(folder) {
83
85
  const baseConfigPath = (0, import_path.resolve)(folder, "settings", "Devnet.toml");
84
86
  const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
85
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true, {
86
- longer: true
87
- });
87
+ const config = (0, import_toml.parse)(configContents);
88
88
  return config;
89
89
  }
90
90
  async function getClarinetConfig(folder) {
91
91
  const baseConfigPath = (0, import_path.resolve)(folder, "Clarinet.toml");
92
92
  const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
93
- const config = (0, import_j_toml.parse)(configContents, 1, "\n", true);
93
+ const config = (0, import_toml.parse)(configContents);
94
94
  return config;
95
95
  }
96
- async function getContractsFromClarinet(folder, accounts) {
97
- const clarinetConfig = await getClarinetConfig(folder);
96
+ function getContractsFromClarinet(clarinetConfig, accounts) {
98
97
  const deployerAddress = accounts.deployer.address;
99
98
  const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
100
99
  const contracts = sortedContracts.map((contractName) => {
@@ -112,8 +111,9 @@ function sortClarinetContracts(contractsConfig) {
112
111
  const edges = [];
113
112
  const nodes = [];
114
113
  Object.entries(contractsConfig).forEach(([contractName, info]) => {
114
+ var _a;
115
115
  nodes.push(contractName);
116
- info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
116
+ (_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
117
117
  });
118
118
  const sorted = (0, import_toposort.array)(nodes, edges).reverse();
119
119
  return sorted;
@@ -162,16 +162,20 @@ async function getConfigFile(rootPath) {
162
162
  return defaultConfigFile;
163
163
  }
164
164
  async function getProjectConfig(rootPath) {
165
+ var _a, _b;
165
166
  const configFile = await getConfigFile(rootPath);
166
- const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet || ".");
167
+ const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet);
168
+ const clarinet = await getClarinetConfig(clarinetPath);
167
169
  const accounts = await getClarinetAccounts(clarinetPath);
168
- const contracts = await getContractsFromClarinet(clarinetPath, accounts);
170
+ const contracts = getContractsFromClarinet(clarinet, accounts);
169
171
  const contractsDir = (0, import_path2.relative)(process.cwd(), (0, import_path2.join)(configFile.clarinet, "contracts"));
170
172
  return __spreadProps(__spreadValues({}, configFile), {
173
+ outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
174
+ docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
171
175
  contracts,
172
176
  contractsDir,
173
177
  accounts,
174
- clarinet: configFile.clarinet || "."
178
+ clarinet: configFile.clarinet
175
179
  });
176
180
  }
177
181
 
@@ -277,53 +281,8 @@ function makePureTypes(abi) {
277
281
  }
278
282
 
279
283
  // src/generate/files.ts
280
- var import_native_bin = require("@clarigen/native-bin");
281
284
  var import_core2 = require("@clarigen/core");
282
285
  var import_path3 = require("path");
283
- var generateInterface = async ({
284
- provider,
285
- contractFile,
286
- contractAddress,
287
- contractName
288
- }) => {
289
- const receipt = await provider.runCommand([
290
- "launch",
291
- `${contractAddress}.${contractName}`,
292
- contractFile,
293
- provider.dbFilePath,
294
- "--output_analysis",
295
- "--costs",
296
- "--assets"
297
- ]);
298
- if ((0, import_native_bin.hasStdErr)(receipt.stderr)) {
299
- throw new Error(`Error on ${contractFile}:
300
- ${receipt.stderr}
301
- `);
302
- }
303
- const output = JSON.parse(receipt.stdout);
304
- if (output.error) {
305
- const { initialization } = output.error;
306
- if (initialization == null ? void 0 : initialization.includes("\nNear:\n")) {
307
- const [error, trace] = initialization.split("\nNear:\n");
308
- let startLine = "";
309
- const matcher = /start_line: (\d+),/;
310
- const matches = matcher.exec(trace);
311
- if (matches)
312
- startLine = matches[1];
313
- throw new Error(`Error on ${contractFile}:
314
- ${error}
315
- ${startLine ? `Near line ${startLine}` : ""}
316
- Raw trace:
317
- ${trace}
318
- `);
319
- }
320
- throw new Error(`Error on ${contractFile}:
321
- ${JSON.stringify(output.error, null, 2)}
322
- `);
323
- }
324
- const abi = output.analysis;
325
- return abi;
326
- };
327
286
  var generateInterfaceFile = ({
328
287
  contractName,
329
288
  abi
@@ -436,9 +395,9 @@ export const contracts = {
436
395
  var import_command = require("@oclif/command");
437
396
 
438
397
  // src/utils.ts
439
- var import_native_bin3 = require("@clarigen/native-bin");
440
- var import_path7 = require("path");
441
- var import_promises6 = require("fs/promises");
398
+ var import_native_bin2 = require("@clarigen/native-bin");
399
+ var import_path8 = require("path");
400
+ var import_promises7 = require("fs/promises");
442
401
 
443
402
  // src/docs.ts
444
403
  var import_claridocs = require("@clarigen/claridocs");
@@ -503,7 +462,7 @@ function generateContractMeta(contract) {
503
462
  const variableLines = contract.variables.map((v) => {
504
463
  let varLine = `${(0, import_core3.toCamelCase)(v.name)}: `;
505
464
  const type = jsTypeFromAbiType(v.type);
506
- const varJSON = (0, import_util.inspect)(v, false, null, false);
465
+ const varJSON = serialize(v);
507
466
  varLine += `${varJSON} as TypedAbiVariable<${type}>`;
508
467
  return varLine;
509
468
  });
@@ -628,7 +587,7 @@ async function writeFile2(path, contents) {
628
587
 
629
588
  // src/generate/vars.ts
630
589
  var import_core4 = require("@clarigen/core");
631
- var import_native_bin2 = require("@clarigen/native-bin");
590
+ var import_native_bin = require("@clarigen/native-bin");
632
591
  var import_clarity = require("micro-stacks/clarity");
633
592
  async function getVariables({
634
593
  abi,
@@ -651,7 +610,7 @@ async function evalVariable({
651
610
  provider
652
611
  }) {
653
612
  const code = getEvalCode(variable);
654
- const result = await (0, import_native_bin2.evalRaw)({
613
+ const result = await (0, import_native_bin.evalRaw)({
655
614
  contractAddress: contractIdentifier,
656
615
  code,
657
616
  provider
@@ -670,6 +629,36 @@ function getEvalCode(variable) {
670
629
  return variable.name;
671
630
  }
672
631
 
632
+ // src/generate/deployment.ts
633
+ var import_js_yaml = require("js-yaml");
634
+ var import_promises6 = require("fs/promises");
635
+ var import_path7 = require("path");
636
+ var import_fs2 = require("fs");
637
+ async function parseDeployment(path) {
638
+ const contents = await (0, import_promises6.readFile)(path, { encoding: "utf-8" });
639
+ const parsed = (0, import_js_yaml.load)(contents);
640
+ return parsed;
641
+ }
642
+ async function generateDeployment(network, config) {
643
+ const file = `default.${network}-plan.yaml`;
644
+ const deploymentPath = (0, import_path7.resolve)(process.cwd(), config.clarinet, "deployments", file);
645
+ if ((0, import_fs2.existsSync)(deploymentPath)) {
646
+ const plan = await parseDeployment(deploymentPath);
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);
652
+ }
653
+ }
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
+
673
662
  // src/utils.ts
674
663
  var generateFilesForContract = async ({
675
664
  contractFile: _contractFile,
@@ -680,9 +669,9 @@ var generateFilesForContract = async ({
680
669
  contractName,
681
670
  docsPath
682
671
  }) => {
683
- const contractFile = (0, import_path7.resolve)(process.cwd(), _contractFile);
672
+ const contractFile = (0, import_path8.resolve)(process.cwd(), _contractFile);
684
673
  const contractIdentifier = `${contractAddress}.${contractName}`;
685
- const abi = await (0, import_native_bin3.deployContract)({
674
+ const abi = await (0, import_native_bin2.deployContract)({
686
675
  contractIdentifier,
687
676
  contractFilePath: contractFile,
688
677
  provider
@@ -694,7 +683,7 @@ var generateFilesForContract = async ({
694
683
  });
695
684
  const typesFile = generateTypesFile(abi, contractName);
696
685
  const indexFile = generateIndexFile({
697
- contractFile: (0, import_path7.relative)(process.cwd(), contractFile),
686
+ contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
698
687
  contractAddress,
699
688
  contractName
700
689
  });
@@ -708,11 +697,11 @@ var generateFilesForContract = async ({
708
697
  dirName
709
698
  });
710
699
  }
711
- const outputPath = (0, import_path7.resolve)(outputFolder, dirName || ".", contractName);
712
- await (0, import_promises6.mkdir)(outputPath, { recursive: true });
713
- await writeFile2((0, import_path7.resolve)(outputPath, "abi.ts"), abiFile);
714
- await writeFile2((0, import_path7.resolve)(outputPath, "index.ts"), indexFile);
715
- await writeFile2((0, import_path7.resolve)(outputPath, "types.ts"), typesFile);
700
+ const outputPath = (0, import_path8.resolve)(outputFolder, dirName || ".", contractName);
701
+ await (0, import_promises7.mkdir)(outputPath, { recursive: true });
702
+ await writeFile2((0, import_path8.resolve)(outputPath, "abi.ts"), abiFile);
703
+ await writeFile2((0, import_path8.resolve)(outputPath, "index.ts"), indexFile);
704
+ await writeFile2((0, import_path8.resolve)(outputPath, "types.ts"), typesFile);
716
705
  return {
717
706
  abi,
718
707
  contractFile,
@@ -725,12 +714,12 @@ var generateFilesForContract = async ({
725
714
  var generateProject = async (projectPath) => {
726
715
  const configFile = await getProjectConfig(projectPath);
727
716
  const { contractsDir, outputDir, contracts } = configFile;
728
- const outputFolder = (0, import_path7.resolve)(projectPath, outputDir);
729
- const provider = await (0, import_native_bin3.createClarityBin)();
717
+ const outputFolder = (0, import_path8.resolve)(projectPath, outputDir);
718
+ const provider = await (0, import_native_bin2.createClarityBin)();
730
719
  const metas = [];
731
720
  for (const contract of contracts) {
732
- const contractFile = (0, import_path7.resolve)(projectPath, contractsDir, contract.file);
733
- const dirName = (0, import_path7.dirname)(contract.file);
721
+ const contractFile = (0, import_path8.resolve)(projectPath, contractsDir, contract.file);
722
+ const dirName = (0, import_path8.dirname)(contract.file);
734
723
  const meta = await generateFilesForContract({
735
724
  contractFile,
736
725
  outputFolder,
@@ -744,24 +733,25 @@ var generateProject = async (projectPath) => {
744
733
  }
745
734
  const indexFile = generateProjectIndexFile(configFile);
746
735
  await generateDocsIndex(configFile);
747
- const indexPath = (0, import_path7.resolve)(outputFolder, "index.ts");
736
+ const indexPath = (0, import_path8.resolve)(outputFolder, "index.ts");
748
737
  await writeFile2(indexPath, indexFile);
749
738
  const singleFile = await generateSingleFile(configFile, metas);
750
- const singlePath = (0, import_path7.resolve)(outputFolder, "single.ts");
739
+ const singlePath = (0, import_path8.resolve)(outputFolder, "single.ts");
751
740
  await writeFile2(singlePath, singleFile);
741
+ await generateDeployments(configFile);
752
742
  };
753
743
 
754
744
  // src/commands/index.ts
755
745
  var import_chokidar = require("chokidar");
756
- var import_path8 = require("path");
746
+ var import_path9 = require("path");
757
747
  var import_chalk = require("chalk");
758
- var ora = require("ora");
748
+ var import_ora = __toESM(require("ora"));
759
749
  var _Generate = class extends import_command.Command {
760
750
  async run() {
761
751
  const { flags: flags2 } = this.parse(_Generate);
762
752
  const cwd = process.cwd();
763
753
  if (flags2.watch) {
764
- const spinner = ora("Generating files").start();
754
+ const spinner = (0, import_ora.default)("Generating files").start();
765
755
  const { contractsDir } = await getProjectConfig(cwd);
766
756
  const watcher = (0, import_chokidar.watch)([contractsDir], {
767
757
  cwd
@@ -771,24 +761,30 @@ var _Generate = class extends import_command.Command {
771
761
  spinner.succeed(`Finished generating files. Watching for changes.`);
772
762
  } catch (error) {
773
763
  spinner.fail(`Error generating files.
774
- ${error.message}`);
764
+ ${String(error.message)}`);
775
765
  }
776
- watcher.on("change", async (path) => {
777
- const file = (0, import_path8.basename)(path);
778
- spinner.clear();
779
- spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
780
- try {
781
- await generateProject(cwd);
782
- spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
783
- } catch (error) {
784
- const msg = error.message;
785
- spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
766
+ watcher.on("change", (path) => {
767
+ const cb = async () => {
768
+ const file = (0, import_path9.basename)(path);
769
+ spinner.clear();
770
+ spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
771
+ try {
772
+ await generateProject(cwd);
773
+ spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
774
+ } catch (error) {
775
+ const msg = error.message;
776
+ spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
786
777
  ${msg}`);
787
- }
778
+ }
779
+ };
780
+ void cb();
788
781
  });
789
- process.on("SIGINT", async () => {
790
- await watcher.close();
791
- process.exit();
782
+ process.on("SIGINT", () => {
783
+ async function cb() {
784
+ await watcher.close();
785
+ process.exit();
786
+ }
787
+ void cb();
792
788
  });
793
789
  } else {
794
790
  await generateProject(cwd);
@@ -814,7 +810,6 @@ Generate.args = [];
814
810
  configFilePath,
815
811
  defaultConfigFile,
816
812
  generateIndexFile,
817
- generateInterface,
818
813
  generateInterfaceFile,
819
814
  generateProjectIndexFile,
820
815
  generateTypesFile,
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.19",
5
+ "version": "1.0.0-next.22",
6
6
  "license": "MIT",
7
7
  "types": "./dist/index.d.ts",
8
8
  "main": "./dist/index.js",
@@ -14,19 +14,6 @@
14
14
  "engines": {
15
15
  "node": ">=10"
16
16
  },
17
- "scripts": {
18
- "start": "tsup-node --watch",
19
- "dev": "tsup-node --watch",
20
- "build": "shx rm -rf ./dist && tsup-node src/index.ts src/commands/index.ts --splitting false",
21
- "compile": "ncc build src/index.ts --no-source-map-register -e @oclif/command -e @oclif/errors",
22
- "build-single-file": "yarn compile && oclif-dev readme",
23
- "test": "jest",
24
- "lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
25
- "typecheck": "tsc --noEmit -p tsconfig-test.json",
26
- "prepublishOnly": "yarn build",
27
- "demo": "yarn build && node bin/run",
28
- "publish:dev": "yalc publish --push"
29
- },
30
17
  "bin": {
31
18
  "clarigen": "./bin/run"
32
19
  },
@@ -43,6 +30,7 @@
43
30
  "devDependencies": {
44
31
  "@oclif/dev-cli": "^1.26.0",
45
32
  "@oclif/errors": "^1.3.4",
33
+ "@types/js-yaml": "^4.0.5",
46
34
  "@types/reserved-words": "0.1.0",
47
35
  "@types/toposort": "2.0.3",
48
36
  "@vercel/ncc": "0.27.0",
@@ -50,16 +38,19 @@
50
38
  "ts-node": "^9.1.1"
51
39
  },
52
40
  "dependencies": {
53
- "@clarigen/claridocs": "1.0.0-next.19",
54
- "@clarigen/core": "1.0.0-next.19",
55
- "@clarigen/native-bin": "1.0.0-next.19",
56
- "@ltd/j-toml": "1.12.2",
41
+ "@clarigen/claridocs": "1.0.0-next.22",
42
+ "@clarigen/core": "1.0.0-next.22",
43
+ "@clarigen/native-bin": "1.0.0-next.22",
44
+ "@iarna/toml": "^2.2.5",
57
45
  "@oclif/command": "^1.8.0",
58
46
  "@oclif/config": "^1.17.0",
59
47
  "@oclif/plugin-help": "3.2.3",
48
+ "@scure/bip32": "^1.1.0",
49
+ "@scure/bip39": "^1.1.0",
60
50
  "chalk": "4.1.0",
61
51
  "chokidar": "3.5.1",
62
- "micro-stacks": "^0.2.0",
52
+ "js-yaml": "^4.1.0",
53
+ "micro-stacks": "^0.5.2",
63
54
  "ora": "5.4.0",
64
55
  "prettier": "2.6.2",
65
56
  "reserved-words": "0.1.2",
@@ -68,5 +59,16 @@
68
59
  "publishConfig": {
69
60
  "access": "public"
70
61
  },
71
- "gitHead": "d6b6fc199e367698d566f38ee3343b04a418c829"
72
- }
62
+ "scripts": {
63
+ "start": "tsup-node --watch",
64
+ "dev": "tsup-node --watch",
65
+ "build": "shx rm -rf ./dist && tsup-node",
66
+ "compile": "ncc build src/index.ts --no-source-map-register -e @oclif/command -e @oclif/errors",
67
+ "build-single-file": "compile && oclif-dev readme",
68
+ "test": "jest",
69
+ "lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
70
+ "typecheck": "tsc --noEmit -p tsconfig-test.json",
71
+ "demo": "pnpm build && node bin/run",
72
+ "publish:dev": "yalc publish --push"
73
+ }
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';
@@ -29,15 +29,13 @@ export async function getClarinetDevConfig(
29
29
  ): Promise<ClarinetDevConfig> {
30
30
  const baseConfigPath = resolve(folder, 'settings', 'Devnet.toml');
31
31
  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;
32
+ const config = parse(configContents);
33
+ return config as unknown as ClarinetDevConfig;
36
34
  }
37
35
 
38
36
  export interface ClarinetContract {
39
37
  path: string;
40
- depends_on: string[];
38
+ depends_on?: string[];
41
39
  }
42
40
 
43
41
  export interface ClarinetContracts {
@@ -46,6 +44,10 @@ export interface ClarinetContracts {
46
44
 
47
45
  export interface ClarinetConfig {
48
46
  contracts: ClarinetContracts;
47
+ clarigen?: {
48
+ output_dir?: string;
49
+ docs?: string;
50
+ };
49
51
  }
50
52
 
51
53
  export const CLARINET_SETTINGS = [
@@ -57,20 +59,14 @@ export const CLARINET_SETTINGS = [
57
59
  export async function getClarinetConfig(folder: string) {
58
60
  const baseConfigPath = resolve(folder, 'Clarinet.toml');
59
61
  const configContents = await readFile(baseConfigPath, { encoding: 'utf-8' });
60
- const config = (parse(
61
- configContents,
62
- 1.0,
63
- '\n',
64
- true
65
- ) as unknown) as ClarinetConfig;
62
+ const config = parse(configContents) as unknown as ClarinetConfig;
66
63
  return config;
67
64
  }
68
65
 
69
- export async function getContractsFromClarinet(
70
- folder: string,
66
+ export function getContractsFromClarinet(
67
+ clarinetConfig: ClarinetConfig,
71
68
  accounts: ClarinetAccounts
72
- ): Promise<ConfigContract[]> {
73
- const clarinetConfig = await getClarinetConfig(folder);
69
+ ): ConfigContract[] {
74
70
  const deployerAddress = accounts.deployer.address;
75
71
  const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
76
72
  const contracts: ConfigContract[] = sortedContracts.map((contractName) => {
@@ -90,7 +86,7 @@ export function sortClarinetContracts(contractsConfig: ClarinetContracts) {
90
86
  const nodes: string[] = [];
91
87
  Object.entries(contractsConfig).forEach(([contractName, info]) => {
92
88
  nodes.push(contractName);
93
- info.depends_on.forEach((dependency) =>
89
+ info.depends_on?.forEach((dependency) =>
94
90
  edges.push([contractName, dependency])
95
91
  );
96
92
  });
@@ -4,8 +4,7 @@ import { getProjectConfig } from '../config';
4
4
  import { watch } from 'chokidar';
5
5
  import { basename } from 'path';
6
6
  import { red, green } from 'chalk';
7
- // eslint-disable-next-line @typescript-eslint/no-var-requires
8
- const ora = require('ora');
7
+ import ora from 'ora';
9
8
 
10
9
  export class Generate extends Command {
11
10
  static description = `Generate project files`;
@@ -36,29 +35,35 @@ export class Generate extends Command {
36
35
  await generateProject(cwd);
37
36
  spinner.succeed(`Finished generating files. Watching for changes.`);
38
37
  } catch (error) {
39
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
40
- spinner.fail(`Error generating files.\n${(error as any).message}`);
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
39
+ spinner.fail(`Error generating files.\n${String(error.message)}`);
41
40
  }
42
- watcher.on('change', async (path) => {
43
- const file = basename(path);
44
- spinner.clear();
45
- spinner.start(`Change detected for ${green(file)}, generating.`);
46
- try {
47
- await generateProject(cwd);
48
- spinner.succeed(
49
- `Finished generating files for ${green(
50
- file
51
- )}. Watching for changes.`
52
- );
53
- } catch (error) {
54
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
55
- const msg = (error as any).message;
56
- spinner.fail(`Error after saving ${red(file)}.\n${msg}`);
57
- }
41
+ watcher.on('change', (path) => {
42
+ const cb = async () => {
43
+ const file = basename(path);
44
+ spinner.clear();
45
+ spinner.start(`Change detected for ${green(file)}, generating.`);
46
+ try {
47
+ await generateProject(cwd);
48
+ spinner.succeed(
49
+ `Finished generating files for ${green(
50
+ file
51
+ )}. Watching for changes.`
52
+ );
53
+ } catch (error) {
54
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
55
+ const msg = error.message as string;
56
+ spinner.fail(`Error after saving ${red(file)}.\n${msg}`);
57
+ }
58
+ };
59
+ void cb();
58
60
  });
59
- process.on('SIGINT', async () => {
60
- await watcher.close();
61
- process.exit();
61
+ process.on('SIGINT', () => {
62
+ async function cb() {
63
+ await watcher.close();
64
+ process.exit();
65
+ }
66
+ void cb();
62
67
  });
63
68
  } else {
64
69
  await generateProject(cwd);
package/src/config.ts CHANGED
@@ -4,6 +4,7 @@ import { constants } from 'fs';
4
4
  import {
5
5
  ClarinetAccounts,
6
6
  getClarinetAccounts,
7
+ getClarinetConfig,
7
8
  getContractsFromClarinet,
8
9
  } from './clarinet-config';
9
10
 
@@ -62,18 +63,21 @@ export async function getConfigFile(
62
63
 
63
64
  export async function getProjectConfig(rootPath: string): Promise<ConfigFile> {
64
65
  const configFile = await getConfigFile(rootPath);
65
- const clarinetPath = resolve(rootPath, configFile.clarinet || '.');
66
+ const clarinetPath = resolve(rootPath, configFile.clarinet);
67
+ const clarinet = await getClarinetConfig(clarinetPath);
66
68
  const accounts = await getClarinetAccounts(clarinetPath);
67
- const contracts = await getContractsFromClarinet(clarinetPath, accounts);
69
+ const contracts = getContractsFromClarinet(clarinet, accounts);
68
70
  const contractsDir = relative(
69
71
  process.cwd(),
70
72
  join(configFile.clarinet, 'contracts')
71
73
  );
72
74
  return {
73
75
  ...configFile,
76
+ outputDir: clarinet.clarigen?.output_dir || configFile.outputDir,
77
+ docs: clarinet.clarigen?.docs || configFile.docs,
74
78
  contracts,
75
79
  contractsDir,
76
80
  accounts,
77
- clarinet: configFile.clarinet || '.',
81
+ clarinet: configFile.clarinet,
78
82
  };
79
83
  }
@@ -39,8 +39,8 @@ export const jsTypeFromAbiType = (
39
39
  } else if (isClarityAbiBuffer(val)) {
40
40
  return 'Uint8Array';
41
41
  } else if (isClarityAbiResponse(val)) {
42
- const ok: any = jsTypeFromAbiType(val.response.ok);
43
- const err: any = jsTypeFromAbiType(val.response.error);
42
+ const ok = jsTypeFromAbiType(val.response.ok);
43
+ const err = jsTypeFromAbiType(val.response.error);
44
44
  return `Response<${ok}, ${err}>`;
45
45
  } else if (isClarityAbiOptional(val)) {
46
46
  const innerType = jsTypeFromAbiType(val.optional);
@@ -55,7 +55,7 @@ export const jsTypeFromAbiType = (
55
55
  ${tupleDefs.join(';\n ')}
56
56
  }`;
57
57
  } else if (isClarityAbiList(val)) {
58
- const innerType: any = jsTypeFromAbiType(val.list.type);
58
+ const innerType = jsTypeFromAbiType(val.list.type);
59
59
  return `${innerType}[]`;
60
60
  } else if (isClarityAbiStringAscii(val)) {
61
61
  return 'string';
@@ -0,0 +1,45 @@
1
+ import { load } from 'js-yaml';
2
+ import { mkdir, readFile } from 'fs/promises';
3
+ import { resolve } from 'path';
4
+ import { existsSync } from 'fs';
5
+ import type { ConfigFile } from '../config';
6
+ import { writeFile } from '../writer';
7
+ import { DeploymentPlan } from '@clarigen/core';
8
+
9
+ export async function parseDeployment(path: string): Promise<DeploymentPlan> {
10
+ const contents = await readFile(path, { encoding: 'utf-8' });
11
+ const parsed = load(contents);
12
+ return parsed as DeploymentPlan;
13
+ }
14
+
15
+ export async function generateDeployment(network: string, config: ConfigFile) {
16
+ const file = `default.${network}-plan.yaml`;
17
+ const deploymentPath = resolve(
18
+ process.cwd(),
19
+ config.clarinet,
20
+ 'deployments',
21
+ file
22
+ );
23
+ if (existsSync(deploymentPath)) {
24
+ const plan = await parseDeployment(deploymentPath);
25
+ const varName = `${network}Deployment`;
26
+ const contents = `export const ${varName} = ${JSON.stringify(
27
+ plan
28
+ )} as const;
29
+ `;
30
+ const outputFile = resolve(
31
+ config.outputDir,
32
+ 'deployments',
33
+ `${network}.ts`
34
+ );
35
+ await writeFile(outputFile, contents);
36
+ }
37
+ }
38
+
39
+ export async function generateDeployments(config: ConfigFile) {
40
+ const networks = ['devnet', 'simnet', 'testnet', 'mainnet'];
41
+ const folder = resolve(process.cwd(), config.outputDir, 'deployments');
42
+ await mkdir(folder, { recursive: true });
43
+ const generates = networks.map((n) => generateDeployment(n, config));
44
+ await Promise.all(generates);
45
+ }
@@ -4,55 +4,6 @@ import { ConfigContract, ConfigFile } from '../config';
4
4
  import { dirname, resolve, join } from 'path';
5
5
  import { makePureTypes } from '..';
6
6
 
7
- export const generateInterface = async ({
8
- provider,
9
- contractFile,
10
- contractAddress,
11
- contractName,
12
- }: {
13
- contractFile: string;
14
- provider: NativeClarityBinProvider;
15
- contractAddress: string;
16
- contractName: string;
17
- }): Promise<ClarityAbi> => {
18
- const receipt = await provider.runCommand([
19
- 'launch',
20
- `${contractAddress}.${contractName}`,
21
- contractFile,
22
- provider.dbFilePath,
23
- '--output_analysis',
24
- '--costs',
25
- '--assets',
26
- ]);
27
- if (hasStdErr(receipt.stderr)) {
28
- throw new Error(`Error on ${contractFile}:
29
- ${receipt.stderr}
30
- `);
31
- }
32
- const output = JSON.parse(receipt.stdout);
33
- if (output.error) {
34
- const { initialization } = output.error;
35
- if (initialization?.includes('\nNear:\n')) {
36
- const [error, trace] = initialization.split('\nNear:\n');
37
- let startLine = '';
38
- const matcher = /start_line: (\d+),/;
39
- const matches = matcher.exec(trace);
40
- if (matches) startLine = matches[1];
41
- throw new Error(`Error on ${contractFile}:
42
- ${error}
43
- ${startLine ? `Near line ${startLine}` : ''}
44
- Raw trace:
45
- ${trace}
46
- `);
47
- }
48
- throw new Error(`Error on ${contractFile}:
49
- ${JSON.stringify(output.error, null, 2)}
50
- `);
51
- }
52
- const abi = output.analysis;
53
- return abi;
54
- };
55
-
56
7
  export const generateInterfaceFile = ({
57
8
  contractName,
58
9
  abi,
@@ -26,7 +26,7 @@ export function generateContractMeta(contract: ContractMeta) {
26
26
  const variableLines = contract.variables.map((v) => {
27
27
  let varLine = `${toCamelCase(v.name)}: `;
28
28
  const type = jsTypeFromAbiType(v.type);
29
- const varJSON = inspect(v, false, null, false);
29
+ const varJSON = serialize(v);
30
30
  varLine += `${varJSON} as TypedAbiVariable<${type}>`;
31
31
  return varLine;
32
32
  });
package/src/utils.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  generateIndexFile,
3
- generateInterface,
4
3
  generateInterfaceFile,
5
4
  generateProjectIndexFile,
6
5
  generateTypesFile,
@@ -19,6 +18,7 @@ import { generateContractMeta, generateSingleFile } from './generate/single';
19
18
  import { writeFile } from './writer';
20
19
  import { getVariables, TypedAbiVariable } from './generate/vars';
21
20
  import { ClarityAbiVariable } from 'micro-stacks/clarity';
21
+ import { generateDeployments } from './generate/deployment';
22
22
 
23
23
  export interface ContractMeta {
24
24
  abi: ClarityAbi;
@@ -126,4 +126,5 @@ export const generateProject = async (projectPath: string) => {
126
126
  const singleFile = await generateSingleFile(configFile, metas);
127
127
  const singlePath = resolve(outputFolder, 'single.ts');
128
128
  await writeFile(singlePath, singleFile);
129
+ await generateDeployments(configFile);
129
130
  };