ms-vite-plugin 1.0.4 → 1.0.6

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/cli.js CHANGED
@@ -40,6 +40,7 @@ const path = __importStar(require("path"));
40
40
  const build_1 = require("./build");
41
41
  const fsExtra = __importStar(require("fs-extra"));
42
42
  const project_1 = require("./project");
43
+ const packager_1 = require("./packager");
43
44
  const ws_manager_1 = require("./ws-manager");
44
45
  /**
45
46
  * WS 状态持久化文件路径(用于跨进程查询 ws-status)
@@ -108,6 +109,26 @@ async function buildCommand(options) {
108
109
  process.exit(1);
109
110
  }
110
111
  }
112
+ /**
113
+ * package 命令处理函数(生产构建 + 加密)
114
+ * @returns 请求完成后退出
115
+ * @example
116
+ * ms package
117
+ */
118
+ async function packageCommand() {
119
+ try {
120
+ const workspacePath = process.cwd();
121
+ console.log(`🔍 检查项目目录: ${workspacePath}`);
122
+ await ensureValidKuaiJSProject(workspacePath);
123
+ console.log("📦 开始打包生产构建并加密 bundle...");
124
+ const encryptedPath = await (0, packager_1.packageProject)(workspacePath);
125
+ console.log(`✅ 打包完成: ${encryptedPath}`);
126
+ }
127
+ catch (error) {
128
+ console.error("❌ 打包失败:", error instanceof Error ? error.message : error);
129
+ process.exit(1);
130
+ }
131
+ }
111
132
  /**
112
133
  * run 命令处理函数
113
134
  * @param options 命令选项
@@ -120,7 +141,6 @@ async function runCommand(options) {
120
141
  const workspacePath = process.cwd();
121
142
  await ensureValidKuaiJSProject(workspacePath);
122
143
  await (0, project_1.runOnDevice)(options);
123
- console.log("✅ 运行请求已发送");
124
144
  }
125
145
  catch (error) {
126
146
  console.error("❌ 运行失败:", error instanceof Error ? error.message : error);
@@ -139,7 +159,6 @@ async function runUICommand(options) {
139
159
  const workspacePath = process.cwd();
140
160
  await ensureValidKuaiJSProject(workspacePath);
141
161
  await (0, project_1.runUIOnDevice)(options);
142
- console.log("✅ UI 预览请求已发送");
143
162
  }
144
163
  catch (error) {
145
164
  console.error("❌ UI 预览失败:", error instanceof Error ? error.message : error);
@@ -158,7 +177,6 @@ async function stopCommand(options) {
158
177
  const workspacePath = process.cwd();
159
178
  await ensureValidKuaiJSProject(workspacePath);
160
179
  await (0, project_1.stopOnDevice)(options);
161
- console.log("✅ 停止请求已发送");
162
180
  }
163
181
  catch (error) {
164
182
  console.error("❌ 停止失败:", error instanceof Error ? error.message : error);
@@ -271,7 +289,14 @@ async function wsStopCommand() {
271
289
  async function wsStatusCommand() {
272
290
  await ensureValidKuaiJSProject(process.cwd());
273
291
  if (!(await fsExtra.pathExists(WS_PID_FILE))) {
274
- console.log("服务状态: stopped");
292
+ console.log(JSON.stringify({
293
+ status: "stopped",
294
+ running: false,
295
+ pid: null,
296
+ address: null,
297
+ connected: false,
298
+ clientIp: null,
299
+ }));
275
300
  return;
276
301
  }
277
302
  const info = await fsExtra.readJSON(WS_PID_FILE);
@@ -291,15 +316,24 @@ async function wsStatusCommand() {
291
316
  }
292
317
  if (!running) {
293
318
  await fsExtra.remove(WS_PID_FILE);
294
- console.log("服务状态: stopped");
319
+ console.log(JSON.stringify({
320
+ status: "stopped",
321
+ running: false,
322
+ pid: null,
323
+ address: null,
324
+ connected: false,
325
+ clientIp: null,
326
+ }));
295
327
  return;
296
328
  }
297
- console.log(`服务状态: running (pid=${pid})`);
298
- console.log(`WS 地址: ${address}`);
299
- console.log(`连接状态: ${connected ? "connected" : "disconnected"}`);
300
- if (connected) {
301
- console.log(`设备IP: ${clientIp || "unknown"}`);
302
- }
329
+ console.log(JSON.stringify({
330
+ status: "running",
331
+ running: true,
332
+ pid,
333
+ address,
334
+ connected,
335
+ clientIp: connected ? clientIp || "unknown" : null,
336
+ }));
303
337
  }
304
338
  /**
305
339
  * 生成顶层 help 的详细命令参数说明
@@ -335,6 +369,11 @@ commander_1.program
335
369
  .description("构建 快点JS 项目")
336
370
  .option("-d, --dev", "开发模式构建 (包含 source map)")
337
371
  .action(buildCommand);
372
+ // 打包命令
373
+ commander_1.program
374
+ .command("package")
375
+ .description("生产构建并加密 ms.msbundle")
376
+ .action(packageCommand);
338
377
  // 运行命令
339
378
  commander_1.program
340
379
  .command("run")
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 执行 package 流程(生产构建 + bundle 加密)
3
+ * @param workspacePath 当前工作目录(项目根目录)
4
+ * @returns 返回加密产物 enc.msbundle 的绝对路径
5
+ * @example
6
+ * const output = await packageProject(process.cwd())
7
+ */
8
+ export declare function packageProject(workspacePath: string): Promise<string>;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.packageProject = packageProject;
37
+ const child_process_1 = require("child_process");
38
+ const fsExtra = __importStar(require("fs-extra"));
39
+ const path = __importStar(require("path"));
40
+ const util_1 = require("util");
41
+ const build_1 = require("./build");
42
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
43
+ /**
44
+ * 打包相关常量
45
+ */
46
+ const PACKAGE_CONSTANTS = {
47
+ /** 加密超时时间(毫秒) */
48
+ ENCRYPT_TIMEOUT: 30000,
49
+ /** 明文 bundle 文件名 */
50
+ BUNDLE_NAME: "ms.msbundle",
51
+ /** 加密后 bundle 文件名 */
52
+ ENCRYPTED_BUNDLE_NAME: "enc.msbundle",
53
+ };
54
+ /**
55
+ * 获取当前插件根目录
56
+ * @returns 插件根目录绝对路径
57
+ * @example
58
+ * const root = getPluginRoot()
59
+ */
60
+ function getPluginRoot() {
61
+ return path.resolve(__dirname, "..");
62
+ }
63
+ /**
64
+ * 获取对应系统的加密工具路径
65
+ * @returns 加密工具绝对路径
66
+ * @example
67
+ * const encryptorPath = getEncryptorPath()
68
+ */
69
+ function getEncryptorPath() {
70
+ const platform = process.platform;
71
+ const arch = process.arch;
72
+ let binSubPath;
73
+ if (platform === "darwin") {
74
+ binSubPath = path.join("bin", "mac", "ms-bundle-enc");
75
+ }
76
+ else if (platform === "win32" && arch === "x64") {
77
+ binSubPath = path.join("bin", "win", "ms-bundle-enc.exe");
78
+ }
79
+ else {
80
+ throw new Error(`不支持的系统平台: ${platform}-${arch}`);
81
+ }
82
+ return path.join(getPluginRoot(), binSubPath);
83
+ }
84
+ /**
85
+ * 加密构建产物 bundle 文件
86
+ * @param bundlePath 明文 bundle 绝对路径
87
+ * @returns 返回加密后的 bundle 绝对路径
88
+ * @example
89
+ * const encryptedPath = await encryptBundle("/tmp/dist/ms.msbundle")
90
+ */
91
+ async function encryptBundle(bundlePath) {
92
+ const encryptorPath = getEncryptorPath();
93
+ if (!(await fsExtra.pathExists(encryptorPath))) {
94
+ throw new Error(`未找到加密工具: ${encryptorPath}`);
95
+ }
96
+ const isWindows = process.platform === "win32";
97
+ if (!isWindows) {
98
+ await fsExtra.chmod(encryptorPath, 0o755);
99
+ }
100
+ await execFileAsync(encryptorPath, [bundlePath], {
101
+ cwd: path.dirname(bundlePath),
102
+ timeout: PACKAGE_CONSTANTS.ENCRYPT_TIMEOUT,
103
+ });
104
+ const encryptedPath = path.join(path.dirname(bundlePath), PACKAGE_CONSTANTS.ENCRYPTED_BUNDLE_NAME);
105
+ if (!(await fsExtra.pathExists(encryptedPath))) {
106
+ throw new Error("加密工具未生成 enc.msbundle 文件");
107
+ }
108
+ await fsExtra.remove(bundlePath);
109
+ return encryptedPath;
110
+ }
111
+ /**
112
+ * 执行 package 流程(生产构建 + bundle 加密)
113
+ * @param workspacePath 当前工作目录(项目根目录)
114
+ * @returns 返回加密产物 enc.msbundle 的绝对路径
115
+ * @example
116
+ * const output = await packageProject(process.cwd())
117
+ */
118
+ async function packageProject(workspacePath) {
119
+ await (0, build_1.buildAll)(false, workspacePath);
120
+ const bundlePath = path.join(workspacePath, "dist", PACKAGE_CONSTANTS.BUNDLE_NAME);
121
+ if (!(await fsExtra.pathExists(bundlePath))) {
122
+ throw new Error(`构建失败,未找到 ${PACKAGE_CONSTANTS.BUNDLE_NAME} 文件`);
123
+ }
124
+ return encryptBundle(bundlePath);
125
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {