@axeth/create-cli 2.0.9 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axeth/create-cli",
3
- "version": "2.0.9",
3
+ "version": "2.1.1",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -36,9 +36,12 @@ class AxethCLI {
36
36
  const spinner = prompt.spinner({ indicator: "dots" });
37
37
 
38
38
  await this.generateTemplate(addonInfo, config, minecraftServerVersion, minecraftServerUIVersion, spinner);
39
+
40
+ const projectDir = path.join(process.cwd(), (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase());
41
+
39
42
  //cd and bun run lint
40
43
  spinner.start("Linting generated add-on...");
41
- await this.runCommand(`cd ./${(addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase()} ; bun run lint`).catch((err) => {
44
+ await this.runCommand("bun run lint", projectDir).catch((err) => {
42
45
  spinner.stop("Linting failed.");
43
46
  console.error(color.red(err));
44
47
  process.exit(1);
@@ -51,7 +54,7 @@ class AxethCLI {
51
54
 
52
55
  if (openVSCode) {
53
56
  spinner.start("Opening VSCode...");
54
- await this.runCommand(`code ${path.join(process.cwd(), (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase())}`);
57
+ await this.runCommand(`code "${projectDir}"`);
55
58
  spinner.stop("VSCode opened.");
56
59
  }
57
60
  prompt.outro(color.green(`\n Successfully created add-on: ${addonInfo.addonName}\n`));
@@ -63,9 +66,9 @@ class AxethCLI {
63
66
  "axethApiVersion": config.axethApiVersion,
64
67
  "pack_name": addonInfo.addonName,
65
68
  "pack_description": addonInfo.description,
66
- "author_name": `[${(addonInfo.authors as string).split(",").map((name: string) => `"${name.trim()}"`)}]`,
67
- "version": `[${addonInfo.version.split(".").map((num: string) => `${parseInt(num, 10)}`)}]`,
68
- "seed": `${Math.floor(Math.random() * 1000000)}`,
69
+ "author_name": (addonInfo.authors as string).split(",").map((name: string) => name.trim()),
70
+ "version": addonInfo.version.split(".").map((num: string) => parseInt(num, 10)),
71
+ "seed": Math.floor(Math.random() * 1000000),
69
72
  "axethApiName": this.axethAPI,
70
73
  "axethCoreName": this.axethCore,
71
74
  "axethCoreVersion": config.axethCoreVersion,
@@ -201,9 +204,13 @@ class AxethCLI {
201
204
  prompt.intro(color.cyan(logo) + `\n ${title} - v${version}\n`);
202
205
  }
203
206
 
204
- private async runCommand(command: string): Promise<void> {
207
+ private async runCommand(command: string, cwd?: string): Promise<void> {
205
208
  return new Promise((resolve, reject) => {
206
- exec(command, (error, stdout, stderr) => {
209
+ const options: any = {};
210
+ if (cwd) {
211
+ options.cwd = cwd;
212
+ }
213
+ exec(command, options, (error, stdout, stderr) => {
207
214
  if (error) {
208
215
  reject(error);
209
216
  return;
@@ -29,10 +29,21 @@ class TemplateGenerators {
29
29
  let populatedContent = fileContent;
30
30
  for (const [key, value] of Object.entries(config)) {
31
31
  const placeholder = `{{${key}}}`;
32
- populatedContent = populatedContent.split(placeholder).join(value);
33
- this.registerFile(filePath, populatedContent);
32
+ let replacementValue: string;
33
+
34
+ // Determine the proper string representation based on type
35
+ if (Array.isArray(value)) {
36
+ replacementValue = JSON.stringify(value);
37
+ } else if (typeof value === "number") {
38
+ replacementValue = value.toString();
39
+ } else {
40
+ replacementValue = String(value);
41
+ }
42
+
43
+ populatedContent = populatedContent.split(placeholder).join(replacementValue);
34
44
  await new Promise((resolve) => setTimeout(resolve, 10)); // Slight delay to ensure responsiveness
35
45
  }
46
+ this.registerFile(filePath, populatedContent);
36
47
  }
37
48
  spinner.stop("Prepared template pack files.");
38
49
  spinner.start("Creating template pack files...");
@@ -53,9 +64,13 @@ class TemplateGenerators {
53
64
  spinner.stop("Dependencies installed.");
54
65
  }
55
66
 
56
- private async runCommand(command: string): Promise<void> {
67
+ private async runCommand(command: string, cwd?: string): Promise<void> {
57
68
  return new Promise((resolve, reject) => {
58
- exec(command, (error, stdout, stderr) => {
69
+ const options: any = {};
70
+ if (cwd) {
71
+ options.cwd = cwd;
72
+ }
73
+ exec(command, options, (error, stdout, stderr) => {
59
74
  if (error) {
60
75
  reject(error);
61
76
  return;
@@ -66,9 +81,9 @@ class TemplateGenerators {
66
81
  }
67
82
 
68
83
  private async installDependencies(projectName: string, dependencies?: string[]): Promise<void> {
69
- //cd to the generated pack directory
70
- const installCommand = `cd ${path.join(process.cwd(), projectName || '')} && bun add ${dependencies ? dependencies.join(' ') : this.dependencies.join(' ')}`;
71
- return await this.runCommand(installCommand);
84
+ const projectPath = path.join(process.cwd(), projectName || '');
85
+ const installCommand = `bun add ${dependencies ? dependencies.join(' ') : this.dependencies.join(' ')}`;
86
+ return await this.runCommand(installCommand, projectPath);
72
87
  }
73
88
  }
74
89