@clarigen/cli 1.0.0-next.21 → 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.
- package/dist/commands/index.js +52 -22
- package/dist/index.js +52 -22
- package/package.json +12 -8
- package/src/clarinet-config.ts +6 -13
- package/src/generate/deployment.ts +45 -0
- package/src/utils.ts +2 -0
package/dist/commands/index.js
CHANGED
|
@@ -69,7 +69,7 @@ var import_promises2 = require("fs/promises");
|
|
|
69
69
|
var import_fs = require("fs");
|
|
70
70
|
|
|
71
71
|
// src/clarinet-config.ts
|
|
72
|
-
var
|
|
72
|
+
var import_toml = require("@iarna/toml");
|
|
73
73
|
var import_path = require("path");
|
|
74
74
|
var import_promises = require("fs/promises");
|
|
75
75
|
var import_wallet_sdk = require("micro-stacks/wallet-sdk");
|
|
@@ -78,15 +78,13 @@ var import_crypto = require("micro-stacks/crypto");
|
|
|
78
78
|
async function getClarinetDevConfig(folder) {
|
|
79
79
|
const baseConfigPath = (0, import_path.resolve)(folder, "settings", "Devnet.toml");
|
|
80
80
|
const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
81
|
-
const config = (0,
|
|
82
|
-
longer: true
|
|
83
|
-
});
|
|
81
|
+
const config = (0, import_toml.parse)(configContents);
|
|
84
82
|
return config;
|
|
85
83
|
}
|
|
86
84
|
async function getClarinetConfig(folder) {
|
|
87
85
|
const baseConfigPath = (0, import_path.resolve)(folder, "Clarinet.toml");
|
|
88
86
|
const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
89
|
-
const config = (0,
|
|
87
|
+
const config = (0, import_toml.parse)(configContents);
|
|
90
88
|
return config;
|
|
91
89
|
}
|
|
92
90
|
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
@@ -107,8 +105,9 @@ function sortClarinetContracts(contractsConfig) {
|
|
|
107
105
|
const edges = [];
|
|
108
106
|
const nodes = [];
|
|
109
107
|
Object.entries(contractsConfig).forEach(([contractName, info]) => {
|
|
108
|
+
var _a;
|
|
110
109
|
nodes.push(contractName);
|
|
111
|
-
info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
|
|
110
|
+
(_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
|
|
112
111
|
});
|
|
113
112
|
const sorted = (0, import_toposort.array)(nodes, edges).reverse();
|
|
114
113
|
return sorted;
|
|
@@ -386,8 +385,8 @@ export const contracts = {
|
|
|
386
385
|
|
|
387
386
|
// src/utils.ts
|
|
388
387
|
var import_native_bin2 = require("@clarigen/native-bin");
|
|
389
|
-
var
|
|
390
|
-
var
|
|
388
|
+
var import_path8 = require("path");
|
|
389
|
+
var import_promises7 = require("fs/promises");
|
|
391
390
|
|
|
392
391
|
// src/docs.ts
|
|
393
392
|
var import_claridocs = require("@clarigen/claridocs");
|
|
@@ -619,6 +618,36 @@ function getEvalCode(variable) {
|
|
|
619
618
|
return variable.name;
|
|
620
619
|
}
|
|
621
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
|
+
|
|
622
651
|
// src/utils.ts
|
|
623
652
|
var generateFilesForContract = async ({
|
|
624
653
|
contractFile: _contractFile,
|
|
@@ -629,7 +658,7 @@ var generateFilesForContract = async ({
|
|
|
629
658
|
contractName,
|
|
630
659
|
docsPath
|
|
631
660
|
}) => {
|
|
632
|
-
const contractFile = (0,
|
|
661
|
+
const contractFile = (0, import_path8.resolve)(process.cwd(), _contractFile);
|
|
633
662
|
const contractIdentifier = `${contractAddress}.${contractName}`;
|
|
634
663
|
const abi = await (0, import_native_bin2.deployContract)({
|
|
635
664
|
contractIdentifier,
|
|
@@ -643,7 +672,7 @@ var generateFilesForContract = async ({
|
|
|
643
672
|
});
|
|
644
673
|
const typesFile = generateTypesFile(abi, contractName);
|
|
645
674
|
const indexFile = generateIndexFile({
|
|
646
|
-
contractFile: (0,
|
|
675
|
+
contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
|
|
647
676
|
contractAddress,
|
|
648
677
|
contractName
|
|
649
678
|
});
|
|
@@ -657,11 +686,11 @@ var generateFilesForContract = async ({
|
|
|
657
686
|
dirName
|
|
658
687
|
});
|
|
659
688
|
}
|
|
660
|
-
const outputPath = (0,
|
|
661
|
-
await (0,
|
|
662
|
-
await writeFile2((0,
|
|
663
|
-
await writeFile2((0,
|
|
664
|
-
await writeFile2((0,
|
|
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);
|
|
665
694
|
return {
|
|
666
695
|
abi,
|
|
667
696
|
contractFile,
|
|
@@ -674,12 +703,12 @@ var generateFilesForContract = async ({
|
|
|
674
703
|
var generateProject = async (projectPath) => {
|
|
675
704
|
const configFile = await getProjectConfig(projectPath);
|
|
676
705
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
677
|
-
const outputFolder = (0,
|
|
706
|
+
const outputFolder = (0, import_path8.resolve)(projectPath, outputDir);
|
|
678
707
|
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
679
708
|
const metas = [];
|
|
680
709
|
for (const contract of contracts) {
|
|
681
|
-
const contractFile = (0,
|
|
682
|
-
const dirName = (0,
|
|
710
|
+
const contractFile = (0, import_path8.resolve)(projectPath, contractsDir, contract.file);
|
|
711
|
+
const dirName = (0, import_path8.dirname)(contract.file);
|
|
683
712
|
const meta = await generateFilesForContract({
|
|
684
713
|
contractFile,
|
|
685
714
|
outputFolder,
|
|
@@ -693,16 +722,17 @@ var generateProject = async (projectPath) => {
|
|
|
693
722
|
}
|
|
694
723
|
const indexFile = generateProjectIndexFile(configFile);
|
|
695
724
|
await generateDocsIndex(configFile);
|
|
696
|
-
const indexPath = (0,
|
|
725
|
+
const indexPath = (0, import_path8.resolve)(outputFolder, "index.ts");
|
|
697
726
|
await writeFile2(indexPath, indexFile);
|
|
698
727
|
const singleFile = await generateSingleFile(configFile, metas);
|
|
699
|
-
const singlePath = (0,
|
|
728
|
+
const singlePath = (0, import_path8.resolve)(outputFolder, "single.ts");
|
|
700
729
|
await writeFile2(singlePath, singleFile);
|
|
730
|
+
await generateDeployments(configFile);
|
|
701
731
|
};
|
|
702
732
|
|
|
703
733
|
// src/commands/index.ts
|
|
704
734
|
var import_chokidar = require("chokidar");
|
|
705
|
-
var
|
|
735
|
+
var import_path9 = require("path");
|
|
706
736
|
var import_chalk = require("chalk");
|
|
707
737
|
var import_ora = __toESM(require("ora"));
|
|
708
738
|
var _Generate = class extends import_command2.Command {
|
|
@@ -724,7 +754,7 @@ ${String(error.message)}`);
|
|
|
724
754
|
}
|
|
725
755
|
watcher.on("change", (path) => {
|
|
726
756
|
const cb = async () => {
|
|
727
|
-
const file = (0,
|
|
757
|
+
const file = (0, import_path9.basename)(path);
|
|
728
758
|
spinner.clear();
|
|
729
759
|
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
730
760
|
try {
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var import_promises2 = require("fs/promises");
|
|
|
75
75
|
var import_fs = require("fs");
|
|
76
76
|
|
|
77
77
|
// src/clarinet-config.ts
|
|
78
|
-
var
|
|
78
|
+
var import_toml = require("@iarna/toml");
|
|
79
79
|
var import_path = require("path");
|
|
80
80
|
var import_promises = require("fs/promises");
|
|
81
81
|
var import_wallet_sdk = require("micro-stacks/wallet-sdk");
|
|
@@ -84,15 +84,13 @@ var import_crypto = require("micro-stacks/crypto");
|
|
|
84
84
|
async function getClarinetDevConfig(folder) {
|
|
85
85
|
const baseConfigPath = (0, import_path.resolve)(folder, "settings", "Devnet.toml");
|
|
86
86
|
const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
87
|
-
const config = (0,
|
|
88
|
-
longer: true
|
|
89
|
-
});
|
|
87
|
+
const config = (0, import_toml.parse)(configContents);
|
|
90
88
|
return config;
|
|
91
89
|
}
|
|
92
90
|
async function getClarinetConfig(folder) {
|
|
93
91
|
const baseConfigPath = (0, import_path.resolve)(folder, "Clarinet.toml");
|
|
94
92
|
const configContents = await (0, import_promises.readFile)(baseConfigPath, { encoding: "utf-8" });
|
|
95
|
-
const config = (0,
|
|
93
|
+
const config = (0, import_toml.parse)(configContents);
|
|
96
94
|
return config;
|
|
97
95
|
}
|
|
98
96
|
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
@@ -113,8 +111,9 @@ function sortClarinetContracts(contractsConfig) {
|
|
|
113
111
|
const edges = [];
|
|
114
112
|
const nodes = [];
|
|
115
113
|
Object.entries(contractsConfig).forEach(([contractName, info]) => {
|
|
114
|
+
var _a;
|
|
116
115
|
nodes.push(contractName);
|
|
117
|
-
info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
|
|
116
|
+
(_a = info.depends_on) == null ? void 0 : _a.forEach((dependency) => edges.push([contractName, dependency]));
|
|
118
117
|
});
|
|
119
118
|
const sorted = (0, import_toposort.array)(nodes, edges).reverse();
|
|
120
119
|
return sorted;
|
|
@@ -397,8 +396,8 @@ var import_command = require("@oclif/command");
|
|
|
397
396
|
|
|
398
397
|
// src/utils.ts
|
|
399
398
|
var import_native_bin2 = require("@clarigen/native-bin");
|
|
400
|
-
var
|
|
401
|
-
var
|
|
399
|
+
var import_path8 = require("path");
|
|
400
|
+
var import_promises7 = require("fs/promises");
|
|
402
401
|
|
|
403
402
|
// src/docs.ts
|
|
404
403
|
var import_claridocs = require("@clarigen/claridocs");
|
|
@@ -630,6 +629,36 @@ function getEvalCode(variable) {
|
|
|
630
629
|
return variable.name;
|
|
631
630
|
}
|
|
632
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
|
+
|
|
633
662
|
// src/utils.ts
|
|
634
663
|
var generateFilesForContract = async ({
|
|
635
664
|
contractFile: _contractFile,
|
|
@@ -640,7 +669,7 @@ var generateFilesForContract = async ({
|
|
|
640
669
|
contractName,
|
|
641
670
|
docsPath
|
|
642
671
|
}) => {
|
|
643
|
-
const contractFile = (0,
|
|
672
|
+
const contractFile = (0, import_path8.resolve)(process.cwd(), _contractFile);
|
|
644
673
|
const contractIdentifier = `${contractAddress}.${contractName}`;
|
|
645
674
|
const abi = await (0, import_native_bin2.deployContract)({
|
|
646
675
|
contractIdentifier,
|
|
@@ -654,7 +683,7 @@ var generateFilesForContract = async ({
|
|
|
654
683
|
});
|
|
655
684
|
const typesFile = generateTypesFile(abi, contractName);
|
|
656
685
|
const indexFile = generateIndexFile({
|
|
657
|
-
contractFile: (0,
|
|
686
|
+
contractFile: (0, import_path8.relative)(process.cwd(), contractFile),
|
|
658
687
|
contractAddress,
|
|
659
688
|
contractName
|
|
660
689
|
});
|
|
@@ -668,11 +697,11 @@ var generateFilesForContract = async ({
|
|
|
668
697
|
dirName
|
|
669
698
|
});
|
|
670
699
|
}
|
|
671
|
-
const outputPath = (0,
|
|
672
|
-
await (0,
|
|
673
|
-
await writeFile2((0,
|
|
674
|
-
await writeFile2((0,
|
|
675
|
-
await writeFile2((0,
|
|
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);
|
|
676
705
|
return {
|
|
677
706
|
abi,
|
|
678
707
|
contractFile,
|
|
@@ -685,12 +714,12 @@ var generateFilesForContract = async ({
|
|
|
685
714
|
var generateProject = async (projectPath) => {
|
|
686
715
|
const configFile = await getProjectConfig(projectPath);
|
|
687
716
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
688
|
-
const outputFolder = (0,
|
|
717
|
+
const outputFolder = (0, import_path8.resolve)(projectPath, outputDir);
|
|
689
718
|
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
690
719
|
const metas = [];
|
|
691
720
|
for (const contract of contracts) {
|
|
692
|
-
const contractFile = (0,
|
|
693
|
-
const dirName = (0,
|
|
721
|
+
const contractFile = (0, import_path8.resolve)(projectPath, contractsDir, contract.file);
|
|
722
|
+
const dirName = (0, import_path8.dirname)(contract.file);
|
|
694
723
|
const meta = await generateFilesForContract({
|
|
695
724
|
contractFile,
|
|
696
725
|
outputFolder,
|
|
@@ -704,16 +733,17 @@ var generateProject = async (projectPath) => {
|
|
|
704
733
|
}
|
|
705
734
|
const indexFile = generateProjectIndexFile(configFile);
|
|
706
735
|
await generateDocsIndex(configFile);
|
|
707
|
-
const indexPath = (0,
|
|
736
|
+
const indexPath = (0, import_path8.resolve)(outputFolder, "index.ts");
|
|
708
737
|
await writeFile2(indexPath, indexFile);
|
|
709
738
|
const singleFile = await generateSingleFile(configFile, metas);
|
|
710
|
-
const singlePath = (0,
|
|
739
|
+
const singlePath = (0, import_path8.resolve)(outputFolder, "single.ts");
|
|
711
740
|
await writeFile2(singlePath, singleFile);
|
|
741
|
+
await generateDeployments(configFile);
|
|
712
742
|
};
|
|
713
743
|
|
|
714
744
|
// src/commands/index.ts
|
|
715
745
|
var import_chokidar = require("chokidar");
|
|
716
|
-
var
|
|
746
|
+
var import_path9 = require("path");
|
|
717
747
|
var import_chalk = require("chalk");
|
|
718
748
|
var import_ora = __toESM(require("ora"));
|
|
719
749
|
var _Generate = class extends import_command.Command {
|
|
@@ -735,7 +765,7 @@ ${String(error.message)}`);
|
|
|
735
765
|
}
|
|
736
766
|
watcher.on("change", (path) => {
|
|
737
767
|
const cb = async () => {
|
|
738
|
-
const file = (0,
|
|
768
|
+
const file = (0, import_path9.basename)(path);
|
|
739
769
|
spinner.clear();
|
|
740
770
|
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
741
771
|
try {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@clarigen/cli",
|
|
3
3
|
"description": "A CLI for generating a Typescript interface for a Clarity contract.",
|
|
4
4
|
"author": "Hank Stoever",
|
|
5
|
-
"version": "1.0.0-next.
|
|
5
|
+
"version": "1.0.0-next.22",
|
|
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/
|
|
41
|
-
"@clarigen/
|
|
42
|
-
"@clarigen/
|
|
43
|
-
"@
|
|
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",
|
|
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
|
-
"
|
|
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
|
-
"
|
|
53
|
-
"
|
|
56
|
+
"reserved-words": "0.1.2",
|
|
57
|
+
"toposort": "2.0.2"
|
|
54
58
|
},
|
|
55
59
|
"publishConfig": {
|
|
56
60
|
"access": "public"
|
package/src/clarinet-config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parse } from '@
|
|
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
|
|
33
|
-
|
|
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
|
|
38
|
+
depends_on?: string[];
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
export interface ClarinetContracts {
|
|
@@ -61,12 +59,7 @@ export const CLARINET_SETTINGS = [
|
|
|
61
59
|
export async function getClarinetConfig(folder: string) {
|
|
62
60
|
const baseConfigPath = resolve(folder, 'Clarinet.toml');
|
|
63
61
|
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;
|
|
62
|
+
const config = parse(configContents) as unknown as ClarinetConfig;
|
|
70
63
|
return config;
|
|
71
64
|
}
|
|
72
65
|
|
|
@@ -93,7 +86,7 @@ export function sortClarinetContracts(contractsConfig: ClarinetContracts) {
|
|
|
93
86
|
const nodes: string[] = [];
|
|
94
87
|
Object.entries(contractsConfig).forEach(([contractName, info]) => {
|
|
95
88
|
nodes.push(contractName);
|
|
96
|
-
info.depends_on
|
|
89
|
+
info.depends_on?.forEach((dependency) =>
|
|
97
90
|
edges.push([contractName, dependency])
|
|
98
91
|
);
|
|
99
92
|
});
|
|
@@ -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
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { generateContractMeta, generateSingleFile } from './generate/single';
|
|
|
18
18
|
import { writeFile } from './writer';
|
|
19
19
|
import { getVariables, TypedAbiVariable } from './generate/vars';
|
|
20
20
|
import { ClarityAbiVariable } from 'micro-stacks/clarity';
|
|
21
|
+
import { generateDeployments } from './generate/deployment';
|
|
21
22
|
|
|
22
23
|
export interface ContractMeta {
|
|
23
24
|
abi: ClarityAbi;
|
|
@@ -125,4 +126,5 @@ export const generateProject = async (projectPath: string) => {
|
|
|
125
126
|
const singleFile = await generateSingleFile(configFile, metas);
|
|
126
127
|
const singlePath = resolve(outputFolder, 'single.ts');
|
|
127
128
|
await writeFile(singlePath, singleFile);
|
|
129
|
+
await generateDeployments(configFile);
|
|
128
130
|
};
|