@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 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
- const url = new URL("../../package.json", import.meta.url);
108
- const pkgData = await Bun.file(url).json();
109
- return pkgData.version;
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
- 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(`
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
- 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
- });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axeth/create-cli",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "module": "dist/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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, spawn } from "child_process";
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
- const url = new URL("../../package.json", import.meta.url);
25
- const pkgData = await Bun.file(url).json();
26
- return pkgData.version;
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
- 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
+ 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
- await this.generateTemplate(
40
- addonInfo,
41
- config,
42
- minecraftServerVersion,
43
- minecraftServerUIVersion,
44
- spinner,
45
- );
48
+ await this.generateTemplate(
49
+ addonInfo,
50
+ config,
51
+ minecraftServerVersion,
52
+ minecraftServerUIVersion,
53
+ spinner,
54
+ );
46
55
 
47
- const projectDir = path.join(
48
- process.cwd(),
49
- (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
50
- );
56
+ const projectDir = path.join(
57
+ process.cwd(),
58
+ (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
59
+ );
51
60
 
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
- });
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
- if (openVSCode === true) {
66
- spinner.start("Opening VSCode...");
67
- await this.runCommand(`code "${projectDir}"`);
68
- spinner.stop("VSCode opened.");
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
- 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
- });
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