@mbler/mcx-core 0.1.2-rc.1 → 0.1.2-rc.11
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 +40 -5
- package/dist/chunk-6Ep1yQYe.js +16 -0
- package/dist/index.d.ts +11 -15
- package/dist/index.js +13660 -310
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
# mcx
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# @mbler/mcx-core
|
|
2
|
+
|
|
3
|
+
The MCX DSL compiler — the core of the MCX ecosystem. Compiles `.mcx` source files into MCBE-compatible JSON components, UI forms, and event systems.
|
|
4
|
+
|
|
5
|
+
## Pipeline
|
|
6
|
+
|
|
7
|
+
`.mcx` file → **parser** → AST → **transform** (Babel) → compiled JS → MCBE JSON
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **MCX Parser** — Parses `.mcx` source into a tokenized AST (`tag`, `prop`)
|
|
12
|
+
- **Transform Pipeline** — Detects file type (`event`, `ui`, `component`, `app`) and generates compiled Babel AST
|
|
13
|
+
- **Component Compilation** — Runs component scripts in a sandboxed VM, generates MCBE JSON, executes file edit operations
|
|
14
|
+
- **CJS Transform** — Rewrites ESM imports to CommonJS `require()` for VM execution
|
|
15
|
+
- **Image Assets** — Compiles PNG, JPG, SVG, GIF image references into MCBE texture assets
|
|
16
|
+
- **Rollup/Rolldown Plugin** — Seamless `.mcx` file resolution and transformation in your build pipeline
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add -D @mbler/mcx-core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Add the plugin to your Rollup or Rolldown config:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { rollupPlugin } from '@mbler/mcx-core'
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
plugins: [rollupPlugin({ moduleDir: './modules', tsconfigPath: './tsconfig.json' })],
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For full documentation, visit the **[Docs](https://mbler-docs.ruanhor.dpdns.org/guide/mcx)**.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
15
|
+
//#endregion
|
|
16
|
+
export { __exportAll as n, __require as r, __commonJSMin as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import * as Parser from "@babel/parser";
|
|
1
2
|
import * as t from "@babel/types";
|
|
2
3
|
import { ArgumentPlaceholder, CallExpression, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, Expression, ImportDeclaration, SpreadElement } from "@babel/types";
|
|
3
|
-
import
|
|
4
|
-
import { BlockComponent, BlockComponent as BlockComponent$1, EnchantableSlot, EntityComponent, EntityComponent as EntityComponent$1, EntityComponentOptions, EntityJson, FoodEffect, GIFImageComponent, GIFImageComponent as GIFImageComponent$1, ItemComponent, ItemComponent as ItemComponent$1, ItemComponentOptions, ItemJson, JPGImageComponent, JPGImageComponent as JPGImageComponent$1, PNGImageComponent, PNGImageComponent as PNGImageComponent$1, ParticleType, Rarity, SVGImageComponent, SVGImageComponent as SVGImageComponent$1, SoundEvent } from "@mbler/mcx-component";
|
|
4
|
+
import { BlockComponent, BlockComponent as BlockComponent$1, EnchantableSlot, EntityComponent, EntityComponent as EntityComponent$1, EntityComponentOptions, FoodEffect, GIFImageComponent, GIFImageComponent as GIFImageComponent$1, ItemComponent, ItemComponent as ItemComponent$1, ItemComponentOptions, JPGImageComponent, JPGImageComponent as JPGImageComponent$1, PNGImageComponent, PNGImageComponent as PNGImageComponent$1, ParticleType, Rarity, SVGImageComponent, SVGImageComponent as SVGImageComponent$1, SoundEvent } from "@mbler/mcx-component";
|
|
5
5
|
import { Plugin, TransformPluginContext } from "rollup";
|
|
6
6
|
import { CompileOpt, CompileOpt as CompileOpt$1 } from "@mbler/mcx-types";
|
|
7
7
|
import { Plugin as Plugin$1 } from "rolldown";
|
|
@@ -178,14 +178,10 @@ declare class McxAst {
|
|
|
178
178
|
private text;
|
|
179
179
|
private includeComments;
|
|
180
180
|
constructor(text: string, includeComments?: boolean);
|
|
181
|
-
private getAST;
|
|
182
|
-
get data(): ParsedTagNode[];
|
|
183
181
|
parseAST(): ParsedTagNode[];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* @returns 代码字符串
|
|
188
|
-
*/
|
|
182
|
+
private convertTemplateChild;
|
|
183
|
+
private convertVueElement;
|
|
184
|
+
private convertVueChildren;
|
|
189
185
|
static generateCode(node: ParsedTagNode): string;
|
|
190
186
|
}
|
|
191
187
|
//#endregion
|
|
@@ -207,7 +203,7 @@ declare class Utils {
|
|
|
207
203
|
static FileExist(path: string): Promise<boolean>;
|
|
208
204
|
static readFile(filePath: string, opt?: ReadFileOpt): Promise<object | string>;
|
|
209
205
|
static sleep(time: number): Promise<void>;
|
|
210
|
-
static TypeVerify<T extends Record<string,
|
|
206
|
+
static TypeVerify<T extends Record<string, unknown>, U extends TypeVerifyBody>(obj: T, types: U): obj is T & { [P in keyof U]: {
|
|
211
207
|
boolean: boolean;
|
|
212
208
|
number: number;
|
|
213
209
|
string: string;
|
|
@@ -263,7 +259,7 @@ declare const compileMCXFn: ((mcxCode: string) => MCXCompileData) & {
|
|
|
263
259
|
cache: Record<string, MCXCompileData>;
|
|
264
260
|
};
|
|
265
261
|
declare namespace types_d_exports {
|
|
266
|
-
export { BaseJson, DefineEntry, EnchantableSlot, EntityComponentOptions,
|
|
262
|
+
export { BaseJson, DefineEntry, EnchantableSlot, EntityComponentOptions, FileBindSource, FileEditExpression, FileEditOption, FilePoint, FoodEffect, ItemComponentOptions, ParticleType, Rarity, SoundEvent, createFileEdit };
|
|
267
263
|
}
|
|
268
264
|
interface FilePoint {
|
|
269
265
|
base: 'behavior' | 'resources' | 'root';
|
|
@@ -293,7 +289,7 @@ type FileEditOption = {
|
|
|
293
289
|
type: 'edit';
|
|
294
290
|
id?: string;
|
|
295
291
|
source: FilePoint | FileBindSource;
|
|
296
|
-
expression: FileEditExpression<
|
|
292
|
+
expression: FileEditExpression<Record<string, DefineEntry>>;
|
|
297
293
|
} | {
|
|
298
294
|
type: 'copy_assets';
|
|
299
295
|
id?: string;
|
|
@@ -353,7 +349,7 @@ declare function clearCachedOptions(): void;
|
|
|
353
349
|
* Resolve a FilePoint to an absolute path on disk.
|
|
354
350
|
*
|
|
355
351
|
* - `base: 'root'` is only allowed when the calling component originates from
|
|
356
|
-
* @mbler/mcx-
|
|
352
|
+
* @mbler/mcx-component (the `sourceIsMcxCore` flag). This prevents third-party
|
|
357
353
|
* components from reading arbitrary filesystem locations.
|
|
358
354
|
* - For `behavior` / `resources`, the file is resolved relative to the
|
|
359
355
|
* corresponding output directory. A path-traversal check ensures the resolved
|
|
@@ -365,7 +361,7 @@ declare function resolveFilePoint(point: FilePoint, ctx: transformCtx, sourceIsM
|
|
|
365
361
|
* Delegates to execEditInternal with a fresh limits counter.
|
|
366
362
|
*
|
|
367
363
|
* @param isMcxCoreSource - when true, the component originates from
|
|
368
|
-
* @mbler/mcx-
|
|
364
|
+
* @mbler/mcx-component and is exempt from file I/O limits and root base
|
|
369
365
|
* restrictions.
|
|
370
366
|
*/
|
|
371
367
|
declare function execEdit(option: BaseJson['_meta']['file_edit'], ctx: transformCtx, isMcxCoreSource?: boolean): Promise<void>;
|
|
@@ -388,7 +384,7 @@ declare function generateItemTextureJson(output: {
|
|
|
388
384
|
*
|
|
389
385
|
* Per-component restrictions (checked after VM execution):
|
|
390
386
|
* - path traversal guard on the output file point
|
|
391
|
-
* - root base: only allowed if the export came from @mbler/mcx-
|
|
387
|
+
* - root base: only allowed if the export came from @mbler/mcx-component
|
|
392
388
|
* - file write limit (≤5) and read limit (≤1): only enforced for
|
|
393
389
|
* non-mcx-core components
|
|
394
390
|
*/
|