mvframe 1.0.58 → 1.0.60

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/vendor.js CHANGED
@@ -9316,7 +9316,7 @@ const _i = {
9316
9316
  }, xi = {
9317
9317
  name: "Matt Avias Frame",
9318
9318
  copyright: "©2026",
9319
- version: "1.0.58",
9319
+ version: "1.0.60",
9320
9320
  author: "Matt Avias",
9321
9321
  date: "2026-02-26",
9322
9322
  /** 默认语言 key,与 `$getLang`、localStorage `lang` 一致;业务在 app.use(mvframe, { config }) 里覆盖 */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mvframe",
3
3
  "packageManager": "yarn@4.4.1",
4
- "version": "1.0.58",
4
+ "version": "1.0.60",
5
5
  "author": "matt avis",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -39,14 +39,17 @@
39
39
  "build": "node scripts/prebuild.js",
40
40
  "install-cursor-skill": "node scripts/install-cursor-skill.js",
41
41
  "scaffold-app": "node scripts/scaffold-app.js",
42
- "gen-icon": "node scripts/gen-iconfont-ant-names.js"
42
+ "gen-icon": "node scripts/gen-iconfont-ant-names.js",
43
+ "b": "node scripts/build-host.js"
43
44
  },
44
45
  "bin": {
45
46
  "mvframe-init-app": "scripts/scaffold-app.js",
46
- "mvframe-install-cursor-skill": "scripts/install-cursor-skill.js"
47
+ "mvframe-install-cursor-skill": "scripts/install-cursor-skill.js",
48
+ "mvframe-b": "scripts/build-host.js"
47
49
  },
48
50
  "files": [
49
51
  "dist/*",
52
+ "scripts/build-host.js",
50
53
  "scripts/install-cursor-skill.js",
51
54
  "scripts/scaffold-app.js",
52
55
  ".cursor/skills/mvframe-app-init",
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 宿主 Vite 工程:打包后写入与 mstar 一致的 `serve.json`(SPA 回写 index.html)。
4
+ *
5
+ * 在宿主 `package.json` 中增加:`"b": "mvframe-b"`
6
+ * 然后执行 `yarn b` 或 `yarn b [outDir] [-t|-p]`。
7
+ *
8
+ * - 默认:--mode development,输出目录 `dev`
9
+ * - `-t`:--mode test,输出 `test`
10
+ * - `-p`:--mode production,输出 `pre`(Vite 环境为 production,对应 .env.production*)
11
+ * - 一个位置参数:自定义输出目录(与 -t / -p 同用时,以 -t / -p 为准)
12
+ */
13
+ const { spawnSync } = require("child_process");
14
+ const fs = require("fs");
15
+ const path = require("path");
16
+ const SERVE_JSON = `{
17
+ "rewrites": [{
18
+ "source": "**",
19
+ "destination": "/index.html"
20
+ }]
21
+ }`;
22
+
23
+ function parseArgs(argv) {
24
+ const args = argv.slice(2);
25
+ let mode = "development";
26
+ let outDir = "dev";
27
+ let preset = false;
28
+ const positional = [];
29
+
30
+ for (const a of args) {
31
+ if (a === "-t") {
32
+ mode = "test";
33
+ outDir = "test";
34
+ preset = true;
35
+ } else if (a === "-p") {
36
+ mode = "production";
37
+ outDir = "pre";
38
+ preset = true;
39
+ } else if (a.startsWith("-")) {
40
+ console.error(`[mvframe-b] 未知参数: ${a}`);
41
+ process.exit(1);
42
+ } else {
43
+ positional.push(a);
44
+ }
45
+ }
46
+
47
+ if (positional.length > 1) {
48
+ console.error(
49
+ "[mvframe-b] 用法: yarn b [outDir] [-t|-p]\n 默认: outDir=dev, mode=development; -t: test/test; -p: pre/production",
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ if (positional.length === 1) {
55
+ if (preset) {
56
+ console.warn(
57
+ `[mvframe-b] 已使用 -t/-p,忽略输出目录参数 "${positional[0]}",实际输出: ${outDir}`,
58
+ );
59
+ } else {
60
+ outDir = positional[0];
61
+ }
62
+ }
63
+
64
+ return { mode, outDir };
65
+ }
66
+
67
+ /**
68
+ * 使用磁盘路径定位 Vite CLI(Vite 7+ 的 `exports` 会阻止 `require.resolve("vite/bin/...")`)。
69
+ */
70
+ function resolveViteCli(cwd) {
71
+ const vpkg = path.join(cwd, "node_modules", "vite", "package.json");
72
+ if (fs.existsSync(vpkg)) {
73
+ const p = require(vpkg);
74
+ const b = p.bin;
75
+ const bin = typeof b === "string" ? b : b && b.vite;
76
+ if (bin) {
77
+ const cli = path.join(path.dirname(vpkg), bin);
78
+ if (fs.existsSync(cli)) {
79
+ return cli;
80
+ }
81
+ }
82
+ }
83
+ throw new Error(
84
+ "未在宿主项目找到可执行的 Vite(请在工程 devDependencies 中安装 `vite` 后再执行 `yarn b` 或 `mvframe-b`)",
85
+ );
86
+ }
87
+
88
+ function main() {
89
+ const cwd = process.cwd();
90
+ const { mode, outDir } = parseArgs(process.argv);
91
+ const viteEntry = resolveViteCli(cwd);
92
+ const env = { ...process.env, NODE_ENV: "production" };
93
+ const child = spawnSync(
94
+ process.execPath,
95
+ [viteEntry, "build", "--outDir", outDir, "--mode", mode],
96
+ { stdio: "inherit", cwd, env, shell: false },
97
+ );
98
+ if (child.status !== 0) {
99
+ process.exit(child.status === null ? 1 : child.status);
100
+ }
101
+ const outAbs = path.resolve(cwd, outDir);
102
+ fs.mkdirSync(outAbs, { recursive: true });
103
+ const servePath = path.join(outAbs, "serve.json");
104
+ fs.writeFileSync(servePath, `${SERVE_JSON}\n`, "utf8");
105
+ console.log(`[mvframe-b] 已写入 ${path.relative(cwd, servePath)}`);
106
+ }
107
+
108
+ main();