@axeth/create-cli 1.0.4 → 2.0.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.
@@ -0,0 +1,2 @@
1
+ [?9001h[?1004h[?25l$tsc
2
+ ]0;C:\WINDOWS\system32\cmd.exe[?25h[?9001l[?1004l
package/README.md CHANGED
@@ -1,34 +1,20 @@
1
- # @axeth/cli
1
+ # @axeth/core
2
2
 
3
- The official CLI for the **Axeth** ecosystem — a toolkit for building, managing, and scaffolding Minecraft Bedrock Edition projects.
3
+ The core engine of the **Axeth** ecosystem.
4
4
 
5
- `@axeth/cli` acts as the command-line interface that connects `@axeth/core` and `@axeth/api` together into a single developer experience.
6
-
7
- ---
8
-
9
- ## ✨ Features
10
-
11
- - Project scaffolding and initialization
12
- - Minecraft Bedrock addon & tool workflows
13
- - Version-aware environment handling
14
- - Extensible command system
15
- - Works with `bun 🐰 `
5
+ `@axeth/core` provides the foundational logic used by Axeth tools, including
6
+ project initialization, configuration handling, environment resolution,
7
+ and internal workflows for Minecraft Bedrock Edition tooling.
16
8
 
9
+ > ⚠️ This package is primarily intended for internal use by Axeth tools.
10
+ > Advanced users may use it directly at their own discretion.
17
11
 
18
12
  ---
19
- ## 🚀 Usage
20
- ```
21
- bun create @axeth/cli
22
- ```
23
13
 
24
- ---
25
- ## 🧩 Ecosystem
26
-
27
- - @axeth/core — core logic & project engine
28
-
29
- - @axeth/api — shared APIs & versioned Minecraft interfaces
30
-
31
- ---
14
+ ## ✨ Responsibilities
32
15
 
33
- ## License
34
- MIT © PUKAN223
16
+ - Project & template resolution
17
+ - Configuration loading and validation
18
+ - Minecraft Bedrock version targeting
19
+ - Environment & workspace management
20
+ - Shared utilities and internal pipelines
package/index.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
3
  import { AxethCLI } from "./src/class/AxethCLI";
4
- import { TemplateGenerators } from "./src/class/TemplateGenerators";
5
4
 
6
- const templateGenerator = new TemplateGenerators();
7
- new AxethCLI(templateGenerator);
5
+ new AxethCLI();
package/package.json CHANGED
@@ -1,20 +1,38 @@
1
1
  {
2
2
  "name": "@axeth/create-cli",
3
- "version": "1.0.4",
3
+ "version": "2.0.1",
4
+ "module": "index.ts",
5
+ "type": "module",
4
6
  "bin": {
5
7
  "axeth-cli": "index.ts"
6
8
  },
7
9
  "publishConfig": {
8
10
  "access": "public"
9
11
  },
12
+ "scripts": {
13
+ "build": "tsc"
14
+ },
15
+ "keywords": [
16
+ "axeth",
17
+ "axeth-cli",
18
+ "minecraft",
19
+ "minecraft-bedrock",
20
+ "bedrock"
21
+ ],
10
22
  "license": "MIT",
23
+ "author": {
24
+ "name": "KisuX3"
25
+ },
11
26
  "devDependencies": {
12
27
  "@types/bun": "latest"
13
28
  },
29
+ "peerDependencies": {
30
+ "typescript": "^5"
31
+ },
14
32
  "dependencies": {
15
33
  "@clack/prompts": "^0.11.0",
16
34
  "@types/fs-extra": "^11.0.4",
17
35
  "colors": "^1.4.0",
18
36
  "fs-extra": "^11.3.3"
19
37
  }
20
- }
38
+ }
@@ -1,8 +1,9 @@
1
1
  import * as prompt from "@clack/prompts";
2
2
  import color from "colors";
3
- import type { TemplateGenerators } from "./TemplateGenerators.js";
3
+ import { TemplateGenerators } from "./TemplateGenerators.js";
4
4
  import fs from "fs-extra";
5
5
  import path from "path";
6
+ import { spawn } from "child_process";
6
7
 
7
8
  class AxethCLI {
8
9
  private promptGroups: Record<string, Record<string, (opts?: any) => any>> = {};
@@ -12,15 +13,13 @@ class AxethCLI {
12
13
  private readonly axethAPI = `@axeth/api`;
13
14
  private readonly axethCore = `@axeth/core`;
14
15
 
15
- constructor(template: TemplateGenerators) {
16
+ constructor() {
16
17
  console.clear();
17
- this.template = template;
18
+ this.template = new TemplateGenerators();
18
19
  this.init();
19
20
  }
20
21
 
21
- // Get current module version from package.json
22
22
  private async version() {
23
- // __dirname is not available in ESM, so use import.meta.url
24
23
  const url = new URL("../../package.json", import.meta.url);
25
24
  const pkgData = await Bun.file(url).json();
26
25
  return pkgData.version;
@@ -32,10 +31,66 @@ class AxethCLI {
32
31
  process.exit(0);
33
32
  });
34
33
  const config = await this.configPrompt();
35
- const spinner = prompt.spinner({ indicator: "dots" });
36
- spinner.start("Generating template files...");
37
34
  const minecraftServerVersion = await this.getMinecraftServerVersion();
38
35
  const minecraftServerUIVersion = await this.getMinecraftServerUIVersion();
36
+ const spinner = prompt.spinner({ indicator: "dots" });
37
+
38
+ await this.generateTemplate(addonInfo, config, minecraftServerVersion, minecraftServerUIVersion, spinner);
39
+ // await this.installDependencies()
40
+ // const projectDir = (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase();
41
+ // const cwd = require('path').resolve(process.cwd(), projectDir);
42
+
43
+ // spinner.start("Installing dependencies...");
44
+ // try {
45
+ // await new Promise<void>((resolve, reject) => {
46
+ // //add dependency installation @minecraft/server{minecraftServerVersion} and @minecraft/server-ui@{minecraftServerUIVersion}
47
+ // //edit package.json to add these dependencies
48
+ // const packageJsonPath = path.join(cwd, 'package.json');
49
+ // const packageJson = fs.readJsonSync(packageJsonPath);
50
+ // packageJson.dependencies = packageJson.dependencies || {};
51
+ // packageJson.dependencies['@minecraft/server'] = `^${minecraftServerVersion}`;
52
+ // packageJson.dependencies['@minecraft/server-ui'] = `^${minecraftServerUIVersion}`;
53
+ // fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
54
+
55
+ // const child = spawn('bun', ['install'], { cwd, shell: true });
56
+ // let errorOutput = '';
57
+ // child.stderr && child.stderr.on('data', (data: Buffer) => {
58
+ // errorOutput += data.toString();
59
+ // });
60
+ // child.on('close', async (code: number) => {
61
+ // if (code === 0) {
62
+ // spinner.stop("Dependencies installed.");
63
+ // resolve();
64
+ // // Prompt to open VS Code
65
+ // const openVSCode = await prompt.confirm({
66
+ // message: "Open project in VS Code now?"
67
+ // });
68
+ // if (openVSCode) {
69
+ // const childCode = spawn('code', ['.'], { cwd, shell: true, stdio: 'ignore', detached: true });
70
+ // childCode.unref();
71
+ // }
72
+ // } else {
73
+ // spinner.stop("Dependency installation failed.");
74
+ // prompt.log.error(`bun install failed with code ${code}`);
75
+ // if (errorOutput) {
76
+ // prompt.log.error(errorOutput.trim());
77
+ // }
78
+ // reject(new Error(`bun install failed with code ${code}`));
79
+ // }
80
+ // });
81
+ // child.on('error', (err: Error) => {
82
+ // spinner.stop("Dependency installation failed.");
83
+ // prompt.log.error(`bun install process error: ${err.message}`);
84
+ // reject(err);
85
+ // });
86
+ // });
87
+ // } catch (err) {
88
+ // // spinner already stopped in error handler above
89
+ // prompt.log.error(`Failed to install dependencies: ${err}`);
90
+ // }
91
+ }
92
+
93
+ private async generateTemplate(addonInfo: { [x: string]: any }, config: { [x: string]: any }, minecraftServerVersion: string, minecraftServerUIVersion: string, spinner: any) {
39
94
  await this.template.generate({
40
95
  "project_name": (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase(),
41
96
  "axethApiVersion": config.axethApiVersion,
@@ -50,58 +105,6 @@ class AxethCLI {
50
105
  "minecraftServerUIVersion": minecraftServerUIVersion,
51
106
  "minecraftServerVersion": minecraftServerVersion
52
107
  }, spinner);
53
- spinner.stop("Template files generated.");
54
- const projectDir = (addonInfo.addonName as string).replace(/\s+/g, "-").toLowerCase();
55
- const cwd = require('path').resolve(process.cwd(), projectDir);
56
- const { spawn } = require('child_process');
57
- spinner.start("Installing dependencies...");
58
- try {
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
-
69
- const child = spawn('bun', ['install'], { cwd, shell: true });
70
- let errorOutput = '';
71
- child.stderr && child.stderr.on('data', (data: Buffer) => {
72
- errorOutput += data.toString();
73
- });
74
- child.on('close', async (code: number) => {
75
- if (code === 0) {
76
- spinner.stop("Dependencies installed.");
77
- resolve();
78
- // Prompt to open VS Code
79
- const openVSCode = await prompt.confirm({
80
- message: "Open project in VS Code now?"
81
- });
82
- if (openVSCode) {
83
- const childCode = spawn('code', ['.'], { cwd, shell: true, stdio: 'ignore', detached: true });
84
- childCode.unref();
85
- }
86
- } else {
87
- spinner.stop("Dependency installation failed.");
88
- prompt.log.error(`bun install failed with code ${code}`);
89
- if (errorOutput) {
90
- prompt.log.error(errorOutput.trim());
91
- }
92
- reject(new Error(`bun install failed with code ${code}`));
93
- }
94
- });
95
- child.on('error', (err: Error) => {
96
- spinner.stop("Dependency installation failed.");
97
- prompt.log.error(`bun install process error: ${err.message}`);
98
- reject(err);
99
- });
100
- });
101
- } catch (err) {
102
- // spinner already stopped in error handler above
103
- prompt.log.error(`Failed to install dependencies: ${err}`);
104
- }
105
108
  }
106
109
 
107
110
  private async addonInfoPrompt(version: string, onCancel?: () => void) {
@@ -1,8 +1,15 @@
1
1
  import path from "path"
2
2
  import fs from 'fs-extra';
3
+ import { exec } from "child_process";
3
4
 
4
5
  class TemplateGenerators {
5
6
  private fileList = new Map<string, string>();
7
+ private dependencies: string[] = [
8
+ "@axeth/api",
9
+ "@axeth/core",
10
+ "@minecraft/server",
11
+ "@minecraft/server-ui"
12
+ ];
6
13
 
7
14
  constructor() {
8
15
  }
@@ -15,50 +22,53 @@ class TemplateGenerators {
15
22
  return this.fileList;
16
23
  }
17
24
 
18
- public async generate(config:{ [key: string]: any }, spinner: any): Promise<void> {
19
- const templateDir = path.resolve(__dirname, "../templates");
20
- const targetDir = config["pack_name"] ? path.resolve(process.cwd(), config["pack_name"]) : process.cwd();
21
-
22
- const readTemplateFiles = async (dir: string) => {
23
- const entries = await fs.readdir(dir, { withFileTypes: true });
24
- for (const entry of entries) {
25
- const fullPath = path.join(dir, entry.name);
26
- if (entry.isDirectory()) {
27
- await readTemplateFiles(fullPath);
28
- } else if (entry.isFile()) {
29
- if (!this.fileList.has(fullPath)) {
30
- const content = await fs.readFile(fullPath, "utf8");
31
- //if folder is .git ignore it
32
- if (fullPath.includes(`${path.sep}.git${path.sep}`)) {
33
- continue;
34
- }
35
- this.registerFile(fullPath, content);
36
- }
37
- }
38
- }
39
- };
40
-
41
- await readTemplateFiles(templateDir);
42
-
43
- for (const [filePath, fileContent] of this.fileList) {
44
- let updatedContent = fileContent;
45
- for (const [key, value] of Object.entries({ ...config })) {
25
+ public async generate(config: { [key: string]: any }, spinner: any): Promise<void> {
26
+ spinner.start("Preparing template pack files...");
27
+ const templateData: { [key: string]: string } = await fs.readJson(path.join(__dirname, '../data/templates.json'));
28
+ for (const [filePath, fileContent] of Object.entries(templateData)) {
29
+ let populatedContent = fileContent;
30
+ for (const [key, value] of Object.entries(config)) {
46
31
  const placeholder = `{{${key}}}`;
47
- updatedContent = updatedContent.split(placeholder).join(value);
48
- }
49
- const absFilePath = path.isAbsolute(filePath) ? filePath : path.resolve(templateDir, filePath);
50
- const relativePath = path.relative(templateDir, absFilePath);
51
- const targetPath = path.join(targetDir, relativePath);
52
- try {
53
- await fs.ensureDir(path.dirname(targetPath));
54
- spinner.message(`Creating file: ${targetPath}`);
55
- await fs.writeFile(targetPath, updatedContent, "utf8");
56
- await fs.utimes(targetPath, new Date(), new Date());
57
- await new Promise((res) => setTimeout(res, 50));
58
- } catch (err) {
59
- throw err;
32
+ populatedContent = populatedContent.split(placeholder).join(value);
33
+ this.registerFile(filePath, populatedContent);
34
+ await new Promise((resolve) => setTimeout(resolve, 10)); // Slight delay to ensure responsiveness
60
35
  }
61
36
  }
37
+ spinner.stop("Prepared template pack files.");
38
+ spinner.start("Creating template pack files...");
39
+
40
+ for (const filePath of this.fileList.keys()) {
41
+ const fullPath = path.join(process.cwd(), config['pack_name'], filePath);
42
+ const shortPath = filePath
43
+ .split('/')
44
+ .slice(-5)
45
+ .join('/');
46
+ spinner.message(`Creating file: ${shortPath}`);
47
+ await Bun.file(fullPath).write(this.fileList.get(filePath) || '');
48
+ await new Promise((resolve) => setTimeout(resolve, 50)); // Slight delay to ensure file system stability
49
+ }
50
+ spinner.stop("Template pack files generated.");
51
+ spinner.start("Installing dependencies...");
52
+ await this.installDependencies(config['pack_name'], this.dependencies);
53
+ spinner.stop("Dependencies installed.");
54
+ }
55
+
56
+ private async runCommand(command: string): Promise<void> {
57
+ return new Promise((resolve, reject) => {
58
+ exec(command, (error, stdout, stderr) => {
59
+ if (error) {
60
+ reject(error);
61
+ return;
62
+ }
63
+ resolve();
64
+ });
65
+ });
66
+ }
67
+
68
+ 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);
62
72
  }
63
73
  }
64
74