@clarigen/cli 1.0.0-next.20 → 1.0.0-next.21
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 +39 -28
- package/dist/index.js +39 -74
- package/package.json +19 -21
- package/src/clarinet-config.ts +11 -8
- package/src/commands/index.ts +28 -23
- package/src/config.ts +7 -3
- package/src/generate/declaration.ts +3 -3
- package/src/generate/files.ts +0 -49
- package/src/utils.ts +0 -1
package/dist/commands/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/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
|
|
|
@@ -87,8 +89,7 @@ async function getClarinetConfig(folder) {
|
|
|
87
89
|
const config = (0, import_j_toml.parse)(configContents, 1, "\n", true);
|
|
88
90
|
return config;
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
const clarinetConfig = await getClarinetConfig(folder);
|
|
92
|
+
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
92
93
|
const deployerAddress = accounts.deployer.address;
|
|
93
94
|
const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
|
|
94
95
|
const contracts = sortedContracts.map((contractName) => {
|
|
@@ -156,16 +157,20 @@ async function getConfigFile(rootPath) {
|
|
|
156
157
|
return defaultConfigFile;
|
|
157
158
|
}
|
|
158
159
|
async function getProjectConfig(rootPath) {
|
|
160
|
+
var _a, _b;
|
|
159
161
|
const configFile = await getConfigFile(rootPath);
|
|
160
|
-
const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet
|
|
162
|
+
const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet);
|
|
163
|
+
const clarinet = await getClarinetConfig(clarinetPath);
|
|
161
164
|
const accounts = await getClarinetAccounts(clarinetPath);
|
|
162
|
-
const contracts =
|
|
165
|
+
const contracts = getContractsFromClarinet(clarinet, accounts);
|
|
163
166
|
const contractsDir = (0, import_path2.relative)(process.cwd(), (0, import_path2.join)(configFile.clarinet, "contracts"));
|
|
164
167
|
return __spreadProps(__spreadValues({}, configFile), {
|
|
168
|
+
outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
|
|
169
|
+
docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
|
|
165
170
|
contracts,
|
|
166
171
|
contractsDir,
|
|
167
172
|
accounts,
|
|
168
|
-
clarinet: configFile.clarinet
|
|
173
|
+
clarinet: configFile.clarinet
|
|
169
174
|
});
|
|
170
175
|
}
|
|
171
176
|
|
|
@@ -380,7 +385,7 @@ export const contracts = {
|
|
|
380
385
|
};
|
|
381
386
|
|
|
382
387
|
// src/utils.ts
|
|
383
|
-
var
|
|
388
|
+
var import_native_bin2 = require("@clarigen/native-bin");
|
|
384
389
|
var import_path7 = require("path");
|
|
385
390
|
var import_promises6 = require("fs/promises");
|
|
386
391
|
|
|
@@ -572,7 +577,7 @@ async function writeFile2(path, contents) {
|
|
|
572
577
|
|
|
573
578
|
// src/generate/vars.ts
|
|
574
579
|
var import_core4 = require("@clarigen/core");
|
|
575
|
-
var
|
|
580
|
+
var import_native_bin = require("@clarigen/native-bin");
|
|
576
581
|
var import_clarity = require("micro-stacks/clarity");
|
|
577
582
|
async function getVariables({
|
|
578
583
|
abi,
|
|
@@ -595,7 +600,7 @@ async function evalVariable({
|
|
|
595
600
|
provider
|
|
596
601
|
}) {
|
|
597
602
|
const code = getEvalCode(variable);
|
|
598
|
-
const result = await (0,
|
|
603
|
+
const result = await (0, import_native_bin.evalRaw)({
|
|
599
604
|
contractAddress: contractIdentifier,
|
|
600
605
|
code,
|
|
601
606
|
provider
|
|
@@ -626,7 +631,7 @@ var generateFilesForContract = async ({
|
|
|
626
631
|
}) => {
|
|
627
632
|
const contractFile = (0, import_path7.resolve)(process.cwd(), _contractFile);
|
|
628
633
|
const contractIdentifier = `${contractAddress}.${contractName}`;
|
|
629
|
-
const abi = await (0,
|
|
634
|
+
const abi = await (0, import_native_bin2.deployContract)({
|
|
630
635
|
contractIdentifier,
|
|
631
636
|
contractFilePath: contractFile,
|
|
632
637
|
provider
|
|
@@ -670,7 +675,7 @@ var generateProject = async (projectPath) => {
|
|
|
670
675
|
const configFile = await getProjectConfig(projectPath);
|
|
671
676
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
672
677
|
const outputFolder = (0, import_path7.resolve)(projectPath, outputDir);
|
|
673
|
-
const provider = await (0,
|
|
678
|
+
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
674
679
|
const metas = [];
|
|
675
680
|
for (const contract of contracts) {
|
|
676
681
|
const contractFile = (0, import_path7.resolve)(projectPath, contractsDir, contract.file);
|
|
@@ -699,13 +704,13 @@ var generateProject = async (projectPath) => {
|
|
|
699
704
|
var import_chokidar = require("chokidar");
|
|
700
705
|
var import_path8 = require("path");
|
|
701
706
|
var import_chalk = require("chalk");
|
|
702
|
-
var
|
|
707
|
+
var import_ora = __toESM(require("ora"));
|
|
703
708
|
var _Generate = class extends import_command2.Command {
|
|
704
709
|
async run() {
|
|
705
710
|
const { flags: flags2 } = this.parse(_Generate);
|
|
706
711
|
const cwd = process.cwd();
|
|
707
712
|
if (flags2.watch) {
|
|
708
|
-
const spinner =
|
|
713
|
+
const spinner = (0, import_ora.default)("Generating files").start();
|
|
709
714
|
const { contractsDir } = await getProjectConfig(cwd);
|
|
710
715
|
const watcher = (0, import_chokidar.watch)([contractsDir], {
|
|
711
716
|
cwd
|
|
@@ -715,24 +720,30 @@ var _Generate = class extends import_command2.Command {
|
|
|
715
720
|
spinner.succeed(`Finished generating files. Watching for changes.`);
|
|
716
721
|
} catch (error) {
|
|
717
722
|
spinner.fail(`Error generating files.
|
|
718
|
-
${error.message}`);
|
|
723
|
+
${String(error.message)}`);
|
|
719
724
|
}
|
|
720
|
-
watcher.on("change",
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
725
|
+
watcher.on("change", (path) => {
|
|
726
|
+
const cb = async () => {
|
|
727
|
+
const file = (0, import_path8.basename)(path);
|
|
728
|
+
spinner.clear();
|
|
729
|
+
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
730
|
+
try {
|
|
731
|
+
await generateProject(cwd);
|
|
732
|
+
spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
const msg = error.message;
|
|
735
|
+
spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
|
|
730
736
|
${msg}`);
|
|
731
|
-
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
void cb();
|
|
732
740
|
});
|
|
733
|
-
process.on("SIGINT",
|
|
734
|
-
|
|
735
|
-
|
|
741
|
+
process.on("SIGINT", () => {
|
|
742
|
+
async function cb() {
|
|
743
|
+
await watcher.close();
|
|
744
|
+
process.exit();
|
|
745
|
+
}
|
|
746
|
+
void cb();
|
|
736
747
|
});
|
|
737
748
|
} else {
|
|
738
749
|
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,
|
|
@@ -93,8 +95,7 @@ async function getClarinetConfig(folder) {
|
|
|
93
95
|
const config = (0, import_j_toml.parse)(configContents, 1, "\n", true);
|
|
94
96
|
return config;
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
const clarinetConfig = await getClarinetConfig(folder);
|
|
98
|
+
function getContractsFromClarinet(clarinetConfig, accounts) {
|
|
98
99
|
const deployerAddress = accounts.deployer.address;
|
|
99
100
|
const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
|
|
100
101
|
const contracts = sortedContracts.map((contractName) => {
|
|
@@ -162,16 +163,20 @@ async function getConfigFile(rootPath) {
|
|
|
162
163
|
return defaultConfigFile;
|
|
163
164
|
}
|
|
164
165
|
async function getProjectConfig(rootPath) {
|
|
166
|
+
var _a, _b;
|
|
165
167
|
const configFile = await getConfigFile(rootPath);
|
|
166
|
-
const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet
|
|
168
|
+
const clarinetPath = (0, import_path2.resolve)(rootPath, configFile.clarinet);
|
|
169
|
+
const clarinet = await getClarinetConfig(clarinetPath);
|
|
167
170
|
const accounts = await getClarinetAccounts(clarinetPath);
|
|
168
|
-
const contracts =
|
|
171
|
+
const contracts = getContractsFromClarinet(clarinet, accounts);
|
|
169
172
|
const contractsDir = (0, import_path2.relative)(process.cwd(), (0, import_path2.join)(configFile.clarinet, "contracts"));
|
|
170
173
|
return __spreadProps(__spreadValues({}, configFile), {
|
|
174
|
+
outputDir: ((_a = clarinet.clarigen) == null ? void 0 : _a.output_dir) || configFile.outputDir,
|
|
175
|
+
docs: ((_b = clarinet.clarigen) == null ? void 0 : _b.docs) || configFile.docs,
|
|
171
176
|
contracts,
|
|
172
177
|
contractsDir,
|
|
173
178
|
accounts,
|
|
174
|
-
clarinet: configFile.clarinet
|
|
179
|
+
clarinet: configFile.clarinet
|
|
175
180
|
});
|
|
176
181
|
}
|
|
177
182
|
|
|
@@ -277,53 +282,8 @@ function makePureTypes(abi) {
|
|
|
277
282
|
}
|
|
278
283
|
|
|
279
284
|
// src/generate/files.ts
|
|
280
|
-
var import_native_bin = require("@clarigen/native-bin");
|
|
281
285
|
var import_core2 = require("@clarigen/core");
|
|
282
286
|
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
287
|
var generateInterfaceFile = ({
|
|
328
288
|
contractName,
|
|
329
289
|
abi
|
|
@@ -436,7 +396,7 @@ export const contracts = {
|
|
|
436
396
|
var import_command = require("@oclif/command");
|
|
437
397
|
|
|
438
398
|
// src/utils.ts
|
|
439
|
-
var
|
|
399
|
+
var import_native_bin2 = require("@clarigen/native-bin");
|
|
440
400
|
var import_path7 = require("path");
|
|
441
401
|
var import_promises6 = require("fs/promises");
|
|
442
402
|
|
|
@@ -628,7 +588,7 @@ async function writeFile2(path, contents) {
|
|
|
628
588
|
|
|
629
589
|
// src/generate/vars.ts
|
|
630
590
|
var import_core4 = require("@clarigen/core");
|
|
631
|
-
var
|
|
591
|
+
var import_native_bin = require("@clarigen/native-bin");
|
|
632
592
|
var import_clarity = require("micro-stacks/clarity");
|
|
633
593
|
async function getVariables({
|
|
634
594
|
abi,
|
|
@@ -651,7 +611,7 @@ async function evalVariable({
|
|
|
651
611
|
provider
|
|
652
612
|
}) {
|
|
653
613
|
const code = getEvalCode(variable);
|
|
654
|
-
const result = await (0,
|
|
614
|
+
const result = await (0, import_native_bin.evalRaw)({
|
|
655
615
|
contractAddress: contractIdentifier,
|
|
656
616
|
code,
|
|
657
617
|
provider
|
|
@@ -682,7 +642,7 @@ var generateFilesForContract = async ({
|
|
|
682
642
|
}) => {
|
|
683
643
|
const contractFile = (0, import_path7.resolve)(process.cwd(), _contractFile);
|
|
684
644
|
const contractIdentifier = `${contractAddress}.${contractName}`;
|
|
685
|
-
const abi = await (0,
|
|
645
|
+
const abi = await (0, import_native_bin2.deployContract)({
|
|
686
646
|
contractIdentifier,
|
|
687
647
|
contractFilePath: contractFile,
|
|
688
648
|
provider
|
|
@@ -726,7 +686,7 @@ var generateProject = async (projectPath) => {
|
|
|
726
686
|
const configFile = await getProjectConfig(projectPath);
|
|
727
687
|
const { contractsDir, outputDir, contracts } = configFile;
|
|
728
688
|
const outputFolder = (0, import_path7.resolve)(projectPath, outputDir);
|
|
729
|
-
const provider = await (0,
|
|
689
|
+
const provider = await (0, import_native_bin2.createClarityBin)();
|
|
730
690
|
const metas = [];
|
|
731
691
|
for (const contract of contracts) {
|
|
732
692
|
const contractFile = (0, import_path7.resolve)(projectPath, contractsDir, contract.file);
|
|
@@ -755,13 +715,13 @@ var generateProject = async (projectPath) => {
|
|
|
755
715
|
var import_chokidar = require("chokidar");
|
|
756
716
|
var import_path8 = require("path");
|
|
757
717
|
var import_chalk = require("chalk");
|
|
758
|
-
var
|
|
718
|
+
var import_ora = __toESM(require("ora"));
|
|
759
719
|
var _Generate = class extends import_command.Command {
|
|
760
720
|
async run() {
|
|
761
721
|
const { flags: flags2 } = this.parse(_Generate);
|
|
762
722
|
const cwd = process.cwd();
|
|
763
723
|
if (flags2.watch) {
|
|
764
|
-
const spinner =
|
|
724
|
+
const spinner = (0, import_ora.default)("Generating files").start();
|
|
765
725
|
const { contractsDir } = await getProjectConfig(cwd);
|
|
766
726
|
const watcher = (0, import_chokidar.watch)([contractsDir], {
|
|
767
727
|
cwd
|
|
@@ -771,24 +731,30 @@ var _Generate = class extends import_command.Command {
|
|
|
771
731
|
spinner.succeed(`Finished generating files. Watching for changes.`);
|
|
772
732
|
} catch (error) {
|
|
773
733
|
spinner.fail(`Error generating files.
|
|
774
|
-
${error.message}`);
|
|
734
|
+
${String(error.message)}`);
|
|
775
735
|
}
|
|
776
|
-
watcher.on("change",
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
736
|
+
watcher.on("change", (path) => {
|
|
737
|
+
const cb = async () => {
|
|
738
|
+
const file = (0, import_path8.basename)(path);
|
|
739
|
+
spinner.clear();
|
|
740
|
+
spinner.start(`Change detected for ${(0, import_chalk.green)(file)}, generating.`);
|
|
741
|
+
try {
|
|
742
|
+
await generateProject(cwd);
|
|
743
|
+
spinner.succeed(`Finished generating files for ${(0, import_chalk.green)(file)}. Watching for changes.`);
|
|
744
|
+
} catch (error) {
|
|
745
|
+
const msg = error.message;
|
|
746
|
+
spinner.fail(`Error after saving ${(0, import_chalk.red)(file)}.
|
|
786
747
|
${msg}`);
|
|
787
|
-
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
void cb();
|
|
788
751
|
});
|
|
789
|
-
process.on("SIGINT",
|
|
790
|
-
|
|
791
|
-
|
|
752
|
+
process.on("SIGINT", () => {
|
|
753
|
+
async function cb() {
|
|
754
|
+
await watcher.close();
|
|
755
|
+
process.exit();
|
|
756
|
+
}
|
|
757
|
+
void cb();
|
|
792
758
|
});
|
|
793
759
|
} else {
|
|
794
760
|
await generateProject(cwd);
|
|
@@ -814,7 +780,6 @@ Generate.args = [];
|
|
|
814
780
|
configFilePath,
|
|
815
781
|
defaultConfigFile,
|
|
816
782
|
generateIndexFile,
|
|
817
|
-
generateInterface,
|
|
818
783
|
generateInterfaceFile,
|
|
819
784
|
generateProjectIndexFile,
|
|
820
785
|
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.
|
|
5
|
+
"version": "1.0.0-next.21",
|
|
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
|
},
|
|
@@ -50,9 +37,9 @@
|
|
|
50
37
|
"ts-node": "^9.1.1"
|
|
51
38
|
},
|
|
52
39
|
"dependencies": {
|
|
53
|
-
"@clarigen/
|
|
54
|
-
"@clarigen/
|
|
55
|
-
"@clarigen/
|
|
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",
|
|
56
43
|
"@ltd/j-toml": "1.12.2",
|
|
57
44
|
"@oclif/command": "^1.8.0",
|
|
58
45
|
"@oclif/config": "^1.17.0",
|
|
@@ -62,11 +49,22 @@
|
|
|
62
49
|
"micro-stacks": "^0.2.0",
|
|
63
50
|
"ora": "5.4.0",
|
|
64
51
|
"prettier": "2.6.2",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
52
|
+
"toposort": "2.0.2",
|
|
53
|
+
"reserved-words": "0.1.2"
|
|
67
54
|
},
|
|
68
55
|
"publishConfig": {
|
|
69
56
|
"access": "public"
|
|
70
57
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
58
|
+
"scripts": {
|
|
59
|
+
"start": "tsup-node --watch",
|
|
60
|
+
"dev": "tsup-node --watch",
|
|
61
|
+
"build": "shx rm -rf ./dist && tsup-node",
|
|
62
|
+
"compile": "ncc build src/index.ts --no-source-map-register -e @oclif/command -e @oclif/errors",
|
|
63
|
+
"build-single-file": "compile && oclif-dev readme",
|
|
64
|
+
"test": "jest",
|
|
65
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
|
|
66
|
+
"typecheck": "tsc --noEmit -p tsconfig-test.json",
|
|
67
|
+
"demo": "pnpm build && node bin/run",
|
|
68
|
+
"publish:dev": "yalc publish --push"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/clarinet-config.ts
CHANGED
|
@@ -29,9 +29,9 @@ 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 =
|
|
32
|
+
const config = parse(configContents, 1.0, '\n', true, {
|
|
33
33
|
longer: true,
|
|
34
|
-
}) as unknown
|
|
34
|
+
}) as unknown as ClarinetDevConfig;
|
|
35
35
|
return config;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -46,6 +46,10 @@ export interface ClarinetContracts {
|
|
|
46
46
|
|
|
47
47
|
export interface ClarinetConfig {
|
|
48
48
|
contracts: ClarinetContracts;
|
|
49
|
+
clarigen?: {
|
|
50
|
+
output_dir?: string;
|
|
51
|
+
docs?: string;
|
|
52
|
+
};
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export const CLARINET_SETTINGS = [
|
|
@@ -57,20 +61,19 @@ export const CLARINET_SETTINGS = [
|
|
|
57
61
|
export async function getClarinetConfig(folder: string) {
|
|
58
62
|
const baseConfigPath = resolve(folder, 'Clarinet.toml');
|
|
59
63
|
const configContents = await readFile(baseConfigPath, { encoding: 'utf-8' });
|
|
60
|
-
const config =
|
|
64
|
+
const config = parse(
|
|
61
65
|
configContents,
|
|
62
66
|
1.0,
|
|
63
67
|
'\n',
|
|
64
68
|
true
|
|
65
|
-
) as unknown
|
|
69
|
+
) as unknown as ClarinetConfig;
|
|
66
70
|
return config;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
export
|
|
70
|
-
|
|
73
|
+
export function getContractsFromClarinet(
|
|
74
|
+
clarinetConfig: ClarinetConfig,
|
|
71
75
|
accounts: ClarinetAccounts
|
|
72
|
-
):
|
|
73
|
-
const clarinetConfig = await getClarinetConfig(folder);
|
|
76
|
+
): ConfigContract[] {
|
|
74
77
|
const deployerAddress = accounts.deployer.address;
|
|
75
78
|
const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
|
|
76
79
|
const contracts: ConfigContract[] = sortedContracts.map((contractName) => {
|
package/src/commands/index.ts
CHANGED
|
@@ -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
|
-
|
|
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-
|
|
40
|
-
spinner.fail(`Error generating files.\n${(error
|
|
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',
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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',
|
|
60
|
-
|
|
61
|
-
|
|
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 =
|
|
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
|
|
43
|
-
const err
|
|
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
|
|
58
|
+
const innerType = jsTypeFromAbiType(val.list.type);
|
|
59
59
|
return `${innerType}[]`;
|
|
60
60
|
} else if (isClarityAbiStringAscii(val)) {
|
|
61
61
|
return 'string';
|
package/src/generate/files.ts
CHANGED
|
@@ -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,
|