@axeth/create-cli 2.1.4 → 3.0.0

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.
@@ -0,0 +1,14 @@
1
+ [?9001h[?1004h[?25l$tsup ./src/index.ts
2
+ ]0;C:\WINDOWS\system32\cmd.exe[?25hCLI Building entry: src/index.ts
3
+ CLI Using tsconfig: tsconfig.json
4
+ CLI tsup v8.5.1
5
+ CLI Using tsup config: C:\Users\KisuX3\Documents\Workspace\Axeth\packages\cli\tsup.config.ts
6
+ CLI Target: es2020
7
+ CLI Cleaning output folder
8
+ ESM Build start
9
+ ESM dist\index.js 11.13 KB
10
+ ESM ⚡️ Build success in 25ms
11
+ DTS Build start
12
+ DTS ⚡️ Build success in 1080ms
13
+ DTS dist\index.d.ts 19.00 B
14
+ [?9001l[?1004l
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @axeth/create-cli
2
+
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - db08190: Change tsc to tsup
package/LISENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PUKAN223
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env bun
package/dist/index.js ADDED
@@ -0,0 +1,326 @@
1
+ #!/usr/bin/env bun
2
+
3
+ // src/class/AxethCLI.ts
4
+ import * as prompt from "@clack/prompts";
5
+ import color from "colors";
6
+
7
+ // src/class/TemplateGenerators.ts
8
+ import path from "path";
9
+ import fs from "fs-extra";
10
+ import { exec } from "child_process";
11
+ var TemplateGenerators = class {
12
+ constructor() {
13
+ this.fileList = /* @__PURE__ */ new Map();
14
+ this.dependencies = [
15
+ "@axeth/api",
16
+ "@axeth/core",
17
+ "@minecraft/server",
18
+ "@minecraft/server-ui"
19
+ ];
20
+ }
21
+ registerFile(path3, content) {
22
+ this.fileList.set(path3, content);
23
+ }
24
+ getFiles() {
25
+ return this.fileList;
26
+ }
27
+ async generate(config, spinner2) {
28
+ spinner2.start("Preparing template pack files...");
29
+ const templateData = await fs.readJson(path.join(__dirname, "../data/templates.json"));
30
+ for (const [filePath, fileContent] of Object.entries(templateData)) {
31
+ let populatedContent = fileContent;
32
+ for (const [key, value] of Object.entries(config)) {
33
+ const placeholder = `{{${key}}}`;
34
+ let replacementValue;
35
+ let isNonStringValue = false;
36
+ if (Array.isArray(value)) {
37
+ replacementValue = JSON.stringify(value);
38
+ isNonStringValue = true;
39
+ } else if (typeof value === "object" && value !== null) {
40
+ replacementValue = JSON.stringify(value);
41
+ isNonStringValue = true;
42
+ } else if (typeof value === "number") {
43
+ replacementValue = value.toString();
44
+ isNonStringValue = true;
45
+ } else {
46
+ replacementValue = String(value);
47
+ }
48
+ if (isNonStringValue) {
49
+ populatedContent = populatedContent.split(`"${placeholder}"`).join(replacementValue);
50
+ } else {
51
+ populatedContent = populatedContent.split(placeholder).join(replacementValue);
52
+ }
53
+ await new Promise((resolve) => setTimeout(resolve, 10));
54
+ }
55
+ this.registerFile(filePath, populatedContent);
56
+ }
57
+ spinner2.stop("Prepared template pack files.");
58
+ spinner2.start("Creating template pack files...");
59
+ for (const filePath of this.fileList.keys()) {
60
+ const fullPath = path.join(process.cwd(), config["project_name"], filePath);
61
+ const shortPath = filePath.split("/").slice(-5).join("/");
62
+ spinner2.message(`Creating file: ${shortPath}`);
63
+ await Bun.file(fullPath).write(this.fileList.get(filePath) || "");
64
+ await new Promise((resolve) => setTimeout(resolve, 50));
65
+ }
66
+ spinner2.stop("Template pack files generated.");
67
+ spinner2.start("Installing dependencies...");
68
+ await this.installDependencies(config["project_name"], this.dependencies);
69
+ spinner2.stop("Dependencies installed.");
70
+ }
71
+ async runCommand(command, cwd) {
72
+ return new Promise((resolve, reject) => {
73
+ const options = {};
74
+ if (cwd) {
75
+ options.cwd = cwd;
76
+ }
77
+ exec(command, options, (error, stdout, stderr) => {
78
+ if (error) {
79
+ reject(error);
80
+ return;
81
+ }
82
+ resolve();
83
+ });
84
+ });
85
+ }
86
+ async installDependencies(projectName, dependencies) {
87
+ const projectPath = path.join(process.cwd(), projectName || "");
88
+ const installCommand = `bun add ${dependencies ? dependencies.join(" ") : this.dependencies.join(" ")}`;
89
+ return await this.runCommand(installCommand, projectPath);
90
+ }
91
+ };
92
+
93
+ // src/class/AxethCLI.ts
94
+ import path2 from "path";
95
+ import { exec as exec2 } from "child_process";
96
+ var AxethCLI = class {
97
+ constructor() {
98
+ this.promptGroups = {};
99
+ this.promptDefaults = {};
100
+ this.axethAPI = `@axeth/api`;
101
+ this.axethCore = `@axeth/core`;
102
+ console.clear();
103
+ this.template = new TemplateGenerators();
104
+ this.init();
105
+ }
106
+ async version() {
107
+ const url = new URL("../../package.json", import.meta.url);
108
+ const pkgData = await Bun.file(url).json();
109
+ return pkgData.version;
110
+ }
111
+ async init() {
112
+ const version = await this.version();
113
+ const addonInfo = await this.addonInfoPrompt(version, () => {
114
+ process.exit(0);
115
+ });
116
+ const config = await this.configPrompt();
117
+ const minecraftServerVersion = await this.getMinecraftServerVersion();
118
+ const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
119
+ const spinner2 = prompt.spinner({ indicator: "dots" });
120
+ await this.generateTemplate(
121
+ addonInfo,
122
+ config,
123
+ minecraftServerVersion,
124
+ minecraftServerUIVersion,
125
+ spinner2
126
+ );
127
+ const projectDir = path2.join(
128
+ process.cwd(),
129
+ addonInfo.addonName.replace(/\s+/g, "-").toLowerCase()
130
+ );
131
+ spinner2.start("Linting generated add-on...");
132
+ await this.runCommand("bun run lint", projectDir).catch((err) => {
133
+ spinner2.stop("Linting failed.");
134
+ console.error(color.red(err));
135
+ process.exit(1);
136
+ });
137
+ spinner2.stop("Add-on linted successfully.");
138
+ const openVSCode = await prompt.confirm({
139
+ message: "Open on VSCode?",
140
+ initialValue: false
141
+ });
142
+ if (openVSCode === true) {
143
+ spinner2.start("Opening VSCode...");
144
+ await this.runCommand(`code "${projectDir}"`);
145
+ spinner2.stop("VSCode opened.");
146
+ }
147
+ prompt.outro(
148
+ color.green(`
149
+ Successfully created add-on: ${addonInfo.addonName}
150
+ `)
151
+ );
152
+ }
153
+ async generateTemplate(addonInfo, config, minecraftServerVersion, minecraftServerUIVersion, spinner2) {
154
+ await this.template.generate(
155
+ {
156
+ project_name: addonInfo.addonName.replace(/\s+/g, "-").toLowerCase(),
157
+ axethApiVersion: config.axethApiVersion,
158
+ pack_name: addonInfo.addonName,
159
+ pack_description: addonInfo.description,
160
+ author_name: addonInfo.authors.split(",").map((name) => name.trim()),
161
+ version: addonInfo.version.split(".").map((num) => parseInt(num, 10)),
162
+ seed: Math.floor(Math.random() * 1e6),
163
+ axethApiName: this.axethAPI,
164
+ axethCoreName: this.axethCore,
165
+ axethCoreVersion: config.axethCoreVersion,
166
+ minecraftServerUIVersion,
167
+ minecraftServerVersion
168
+ },
169
+ spinner2
170
+ );
171
+ }
172
+ async addonInfoPrompt(version, onCancel) {
173
+ return await new Promise((resolve) => {
174
+ this.registerIntro(
175
+ "\n _ _ \n /_\\ __ _____| |_ \n / _ \\ \\ \\ / -_) _|\n /_/ \\_\\/\\_\\_\\___|\\__|\n ",
176
+ "Axeth CLI",
177
+ version
178
+ );
179
+ this.registerPrompt("addonInfo", "addonName", "Add-on Name", "text", {
180
+ placeholder: "My-Addon"
181
+ });
182
+ this.registerPrompt("addonInfo", "description", "Description", "text", {
183
+ placeholder: "This addon create for Minecraft Bedrock (Axeth)"
184
+ });
185
+ this.registerPrompt("addonInfo", "version", "Version", "text", {
186
+ placeholder: "1.0.0"
187
+ });
188
+ this.registerPrompt("addonInfo", "authors", "Authors", "text", {
189
+ placeholder: "YourName,Axeth"
190
+ });
191
+ this.runPrompts("addonInfo", onCancel).then((responses) => {
192
+ resolve(responses);
193
+ });
194
+ });
195
+ }
196
+ async configPrompt() {
197
+ return new Promise(async (resolve) => {
198
+ const spinner2 = prompt.spinner({ indicator: "dots" });
199
+ spinner2.start("Fetching latest Axeth API version...");
200
+ const versions = await this.getAxethApiVersion();
201
+ spinner2.stop(`Fetched @axeth/api ${versions.length} versions.`);
202
+ this.registerPrompt(
203
+ "config",
204
+ "axethApiVersion",
205
+ "Select Axeth API version",
206
+ "select",
207
+ {
208
+ options: versions.slice(0, 10).map((ver) => ({ label: ver, value: ver })),
209
+ initial: versions[0]
210
+ }
211
+ );
212
+ const axethCoreVersion = await this.getAxethCoreVersion();
213
+ await this.runPrompts("config", () => {
214
+ process.exit(0);
215
+ }).then((response) => {
216
+ resolve({
217
+ axethApiVersion: response.axethApiVersion,
218
+ axethCoreVersion
219
+ });
220
+ });
221
+ });
222
+ }
223
+ async getMinecraftServerVersion() {
224
+ const moduleData = await fetch(
225
+ `https://registry.npmjs.org/@minecraft/server`
226
+ ).then((res) => res.json());
227
+ const distTag = moduleData["dist-tags"];
228
+ return distTag.latest;
229
+ }
230
+ async getMinecraftServerUIVersion() {
231
+ const moduleData = await fetch(
232
+ `https://registry.npmjs.org/@minecraft/server-ui`
233
+ ).then((res) => res.json());
234
+ const distTag = moduleData["dist-tags"];
235
+ return distTag.latest;
236
+ }
237
+ registerPrompt(groupId, key, message, type = "text", options = {}) {
238
+ if (!this.promptGroups[groupId]) this.promptGroups[groupId] = {};
239
+ this.promptDefaults[groupId] = this.promptDefaults[groupId] || {};
240
+ switch (type) {
241
+ case "text":
242
+ this.promptGroups[groupId][key] = () => prompt.text({ message, ...options });
243
+ this.promptDefaults[groupId][key] = options.placeholder || void 0;
244
+ break;
245
+ case "password":
246
+ this.promptGroups[groupId][key] = () => prompt.password({ message, ...options });
247
+ this.promptDefaults[groupId][key] = options.placeholder || void 0;
248
+ break;
249
+ case "confirm":
250
+ this.promptGroups[groupId][key] = () => prompt.confirm({ message, ...options });
251
+ this.promptDefaults[groupId][key] = options.initial || void 0;
252
+ break;
253
+ case "select":
254
+ this.promptGroups[groupId][key] = () => prompt.select({ message, ...options });
255
+ this.promptDefaults[groupId][key] = options.initial || void 0;
256
+ break;
257
+ case "multiselect":
258
+ this.promptGroups[groupId][key] = () => prompt.multiselect({ message, ...options });
259
+ this.promptDefaults[groupId][key] = options.initial || void 0;
260
+ break;
261
+ default:
262
+ throw new Error(`Unknown prompt type: ${type}`);
263
+ }
264
+ }
265
+ async getAxethCoreVersion() {
266
+ const moduleData = await fetch(
267
+ `https://registry.npmjs.org/${this.axethCore}`
268
+ ).then((res) => res.json());
269
+ const versions = Object.keys(moduleData.versions);
270
+ return versions.reverse()[0];
271
+ }
272
+ async getAxethApiVersion() {
273
+ const moduleData = await fetch(
274
+ `https://registry.npmjs.org/${this.axethAPI}`
275
+ ).then((res) => res.json());
276
+ const versions = Object.keys(moduleData.versions);
277
+ return versions.reverse();
278
+ }
279
+ async runPrompts(groupId, onCancel) {
280
+ if (!this.promptGroups[groupId] || Object.keys(this.promptGroups[groupId]).length === 0) {
281
+ throw new Error(`No prompts to run for group: ${groupId}`);
282
+ }
283
+ const responses = {};
284
+ for (const key of Object.keys(this.promptGroups[groupId])) {
285
+ const response = await this.promptGroups[groupId][key]();
286
+ if (String(response).includes("clack:cancel")) {
287
+ prompt.cancel("Operation cancelled.");
288
+ if (onCancel) onCancel();
289
+ return {};
290
+ }
291
+ if (response === void 0) {
292
+ if (this.promptDefaults[groupId] && this.promptDefaults[groupId][key] !== void 0) {
293
+ responses[key] = this.promptDefaults[groupId][key];
294
+ } else {
295
+ responses[key] = void 0;
296
+ }
297
+ } else {
298
+ responses[key] = response;
299
+ }
300
+ }
301
+ return responses;
302
+ }
303
+ registerIntro(logo, title, version) {
304
+ prompt.intro(color.cyan(logo) + `
305
+ ${title} - v${version}
306
+ `);
307
+ }
308
+ async runCommand(command, cwd) {
309
+ return new Promise((resolve, reject) => {
310
+ const options = {};
311
+ if (cwd) {
312
+ options.cwd = cwd;
313
+ }
314
+ exec2(command, options, (error, stdout, stderr) => {
315
+ if (error) {
316
+ reject(error);
317
+ return;
318
+ }
319
+ resolve();
320
+ });
321
+ });
322
+ }
323
+ };
324
+
325
+ // src/index.ts
326
+ new AxethCLI();
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@axeth/create-cli",
3
- "version": "2.1.4",
4
- "module": "index.ts",
5
- "files": ["dist"],
3
+ "version": "3.0.0",
4
+ "module": "dist/index.js",
6
5
  "type": "module",
7
6
  "bin": {
8
7
  "axeth-cli": "index.ts"
@@ -10,8 +9,14 @@
10
9
  "publishConfig": {
11
10
  "access": "public"
12
11
  },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
13
18
  "scripts": {
14
- "build": "tsc",
19
+ "build": "tsup ./src/index.ts",
15
20
  "prepublishOnly": "bun run build"
16
21
  },
17
22
  "keywords": [
@@ -0,0 +1,290 @@
1
+ import * as prompt from "@clack/prompts";
2
+ import color from "colors";
3
+ import { TemplateGenerators } from "./TemplateGenerators";
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import { exec, spawn } from "child_process";
7
+
8
+ class AxethCLI {
9
+ private promptGroups: Record<string, Record<string, (opts?: any) => any>> =
10
+ {};
11
+ private promptDefaults: Record<string, Record<string, any>> = {};
12
+ private template: TemplateGenerators;
13
+
14
+ private readonly axethAPI = `@axeth/api`;
15
+ private readonly axethCore = `@axeth/core`;
16
+
17
+ constructor() {
18
+ console.clear();
19
+ this.template = new TemplateGenerators();
20
+ this.init();
21
+ }
22
+
23
+ private async version() {
24
+ const url = new URL("../../package.json", import.meta.url);
25
+ const pkgData = await Bun.file(url).json();
26
+ return pkgData.version;
27
+ }
28
+
29
+ private async init() {
30
+ const version = await this.version();
31
+ const addonInfo = await this.addonInfoPrompt(version, () => {
32
+ process.exit(0);
33
+ });
34
+ const config = await this.configPrompt();
35
+ const minecraftServerVersion = await this.getMinecraftServerVersion();
36
+ const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
37
+ const spinner = prompt.spinner({ indicator: "dots" });
38
+
39
+ await this.generateTemplate(
40
+ addonInfo,
41
+ config,
42
+ minecraftServerVersion,
43
+ minecraftServerUIVersion,
44
+ spinner,
45
+ );
46
+
47
+ const projectDir = path.join(
48
+ process.cwd(),
49
+ (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
50
+ );
51
+
52
+ //cd and bun run lint
53
+ spinner.start("Linting generated add-on...");
54
+ await this.runCommand("bun run lint", projectDir).catch((err) => {
55
+ spinner.stop("Linting failed.");
56
+ console.error(color.red(err));
57
+ process.exit(1);
58
+ });
59
+ spinner.stop("Add-on linted successfully.");
60
+ const openVSCode = await prompt.confirm({
61
+ message: "Open on VSCode?",
62
+ initialValue: false,
63
+ });
64
+
65
+ if (openVSCode === true) {
66
+ spinner.start("Opening VSCode...");
67
+ await this.runCommand(`code "${projectDir}"`);
68
+ spinner.stop("VSCode opened.");
69
+ }
70
+ prompt.outro(
71
+ color.green(`\n Successfully created add-on: ${addonInfo.addonName}\n`),
72
+ );
73
+ }
74
+
75
+ private async generateTemplate(
76
+ addonInfo: { [x: string]: any },
77
+ config: { [x: string]: any },
78
+ minecraftServerVersion: string,
79
+ minecraftServerUIVersion: string,
80
+ spinner: any,
81
+ ) {
82
+ await this.template.generate(
83
+ {
84
+ project_name: (addonInfo.addonName as string)
85
+ .replace(/\s+/g, "-")
86
+ .toLowerCase(),
87
+ axethApiVersion: config.axethApiVersion,
88
+ pack_name: addonInfo.addonName,
89
+ pack_description: addonInfo.description,
90
+ author_name: (addonInfo.authors as string)
91
+ .split(",")
92
+ .map((name: string) => name.trim()),
93
+ version: addonInfo.version
94
+ .split(".")
95
+ .map((num: string) => parseInt(num, 10)),
96
+ seed: Math.floor(Math.random() * 1000000),
97
+ axethApiName: this.axethAPI,
98
+ axethCoreName: this.axethCore,
99
+ axethCoreVersion: config.axethCoreVersion,
100
+ minecraftServerUIVersion: minecraftServerUIVersion,
101
+ minecraftServerVersion: minecraftServerVersion,
102
+ },
103
+ spinner,
104
+ );
105
+ }
106
+
107
+ private async addonInfoPrompt(version: string, onCancel?: () => void) {
108
+ return await new Promise<{ [x: string]: any }>((resolve) => {
109
+ this.registerIntro(
110
+ "\n _ _ \n /_\\ __ _____| |_ \n / _ \\ \\ \\ / -_) _|\n /_/ \\_\\/\\_\\_\\___|\\__|\n ",
111
+ "Axeth CLI",
112
+ version,
113
+ );
114
+ this.registerPrompt("addonInfo", "addonName", "Add-on Name", "text", {
115
+ placeholder: "My-Addon",
116
+ });
117
+ this.registerPrompt("addonInfo", "description", "Description", "text", {
118
+ placeholder: "This addon create for Minecraft Bedrock (Axeth)",
119
+ });
120
+ this.registerPrompt("addonInfo", "version", "Version", "text", {
121
+ placeholder: "1.0.0",
122
+ });
123
+ this.registerPrompt("addonInfo", "authors", "Authors", "text", {
124
+ placeholder: "YourName,Axeth",
125
+ });
126
+ this.runPrompts("addonInfo", onCancel).then((responses) => {
127
+ resolve(responses);
128
+ });
129
+ });
130
+ }
131
+
132
+ private async configPrompt() {
133
+ return new Promise<{ [x: string]: any }>(async (resolve) => {
134
+ const spinner = prompt.spinner({ indicator: "dots" });
135
+ spinner.start("Fetching latest Axeth API version...");
136
+ const versions = await this.getAxethApiVersion();
137
+ spinner.stop(`Fetched @axeth/api ${versions.length} versions.`);
138
+ this.registerPrompt(
139
+ "config",
140
+ "axethApiVersion",
141
+ "Select Axeth API version",
142
+ "select",
143
+ {
144
+ options: versions
145
+ .slice(0, 10)
146
+ .map((ver) => ({ label: ver, value: ver })),
147
+ initial: versions[0],
148
+ },
149
+ );
150
+ const axethCoreVersion = await this.getAxethCoreVersion();
151
+ await this.runPrompts("config", () => {
152
+ process.exit(0);
153
+ }).then((response) => {
154
+ resolve({
155
+ axethApiVersion: response.axethApiVersion,
156
+ axethCoreVersion: axethCoreVersion,
157
+ });
158
+ });
159
+ });
160
+ }
161
+
162
+ private async getMinecraftServerVersion() {
163
+ const moduleData: any = await fetch(
164
+ `https://registry.npmjs.org/@minecraft/server`,
165
+ ).then((res) => res.json());
166
+
167
+ const distTag = moduleData["dist-tags"];
168
+ return distTag.latest;
169
+ }
170
+
171
+ private async getMinecraftServerUIVersion() {
172
+ const moduleData: any = await fetch(
173
+ `https://registry.npmjs.org/@minecraft/server-ui`,
174
+ ).then((res) => res.json());
175
+ const distTag = moduleData["dist-tags"];
176
+ return distTag.latest;
177
+ }
178
+
179
+ private registerPrompt(
180
+ groupId: string,
181
+ key: string,
182
+ message: string,
183
+ type: "text" | "password" | "confirm" | "select" | "multiselect" = "text",
184
+ options: any = {},
185
+ ) {
186
+ if (!this.promptGroups[groupId]) this.promptGroups[groupId] = {};
187
+ this.promptDefaults[groupId] = this.promptDefaults[groupId] || {};
188
+ switch (type) {
189
+ case "text":
190
+ this.promptGroups[groupId][key] = () =>
191
+ prompt.text({ message, ...options });
192
+ this.promptDefaults[groupId][key] = options.placeholder || undefined;
193
+ break;
194
+ case "password":
195
+ this.promptGroups[groupId][key] = () =>
196
+ prompt.password({ message, ...options });
197
+ this.promptDefaults[groupId][key] = options.placeholder || undefined;
198
+ break;
199
+ case "confirm":
200
+ this.promptGroups[groupId][key] = () =>
201
+ prompt.confirm({ message, ...options });
202
+ this.promptDefaults[groupId][key] = options.initial || undefined;
203
+ break;
204
+ case "select":
205
+ this.promptGroups[groupId][key] = () =>
206
+ prompt.select({ message, ...options });
207
+ this.promptDefaults[groupId][key] = options.initial || undefined;
208
+ break;
209
+ case "multiselect":
210
+ this.promptGroups[groupId][key] = () =>
211
+ prompt.multiselect({ message, ...options });
212
+ this.promptDefaults[groupId][key] = options.initial || undefined;
213
+ break;
214
+ default:
215
+ throw new Error(`Unknown prompt type: ${type}`);
216
+ }
217
+ }
218
+
219
+ private async getAxethCoreVersion() {
220
+ const moduleData: any = await fetch(
221
+ `https://registry.npmjs.org/${this.axethCore}`,
222
+ ).then((res) => res.json());
223
+
224
+ const versions = Object.keys(moduleData.versions);
225
+ return versions.reverse()[0];
226
+ }
227
+
228
+ private async getAxethApiVersion() {
229
+ const moduleData: any = await fetch(
230
+ `https://registry.npmjs.org/${this.axethAPI}`,
231
+ ).then((res) => res.json());
232
+
233
+ const versions = Object.keys(moduleData.versions);
234
+ return versions.reverse();
235
+ }
236
+
237
+ async runPrompts(groupId: string, onCancel?: () => void) {
238
+ if (
239
+ !this.promptGroups[groupId] ||
240
+ Object.keys(this.promptGroups[groupId]).length === 0
241
+ ) {
242
+ throw new Error(`No prompts to run for group: ${groupId}`);
243
+ }
244
+
245
+ const responses: { [x: string]: any } = {};
246
+ for (const key of Object.keys(this.promptGroups[groupId])) {
247
+ const response = await this.promptGroups[groupId][key]!();
248
+ if (String(response).includes("clack:cancel")) {
249
+ prompt.cancel("Operation cancelled.");
250
+ if (onCancel) onCancel();
251
+ return {};
252
+ }
253
+ if (response === undefined) {
254
+ if (
255
+ this.promptDefaults[groupId] &&
256
+ this.promptDefaults[groupId][key] !== undefined
257
+ ) {
258
+ responses[key] = this.promptDefaults[groupId][key];
259
+ } else {
260
+ responses[key] = undefined;
261
+ }
262
+ } else {
263
+ responses[key] = response;
264
+ }
265
+ }
266
+ return responses;
267
+ }
268
+
269
+ private registerIntro(logo: string, title: string, version: string) {
270
+ prompt.intro(color.cyan(logo) + `\n ${title} - v${version}\n`);
271
+ }
272
+
273
+ private async runCommand(command: string, cwd?: string): Promise<void> {
274
+ return new Promise((resolve, reject) => {
275
+ const options: any = {};
276
+ if (cwd) {
277
+ options.cwd = cwd;
278
+ }
279
+ exec(command, options, (error, stdout, stderr) => {
280
+ if (error) {
281
+ reject(error);
282
+ return;
283
+ }
284
+ resolve();
285
+ });
286
+ });
287
+ }
288
+ }
289
+
290
+ export { AxethCLI };