@axeth/create-cli 3.0.1 → 3.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/CHANGELOG.md +6 -0
- package/dist/index.js +93 -63
- package/package.json +1 -1
- package/src/class/AxethCLI.ts +93 -63
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -91,6 +91,7 @@ var TemplateGenerators = class {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
// src/class/AxethCLI.ts
|
|
94
|
+
import fs2 from "fs-extra";
|
|
94
95
|
import path2 from "path";
|
|
95
96
|
import { exec as exec2 } from "child_process";
|
|
96
97
|
var AxethCLI = class {
|
|
@@ -101,54 +102,74 @@ var AxethCLI = class {
|
|
|
101
102
|
this.axethCore = `@axeth/core`;
|
|
102
103
|
console.clear();
|
|
103
104
|
this.template = new TemplateGenerators();
|
|
104
|
-
|
|
105
|
+
console.log("Initializing Axeth CLI...");
|
|
106
|
+
this.init().catch((err) => {
|
|
107
|
+
console.error("Fatal error:", err);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
});
|
|
105
110
|
}
|
|
106
111
|
async version() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
try {
|
|
113
|
+
const pkgPath = path2.join(__dirname, "../../../package.json");
|
|
114
|
+
const pkgData = JSON.parse(await fs2.readFile(pkgPath, "utf-8"));
|
|
115
|
+
return pkgData.version;
|
|
116
|
+
} catch (err) {
|
|
117
|
+
try {
|
|
118
|
+
const cliPkgPath = path2.join(__dirname, "../../package.json");
|
|
119
|
+
const cliPkgData = JSON.parse(await fs2.readFile(cliPkgPath, "utf-8"));
|
|
120
|
+
return cliPkgData.version;
|
|
121
|
+
} catch {
|
|
122
|
+
return "3.0.0";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
110
125
|
}
|
|
111
126
|
async init() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
127
|
+
try {
|
|
128
|
+
const version = await this.version();
|
|
129
|
+
const addonInfo = await this.addonInfoPrompt(version, () => {
|
|
130
|
+
process.exit(0);
|
|
131
|
+
});
|
|
132
|
+
const config = await this.configPrompt();
|
|
133
|
+
const minecraftServerVersion = await this.getMinecraftServerVersion();
|
|
134
|
+
const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
|
|
135
|
+
const spinner2 = prompt.spinner({ indicator: "dots" });
|
|
136
|
+
await this.generateTemplate(
|
|
137
|
+
addonInfo,
|
|
138
|
+
config,
|
|
139
|
+
minecraftServerVersion,
|
|
140
|
+
minecraftServerUIVersion,
|
|
141
|
+
spinner2
|
|
142
|
+
);
|
|
143
|
+
const projectDir = path2.join(
|
|
144
|
+
process.cwd(),
|
|
145
|
+
addonInfo.addonName.replace(/\s+/g, "-").toLowerCase()
|
|
146
|
+
);
|
|
147
|
+
spinner2.start("Linting generated add-on...");
|
|
148
|
+
await this.runCommand("bun run lint", projectDir).catch((err) => {
|
|
149
|
+
spinner2.stop("Linting failed.");
|
|
150
|
+
console.error(color.red(err));
|
|
151
|
+
process.exit(1);
|
|
152
|
+
});
|
|
153
|
+
spinner2.stop("Add-on linted successfully.");
|
|
154
|
+
const openVSCode = await prompt.confirm({
|
|
155
|
+
message: "Open on VSCode?",
|
|
156
|
+
initialValue: false
|
|
157
|
+
});
|
|
158
|
+
if (openVSCode === true) {
|
|
159
|
+
spinner2.start("Opening VSCode...");
|
|
160
|
+
await this.runCommand(`code "${projectDir}"`);
|
|
161
|
+
spinner2.stop("VSCode opened.");
|
|
162
|
+
}
|
|
163
|
+
prompt.outro(
|
|
164
|
+
color.green(`
|
|
149
165
|
Successfully created add-on: ${addonInfo.addonName}
|
|
150
166
|
`)
|
|
151
|
-
|
|
167
|
+
);
|
|
168
|
+
process.exit(0);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
console.error("Error in init:", err);
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
152
173
|
}
|
|
153
174
|
async generateTemplate(addonInfo, config, minecraftServerVersion, minecraftServerUIVersion, spinner2) {
|
|
154
175
|
await this.template.generate(
|
|
@@ -170,27 +191,36 @@ var AxethCLI = class {
|
|
|
170
191
|
);
|
|
171
192
|
}
|
|
172
193
|
async addonInfoPrompt(version, onCancel) {
|
|
173
|
-
return await new Promise((resolve) => {
|
|
174
|
-
|
|
175
|
-
"
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
return await new Promise((resolve, reject) => {
|
|
195
|
+
try {
|
|
196
|
+
console.log("Starting addon info prompt...");
|
|
197
|
+
this.registerIntro(
|
|
198
|
+
"\n _ _ \n /_\\ __ _____| |_ \n / _ \\ \\ \\ / -_) _|\n /_/ \\_\\/\\_\\_\\___|\\__|\n ",
|
|
199
|
+
"Axeth CLI",
|
|
200
|
+
version
|
|
201
|
+
);
|
|
202
|
+
this.registerPrompt("addonInfo", "addonName", "Add-on Name", "text", {
|
|
203
|
+
placeholder: "My-Addon"
|
|
204
|
+
});
|
|
205
|
+
this.registerPrompt("addonInfo", "description", "Description", "text", {
|
|
206
|
+
placeholder: "This addon create for Minecraft Bedrock (Axeth)"
|
|
207
|
+
});
|
|
208
|
+
this.registerPrompt("addonInfo", "version", "Version", "text", {
|
|
209
|
+
placeholder: "1.0.0"
|
|
210
|
+
});
|
|
211
|
+
this.registerPrompt("addonInfo", "authors", "Authors", "text", {
|
|
212
|
+
placeholder: "YourName,Axeth"
|
|
213
|
+
});
|
|
214
|
+
this.runPrompts("addonInfo", onCancel).then((responses) => {
|
|
215
|
+
resolve(responses);
|
|
216
|
+
}).catch((err) => {
|
|
217
|
+
console.error("Error in runPrompts:", err);
|
|
218
|
+
reject(err);
|
|
219
|
+
});
|
|
220
|
+
} catch (err) {
|
|
221
|
+
console.error("Error in addonInfoPrompt:", err);
|
|
222
|
+
reject(err);
|
|
223
|
+
}
|
|
194
224
|
});
|
|
195
225
|
}
|
|
196
226
|
async configPrompt() {
|
package/package.json
CHANGED
package/src/class/AxethCLI.ts
CHANGED
|
@@ -17,59 +17,80 @@ class AxethCLI {
|
|
|
17
17
|
constructor() {
|
|
18
18
|
console.clear();
|
|
19
19
|
this.template = new TemplateGenerators();
|
|
20
|
-
|
|
20
|
+
console.log("Initializing Axeth CLI...");
|
|
21
|
+
this.init().catch((err) => {
|
|
22
|
+
console.error("Fatal error:", err);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
private async version() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
try {
|
|
29
|
+
const pkgPath = path.join(__dirname, "../../../package.json");
|
|
30
|
+
const pkgData = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
|
|
31
|
+
return pkgData.version;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
// Fallback to reading from cli package.json
|
|
34
|
+
try {
|
|
35
|
+
const cliPkgPath = path.join(__dirname, "../../package.json");
|
|
36
|
+
const cliPkgData = JSON.parse(await fs.readFile(cliPkgPath, "utf-8"));
|
|
37
|
+
return cliPkgData.version;
|
|
38
|
+
} catch {
|
|
39
|
+
return "3.0.0";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
private async init() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
try {
|
|
46
|
+
const version = await this.version();
|
|
47
|
+
const addonInfo = await this.addonInfoPrompt(version, () => {
|
|
48
|
+
process.exit(0);
|
|
49
|
+
});
|
|
50
|
+
const config = await this.configPrompt();
|
|
51
|
+
const minecraftServerVersion = await this.getMinecraftServerVersion();
|
|
52
|
+
const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
|
|
53
|
+
const spinner = prompt.spinner({ indicator: "dots" });
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
await this.generateTemplate(
|
|
56
|
+
addonInfo,
|
|
57
|
+
config,
|
|
58
|
+
minecraftServerVersion,
|
|
59
|
+
minecraftServerUIVersion,
|
|
60
|
+
spinner,
|
|
61
|
+
);
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
const projectDir = path.join(
|
|
64
|
+
process.cwd(),
|
|
65
|
+
(addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
|
|
66
|
+
);
|
|
51
67
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
//cd and bun run lint
|
|
69
|
+
spinner.start("Linting generated add-on...");
|
|
70
|
+
await this.runCommand("bun run lint", projectDir).catch((err) => {
|
|
71
|
+
spinner.stop("Linting failed.");
|
|
72
|
+
console.error(color.red(err));
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
|
75
|
+
spinner.stop("Add-on linted successfully.");
|
|
76
|
+
const openVSCode = await prompt.confirm({
|
|
77
|
+
message: "Open on VSCode?",
|
|
78
|
+
initialValue: false,
|
|
79
|
+
});
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
if (openVSCode === true) {
|
|
82
|
+
spinner.start("Opening VSCode...");
|
|
83
|
+
await this.runCommand(`code "${projectDir}"`);
|
|
84
|
+
spinner.stop("VSCode opened.");
|
|
85
|
+
}
|
|
86
|
+
prompt.outro(
|
|
87
|
+
color.green(`\n Successfully created add-on: ${addonInfo.addonName}\n`),
|
|
88
|
+
);
|
|
89
|
+
process.exit(0);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error("Error in init:", err);
|
|
92
|
+
throw err;
|
|
69
93
|
}
|
|
70
|
-
prompt.outro(
|
|
71
|
-
color.green(`\n Successfully created add-on: ${addonInfo.addonName}\n`),
|
|
72
|
-
);
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
private async generateTemplate(
|
|
@@ -105,27 +126,36 @@ class AxethCLI {
|
|
|
105
126
|
}
|
|
106
127
|
|
|
107
128
|
private async addonInfoPrompt(version: string, onCancel?: () => void) {
|
|
108
|
-
return await new Promise<{ [x: string]: any }>((resolve) => {
|
|
109
|
-
|
|
110
|
-
"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
return await new Promise<{ [x: string]: any }>((resolve, reject) => {
|
|
130
|
+
try {
|
|
131
|
+
console.log("Starting addon info prompt...");
|
|
132
|
+
this.registerIntro(
|
|
133
|
+
"\n _ _ \n /_\\ __ _____| |_ \n / _ \\ \\ \\ / -_) _|\n /_/ \\_\\/\\_\\_\\___|\\__|\n ",
|
|
134
|
+
"Axeth CLI",
|
|
135
|
+
version,
|
|
136
|
+
);
|
|
137
|
+
this.registerPrompt("addonInfo", "addonName", "Add-on Name", "text", {
|
|
138
|
+
placeholder: "My-Addon",
|
|
139
|
+
});
|
|
140
|
+
this.registerPrompt("addonInfo", "description", "Description", "text", {
|
|
141
|
+
placeholder: "This addon create for Minecraft Bedrock (Axeth)",
|
|
142
|
+
});
|
|
143
|
+
this.registerPrompt("addonInfo", "version", "Version", "text", {
|
|
144
|
+
placeholder: "1.0.0",
|
|
145
|
+
});
|
|
146
|
+
this.registerPrompt("addonInfo", "authors", "Authors", "text", {
|
|
147
|
+
placeholder: "YourName,Axeth",
|
|
148
|
+
});
|
|
149
|
+
this.runPrompts("addonInfo", onCancel).then((responses) => {
|
|
150
|
+
resolve(responses);
|
|
151
|
+
}).catch((err) => {
|
|
152
|
+
console.error("Error in runPrompts:", err);
|
|
153
|
+
reject(err);
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error("Error in addonInfoPrompt:", err);
|
|
157
|
+
reject(err);
|
|
158
|
+
}
|
|
129
159
|
});
|
|
130
160
|
}
|
|
131
161
|
|