create-mbler 0.0.1-beta

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RuanhoR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ require("../dist/main.mjs").cli()
package/dist/main.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ type I18nKey = 'InputCreateAt' | 'Name' | 'Description' | 'McVersion' | 'Need' | 'PackageManager';
2
+ declare const LanguageList: readonly ["zh", "en"];
3
+ type Language = (typeof LanguageList)[number];
4
+ declare const LanguageMap: {
5
+ zh: {
6
+ InputCreateAt: string;
7
+ Name: string;
8
+ Need: string;
9
+ McVersion: string;
10
+ Description: string;
11
+ PackageManager: string;
12
+ };
13
+ en: {
14
+ InputCreateAt: string;
15
+ Need: string;
16
+ Description: string;
17
+ McVersion: string;
18
+ Name: string;
19
+ PackageManager: string;
20
+ };
21
+ };
22
+ declare function getI18n(key: I18nKey, language: Language): string;
23
+
24
+ declare const cli: () => void;
25
+
26
+ export { LanguageList, LanguageMap, cli, getI18n };
27
+ export type { I18nKey, Language };
package/dist/main.mjs ADDED
@@ -0,0 +1,236 @@
1
+ import { Command, Argument } from 'commander';
2
+ import inpurer from 'inquirer';
3
+ import { stdout } from 'node:process';
4
+ import path from 'node:path';
5
+ import { spawn } from 'node:child_process';
6
+ import { mkdir, cp, writeFile, stat } from 'node:fs/promises';
7
+
8
+ const LanguageList = ['zh', 'en'];
9
+ const LanguageMap = {
10
+ zh: {
11
+ InputCreateAt: '创建在哪呢?',
12
+ Name: '项目名称',
13
+ Need: '需要什么?',
14
+ McVersion: '依赖的 mc 版本(像 1.21.100 )?',
15
+ Description: '项目描述?',
16
+ PackageManager: '使用哪个包管理器?',
17
+ },
18
+ en: {
19
+ InputCreateAt: 'Create mbler project at ...?',
20
+ Need: 'Need?',
21
+ Description: 'Project description?',
22
+ McVersion: 'Need mcbe version(like 1.21.100)?',
23
+ Name: 'Project name? ',
24
+ PackageManager: 'Which package manager to use?',
25
+ },
26
+ };
27
+ function getI18n(key, language) {
28
+ return LanguageMap[language][key];
29
+ }
30
+
31
+ function showText(etxt) {
32
+ stdout.write(etxt + '\n');
33
+ }
34
+ function verifyType(obj, typeMapping) {
35
+ for (const key in typeMapping) {
36
+ const expected = typeMapping[key];
37
+ const val = obj[key];
38
+ if (typeof val !== expected)
39
+ return false;
40
+ }
41
+ return true;
42
+ }
43
+
44
+ function spawnCmd(cmd, args, cwd) {
45
+ return new Promise((resolve, reject) => {
46
+ const child = spawn(cmd, args, { cwd, stdio: 'inherit', shell: true });
47
+ child.on('close', (code) => {
48
+ if (code === 0)
49
+ resolve();
50
+ else
51
+ reject(new Error(`${cmd} exited with code ${code}`));
52
+ });
53
+ child.on('error', reject);
54
+ });
55
+ }
56
+ async function fileExists(f) {
57
+ try {
58
+ await stat(path.resolve(f));
59
+ return true;
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ }
65
+ async function findTemplate(language) {
66
+ const d = path.join('template', language);
67
+ if (await fileExists(path.join(import.meta.dirname, '../', d))) {
68
+ return path.join(import.meta.dirname, '../', d);
69
+ }
70
+ if (await fileExists(path.join(import.meta.dirname, '../../', d))) {
71
+ return path.join(import.meta.dirname, '../../', d);
72
+ }
73
+ throw new Error("Can't find template");
74
+ }
75
+ function mcVersionToGameTest(mcVersion) {
76
+ const map = {
77
+ '1.21.100': '2.0.0',
78
+ '1.21.120': '2.0.0',
79
+ };
80
+ return map[mcVersion] || '2.0.0';
81
+ }
82
+ async function initProject(inputOpt) {
83
+ const dir = path.resolve(inputOpt.createAt);
84
+ const isMcx = inputOpt.Language === 'mcx';
85
+ await mkdir(dir, { recursive: true });
86
+ const templatePath = await findTemplate(inputOpt.Language);
87
+ await cp(templatePath, dir, { recursive: true, force: true });
88
+ const packageJson = {
89
+ name: inputOpt.Name,
90
+ description: inputOpt.Description,
91
+ version: '0.0.1',
92
+ packageManager: inputOpt.PackageManager,
93
+ engines: { node: '>=18.0.0' },
94
+ scripts: {
95
+ dev: 'mbler watch',
96
+ build: 'mcx-tsc && BUILD_MODULE=release mbler build',
97
+ 'dev-build': 'mbler build',
98
+ },
99
+ type: 'module',
100
+ dependencies: {
101
+ '@minecraft/server': mcVersionToGameTest(inputOpt.McVersion),
102
+ },
103
+ devDependencies: {
104
+ mbler: '0.2.4-rc.6',
105
+ },
106
+ };
107
+ if (isMcx) {
108
+ packageJson.dependencies['@mbler/mcx'] = '0.0.3-alpha.r1';
109
+ packageJson.devDependencies['@mbler/mcx-core'] = '0.0.8-rc.4';
110
+ }
111
+ await writeFile(path.join(dir, 'package.json'), JSON.stringify(packageJson, null, 2) + '\n');
112
+ const ui = inputOpt.OtherModule.includes('ui');
113
+ const beta = inputOpt.OtherModule.includes('beta-api');
114
+ const mblerConfig = `import { defineConfig } from "mbler"
115
+ export default defineConfig({
116
+ name: '${inputOpt.Name}',
117
+ description: '${inputOpt.Description}',
118
+ mcVersion: '${inputOpt.McVersion}',
119
+ version: '0.0.1',
120
+ minify: false,
121
+ script: { main: 'index.ts', ui: ${ui}, lang: '${inputOpt.Language}', UseBeta: ${beta} },
122
+ build: { bundle: true, cache: "file" },
123
+ outdir: { resources: './dist/res', behavior: './dist/dep', dist: './dist.mcaddon' }
124
+ });\n`;
125
+ await writeFile(path.join(dir, 'mbler.config.js'), mblerConfig);
126
+ if (inputOpt.Language !== 'js') {
127
+ const tsconfig = {
128
+ compilerOptions: {
129
+ module: 'esnext',
130
+ noEmit: true,
131
+ target: 'esnext',
132
+ sourceMap: true,
133
+ declaration: false,
134
+ strict: true,
135
+ moduleResolution: 'bundler',
136
+ allowImportingTsExtensions: true,
137
+ isolatedModules: true,
138
+ moduleDetection: 'force',
139
+ skipLibCheck: true,
140
+ types: ['mbler/client'],
141
+ },
142
+ include: ['./behavior/scripts/**/*'],
143
+ };
144
+ await writeFile(path.join(dir, 'tsconfig.json'), JSON.stringify(tsconfig, null, 2) + '\n');
145
+ }
146
+ await writeFile(path.join(dir, '.gitignore'), 'node_modules\ndist\ndist.mcaddon\n.mbler\ncache\n');
147
+ if (inputOpt.OtherModule.includes('init git')) {
148
+ try {
149
+ await spawnCmd('git', ['init'], dir);
150
+ }
151
+ catch { }
152
+ }
153
+ if (inputOpt.OtherModule.includes('init dep')) {
154
+ try {
155
+ await spawnCmd(inputOpt.PackageManager, ['install'], dir);
156
+ }
157
+ catch { }
158
+ }
159
+ }
160
+
161
+ function throwErr(text) {
162
+ showText('×: ERR: ' + text);
163
+ process.exit(1);
164
+ }
165
+ const program = new Command('create-mbler');
166
+ program
167
+ .name('mbler')
168
+ .description('Create mbler project')
169
+ .addArgument(new Argument('[dir]', 'Where to create mbler project'))
170
+ .option('-l, --language <value>', 'Define Create mbler tool language', 'en')
171
+ .action(async function (...argv) {
172
+ const language = this.getOptionValue('language');
173
+ if (!LanguageList.includes(language)) {
174
+ throwErr('Invaild Language, should such as ' + JSON.stringify(LanguageList));
175
+ }
176
+ const inputResult = (await inpurer.prompt([
177
+ {
178
+ type: 'input',
179
+ default: argv[0] || './',
180
+ message: getI18n('InputCreateAt', language),
181
+ name: 'createAt',
182
+ },
183
+ {
184
+ type: 'input',
185
+ name: 'Name',
186
+ message: getI18n('Name', language),
187
+ },
188
+ {
189
+ type: 'input',
190
+ name: 'Description',
191
+ message: getI18n('Description', language),
192
+ default: 'The package is a ...',
193
+ },
194
+ {
195
+ type: 'input',
196
+ name: 'McVersion',
197
+ message: getI18n('McVersion', language),
198
+ default: '1.21.100',
199
+ },
200
+ {
201
+ type: 'checkbox',
202
+ name: 'OtherModule',
203
+ message: getI18n('Need', language),
204
+ choices: ['ui', 'beta-api', 'init git', 'init dep'],
205
+ },
206
+ {
207
+ type: 'select',
208
+ name: 'Language',
209
+ message: getI18n('Need', language),
210
+ choices: ['mcx', 'js', 'ts'],
211
+ },
212
+ {
213
+ type: 'select',
214
+ name: 'PackageManager',
215
+ message: getI18n('PackageManager', language),
216
+ choices: ['npm', 'pnpm'],
217
+ },
218
+ ]));
219
+ if (!verifyType(inputResult, {
220
+ createAt: 'string',
221
+ Description: 'string',
222
+ Language: 'string',
223
+ McVersion: 'string',
224
+ PackageManager: 'string',
225
+ Name: 'string',
226
+ OtherModule: 'object',
227
+ })) {
228
+ throwErr('basic type error');
229
+ }
230
+ await initProject(inputResult);
231
+ });
232
+ const cli = () => {
233
+ program.parse();
234
+ };
235
+
236
+ export { LanguageList, LanguageMap, cli, getI18n };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "create-mbler",
3
+ "description": "Create a mbler with cli",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "ruanhor",
7
+ "email": "root@ruanhor.dpdns.org",
8
+ "url": "https://github.com/RuanhoR"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/RuanhoR/mcx-core",
13
+ "directory": "packages/create-mbler"
14
+ },
15
+ "engines": {
16
+ "node": ">= 20"
17
+ },
18
+ "version": "0.0.1-beta",
19
+ "dependencies": {
20
+ "commander": "14.0.3",
21
+ "inquirer": "13.4.3"
22
+ },
23
+ "bin": {
24
+ "create-mbler": "./bin/create-mbler.js"
25
+ },
26
+ "exports": {
27
+ "./cli": "./bin/cli.js",
28
+ ".": "./dist/main.mjs"
29
+ },
30
+ "main": "./dist/main.js",
31
+ "scripts": {
32
+ "build": "rollup -c && rm -rf ./dist/_tmp",
33
+ "dev": "rollup -c -w",
34
+ "lint": "eslint src --ext .js,.ts",
35
+ "lint:fix": "eslint src --ext .js,.ts --fix"
36
+ }
37
+ }
@@ -0,0 +1,40 @@
1
+ import path from "node:path"
2
+ import ts from "@rollup/plugin-typescript"
3
+ import resolve from "@rollup/plugin-node-resolve"
4
+ import commjs from "@rollup/plugin-commonjs"
5
+ import json from "@rollup/plugin-json"
6
+ import dts from "rollup-plugin-dts"
7
+ import terser from "@rollup/plugin-terser"
8
+ export default [
9
+ {
10
+ input: path.resolve("src/main.ts"),
11
+ plugins: [
12
+ ts(),
13
+ resolve(),
14
+ commjs(),
15
+ json(),
16
+ // terser()
17
+ ],
18
+ external: [
19
+ "inquirer",
20
+ "commander"
21
+ ],
22
+ output: [
23
+ {
24
+ file: "./dist/main.mjs",
25
+ format: "esm"
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ input: path.resolve("src/main.ts"),
31
+ plugins: [
32
+ dts()
33
+ ],
34
+ output: [
35
+ {
36
+ file: "./dist/main.d.ts"
37
+ }
38
+ ]
39
+ }
40
+ ]
package/src/i18n.ts ADDED
@@ -0,0 +1,34 @@
1
+ export type I18nKey =
2
+ | 'InputCreateAt'
3
+ | 'Name'
4
+ | 'Description'
5
+ | 'McVersion'
6
+ | 'Need'
7
+ | 'PackageManager'
8
+ export const LanguageList = ['zh', 'en'] as const
9
+ export type Language = (typeof LanguageList)[number]
10
+ export const LanguageMap = {
11
+ zh: {
12
+ InputCreateAt: '创建在哪呢?',
13
+ Name: '项目名称',
14
+ Need: '需要什么?',
15
+ McVersion: '依赖的 mc 版本(像 1.21.100 )?',
16
+ Description: '项目描述?',
17
+ PackageManager: '使用哪个包管理器?',
18
+ },
19
+ en: {
20
+ InputCreateAt: 'Create mbler project at ...?',
21
+ Need: 'Need?',
22
+ Description: 'Project description?',
23
+ McVersion: 'Need mcbe version(like 1.21.100)?',
24
+ Name: 'Project name? ',
25
+ PackageManager: 'Which package manager to use?',
26
+ },
27
+ } satisfies {
28
+ [key in Language]: {
29
+ [key in I18nKey]: string
30
+ }
31
+ }
32
+ export function getI18n(key: I18nKey, language: Language): string {
33
+ return LanguageMap[language][key]
34
+ }
package/src/init.ts ADDED
@@ -0,0 +1,125 @@
1
+ import path from 'node:path'
2
+ import { spawn } from 'node:child_process'
3
+ import { InputResult } from './types'
4
+ import { stat, mkdir, cp, writeFile } from 'node:fs/promises'
5
+
6
+ function spawnCmd(cmd: string, args: string[], cwd: string): Promise<void> {
7
+ return new Promise((resolve, reject) => {
8
+ const child = spawn(cmd, args, { cwd, stdio: 'inherit', shell: true })
9
+ child.on('close', (code) => {
10
+ if (code === 0) resolve()
11
+ else reject(new Error(`${cmd} exited with code ${code}`))
12
+ })
13
+ child.on('error', reject)
14
+ })
15
+ }
16
+
17
+ export async function fileExists(f: string) {
18
+ try {
19
+ await stat(path.resolve(f))
20
+ return true
21
+ } catch {
22
+ return false
23
+ }
24
+ }
25
+
26
+ async function findTemplate(language: InputResult['Language']) {
27
+ const d = path.join('template', language)
28
+ if (await fileExists(path.join(import.meta.dirname, '../', d))) {
29
+ return path.join(import.meta.dirname, '../', d)
30
+ }
31
+ if (await fileExists(path.join(import.meta.dirname, '../../', d))) {
32
+ return path.join(import.meta.dirname, '../../', d)
33
+ }
34
+ throw new Error("Can't find template")
35
+ }
36
+
37
+ function mcVersionToGameTest(mcVersion: string): string {
38
+ const map: Record<string, string> = {
39
+ '1.21.100': '2.0.0',
40
+ '1.21.120': '2.0.0',
41
+ }
42
+ return map[mcVersion] || '2.0.0'
43
+ }
44
+
45
+ export async function initProject(inputOpt: InputResult) {
46
+ const dir = path.resolve(inputOpt.createAt)
47
+ const isMcx = inputOpt.Language === 'mcx'
48
+ await mkdir(dir, { recursive: true })
49
+ const templatePath = await findTemplate(inputOpt.Language)
50
+ await cp(templatePath, dir, { recursive: true, force: true })
51
+ const packageJson: Record<string, any> = {
52
+ name: inputOpt.Name,
53
+ description: inputOpt.Description,
54
+ version: '0.0.1',
55
+ packageManager: inputOpt.PackageManager,
56
+ engines: { node: '>=18.0.0' },
57
+ scripts: {
58
+ dev: 'mbler watch',
59
+ build: 'mcx-tsc && BUILD_MODULE=release mbler build',
60
+ 'dev-build': 'mbler build',
61
+ },
62
+ type: 'module',
63
+ dependencies: {
64
+ '@minecraft/server': mcVersionToGameTest(inputOpt.McVersion),
65
+ },
66
+ devDependencies: {
67
+ mbler: '0.2.4-rc.6',
68
+ },
69
+ }
70
+ if (isMcx) {
71
+ packageJson.dependencies['@mbler/mcx'] = '0.0.3-alpha.r1'
72
+ packageJson.devDependencies['@mbler/mcx-core'] = '0.0.8-rc.4'
73
+ }
74
+ await writeFile(
75
+ path.join(dir, 'package.json'),
76
+ JSON.stringify(packageJson, null, 2) + '\n',
77
+ )
78
+ const ui = inputOpt.OtherModule.includes('ui')
79
+ const beta = inputOpt.OtherModule.includes('beta-api')
80
+ const mblerConfig = `import { defineConfig } from "mbler"
81
+ export default defineConfig({
82
+ name: '${inputOpt.Name}',
83
+ description: '${inputOpt.Description}',
84
+ mcVersion: '${inputOpt.McVersion}',
85
+ version: '0.0.1',
86
+ minify: false,
87
+ script: { main: 'index.ts', ui: ${ui}, lang: '${inputOpt.Language}', UseBeta: ${beta} },
88
+ build: { bundle: true, cache: "file" },
89
+ outdir: { resources: './dist/res', behavior: './dist/dep', dist: './dist.mcaddon' }
90
+ });\n`
91
+ await writeFile(path.join(dir, 'mbler.config.js'), mblerConfig)
92
+ if (inputOpt.Language !== 'js') {
93
+ const tsconfig = {
94
+ compilerOptions: {
95
+ module: 'esnext',
96
+ noEmit: true,
97
+ target: 'esnext',
98
+ sourceMap: true,
99
+ declaration: false,
100
+ strict: true,
101
+ moduleResolution: 'bundler',
102
+ allowImportingTsExtensions: true,
103
+ isolatedModules: true,
104
+ moduleDetection: 'force',
105
+ skipLibCheck: true,
106
+ types: ['mbler/client'],
107
+ },
108
+ include: ['./behavior/scripts/**/*'],
109
+ }
110
+ await writeFile(
111
+ path.join(dir, 'tsconfig.json'),
112
+ JSON.stringify(tsconfig, null, 2) + '\n',
113
+ )
114
+ }
115
+ await writeFile(
116
+ path.join(dir, '.gitignore'),
117
+ 'node_modules\ndist\ndist.mcaddon\n.mbler\ncache\n',
118
+ )
119
+ if (inputOpt.OtherModule.includes('init git')) {
120
+ try { await spawnCmd('git', ['init'], dir) } catch {}
121
+ }
122
+ if (inputOpt.OtherModule.includes('init dep')) {
123
+ try { await spawnCmd(inputOpt.PackageManager, ['install'], dir) } catch {}
124
+ }
125
+ }
package/src/main.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { Argument, Command } from 'commander'
2
+ import inpurer from 'inquirer'
3
+ import { getI18n, LanguageList } from './i18n'
4
+ import { showText, verifyType } from './utils'
5
+ import { InputResult } from './types'
6
+ import { initProject } from './init'
7
+ function throwErr(text: string) {
8
+ showText('×: ERR: ' + text)
9
+ process.exit(1)
10
+ }
11
+ const program = new Command('create-mbler')
12
+ program
13
+ .name('mbler')
14
+ .description('Create mbler project')
15
+ .addArgument(new Argument('[dir]', 'Where to create mbler project'))
16
+ .option('-l, --language <value>', 'Define Create mbler tool language', 'en')
17
+ .action(async function (...argv) {
18
+ const language = this.getOptionValue('language')
19
+ if (!LanguageList.includes(language)) {
20
+ throwErr(
21
+ 'Invaild Language, should such as ' + JSON.stringify(LanguageList),
22
+ )
23
+ }
24
+ const inputResult = (await inpurer.prompt([
25
+ {
26
+ type: 'input',
27
+ default: argv[0] || './',
28
+ message: getI18n('InputCreateAt', language),
29
+ name: 'createAt',
30
+ },
31
+ {
32
+ type: 'input',
33
+ name: 'Name',
34
+ message: getI18n('Name', language),
35
+ },
36
+ {
37
+ type: 'input',
38
+ name: 'Description',
39
+ message: getI18n('Description', language),
40
+ default: 'The package is a ...',
41
+ },
42
+ {
43
+ type: 'input',
44
+ name: 'McVersion',
45
+ message: getI18n('McVersion', language),
46
+ default: '1.21.100',
47
+ },
48
+ {
49
+ type: 'checkbox',
50
+ name: 'OtherModule',
51
+ message: getI18n('Need', language),
52
+ choices: ['ui', 'beta-api', 'init git', 'init dep'],
53
+ },
54
+ {
55
+ type: 'select',
56
+ name: 'Language',
57
+ message: getI18n('Need', language),
58
+ choices: ['mcx', 'js', 'ts'],
59
+ },
60
+ {
61
+ type: 'select',
62
+ name: 'PackageManager',
63
+ message: getI18n('PackageManager', language),
64
+ choices: ['npm', 'pnpm'],
65
+ },
66
+ ])) as InputResult
67
+ if (
68
+ !verifyType(inputResult, {
69
+ createAt: 'string',
70
+ Description: 'string',
71
+ Language: 'string',
72
+ McVersion: 'string',
73
+ PackageManager: 'string',
74
+ Name: 'string',
75
+ OtherModule: 'object',
76
+ })
77
+ ) {
78
+ throwErr('basic type error')
79
+ }
80
+ await initProject(inputResult)
81
+ })
82
+ export const cli = () => {
83
+ program.parse()
84
+ }
85
+ export * from './i18n'
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ export type PackageManager = 'npm' | 'pnpm'
2
+
3
+ export interface InputResult {
4
+ createAt: string
5
+ OtherModule: ('ui' | 'beta-api' | 'init git' | 'init dep')[]
6
+ McVersion: string
7
+ Description: string
8
+ Name: string
9
+ Language: 'mcx' | 'js' | 'ts'
10
+ PackageManager: PackageManager
11
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { stdout } from 'node:process'
2
+
3
+ export function showText(etxt: string) {
4
+ stdout.write(etxt + '\n')
5
+ }
6
+ export interface JSTypeMap {
7
+ string: string
8
+ boolean: boolean
9
+ bigint: bigint
10
+ symbol: symbol
11
+ object: object
12
+ number: number
13
+ undefined: undefined
14
+ null: null
15
+ }
16
+ export function verifyType<
17
+ T extends object,
18
+ U extends Record<keyof T, keyof JSTypeMap>,
19
+ >(obj: T, typeMapping: U): obj is T & { [P in keyof U]: JSTypeMap[U[P]] } {
20
+ for (const key in typeMapping) {
21
+ const expected = typeMapping[key]
22
+ const val = (obj as any)[key]
23
+ if (typeof val !== expected) return false
24
+ }
25
+ return true
26
+ }
@@ -0,0 +1 @@
1
+ console.log('Hello world in minecraft')
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ import { Event } from "@mbler/mcx";
3
+ import event from "./event/event.mcx";
4
+ (event as unknown as Event).subscribe();
5
+ </script>
@@ -0,0 +1,19 @@
1
+ <Component>
2
+ <items>
3
+ <item id="test.json">item</item>
4
+ </items>
5
+ </Component>
6
+ <script lang="ts">
7
+ import { ItemComponent } from "@mbler/mcx-core";
8
+ import { component } from "./../config/config.json"
9
+ const item = new ItemComponent({
10
+ id: "demo:item",
11
+ name: "AAA",
12
+ format: component.format,
13
+ components: {}
14
+ });
15
+ item.setName("Demo")
16
+ export {
17
+ item,
18
+ }
19
+ </script>
@@ -0,0 +1,5 @@
1
+ {
2
+ "component": {
3
+ "format": "1.21.100"
4
+ }
5
+ }
@@ -0,0 +1,8 @@
1
+ <Event @before tick=100>
2
+ EntityHitBlock = default
3
+ <!-- 100 tick only use one --></Event>
4
+ <script lang="ts">
5
+ export default function Handler(event: any) {
6
+ console.log(`${event.entity.typeId} break block`)
7
+ }
8
+ </script>
@@ -0,0 +1,10 @@
1
+ <Event @after>
2
+ McxExtendsBy = ./event$1.mcx
3
+ PlayerJoin = eventHandler
4
+ </Event>
5
+ <script lang="ts">
6
+ import { add } from "./test.ts";
7
+ export const eventHandler = function(event: any) {
8
+ event.player.sendMessage("欢迎进入游戏 " + add(1, 10))
9
+ }
10
+ </script>
@@ -0,0 +1,3 @@
1
+ export function add(a: number, b: number) {
2
+ return a + b
3
+ }
@@ -0,0 +1,5 @@
1
+ import App from "./app.mcx";
2
+ import "./component/ComponentTest.mcx"
3
+ import { createApp } from "@mbler/mcx";
4
+ import { world } from "@minecraft/server";
5
+ createApp(App).mount(world);
@@ -0,0 +1,2 @@
1
+ pack.name=mcx template
2
+ pack.description=mcx template
@@ -0,0 +1,2 @@
1
+ pack.name=MCX模板包
2
+ pack.description=§l模板包
@@ -0,0 +1 @@
1
+ console.log("ts in minecraft")
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./src",
4
+ "outDir": "./dist",
5
+ "module": "esnext",
6
+ "target": "esnext",
7
+ "lib": [
8
+ "esnext"
9
+ ],
10
+ "types": [
11
+ "node"
12
+ ],
13
+ "sourceMap": false,
14
+ "declaration": true,
15
+ "declarationMap": false,
16
+ "noUncheckedIndexedAccess": true,
17
+ "exactOptionalPropertyTypes": true,
18
+ "allowJs": true,
19
+ "strict": true,
20
+ "moduleResolution": "bundler",
21
+ "verbatimModuleSyntax": false,
22
+ "isolatedModules": true,
23
+ "noUncheckedSideEffectImports": true,
24
+ "moduleDetection": "force",
25
+ "noEmit": true,
26
+ "skipLibCheck": true,
27
+ "declarationDir": "./dist/_tmp"
28
+ },
29
+ "include": [
30
+ "./src/**/*"
31
+ ]
32
+ }