@axeth/create-cli 1.0.2 → 1.0.4

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": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "bin": {
5
5
  "axeth-cli": "index.ts"
6
6
  },
@@ -8,6 +8,9 @@
8
8
  "access": "public"
9
9
  },
10
10
  "license": "MIT",
11
+ "devDependencies": {
12
+ "@types/bun": "latest"
13
+ },
11
14
  "dependencies": {
12
15
  "@clack/prompts": "^0.11.0",
13
16
  "@types/fs-extra": "^11.0.4",
@@ -1,6 +1,8 @@
1
1
  import * as prompt from "@clack/prompts";
2
2
  import color from "colors";
3
3
  import type { TemplateGenerators } from "./TemplateGenerators.js";
4
+ import fs from "fs-extra";
5
+ import path from "path";
4
6
 
5
7
  class AxethCLI {
6
8
  private promptGroups: Record<string, Record<string, (opts?: any) => any>> = {};
@@ -32,6 +34,8 @@ class AxethCLI {
32
34
  const config = await this.configPrompt();
33
35
  const spinner = prompt.spinner({ indicator: "dots" });
34
36
  spinner.start("Generating template files...");
37
+ const minecraftServerVersion = await this.getMinecraftServerVersion();
38
+ const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
35
39
  await this.template.generate({
36
40
  "project_name": (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
37
41
  "axethApiVersion": config.axethApiVersion,
@@ -43,6 +47,8 @@ class AxethCLI {
43
47
  "axethApiName": this.axethAPI,
44
48
  "axethCoreName": this.axethCore,
45
49
  "axethCoreVersion": config.axethCoreVersion,
50
+ "minecraftServerUIVersion": minecraftServerUIVersion,
51
+ "minecraftServerVersion": minecraftServerVersion
46
52
  }, spinner);
47
53
  spinner.stop("Template files generated.");
48
54
  const projectDir = (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase();
@@ -51,6 +57,15 @@ class AxethCLI {
51
57
  spinner.start("Installing dependencies...");
52
58
  try {
53
59
  await new Promise<void>((resolve, reject) => {
60
+ //add dependency installation @minecraft/server{minecraftServerVersion} and @minecraft/server-ui@{minecraftServerUIVersion}
61
+ //edit package.json to add these dependencies
62
+ const packageJsonPath = path.join(cwd, 'package.json');
63
+ const packageJson = fs.readJsonSync(packageJsonPath);
64
+ packageJson.dependencies = packageJson.dependencies || {};
65
+ packageJson.dependencies['@minecraft/server'] = `^${minecraftServerVersion}`;
66
+ packageJson.dependencies['@minecraft/server-ui'] = `^${minecraftServerUIVersion}`;
67
+ fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
68
+
54
69
  const child = spawn('bun', ['install'], { cwd, shell: true });
55
70
  let errorOutput = '';
56
71
  child.stderr && child.stderr.on('data', (data: Buffer) => {
@@ -111,7 +126,6 @@ class AxethCLI {
111
126
  const spinner = prompt.spinner({ indicator: "dots" });
112
127
  spinner.start("Fetching latest Axeth API version...");
113
128
  const versions = await this.getAxethApiVersion();
114
- console.log(versions);
115
129
  spinner.stop(`Fetched @axeth/api ${versions.length} versions.`);
116
130
  this.registerPrompt("config", "axethApiVersion", "Select Axeth API version", "select", {
117
131
  options: versions.slice(0, 10).map((ver) => ({ label: ver, value: ver })),
@@ -127,6 +141,21 @@ class AxethCLI {
127
141
  })
128
142
  }
129
143
 
144
+ private async getMinecraftServerVersion() {
145
+ const moduleData: any = await fetch(`https://registry.npmjs.org/@minecraft/server`)
146
+ .then(res => res.json());
147
+
148
+ const distTag = moduleData["dist-tags"];
149
+ return distTag.latest;
150
+ }
151
+
152
+ private async getMinecraftServerUIVersion() {
153
+ const moduleData: any = await fetch(`https://registry.npmjs.org/@minecraft/server-ui`)
154
+ .then(res => res.json());
155
+ const distTag = moduleData["dist-tags"];
156
+ return distTag.latest;
157
+ }
158
+
130
159
  private registerPrompt(groupId: string, key: string, message: string, type: "text" | "password" | "confirm" | "select" | "multiselect" = "text", options: any = {}) {
131
160
  if (!this.promptGroups[groupId]) this.promptGroups[groupId] = {};
132
161
  this.promptDefaults[groupId] = this.promptDefaults[groupId] || {};