create-mcbepack 1.0.5 → 1.0.7
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/README.md +4 -179
- package/dist/config/constant.js +21 -0
- package/dist/config/enum.js +24 -0
- package/dist/generator/manifest.js +84 -0
- package/dist/generator/package.js +23 -0
- package/dist/generator/readme.js +20 -0
- package/dist/index.js +70 -0
- package/dist/prompts.js +92 -0
- package/dist/utils.js +47 -0
- package/package.json +10 -15
- package/templates/tsconfig.json +2 -2
- package/out/index.js +0 -60
- package/out/prompt.js +0 -92
- package/out/types.js +0 -1
- package/out/utils/collect-info.js +0 -54
- package/out/utils/create-files.js +0 -77
- package/out/utils/generate-files.js +0 -191
- package/templates/README.md +0 -57
package/README.md
CHANGED
|
@@ -1,197 +1,22 @@
|
|
|
1
1
|
# create-mcbepack
|
|
2
2
|
|
|
3
|
-
Interactive
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/create-mcbepack)
|
|
6
|
-
[](https://www.gnu.org/licenses/gpl-3.0)
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
`create-mcbepack` is an interactive command-line tool that facilitates rapid scaffolding of Minecraft Bedrock Edition addon projects with best practices and modern development tooling.
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
- **Interactive Project Setup** - Guided prompts for project configuration
|
|
15
|
-
- **Multiple Pack Types** - Support for Behavior Packs and Resource Packs
|
|
16
|
-
- **Script API Integration** - Optional Script API setup with package selection
|
|
17
|
-
- **Language Choice** - TypeScript or JavaScript support
|
|
18
|
-
- **Release Channel Selection** - Choose between stable, beta, or preview releases
|
|
19
|
-
- **Auto-generated Configuration** - Automatic manifest, package.json, and tsconfig generation
|
|
20
|
-
- **Project Templates** - Pre-configured templates with best practices
|
|
3
|
+
Interactive scaffolder for MCBEPACK projects.
|
|
21
4
|
|
|
22
5
|
## Usage
|
|
23
6
|
|
|
24
|
-
### Quick Start
|
|
25
|
-
|
|
26
7
|
```bash
|
|
27
8
|
bunx create-mcbepack
|
|
28
9
|
```
|
|
29
10
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
The CLI will guide you through the following steps:
|
|
33
|
-
|
|
34
|
-
1. **Pack Type Selection**
|
|
35
|
-
- Choose between Behavior Pack and/or Resource Pack
|
|
36
|
-
|
|
37
|
-
2. **Project Information**
|
|
38
|
-
- Project name
|
|
39
|
-
- Description
|
|
40
|
-
- Author name(s)
|
|
41
|
-
- Minimum engine version
|
|
42
|
-
|
|
43
|
-
3. **Script API Configuration** (if Behavior Pack is selected)
|
|
44
|
-
- Enable/disable Script API
|
|
45
|
-
- Select programming language (TypeScript/JavaScript)
|
|
46
|
-
- Choose game release channel (stable/beta/preview)
|
|
47
|
-
- Select Script API packages to include:
|
|
48
|
-
- `@minecraft/server`
|
|
49
|
-
- `@minecraft/server-ui`
|
|
50
|
-
- `@minecraft/server-net`
|
|
51
|
-
- `@minecraft/server-admin`
|
|
52
|
-
- `@minecraft/server-gametest`
|
|
53
|
-
- `@minecraft/vanilla-data`
|
|
54
|
-
- `@minecraft/math`
|
|
55
|
-
|
|
56
|
-
4. **Project Preview**
|
|
57
|
-
- Review generated file structure
|
|
58
|
-
- Confirm project creation
|
|
59
|
-
|
|
60
|
-
### Example
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
$ bunx create-mcbepack
|
|
64
|
-
|
|
65
|
-
Create MCBEPack
|
|
66
|
-
|
|
67
|
-
? Select a extension type?
|
|
68
|
-
◉ Behavior Pack
|
|
69
|
-
◉ Resource Pack
|
|
70
|
-
|
|
71
|
-
? What is the name of the project? my-awesome-addon
|
|
72
|
-
? What is the description of the project? An amazing Minecraft addon
|
|
73
|
-
? What is the author's name? YourName
|
|
74
|
-
? What is the minimum engine version required? 1.21.0
|
|
75
|
-
|
|
76
|
-
? Do you want to add a script api to behavior? Yes
|
|
77
|
-
? Which language do you want to use? typescript
|
|
78
|
-
? What game type would you like to use? stable
|
|
79
|
-
? Which packages would you like to add?
|
|
80
|
-
◉ @minecraft/server
|
|
81
|
-
◉ @minecraft/server-ui
|
|
82
|
-
|
|
83
|
-
Success! Created project my-awesome-addon
|
|
84
|
-
at: /path/to/my-awesome-addon
|
|
85
|
-
|
|
86
|
-
Next steps:
|
|
87
|
-
|
|
88
|
-
1. cd my-awesome-addon
|
|
89
|
-
2. bun install
|
|
90
|
-
3. bun run dev
|
|
91
|
-
|
|
92
|
-
Available commands:
|
|
93
|
-
• bun run dev - Start development server
|
|
94
|
-
• bun run build:zip - Build project
|
|
95
|
-
• bun run build:mcpack - Build project
|
|
96
|
-
• bun run build:addon - Build project
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Generated Project Structure
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
my-awesome-addon/
|
|
103
|
-
├── scripts/ # TypeScript/JavaScript source files (if Script API enabled)
|
|
104
|
-
│ └── index.ts
|
|
105
|
-
├── .env.local # Minecraft path configuration
|
|
106
|
-
├── .gitignore
|
|
107
|
-
├── package.json
|
|
108
|
-
├── tsconfig.json # TypeScript configuration (if TypeScript selected)
|
|
109
|
-
├── pack_icon.png
|
|
110
|
-
└── README.md
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Configuration Files
|
|
114
|
-
|
|
115
|
-
### package.json
|
|
116
|
-
|
|
117
|
-
Automatically generated with:
|
|
118
|
-
|
|
119
|
-
- Project metadata
|
|
120
|
-
- Script API dependencies (if enabled)
|
|
121
|
-
- Development scripts
|
|
122
|
-
- Peer dependencies (`@mcbepack/cli`, `@mcbepack/api`)
|
|
123
|
-
|
|
124
|
-
### tsconfig.json
|
|
125
|
-
|
|
126
|
-
Pre-configured TypeScript settings optimized for Minecraft addon development:
|
|
127
|
-
|
|
128
|
-
- ESNext target
|
|
129
|
-
- Bundler module resolution
|
|
130
|
-
- Source maps disabled for production
|
|
131
|
-
|
|
132
|
-
### .env.local
|
|
133
|
-
|
|
134
|
-
Minecraft installation paths configuration:
|
|
135
|
-
|
|
136
|
-
```env
|
|
137
|
-
BASE_PATH="C:\Users\YourName\AppData\Roaming\Minecraft Bedrock\Users\Shared\games\com.mojang"
|
|
138
|
-
RESOURCE_PATH="development_resource_packs"
|
|
139
|
-
BEHAVIOR_PATH="development_behavior_packs"
|
|
140
|
-
```
|
|
11
|
+
It creates behavior/resource packs, manifests, package scripts, and optional Script API setup.
|
|
141
12
|
|
|
142
13
|
## Development
|
|
143
14
|
|
|
144
|
-
### Building from Source
|
|
145
|
-
|
|
146
15
|
```bash
|
|
147
|
-
# Clone the repository
|
|
148
|
-
git clone https://github.com/bugphxne/create-mcbepack.git
|
|
149
|
-
cd mcbepack/packages/create-mcbepack
|
|
150
|
-
|
|
151
|
-
# Install dependencies
|
|
152
16
|
bun install
|
|
153
|
-
|
|
154
|
-
# Build
|
|
155
|
-
bun run build
|
|
156
|
-
|
|
157
|
-
# Test locally
|
|
158
|
-
bun run test
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Project Structure
|
|
162
|
-
|
|
163
|
-
```
|
|
164
|
-
create-mcbepack/
|
|
165
|
-
├── src/
|
|
166
|
-
│ ├── index.ts # Main CLI entry point
|
|
167
|
-
│ ├── prompt.ts # Interactive prompts
|
|
168
|
-
│ ├── types.ts # TypeScript type definitions
|
|
169
|
-
│ └── utils/
|
|
170
|
-
│ ├── collect-info.ts # Project information collection
|
|
171
|
-
│ ├── create-files.ts # File generation
|
|
172
|
-
│ └── generate-files.ts # File list generation
|
|
173
|
-
├── templates/ # Project templates
|
|
174
|
-
│ ├── README.md
|
|
175
|
-
│ ├── tsconfig.json
|
|
176
|
-
│ ├── .env.local
|
|
177
|
-
│ ├── .gitignore
|
|
178
|
-
│ └── pack_icon.png
|
|
179
|
-
└── bin/ # Compiled output
|
|
17
|
+
bun --cwd packages/create-mcbepack run build
|
|
180
18
|
```
|
|
181
19
|
|
|
182
|
-
## Related Packages
|
|
183
|
-
|
|
184
|
-
- [`@mcbepack/cli`](../cli) - Development and build tooling
|
|
185
|
-
- [`@mcbepack/api`](../api) - Utility APIs for Script API
|
|
186
|
-
- [`@mcbepack/common`](../common) - Shared utilities
|
|
187
|
-
|
|
188
20
|
## License
|
|
189
21
|
|
|
190
|
-
GPL-3.0
|
|
191
|
-
|
|
192
|
-
## Resources
|
|
193
|
-
|
|
194
|
-
- [GitHub Repository](https://github.com/bugphxne/create-mcbepack)
|
|
195
|
-
- [npm Package](https://www.npmjs.com/package/create-mcbepack)
|
|
196
|
-
- [Documentation](https://docs.mbext.online/mcbepack)
|
|
197
|
-
- [Issue Tracker](https://github.com/bugphxne/create-mcbepack/issues)
|
|
22
|
+
GPL-3.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { Extension } from "./enum.js";
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
export const SCRIPTS_BASE = [
|
|
6
|
+
{ name: "export:zip", cmd: "mcbepack export zip", desc: "Export .zip" },
|
|
7
|
+
{ name: "export:mcpack", cmd: "mcbepack export mcpack", desc: "Export .mcpack" },
|
|
8
|
+
{ name: "export:mcaddon", cmd: "mcbepack export mcaddon", desc: "Export .mcaddon" },
|
|
9
|
+
];
|
|
10
|
+
export const SCRIPTS_SCRIPT_API = [
|
|
11
|
+
{ name: "dev", cmd: "mcbepack dev", desc: "Dev server" },
|
|
12
|
+
{ name: "build", cmd: "mcbepack build", desc: "Build" },
|
|
13
|
+
{ name: "update:stable", cmd: "mcbepack update stable", desc: "Update stable" },
|
|
14
|
+
{ name: "update:beta", cmd: "mcbepack update beta", desc: "Update beta" },
|
|
15
|
+
{ name: "update:preview", cmd: "mcbepack update preview", desc: "Update preview" },
|
|
16
|
+
];
|
|
17
|
+
export const DIRECTORIES = {
|
|
18
|
+
template: path.join(__dirname, "..", "..", "templates"),
|
|
19
|
+
[Extension.Behavior]: path.join("src", "behavior_pack"),
|
|
20
|
+
[Extension.Resource]: path.join("src", "resource_pack"),
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var Extension;
|
|
2
|
+
(function (Extension) {
|
|
3
|
+
Extension["Behavior"] = "behavior";
|
|
4
|
+
Extension["Resource"] = "resource";
|
|
5
|
+
})(Extension || (Extension = {}));
|
|
6
|
+
export var ScriptLanguage;
|
|
7
|
+
(function (ScriptLanguage) {
|
|
8
|
+
ScriptLanguage["TypeScript"] = "typescript";
|
|
9
|
+
ScriptLanguage["JavaScript"] = "javascript";
|
|
10
|
+
})(ScriptLanguage || (ScriptLanguage = {}));
|
|
11
|
+
export var Release;
|
|
12
|
+
(function (Release) {
|
|
13
|
+
Release["Stable"] = "stable";
|
|
14
|
+
Release["Beta"] = "beta";
|
|
15
|
+
Release["Preview"] = "preview";
|
|
16
|
+
})(Release || (Release = {}));
|
|
17
|
+
export var PackageManager;
|
|
18
|
+
(function (PackageManager) {
|
|
19
|
+
PackageManager["Npm"] = "npm";
|
|
20
|
+
PackageManager["Yarn"] = "yarn";
|
|
21
|
+
PackageManager["Pnpm"] = "pnpm";
|
|
22
|
+
PackageManager["Bun"] = "bun";
|
|
23
|
+
PackageManager["Deno"] = "deno";
|
|
24
|
+
})(PackageManager || (PackageManager = {}));
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
2
|
+
import { Extension } from "../config/enum.js";
|
|
3
|
+
import { json } from "../utils.js";
|
|
4
|
+
const pluginPackages = new Set();
|
|
5
|
+
export const ver = () => [1, 0, 0];
|
|
6
|
+
export function buildBaseManifest(context) {
|
|
7
|
+
return {
|
|
8
|
+
format_version: 2,
|
|
9
|
+
header: {
|
|
10
|
+
name: context.name,
|
|
11
|
+
description: context.description,
|
|
12
|
+
uuid: "",
|
|
13
|
+
version: ver(),
|
|
14
|
+
min_engine_version: context.minEngineVersion,
|
|
15
|
+
},
|
|
16
|
+
metadata: {
|
|
17
|
+
authors: context.author.split(",").map((s) => s.trim()).filter(Boolean),
|
|
18
|
+
generated_with: {
|
|
19
|
+
"create-mcbepack": pkg.version
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function buildBehaviorManifest(context) {
|
|
25
|
+
const base = buildBaseManifest(context);
|
|
26
|
+
const scriptDeps = context.script?.enabled
|
|
27
|
+
? context.script.dependencies
|
|
28
|
+
.filter((d) => !pluginPackages.has(d.packageName))
|
|
29
|
+
.map((d) => ({ module_name: d.packageName, version: d.version }))
|
|
30
|
+
: [];
|
|
31
|
+
const resourceDep = context.script?.enabled && context.extensions.includes(Extension.Resource)
|
|
32
|
+
? [
|
|
33
|
+
{
|
|
34
|
+
uuid: context.uuids.resource,
|
|
35
|
+
version: ver()
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
: [];
|
|
39
|
+
return json({
|
|
40
|
+
...base,
|
|
41
|
+
header: {
|
|
42
|
+
...base.header,
|
|
43
|
+
uuid: context.uuids.behavior
|
|
44
|
+
},
|
|
45
|
+
...(context.script?.enabled ? { capabilities: ["script_eval"] } : {}),
|
|
46
|
+
modules: context.script?.enabled
|
|
47
|
+
? [
|
|
48
|
+
{
|
|
49
|
+
type: "script",
|
|
50
|
+
language: "javascript",
|
|
51
|
+
entry: "scripts/index.js",
|
|
52
|
+
uuid: context.uuids.scriptModule,
|
|
53
|
+
version: ver(),
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
: [],
|
|
57
|
+
dependencies: [...scriptDeps, ...resourceDep],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function buildResourceManifest(context) {
|
|
61
|
+
const base = buildBaseManifest(context);
|
|
62
|
+
return json({
|
|
63
|
+
...base,
|
|
64
|
+
header: {
|
|
65
|
+
...base.header,
|
|
66
|
+
uuid: context.uuids.resource
|
|
67
|
+
},
|
|
68
|
+
modules: [
|
|
69
|
+
{
|
|
70
|
+
type: "resources",
|
|
71
|
+
uuid: context.uuids.resourceModule,
|
|
72
|
+
version: ver()
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
dependencies: context.extensions.includes(Extension.Behavior)
|
|
76
|
+
? [
|
|
77
|
+
{
|
|
78
|
+
uuid: context.uuids.behavior,
|
|
79
|
+
version: ver()
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
: [],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SCRIPTS_BASE, SCRIPTS_SCRIPT_API } from "../config/constant.js";
|
|
2
|
+
import { ScriptLanguage } from "../config/enum.js";
|
|
3
|
+
import { json } from "../utils.js";
|
|
4
|
+
export function buildPackageJson(context) {
|
|
5
|
+
const scripts = context.script?.enabled
|
|
6
|
+
? [...SCRIPTS_SCRIPT_API, ...SCRIPTS_BASE]
|
|
7
|
+
: [...SCRIPTS_BASE];
|
|
8
|
+
const devDeps = { "@mcbepack/cli": "latest" };
|
|
9
|
+
if (context.script?.enabled) {
|
|
10
|
+
devDeps["@mcbepack/api"] = "latest";
|
|
11
|
+
if (context.script.language === ScriptLanguage.TypeScript) {
|
|
12
|
+
devDeps["typescript"] = "latest";
|
|
13
|
+
}
|
|
14
|
+
for (const dep of context.script.dependencies) {
|
|
15
|
+
devDeps[dep.packageName] = dep.fullVersion;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return json({
|
|
19
|
+
name: context.name,
|
|
20
|
+
scripts: Object.fromEntries(scripts.map((s) => [s.name, s.cmd])),
|
|
21
|
+
devDependencies: devDeps,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SCRIPTS_BASE, SCRIPTS_SCRIPT_API } from "../config/constant.js";
|
|
2
|
+
export function buildReadme(context) {
|
|
3
|
+
const pm = context.packageManager;
|
|
4
|
+
const scripts = context.script?.enabled
|
|
5
|
+
? [...SCRIPTS_SCRIPT_API, ...SCRIPTS_BASE]
|
|
6
|
+
: [...SCRIPTS_BASE];
|
|
7
|
+
const cmds = scripts.map((s) => `${pm} run ${s.name.padEnd(16)} # ${s.desc}`).join("\n");
|
|
8
|
+
return `# ${context.name}
|
|
9
|
+
|
|
10
|
+
${context.description}
|
|
11
|
+
|
|
12
|
+
> Generated with \`create-mcbepack\`
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
\`\`\`bash
|
|
17
|
+
${cmds}
|
|
18
|
+
\`\`\`
|
|
19
|
+
`;
|
|
20
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { logger } from "@mcbepack/common";
|
|
6
|
+
import { DIRECTORIES } from "./config/constant.js";
|
|
7
|
+
import { Extension, ScriptLanguage } from "./config/enum.js";
|
|
8
|
+
import { buildBehaviorManifest, buildResourceManifest } from "./generator/manifest.js";
|
|
9
|
+
import { buildPackageJson } from "./generator/package.js";
|
|
10
|
+
import { buildReadme } from "./generator/readme.js";
|
|
11
|
+
import { confirmPrompt, createContext } from "./prompts.js";
|
|
12
|
+
import { FileGenerator } from "./utils.js";
|
|
13
|
+
try {
|
|
14
|
+
const context = await createContext();
|
|
15
|
+
const projectRoot = path.join(process.cwd(), context.name);
|
|
16
|
+
const confirmed = await confirmPrompt(`Do you want to continue with the following configuration?`);
|
|
17
|
+
if (!confirmed) {
|
|
18
|
+
logger.warn("Project creation cancelled.");
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
const generator = new FileGenerator(projectRoot);
|
|
22
|
+
generator.create(path.join(projectRoot, "README.md"), buildReadme(context));
|
|
23
|
+
generator.create(path.join(projectRoot, "package.json"), buildPackageJson(context));
|
|
24
|
+
if (context.extensions.includes(Extension.Behavior)) {
|
|
25
|
+
generator.create(path.join(projectRoot, DIRECTORIES.behavior, "manifest.json"), buildBehaviorManifest(context));
|
|
26
|
+
generator.copy(path.join(projectRoot, DIRECTORIES.behavior, "pack_icon.png"), path.join(DIRECTORIES.template, "pack_icon.png"));
|
|
27
|
+
}
|
|
28
|
+
if (context.extensions.includes(Extension.Resource)) {
|
|
29
|
+
generator.create(path.join(projectRoot, DIRECTORIES.resource, "manifest.json"), buildResourceManifest(context));
|
|
30
|
+
generator.copy(path.join(projectRoot, DIRECTORIES.resource, "pack_icon.png"), path.join(DIRECTORIES.template, "pack_icon.png"));
|
|
31
|
+
}
|
|
32
|
+
if (context.script?.enabled) {
|
|
33
|
+
const lang = context.script.language;
|
|
34
|
+
generator.create(path.join(projectRoot, "scripts", lang === ScriptLanguage.TypeScript ? "index.ts" : "index.js"), "export {};\n");
|
|
35
|
+
generator.copy(path.join(projectRoot, ".env.local"), path.join(DIRECTORIES.template, ".env.local.txt"));
|
|
36
|
+
generator.copy(path.join(projectRoot, ".gitignore"), path.join(DIRECTORIES.template, ".gitignore.txt"));
|
|
37
|
+
if (lang === ScriptLanguage.TypeScript) {
|
|
38
|
+
generator.copy(path.join(projectRoot, "tsconfig.json"), path.join(DIRECTORIES.template, "tsconfig.json"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
generator.generate();
|
|
42
|
+
execFileSync(context.packageManager, ["install"], { cwd: projectRoot, stdio: "inherit" });
|
|
43
|
+
logger.done(`Created project ${context.name}`);
|
|
44
|
+
logger.field("Path", chalk.dim(projectRoot));
|
|
45
|
+
logger.section("Next steps");
|
|
46
|
+
logger.item(`${chalk.cyan("1.")} cd ${context.name}`);
|
|
47
|
+
if (context.script?.enabled) {
|
|
48
|
+
logger.item(`${chalk.cyan("2.")} ${context.packageManager} dev`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
logger.item(`${chalk.cyan("2.")} Start developing your project`);
|
|
52
|
+
}
|
|
53
|
+
logger.section("Available commands");
|
|
54
|
+
if (context.script?.enabled) {
|
|
55
|
+
logger.info(`${context.packageManager} run dev - Start development server`);
|
|
56
|
+
logger.info(`${context.packageManager} run build - Build project files`);
|
|
57
|
+
}
|
|
58
|
+
logger.info(`${context.packageManager} run export:zip - Export a .zip archive`);
|
|
59
|
+
logger.info(`${context.packageManager} run export:mcpack - Export .mcpack archive(s)`);
|
|
60
|
+
logger.info(`${context.packageManager} run export:mcaddon - Export a .mcaddon archive`);
|
|
61
|
+
if (context.script?.enabled) {
|
|
62
|
+
logger.info(`${context.packageManager} run update:stable - Update Script API (stable) packages`);
|
|
63
|
+
logger.info(`${context.packageManager} run update:beta - Update Script API (beta) packages`);
|
|
64
|
+
logger.info(`${context.packageManager} run update:preview - Update Script API (preview) packages`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
logger.error(err instanceof Error ? err.message : String(err));
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
package/dist/prompts.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import enquirer from "enquirer";
|
|
3
|
+
import { getDependency, MINECRAFT_PACKAGES } from "@mcbepack/common";
|
|
4
|
+
import { Extension, Release, ScriptLanguage } from "./config/enum.js";
|
|
5
|
+
import { detectPackageManager } from "./utils.js";
|
|
6
|
+
export async function createContext() {
|
|
7
|
+
const { extensions } = await enquirer.prompt({
|
|
8
|
+
type: "multiselect",
|
|
9
|
+
name: "extensions",
|
|
10
|
+
message: "What types of development do you need?",
|
|
11
|
+
choices: Object.values(Extension),
|
|
12
|
+
validate: (v) => v.length > 0 || "At least one extension type is required",
|
|
13
|
+
});
|
|
14
|
+
const info = await enquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
type: "input",
|
|
17
|
+
name: "name",
|
|
18
|
+
message: "What is the name of your project?"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "input",
|
|
22
|
+
name: "description",
|
|
23
|
+
message: "What is the description of your project?"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: "input",
|
|
27
|
+
name: "author",
|
|
28
|
+
message: "What is the author's name? Use commas to separate multiple authors.",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "input",
|
|
32
|
+
name: "minEngineVersion",
|
|
33
|
+
message: "What is the minimum engine version required?",
|
|
34
|
+
initial: "1.26.0",
|
|
35
|
+
validate: (v) => /^\d+\.\d+\.\d+$/.test(v) || "Minimum engine version must be in the format x.x.x",
|
|
36
|
+
}
|
|
37
|
+
]);
|
|
38
|
+
const context = {
|
|
39
|
+
...info,
|
|
40
|
+
extensions,
|
|
41
|
+
packageManager: await detectPackageManager(),
|
|
42
|
+
uuids: {
|
|
43
|
+
behavior: randomUUID(),
|
|
44
|
+
resource: randomUUID(),
|
|
45
|
+
scriptModule: randomUUID(),
|
|
46
|
+
resourceModule: randomUUID(),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
if (extensions.includes(Extension.Behavior)) {
|
|
50
|
+
const { useScript } = await enquirer.prompt({
|
|
51
|
+
type: "confirm",
|
|
52
|
+
name: "useScript",
|
|
53
|
+
message: "Do you want to add Script API to the behavior pack?",
|
|
54
|
+
initial: true,
|
|
55
|
+
});
|
|
56
|
+
if (useScript) {
|
|
57
|
+
const scriptConfig = await enquirer.prompt([
|
|
58
|
+
{
|
|
59
|
+
type: "select",
|
|
60
|
+
name: "language",
|
|
61
|
+
message: "Which language do you want to use?",
|
|
62
|
+
choices: Object.values(ScriptLanguage),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "select",
|
|
66
|
+
name: "release",
|
|
67
|
+
message: "What release channel would you like to use?",
|
|
68
|
+
choices: Object.values(Release),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "multiselect",
|
|
72
|
+
name: "packages",
|
|
73
|
+
message: "Which packages would you like to add?",
|
|
74
|
+
choices: [...MINECRAFT_PACKAGES.modules, ...MINECRAFT_PACKAGES.plugins],
|
|
75
|
+
validate: (v) => v.length > 0 || "At least one package is required",
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
const dependencies = await Promise.all(scriptConfig.packages.map((pkg) => getDependency(pkg, scriptConfig.release)));
|
|
79
|
+
context.script = { enabled: true, ...scriptConfig, dependencies };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return context;
|
|
83
|
+
}
|
|
84
|
+
export async function confirmPrompt(message, initial = true) {
|
|
85
|
+
const { ok } = await enquirer.prompt({
|
|
86
|
+
type: "confirm",
|
|
87
|
+
name: "ok",
|
|
88
|
+
message,
|
|
89
|
+
initial,
|
|
90
|
+
});
|
|
91
|
+
return ok;
|
|
92
|
+
}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { detect } from "package-manager-detector/detect";
|
|
4
|
+
import { PackageManager } from "./config/enum.js";
|
|
5
|
+
export function json(v) {
|
|
6
|
+
return `${JSON.stringify(v, null, 2)}\n`;
|
|
7
|
+
}
|
|
8
|
+
export async function detectPackageManager() {
|
|
9
|
+
const detected = await detect();
|
|
10
|
+
const name = detected?.name;
|
|
11
|
+
return Object.values(PackageManager).includes(name)
|
|
12
|
+
? name
|
|
13
|
+
: PackageManager.Bun;
|
|
14
|
+
}
|
|
15
|
+
export class FileGenerator {
|
|
16
|
+
projectRoot;
|
|
17
|
+
files = [];
|
|
18
|
+
constructor(projectRoot) {
|
|
19
|
+
this.projectRoot = projectRoot;
|
|
20
|
+
}
|
|
21
|
+
create(destinationDir, content) {
|
|
22
|
+
this.files.push({ action: "create", destinationDir, content });
|
|
23
|
+
}
|
|
24
|
+
copy(destinationDir, originDir) {
|
|
25
|
+
this.files.push({ action: "copy", destinationDir, originDir });
|
|
26
|
+
}
|
|
27
|
+
generate() {
|
|
28
|
+
if (fs.existsSync(this.projectRoot)) {
|
|
29
|
+
throw new Error(`Directory already exists: ${path.basename(this.projectRoot)}`);
|
|
30
|
+
}
|
|
31
|
+
fs.mkdirSync(this.projectRoot);
|
|
32
|
+
const created = new Set([this.projectRoot]);
|
|
33
|
+
for (const file of this.files) {
|
|
34
|
+
const dir = path.dirname(file.destinationDir);
|
|
35
|
+
if (!created.has(dir)) {
|
|
36
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
37
|
+
created.add(dir);
|
|
38
|
+
}
|
|
39
|
+
if (file.action === "copy") {
|
|
40
|
+
fs.copyFileSync(file.originDir, file.destinationDir);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
fs.writeFileSync(file.destinationDir, file.content);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mcbepack",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-mcbepack": "./dist/index.js"
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
7
10
|
"dev": "tsc --watch",
|
|
8
11
|
"build": "tsc"
|
|
9
12
|
},
|
|
10
|
-
"bin": {
|
|
11
|
-
"create-mcbepack": "./out/index.js"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@types/bun": "latest"
|
|
15
|
-
},
|
|
16
|
-
"peerDependencies": {
|
|
17
|
-
"typescript": "^5"
|
|
18
|
-
},
|
|
19
13
|
"dependencies": {
|
|
20
|
-
"@mcbepack/common": "^1.0.
|
|
14
|
+
"@mcbepack/common": "^1.0.1",
|
|
21
15
|
"enquirer": "^2.4.1",
|
|
22
|
-
"node-fetch": "^3.3.2",
|
|
23
16
|
"nodemon": "^3.1.11",
|
|
24
|
-
"
|
|
25
|
-
|
|
17
|
+
"package-manager-detector": "^1.6.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5"
|
|
26
21
|
}
|
|
27
22
|
}
|
package/templates/tsconfig.json
CHANGED
package/out/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import pc from "picocolors";
|
|
5
|
-
import { collectProjectInfo } from "./utils/collect-info";
|
|
6
|
-
import { generateFileList } from "./utils/generate-files";
|
|
7
|
-
import { createFiles, previewFiles } from "./utils/create-files";
|
|
8
|
-
import prompt from "./prompt";
|
|
9
|
-
async function main() {
|
|
10
|
-
try {
|
|
11
|
-
console.log(pc.bold(pc.cyan("\nCreate MCBEPack\n")));
|
|
12
|
-
const config = await collectProjectInfo();
|
|
13
|
-
const files = generateFileList(config);
|
|
14
|
-
previewFiles(files, config.name);
|
|
15
|
-
console.log();
|
|
16
|
-
const { confirmed } = await prompt.confirm({
|
|
17
|
-
message: "Do you want to create this project?",
|
|
18
|
-
default: true,
|
|
19
|
-
});
|
|
20
|
-
if (!confirmed) {
|
|
21
|
-
console.log(pc.yellow("\nProject creation cancelled"));
|
|
22
|
-
process.exit(0);
|
|
23
|
-
}
|
|
24
|
-
const projectRoot = path.join(process.cwd(), config.name);
|
|
25
|
-
if (fs.existsSync(projectRoot)) {
|
|
26
|
-
console.log(pc.red(`\nDirectory ${config.name} already exists`));
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
createFiles(files);
|
|
30
|
-
console.log(`\n${pc.green("Success!")} Created project ${pc.cyan(config.name)}`);
|
|
31
|
-
console.log(pc.dim(` at: ${projectRoot}\n`));
|
|
32
|
-
console.log(pc.bold("Next steps:\n"));
|
|
33
|
-
console.log(` ${pc.cyan("1.")} cd ${config.name}`);
|
|
34
|
-
if (config.script?.enabled) {
|
|
35
|
-
console.log(` ${pc.cyan("2.")} bun install`);
|
|
36
|
-
console.log(` ${pc.cyan("3.")} bun run dev\n`);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
console.log(` ${pc.cyan("2.")} Start developing your project\n`);
|
|
40
|
-
}
|
|
41
|
-
if (config.script?.enabled) {
|
|
42
|
-
console.log(pc.dim("Available commands:"));
|
|
43
|
-
console.log(pc.dim(" • bun run dev - Start development server"));
|
|
44
|
-
console.log(pc.dim(" • bun run build:zip - Build project"));
|
|
45
|
-
console.log(pc.dim(" • bun run build:mcpack - Build project"));
|
|
46
|
-
console.log(pc.dim(" • bun run build:addon - Build project"));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
console.log(pc.dim("Available commands:"));
|
|
50
|
-
console.log(pc.dim(" • bun run build:zip - Build project"));
|
|
51
|
-
console.log(pc.dim(" • bun run build:mcpack - Build project"));
|
|
52
|
-
console.log(pc.dim(" • bun run build:addon - Build project"));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error(pc.red("\nError occurred:"), error);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
main();
|
package/out/prompt.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import enquirer from 'enquirer';
|
|
2
|
-
import { constants } from '@mcbepack/common';
|
|
3
|
-
const extension = async () => {
|
|
4
|
-
const response = await enquirer.prompt({
|
|
5
|
-
type: 'multiselect',
|
|
6
|
-
name: 'extensions',
|
|
7
|
-
message: 'Select a extension type?',
|
|
8
|
-
choices: [
|
|
9
|
-
{ name: 'behavior', message: 'Behavior Pack' },
|
|
10
|
-
{ name: 'resource', message: 'Resource Pack' },
|
|
11
|
-
]
|
|
12
|
-
});
|
|
13
|
-
return response;
|
|
14
|
-
};
|
|
15
|
-
const api = async () => {
|
|
16
|
-
const response = await enquirer.prompt({
|
|
17
|
-
type: "confirm",
|
|
18
|
-
name: "api",
|
|
19
|
-
message: "Do you want to add a script api to behavior?",
|
|
20
|
-
initial: true
|
|
21
|
-
});
|
|
22
|
-
return response;
|
|
23
|
-
};
|
|
24
|
-
const info = async () => {
|
|
25
|
-
const response = await enquirer.prompt([
|
|
26
|
-
{
|
|
27
|
-
type: 'input',
|
|
28
|
-
name: 'name',
|
|
29
|
-
message: 'What is the name of the project?',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
type: 'input',
|
|
33
|
-
name: 'description',
|
|
34
|
-
message: 'What is the description of the project?',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
type: 'input',
|
|
38
|
-
name: 'author',
|
|
39
|
-
message: 'What is the author\'s name? Use commas to separate multiple authors(,).',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: 'input',
|
|
43
|
-
name: 'minimumEngineVersion',
|
|
44
|
-
message: 'What is the minimum engine version required?',
|
|
45
|
-
validate: input => {
|
|
46
|
-
if (input.length === 0)
|
|
47
|
-
return 'Minimum engine version is required';
|
|
48
|
-
const version = input.split('.');
|
|
49
|
-
const response = 'Minimum engine version must be in the format x.x.x';
|
|
50
|
-
return version.every((v) => !isNaN(parseInt(v))) || response;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
]);
|
|
54
|
-
return response;
|
|
55
|
-
};
|
|
56
|
-
const script = async () => {
|
|
57
|
-
const response = await enquirer.prompt([
|
|
58
|
-
{
|
|
59
|
-
type: 'select',
|
|
60
|
-
name: 'language',
|
|
61
|
-
message: 'Which language do you want to use?',
|
|
62
|
-
choices: ['typescript', 'javascript']
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: 'select',
|
|
66
|
-
name: 'release',
|
|
67
|
-
message: 'What game type would you like to use?',
|
|
68
|
-
choices: ['stable', 'beta', 'preview'],
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
type: 'multiselect',
|
|
72
|
-
name: 'packages',
|
|
73
|
-
message: 'Which packages would you like to add?',
|
|
74
|
-
choices: [
|
|
75
|
-
...constants.packages.modules,
|
|
76
|
-
...constants.packages.plugins
|
|
77
|
-
],
|
|
78
|
-
validate: input => input.length > 0 || 'At least one package is required'
|
|
79
|
-
}
|
|
80
|
-
]);
|
|
81
|
-
return response;
|
|
82
|
-
};
|
|
83
|
-
const confirm = async (options) => {
|
|
84
|
-
const response = await enquirer.prompt({
|
|
85
|
-
type: "confirm",
|
|
86
|
-
name: "confirmed",
|
|
87
|
-
message: options.message,
|
|
88
|
-
initial: options.default ?? true
|
|
89
|
-
});
|
|
90
|
-
return response;
|
|
91
|
-
};
|
|
92
|
-
export default { extension, api, info, script, confirm };
|
package/out/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import pc from "picocolors";
|
|
3
|
-
import { getDependency } from "@mcbepack/common";
|
|
4
|
-
import prompt from "../prompt";
|
|
5
|
-
export async function collectProjectInfo() {
|
|
6
|
-
console.log(pc.bold("Please provide project information\n"));
|
|
7
|
-
const { extensions } = await prompt.extension();
|
|
8
|
-
const { name, description, author, minimumEngineVersion } = await prompt.info();
|
|
9
|
-
const uuids = {
|
|
10
|
-
behavior: uuidv4(),
|
|
11
|
-
resource: uuidv4(),
|
|
12
|
-
scriptModule: uuidv4(),
|
|
13
|
-
};
|
|
14
|
-
const config = {
|
|
15
|
-
name,
|
|
16
|
-
description,
|
|
17
|
-
author,
|
|
18
|
-
minimumEngineVersion,
|
|
19
|
-
extensions,
|
|
20
|
-
uuids,
|
|
21
|
-
};
|
|
22
|
-
if (extensions.includes("behavior")) {
|
|
23
|
-
const { api } = await prompt.api();
|
|
24
|
-
if (api) {
|
|
25
|
-
const { language, release, packages } = await prompt.script();
|
|
26
|
-
console.log(pc.dim("\nFetching dependencies..."));
|
|
27
|
-
const dependencies = await Promise.all(packages.map(async (packageName) => {
|
|
28
|
-
const dep = await getDependency(packageName, release);
|
|
29
|
-
return {
|
|
30
|
-
packageName: dep.packageName,
|
|
31
|
-
version: dep.version,
|
|
32
|
-
fullVersion: dep.fullVersion,
|
|
33
|
-
};
|
|
34
|
-
}));
|
|
35
|
-
config.script = {
|
|
36
|
-
enabled: true,
|
|
37
|
-
language,
|
|
38
|
-
release,
|
|
39
|
-
packages,
|
|
40
|
-
dependencies,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
config.script = {
|
|
45
|
-
enabled: false,
|
|
46
|
-
language: "javascript",
|
|
47
|
-
release: "",
|
|
48
|
-
packages: [],
|
|
49
|
-
dependencies: [],
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return config;
|
|
54
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import pc from "picocolors";
|
|
4
|
-
export function createFiles(files) {
|
|
5
|
-
console.log(`\nCreating ${files.length} files...\n`);
|
|
6
|
-
for (const file of files) {
|
|
7
|
-
try {
|
|
8
|
-
const dir = path.dirname(file.path);
|
|
9
|
-
if (!fs.existsSync(dir)) {
|
|
10
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
11
|
-
}
|
|
12
|
-
if (file.type === "copy" && file.source) {
|
|
13
|
-
fs.copyFileSync(file.source, file.path);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
fs.writeFileSync(file.path, file.content);
|
|
17
|
-
}
|
|
18
|
-
console.log(` ${pc.green("✓")} ${path.relative(process.cwd(), file.path)}`);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
console.error(` ${pc.red("✗")} ${path.relative(process.cwd(), file.path)}`);
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function previewFiles(files, projectName) {
|
|
27
|
-
console.log(`\nFiles to be created in ${pc.cyan(projectName)}:\n`);
|
|
28
|
-
const projectRoot = path.join(process.cwd(), projectName);
|
|
29
|
-
const tree = buildFileTree(files, projectRoot);
|
|
30
|
-
printTree(tree);
|
|
31
|
-
}
|
|
32
|
-
function buildFileTree(files, projectRoot) {
|
|
33
|
-
const root = {
|
|
34
|
-
name: path.basename(projectRoot),
|
|
35
|
-
type: "directory",
|
|
36
|
-
children: new Map(),
|
|
37
|
-
};
|
|
38
|
-
for (const file of files) {
|
|
39
|
-
const relativePath = path.relative(projectRoot, file.path);
|
|
40
|
-
const parts = relativePath.split(path.sep);
|
|
41
|
-
let current = root;
|
|
42
|
-
for (let i = 0; i < parts.length; i++) {
|
|
43
|
-
const part = parts[i];
|
|
44
|
-
const isLast = i === parts.length - 1;
|
|
45
|
-
if (!current.children) {
|
|
46
|
-
current.children = new Map();
|
|
47
|
-
}
|
|
48
|
-
if (!current.children.has(part)) {
|
|
49
|
-
current.children.set(part, {
|
|
50
|
-
name: part,
|
|
51
|
-
type: isLast ? "file" : "directory",
|
|
52
|
-
children: isLast ? undefined : new Map(),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
current = current.children.get(part);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return root;
|
|
59
|
-
}
|
|
60
|
-
function printTree(node, prefix = "", isLast = true) {
|
|
61
|
-
const connector = isLast ? "└── " : "├── ";
|
|
62
|
-
if (prefix === "") {
|
|
63
|
-
console.log(` ${pc.cyan(node.name)}/`);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const displayName = node.type === "directory" ? `${pc.cyan(node.name)}/` : node.name;
|
|
67
|
-
console.log(` ${prefix}${connector}${displayName}`);
|
|
68
|
-
}
|
|
69
|
-
if (node.children) {
|
|
70
|
-
const children = Array.from(node.children.values());
|
|
71
|
-
children.forEach((child, index) => {
|
|
72
|
-
const isLastChild = index === children.length - 1;
|
|
73
|
-
const newPrefix = prefix + (isLast ? " " : "│ ");
|
|
74
|
-
printTree(child, newPrefix, isLastChild);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { constants } from "@mcbepack/common";
|
|
4
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
-
const __dirname = path.dirname(__filename);
|
|
6
|
-
export function generateFileList(config) {
|
|
7
|
-
const files = [];
|
|
8
|
-
const projectRoot = path.join(process.cwd(), config.name);
|
|
9
|
-
const templatesDir = path.join(__dirname, "..", "..", "templates");
|
|
10
|
-
const baseManifest = {
|
|
11
|
-
format_version: 2,
|
|
12
|
-
header: {
|
|
13
|
-
name: config.name,
|
|
14
|
-
description: config.description,
|
|
15
|
-
uuid: "",
|
|
16
|
-
version: [1, 0, 0],
|
|
17
|
-
min_engine_version: config.minimumEngineVersion.split('.').map(Number),
|
|
18
|
-
},
|
|
19
|
-
metadata: {
|
|
20
|
-
authors: config.author.split(',').map(a => a.trim()),
|
|
21
|
-
generated_with: {
|
|
22
|
-
"create-mcbepack": [1, 0, 0],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
files.push({
|
|
27
|
-
path: path.join(projectRoot, "README.md"),
|
|
28
|
-
content: "",
|
|
29
|
-
type: "copy",
|
|
30
|
-
source: path.join(templatesDir, "README.md"),
|
|
31
|
-
});
|
|
32
|
-
if (config.extensions.includes("behavior")) {
|
|
33
|
-
const bpRoot = path.join(projectRoot, "src", "behavior_pack");
|
|
34
|
-
files.push({
|
|
35
|
-
path: path.join(bpRoot, "pack_icon.png"),
|
|
36
|
-
content: "",
|
|
37
|
-
type: "copy",
|
|
38
|
-
source: path.join(templatesDir, "pack_icon.png"),
|
|
39
|
-
});
|
|
40
|
-
const bpManifest = {
|
|
41
|
-
...baseManifest,
|
|
42
|
-
header: {
|
|
43
|
-
...baseManifest.header,
|
|
44
|
-
uuid: config.uuids.behavior,
|
|
45
|
-
},
|
|
46
|
-
capabilities: ['script_eval'],
|
|
47
|
-
modules: [],
|
|
48
|
-
dependencies: [],
|
|
49
|
-
};
|
|
50
|
-
if (config.script?.enabled) {
|
|
51
|
-
bpManifest.modules = [
|
|
52
|
-
{
|
|
53
|
-
type: "script",
|
|
54
|
-
language: "javascript",
|
|
55
|
-
entry: "scripts/index.js",
|
|
56
|
-
uuid: config.uuids.scriptModule,
|
|
57
|
-
version: [1, 0, 0],
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
bpManifest.dependencies = [
|
|
61
|
-
...config.script.dependencies
|
|
62
|
-
.filter(dep => !constants.packages.plugins.includes(dep.packageName))
|
|
63
|
-
.map(dep => ({
|
|
64
|
-
module_name: dep.packageName,
|
|
65
|
-
version: dep.version,
|
|
66
|
-
})),
|
|
67
|
-
];
|
|
68
|
-
if (config.extensions.includes("resource")) {
|
|
69
|
-
bpManifest.dependencies.push({
|
|
70
|
-
uuid: config.uuids.resource,
|
|
71
|
-
version: [1, 0, 0],
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
files.push({
|
|
75
|
-
path: path.join(projectRoot, ".env.local"),
|
|
76
|
-
content: "",
|
|
77
|
-
type: "copy",
|
|
78
|
-
source: path.join(templatesDir, ".env.local.txt"),
|
|
79
|
-
});
|
|
80
|
-
files.push({
|
|
81
|
-
path: path.join(projectRoot, ".gitignore"),
|
|
82
|
-
content: "",
|
|
83
|
-
type: "copy",
|
|
84
|
-
source: path.join(templatesDir, ".gitignore.txt"),
|
|
85
|
-
});
|
|
86
|
-
const packageJson = {
|
|
87
|
-
name: config.name,
|
|
88
|
-
scripts: {
|
|
89
|
-
dev: "mcbepack dev",
|
|
90
|
-
"build:zip": "mcbepack build -o zip",
|
|
91
|
-
"build:mcpack": "mcbepack build -o mcpack",
|
|
92
|
-
"build:addon": "mcbepack build -o addon",
|
|
93
|
-
"update:stable": "mcbepack update -t stable",
|
|
94
|
-
"update:beta": "mcbepack update -t beta",
|
|
95
|
-
"update:preview": "mcbepack update -t preview",
|
|
96
|
-
},
|
|
97
|
-
devDependencies: Object.fromEntries(config.script.dependencies.map(dep => [dep.packageName, dep.fullVersion])),
|
|
98
|
-
peerDependencies: {
|
|
99
|
-
"@mcbepack/cli": "latest",
|
|
100
|
-
"@mcbepack/api": "latest",
|
|
101
|
-
...(config.script.language === "typescript" ? { "typescript": "latest" } : {})
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
files.push({
|
|
105
|
-
path: path.join(projectRoot, "package.json"),
|
|
106
|
-
content: JSON.stringify(packageJson, null, 2),
|
|
107
|
-
type: "file",
|
|
108
|
-
});
|
|
109
|
-
const scriptsDir = path.join(projectRoot, "scripts");
|
|
110
|
-
if (config.script.language === "typescript") {
|
|
111
|
-
files.push({
|
|
112
|
-
path: path.join(scriptsDir, "index.ts"),
|
|
113
|
-
content: "console.log('Hello World!');",
|
|
114
|
-
type: "file",
|
|
115
|
-
});
|
|
116
|
-
files.push({
|
|
117
|
-
path: path.join(projectRoot, "tsconfig.json"),
|
|
118
|
-
content: "",
|
|
119
|
-
type: "copy",
|
|
120
|
-
source: path.join(templatesDir, "tsconfig.json"),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
files.push({
|
|
125
|
-
path: path.join(scriptsDir, "index.js"),
|
|
126
|
-
content: "console.log('Hello World!');",
|
|
127
|
-
type: "file",
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
files.push({
|
|
132
|
-
path: path.join(bpRoot, "manifest.json"),
|
|
133
|
-
content: JSON.stringify(bpManifest, null, 2),
|
|
134
|
-
type: "file",
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (config.extensions.includes("resource")) {
|
|
138
|
-
const rpRoot = path.join(projectRoot, "src", "resource_pack");
|
|
139
|
-
files.push({
|
|
140
|
-
path: path.join(rpRoot, "pack_icon.png"),
|
|
141
|
-
content: "",
|
|
142
|
-
type: "copy",
|
|
143
|
-
source: path.join(templatesDir, "pack_icon.png"),
|
|
144
|
-
});
|
|
145
|
-
const rpManifest = {
|
|
146
|
-
...baseManifest,
|
|
147
|
-
header: {
|
|
148
|
-
...baseManifest.header,
|
|
149
|
-
uuid: config.uuids.resource,
|
|
150
|
-
},
|
|
151
|
-
modules: [
|
|
152
|
-
{
|
|
153
|
-
type: "resources",
|
|
154
|
-
uuid: crypto.randomUUID(),
|
|
155
|
-
version: [1, 0, 0],
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
dependencies: [],
|
|
159
|
-
};
|
|
160
|
-
if (config.extensions.includes("behavior")) {
|
|
161
|
-
rpManifest.dependencies = [
|
|
162
|
-
{
|
|
163
|
-
uuid: config.uuids.behavior,
|
|
164
|
-
version: [1, 0, 0],
|
|
165
|
-
}
|
|
166
|
-
];
|
|
167
|
-
}
|
|
168
|
-
files.push({
|
|
169
|
-
path: path.join(rpRoot, "manifest.json"),
|
|
170
|
-
content: JSON.stringify(rpManifest, null, 2),
|
|
171
|
-
type: "file",
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (!config.script?.enabled) {
|
|
175
|
-
files.push({
|
|
176
|
-
path: path.join(projectRoot, "package.json"),
|
|
177
|
-
content: JSON.stringify({
|
|
178
|
-
scripts: {
|
|
179
|
-
"build:zip": "mcbepack build -o zip",
|
|
180
|
-
"build:mcpack": "mcbepack build -o mcpack",
|
|
181
|
-
"build:addon": "mcbepack build -o addon",
|
|
182
|
-
},
|
|
183
|
-
peerDependencies: {
|
|
184
|
-
"@mcbepack/cli": "latest"
|
|
185
|
-
}
|
|
186
|
-
}, null, 2),
|
|
187
|
-
type: "file",
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return files;
|
|
191
|
-
}
|
package/templates/README.md
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
This is a **MCBEPACK** project bootstrapped with [`create-mcbepack`](https://npmjs.com/package/create-mcbepack)
|
|
2
|
-
|
|
3
|
-
## Getting Started
|
|
4
|
-
|
|
5
|
-
First, install dependencies:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun install
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Then, run the development server:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
bun run dev
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
You can start editing your addon by modifying files in the `src` directory. The development server will automatically watch for changes and sync them to your Minecraft development folder.
|
|
18
|
-
|
|
19
|
-
## Available Commands
|
|
20
|
-
|
|
21
|
-
### For general development
|
|
22
|
-
|
|
23
|
-
- **`bun run build:zip`** - Build the addon as a .zip file
|
|
24
|
-
- **`bun run build:mcpack`** - Build the addon as a .mcpack file
|
|
25
|
-
- **`bun run build:addon`** - Build the addon as a .mcaddon file
|
|
26
|
-
|
|
27
|
-
### For script development
|
|
28
|
-
|
|
29
|
-
- **`bun run dev`** - Start development server with file watching
|
|
30
|
-
- **`bun run update:stable`** - Update the addon to the latest stable version
|
|
31
|
-
- **`bun run update:beta`** - Update the addon to the latest beta version
|
|
32
|
-
- **`bun run update:preview`** - Update the addon to the latest preview version
|
|
33
|
-
|
|
34
|
-
## Development
|
|
35
|
-
|
|
36
|
-
Edit your addon code in the `scripts` directory. The development server will automatically:
|
|
37
|
-
|
|
38
|
-
- Compile TypeScript/JavaScript code
|
|
39
|
-
- Sync changes to the Minecraft development folder
|
|
40
|
-
- Watch for file changes and rebuild automatically
|
|
41
|
-
|
|
42
|
-
### Configuration
|
|
43
|
-
|
|
44
|
-
Update `.env.local` to configure your Minecraft installation paths:
|
|
45
|
-
|
|
46
|
-
```env
|
|
47
|
-
BASE_PATH="C:\Users\YourName\AppData\Roaming\Minecraft Bedrock\Users\Shared\games\com.mojang"
|
|
48
|
-
RESOURCE_PATH="development_resource_packs"
|
|
49
|
-
BEHAVIOR_PATH="development_behavior_packs"
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Learn More
|
|
53
|
-
|
|
54
|
-
To learn more about MCBEPACK, take a look at the following resources:
|
|
55
|
-
|
|
56
|
-
- [MCBEPACK Documentation](https://mcbepack.roverdosh.studio) - learn about MCBEPACK features and API
|
|
57
|
-
- [MCBEPACK GitHub Repository](https://github.com/posroe/create-mcbepack) - your feedback and contributions are welcome!
|