ms-vite-plugin 1.0.4 → 1.0.5
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 +26 -3
- package/dist/packager.d.ts +8 -0
- package/dist/packager.js +125 -0
- package/package.json +1 -1
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);
|
|
@@ -335,6 +353,11 @@ commander_1.program
|
|
|
335
353
|
.description("构建 快点JS 项目")
|
|
336
354
|
.option("-d, --dev", "开发模式构建 (包含 source map)")
|
|
337
355
|
.action(buildCommand);
|
|
356
|
+
// 打包命令
|
|
357
|
+
commander_1.program
|
|
358
|
+
.command("package")
|
|
359
|
+
.description("生产构建并加密 ms.msbundle")
|
|
360
|
+
.action(packageCommand);
|
|
338
361
|
// 运行命令
|
|
339
362
|
commander_1.program
|
|
340
363
|
.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>;
|
package/dist/packager.js
ADDED
|
@@ -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
|
+
}
|