mbler 0.2.7-rc.5 → 0.2.8
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/dist/build.d.ts +1 -1
- package/dist/build.esm.mjs +106 -69
- package/dist/build.esm.mjs.map +1 -1
- package/dist/build.js +108 -71
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.mjs +4 -11
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.js +4 -11
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/build.d.ts
CHANGED
package/dist/build.esm.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import * as mcxDef from "@mbler/mcx-core";
|
|
3
|
-
import minifyPlugin from "@rollup/plugin-terser";
|
|
4
3
|
import { watch as watch$1 } from "chokidar";
|
|
5
4
|
import * as fs$3 from "node:fs/promises";
|
|
6
5
|
import fs from "node:fs/promises";
|
|
@@ -11,9 +10,10 @@ import * as readline from "readline";
|
|
|
11
10
|
import * as fs$2 from "node:fs";
|
|
12
11
|
import fs$1 from "node:fs";
|
|
13
12
|
import os, { homedir, tmpdir } from "node:os";
|
|
14
|
-
import crypto from "node:crypto";
|
|
15
13
|
import { env } from "node:process";
|
|
16
14
|
import { styleText } from "node:util";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import crypto from "node:crypto";
|
|
17
17
|
import { createMCXLanguagePlugin } from "@mbler/mcx-server";
|
|
18
18
|
import { runTsc } from "@volar/typescript/lib/quickstart/runTsc.js";
|
|
19
19
|
//#region \0rolldown/runtime.js
|
|
@@ -48,7 +48,6 @@ const templateMblerConfig = {
|
|
|
48
48
|
version: "0.0.0",
|
|
49
49
|
mcVersion: "1.21.100",
|
|
50
50
|
script: { main: "" },
|
|
51
|
-
minify: false,
|
|
52
51
|
outdir: {
|
|
53
52
|
behavior: "",
|
|
54
53
|
resources: "",
|
|
@@ -68,19 +67,13 @@ const templateMblerConfig = {
|
|
|
68
67
|
//#endregion
|
|
69
68
|
//#region src/version.ts
|
|
70
69
|
var version_default = {
|
|
71
|
-
commit: `commit
|
|
70
|
+
commit: `commit f8f06b781506c12365e8227dadc3e09f8bbaef86
|
|
72
71
|
Author: ruanhor <3915264929@qq.com>
|
|
73
|
-
Date: Sat Jun
|
|
72
|
+
Date: Sat Jun 20 14:34:40 2026 +0800
|
|
74
73
|
|
|
75
|
-
refactor
|
|
76
|
-
|
|
77
|
-
- Add src/cli/command.ts with CommandDef, parseArgs, parseRawParams
|
|
78
|
-
- Refactor CLI dispatcher to use CommandDef-based dispatch
|
|
79
|
-
- Convert all 11 command handlers to declarative CommandDef format
|
|
80
|
-
- Fix parseParam to handle -flag=value correctly
|
|
81
|
-
- Add 63 new tests for CLI framework and publisher modules
|
|
74
|
+
refactor: replace @rollup/plugin-terser with custom minify plugins (oxc/terser/esbuild)
|
|
82
75
|
`,
|
|
83
|
-
version: "0.2.
|
|
76
|
+
version: "0.2.8"
|
|
84
77
|
};
|
|
85
78
|
//#endregion
|
|
86
79
|
//#region src/i18n/zh.ts
|
|
@@ -733,6 +726,91 @@ var BuildCacheManager = class {
|
|
|
733
726
|
}
|
|
734
727
|
};
|
|
735
728
|
//#endregion
|
|
729
|
+
//#region src/build/release.ts
|
|
730
|
+
function Release() {
|
|
731
|
+
const AdmZip = __require("adm-zip");
|
|
732
|
+
function createFullZip(dir) {
|
|
733
|
+
const zip = new AdmZip();
|
|
734
|
+
zip.addLocalFolder(dir);
|
|
735
|
+
return zip;
|
|
736
|
+
}
|
|
737
|
+
function createZipWithMoreFolder(dir) {
|
|
738
|
+
const zip = new AdmZip();
|
|
739
|
+
for (const folder of dir) zip.addLocalFolder(folder[0], folder[1]);
|
|
740
|
+
return zip;
|
|
741
|
+
}
|
|
742
|
+
return async function generateRelease(build) {
|
|
743
|
+
if (!build.outdirs) throw new Error("invalid Build");
|
|
744
|
+
if (env.BUILD_MODULE !== "release") return;
|
|
745
|
+
let zip;
|
|
746
|
+
if (build.module == "all") zip = createZipWithMoreFolder([[build.outdirs?.behavior, "behavior"], [build.outdirs?.resources, "resources"]]);
|
|
747
|
+
else if (build.module == "behavior") zip = createFullZip(build.outdirs?.behavior);
|
|
748
|
+
else zip = createFullZip(build.outdirs?.resources);
|
|
749
|
+
await zip.writeZipPromise(build.outdirs?.dist);
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
let releaseEmul = null;
|
|
753
|
+
const generateRelease = (...argv) => {
|
|
754
|
+
if (!releaseEmul) releaseEmul = Release();
|
|
755
|
+
return releaseEmul(...argv);
|
|
756
|
+
};
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/build/postgress.ts
|
|
759
|
+
var Postgress = class {
|
|
760
|
+
max;
|
|
761
|
+
constructor(max) {
|
|
762
|
+
this.max = max;
|
|
763
|
+
}
|
|
764
|
+
update(current) {
|
|
765
|
+
const percentage = Math.min(current, this.max) / this.max;
|
|
766
|
+
const barWidth = 30;
|
|
767
|
+
const filledWidth = Math.round(barWidth * percentage);
|
|
768
|
+
const emptyWidth = barWidth - filledWidth;
|
|
769
|
+
showText(`\n\u001B[1A\r[${`${styleText("green", "█".repeat(filledWidth))}${styleText("white", "█".repeat(emptyWidth))}`}] ${styleText("blue", `${Math.round(percentage * 100)}%`)} (${current}/${this.max})`, false);
|
|
770
|
+
if (current == this.max) showText("", true);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
//#endregion
|
|
774
|
+
//#region src/build/minify.ts
|
|
775
|
+
function resolvePackage(name, baseDir) {
|
|
776
|
+
const require = createRequire(path.join(baseDir, "noop.js"));
|
|
777
|
+
try {
|
|
778
|
+
return require.resolve(name, { paths: [baseDir] });
|
|
779
|
+
} catch {
|
|
780
|
+
throw new Error(`\`${name}\` is required for minification. Install it in your project:\n npm i -D ${name}\n pnpm add -D ${name}\n yarn add -D ${name}`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function terserPlugin(baseBuildDir) {
|
|
784
|
+
return {
|
|
785
|
+
name: "mbler:terser",
|
|
786
|
+
async renderChunk(code) {
|
|
787
|
+
const res = await (await import(pathToFileURL(resolvePackage("terser", baseBuildDir)).href)).minify(code, {
|
|
788
|
+
format: { comments: false },
|
|
789
|
+
compress: { unused: true }
|
|
790
|
+
});
|
|
791
|
+
return {
|
|
792
|
+
code: res.code,
|
|
793
|
+
map: res.map
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function esbuildPlugin(baseBuildDir) {
|
|
799
|
+
return {
|
|
800
|
+
name: "mbler:esbuild",
|
|
801
|
+
async renderChunk(code) {
|
|
802
|
+
const res = await (await import(pathToFileURL(resolvePackage("esbuild", baseBuildDir)).href)).transform(code, {
|
|
803
|
+
minify: true,
|
|
804
|
+
loader: "js"
|
|
805
|
+
});
|
|
806
|
+
return {
|
|
807
|
+
code: res.code,
|
|
808
|
+
map: res.map
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
//#endregion
|
|
736
814
|
//#region src/uuid/index.ts
|
|
737
815
|
/**
|
|
738
816
|
* @description To generate uuid
|
|
@@ -939,51 +1017,6 @@ async function generateManifest(config, type) {
|
|
|
939
1017
|
return manifest;
|
|
940
1018
|
}
|
|
941
1019
|
//#endregion
|
|
942
|
-
//#region src/build/release.ts
|
|
943
|
-
function Release() {
|
|
944
|
-
const AdmZip = __require("adm-zip");
|
|
945
|
-
function createFullZip(dir) {
|
|
946
|
-
const zip = new AdmZip();
|
|
947
|
-
zip.addLocalFolder(dir);
|
|
948
|
-
return zip;
|
|
949
|
-
}
|
|
950
|
-
function createZipWithMoreFolder(dir) {
|
|
951
|
-
const zip = new AdmZip();
|
|
952
|
-
for (const folder of dir) zip.addLocalFolder(folder[0], folder[1]);
|
|
953
|
-
return zip;
|
|
954
|
-
}
|
|
955
|
-
return async function generateRelease(build) {
|
|
956
|
-
if (!build.outdirs) throw new Error("invalid Build");
|
|
957
|
-
if (env.BUILD_MODULE !== "release") return;
|
|
958
|
-
let zip;
|
|
959
|
-
if (build.module == "all") zip = createZipWithMoreFolder([[build.outdirs?.behavior, "behavior"], [build.outdirs?.resources, "resources"]]);
|
|
960
|
-
else if (build.module == "behavior") zip = createFullZip(build.outdirs?.behavior);
|
|
961
|
-
else zip = createFullZip(build.outdirs?.resources);
|
|
962
|
-
await zip.writeZipPromise(build.outdirs?.dist);
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
let releaseEmul = null;
|
|
966
|
-
const generateRelease = (...argv) => {
|
|
967
|
-
if (!releaseEmul) releaseEmul = Release();
|
|
968
|
-
return releaseEmul(...argv);
|
|
969
|
-
};
|
|
970
|
-
//#endregion
|
|
971
|
-
//#region src/build/postgress.ts
|
|
972
|
-
var Postgress = class {
|
|
973
|
-
max;
|
|
974
|
-
constructor(max) {
|
|
975
|
-
this.max = max;
|
|
976
|
-
}
|
|
977
|
-
update(current) {
|
|
978
|
-
const percentage = Math.min(current, this.max) / this.max;
|
|
979
|
-
const barWidth = 30;
|
|
980
|
-
const filledWidth = Math.round(barWidth * percentage);
|
|
981
|
-
const emptyWidth = barWidth - filledWidth;
|
|
982
|
-
showText(`\n\u001B[1A\r[${`${styleText("green", "█".repeat(filledWidth))}${styleText("white", "█".repeat(emptyWidth))}`}] ${styleText("blue", `${Math.round(percentage * 100)}%`)} (${current}/${this.max})`, false);
|
|
983
|
-
if (current == this.max) showText("", true);
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
//#endregion
|
|
987
1020
|
//#region src/build/plugin-mcx-tsc.ts
|
|
988
1021
|
/**
|
|
989
1022
|
* 运行 MCX TypeScript 编译器
|
|
@@ -1154,11 +1187,13 @@ var Build = class {
|
|
|
1154
1187
|
if (path.extname(output) !== "js") output = output.slice(0, output.length - path.extname(output).length) + ".js";
|
|
1155
1188
|
if (this.buildConfig?.outputFilename) output = this.buildConfig.outputFilename;
|
|
1156
1189
|
const outputDir = this.buildConfig?.outputDir || "scripts";
|
|
1157
|
-
|
|
1190
|
+
const writeOptions = {
|
|
1158
1191
|
file: join(path.join(this.outdirs.behavior, outputDir), output),
|
|
1159
1192
|
format: "esm",
|
|
1160
1193
|
sourcemap: false
|
|
1161
|
-
}
|
|
1194
|
+
};
|
|
1195
|
+
if (this.currentConfig.minify === "oxc") writeOptions.minify = true;
|
|
1196
|
+
await rBuild.write(writeOptions);
|
|
1162
1197
|
} else {
|
|
1163
1198
|
const srcScriptDir = path.join(this.srcDirs.behavior, "scripts");
|
|
1164
1199
|
const outputDir = this.buildConfig?.outputDir || "scripts";
|
|
@@ -1198,10 +1233,10 @@ var Build = class {
|
|
|
1198
1233
|
const plugin = [];
|
|
1199
1234
|
const moduleDir = path.join(this.baseBuildDir, "node_modules");
|
|
1200
1235
|
if (!await FileExist(moduleDir)) throw new Error(`[build addon]: node_modules is not exist in project root: can't resolve node_modules for rollup: ${moduleDir}`);
|
|
1201
|
-
if (this.currentConfig.minify)
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
}
|
|
1236
|
+
if (this.currentConfig.minify) {
|
|
1237
|
+
if (this.currentConfig.minify === "terser") plugin.push(terserPlugin(this.baseBuildDir));
|
|
1238
|
+
else if (this.currentConfig.minify === "esbuild") plugin.push(esbuildPlugin(this.baseBuildDir));
|
|
1239
|
+
}
|
|
1205
1240
|
if (this.buildConfig?.rollupPlugins) plugin.push(...this.buildConfig.rollupPlugins);
|
|
1206
1241
|
if (this.currentConfig.script?.lang == "mcx") try {
|
|
1207
1242
|
const tsconfigPath = path.join(this.baseBuildDir, "tsconfig.json");
|
|
@@ -1268,6 +1303,12 @@ var Build = class {
|
|
|
1268
1303
|
if (path.extname(output) !== "js") output = output.slice(0, output.length - path.extname(output).length) + ".js";
|
|
1269
1304
|
if (this.buildConfig?.outputFilename) output = this.buildConfig.outputFilename;
|
|
1270
1305
|
const outputDir = this.buildConfig?.outputDir || "scripts";
|
|
1306
|
+
const outputOptions = {
|
|
1307
|
+
file: join(path.join(this.outdirs.behavior, outputDir), output),
|
|
1308
|
+
format: "esm",
|
|
1309
|
+
sourcemap: false
|
|
1310
|
+
};
|
|
1311
|
+
if (this.currentConfig.minify === "oxc") outputOptions.minify = true;
|
|
1271
1312
|
const rollupWatcher = watch$2({
|
|
1272
1313
|
input: path.join(this.srcDirs.behavior, "scripts", this.currentConfig?.script?.main || ""),
|
|
1273
1314
|
external: [
|
|
@@ -1277,11 +1318,7 @@ var Build = class {
|
|
|
1277
1318
|
],
|
|
1278
1319
|
plugins: this.rollupPlugin,
|
|
1279
1320
|
experimental: { ...this.cacheManager?.shouldUseIncrementalBuild() ? { incrementalBuild: true } : {} },
|
|
1280
|
-
output:
|
|
1281
|
-
file: join(path.join(this.outdirs.behavior, outputDir), output),
|
|
1282
|
-
format: "esm",
|
|
1283
|
-
sourcemap: false
|
|
1284
|
-
},
|
|
1321
|
+
output: outputOptions,
|
|
1285
1322
|
watch: {
|
|
1286
1323
|
clearScreen: false,
|
|
1287
1324
|
include: path.join(this.srcDirs.behavior, "scripts/**/*"),
|