@axeth/create-cli 2.1.5 → 3.0.1
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/.turbo/turbo-build.log +14 -2
- package/CHANGELOG.md +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +326 -0
- package/package.json +10 -4
- package/src/class/AxethCLI.ts +290 -224
- package/src/index.ts +5 -0
- package/tsconfig.json +3 -15
- package/tsup.config.ts +6 -0
- package/index.ts +0 -5
- package/src/class/AxethCLI.d.ts +0 -25
- package/src/class/AxethCLI.d.ts.map +0 -1
- package/src/class/AxethCLI.js +0 -199
- package/src/class/AxethCLI.js.map +0 -1
- package/src/class/TemplateGenerators.d.ts +0 -14
- package/src/class/TemplateGenerators.d.ts.map +0 -1
- package/src/class/TemplateGenerators.js +0 -95
- package/src/class/TemplateGenerators.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
[?9001h[?1004h[?25l[2J[m[35m[2m[H$[m[1m[2m[
|
|
2
|
-
]0;C:\WINDOWS\system32\cmd.exe[?25h[22m[
|
|
1
|
+
[?9001h[?1004h[?25l[2J[m[35m[2m[H$[m[1m[2m[1Ctsup ./src/index.ts
|
|
2
|
+
]0;C:\WINDOWS\system32\cmd.exe[?25h[22m[34mCLI [mBuilding entry: src/index.ts
|
|
3
|
+
[34mCLI [mUsing tsconfig: tsconfig.json[34m
|
|
4
|
+
CLI [mtsup v8.5.1[34m
|
|
5
|
+
CLI [mUsing tsup config: C:\Users\KisuX3\Documents\Workspace\Axeth\packages\cli\tsup.config.ts[34m
|
|
6
|
+
CLI [mTarget: es2020[34m
|
|
7
|
+
CLI [mCleaning output folder[34m
|
|
8
|
+
ESM [mBuild start
|
|
9
|
+
[32mESM [m[1mdist\index.js [32m[22m11.13 KB
|
|
10
|
+
[m[32mESM [m⚡️ Build success in 25ms
|
|
11
|
+
[34mDTS [mBuild start
|
|
12
|
+
[32mDTS [m⚡️ Build success in 1080ms
|
|
13
|
+
[32mDTS [m[1mdist\index.d.ts [32m[22m19.00 B
|
|
14
|
+
[?9001l[?1004l
|
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -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,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axeth/create-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"module": "index.
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"module": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"axeth-cli": "index.
|
|
7
|
+
"axeth-cli": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
12
18
|
"scripts": {
|
|
13
|
-
"build": "
|
|
19
|
+
"build": "tsup ./src/index.ts",
|
|
14
20
|
"prepublishOnly": "bun run build"
|
|
15
21
|
},
|
|
16
22
|
"keywords": [
|