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