@awarizon/cli 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.mjs → index.js} +41 -18
- package/package.json +1 -1
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
2
25
|
|
|
3
26
|
// src/index.ts
|
|
4
|
-
|
|
27
|
+
var import_commander = require("commander");
|
|
5
28
|
|
|
6
29
|
// src/commands/generate.ts
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
31
|
+
var import_node_path = __toESM(require("path"));
|
|
9
32
|
|
|
10
33
|
// src/codegen.ts
|
|
11
|
-
|
|
34
|
+
var import_abi_engine = require("@awarizon/abi-engine");
|
|
12
35
|
function generateContractClient(contractName, address, abi) {
|
|
13
|
-
const parsed = parseABI(abi);
|
|
14
|
-
const methods = generateAllMethodSignatures(parsed);
|
|
36
|
+
const parsed = (0, import_abi_engine.parseABI)(abi);
|
|
37
|
+
const methods = (0, import_abi_engine.generateAllMethodSignatures)(parsed);
|
|
15
38
|
const readMethods = methods.filter((m) => m.kind === "read");
|
|
16
39
|
const writeMethods = methods.filter((m) => m.kind !== "read");
|
|
17
40
|
const methodDocs = methods.map((m) => {
|
|
@@ -81,8 +104,8 @@ ${methodImpls}
|
|
|
81
104
|
`;
|
|
82
105
|
}
|
|
83
106
|
function generateReactHooks(contractName, address, abi) {
|
|
84
|
-
const parsed = parseABI(abi);
|
|
85
|
-
const methods = generateAllMethodSignatures(parsed);
|
|
107
|
+
const parsed = (0, import_abi_engine.parseABI)(abi);
|
|
108
|
+
const methods = (0, import_abi_engine.generateAllMethodSignatures)(parsed);
|
|
86
109
|
const readHooks = parsed.readFunctions.map((fn) => {
|
|
87
110
|
const meta = methods.find((m) => m.name === fn.name);
|
|
88
111
|
const paramList = meta.params.map((p) => `${p.name}: ${p.type}`).join(", ");
|
|
@@ -171,29 +194,29 @@ function registerGenerateCommand(program2) {
|
|
|
171
194
|
const ora = (await import("ora")).default;
|
|
172
195
|
const spinner = ora("Reading ABI\u2026").start();
|
|
173
196
|
try {
|
|
174
|
-
const abiPath =
|
|
175
|
-
if (!
|
|
197
|
+
const abiPath = import_node_path.default.resolve(process.cwd(), opts.abi);
|
|
198
|
+
if (!import_fs_extra.default.existsSync(abiPath)) {
|
|
176
199
|
spinner.fail(chalk.red(`ABI file not found: ${abiPath}`));
|
|
177
200
|
process.exit(1);
|
|
178
201
|
}
|
|
179
|
-
const raw = await
|
|
202
|
+
const raw = await import_fs_extra.default.readJson(abiPath);
|
|
180
203
|
const abi = Array.isArray(raw) ? raw : raw.abi;
|
|
181
204
|
if (!Array.isArray(abi)) {
|
|
182
205
|
spinner.fail(chalk.red('Invalid ABI: expected an array or an object with an "abi" field.'));
|
|
183
206
|
process.exit(1);
|
|
184
207
|
}
|
|
185
|
-
const outDir =
|
|
186
|
-
await
|
|
208
|
+
const outDir = import_node_path.default.resolve(process.cwd(), opts.out);
|
|
209
|
+
await import_fs_extra.default.ensureDir(outDir);
|
|
187
210
|
spinner.text = `Generating ${opts.name}Client\u2026`;
|
|
188
211
|
const clientCode = generateContractClient(opts.name, opts.address, abi);
|
|
189
|
-
const clientFile =
|
|
190
|
-
await
|
|
212
|
+
const clientFile = import_node_path.default.join(outDir, `${opts.name}Client.ts`);
|
|
213
|
+
await import_fs_extra.default.writeFile(clientFile, clientCode, "utf-8");
|
|
191
214
|
let hooksFile = null;
|
|
192
215
|
if (opts.react !== false) {
|
|
193
216
|
spinner.text = `Generating React hooks for ${opts.name}\u2026`;
|
|
194
217
|
const hooksCode = generateReactHooks(opts.name, opts.address, abi);
|
|
195
|
-
hooksFile =
|
|
196
|
-
await
|
|
218
|
+
hooksFile = import_node_path.default.join(outDir, `use${opts.name}.ts`);
|
|
219
|
+
await import_fs_extra.default.writeFile(hooksFile, hooksCode, "utf-8");
|
|
197
220
|
}
|
|
198
221
|
spinner.succeed(chalk.green(`Generated ${opts.name} contract client`));
|
|
199
222
|
console.log("");
|
|
@@ -213,7 +236,7 @@ function registerGenerateCommand(program2) {
|
|
|
213
236
|
}
|
|
214
237
|
|
|
215
238
|
// src/index.ts
|
|
216
|
-
var program = new Command();
|
|
239
|
+
var program = new import_commander.Command();
|
|
217
240
|
program.name("awarizon").description(
|
|
218
241
|
"Awarizon Web3 CLI \u2014 generate typed contract clients and React hooks from ABI files"
|
|
219
242
|
).version("1.0.0");
|