ms-vite-plugin 1.4.47 → 1.4.48

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.
Files changed (43) hide show
  1. package/dist/build.js +1 -292
  2. package/dist/cli.js +6 -1234
  3. package/dist/mcp/device-config.d.ts +0 -47
  4. package/dist/mcp/device-config.js +1 -183
  5. package/dist/mcp/device-log.d.ts +0 -8
  6. package/dist/mcp/device-log.js +3 -27
  7. package/dist/mcp/doc-tools.d.ts +0 -7
  8. package/dist/mcp/doc-tools.js +2 -39
  9. package/dist/mcp/docs-service.d.ts +0 -13
  10. package/dist/mcp/docs-service.js +1 -63
  11. package/dist/mcp/httpapi-docs-service.d.ts +0 -31
  12. package/dist/mcp/httpapi-docs-service.js +1 -122
  13. package/dist/mcp/httpapi-tools.d.ts +0 -7
  14. package/dist/mcp/httpapi-tools.js +4 -222
  15. package/dist/mcp/image-tools.d.ts +0 -62
  16. package/dist/mcp/image-tools.js +8 -607
  17. package/dist/mcp/ocr-tools.d.ts +0 -25
  18. package/dist/mcp/ocr-tools.js +5 -413
  19. package/dist/mcp/project.d.ts +0 -14
  20. package/dist/mcp/project.js +1 -74
  21. package/dist/mcp/runtime-tools.d.ts +0 -7
  22. package/dist/mcp/runtime-tools.js +11 -308
  23. package/dist/mcp/tool-utils.d.ts +0 -40
  24. package/dist/mcp/tool-utils.js +1 -81
  25. package/dist/mcp/tools.d.ts +0 -12
  26. package/dist/mcp/tools.js +1 -31
  27. package/dist/mcp/types.d.ts +0 -12
  28. package/dist/mcp/types.js +1 -11
  29. package/dist/mcp-server.js +1 -85
  30. package/dist/packager.d.ts +0 -7
  31. package/dist/packager.js +1 -125
  32. package/dist/project.d.ts +0 -61
  33. package/dist/project.js +1 -619
  34. package/dist/stopGuardPlugin.d.ts +0 -6
  35. package/dist/stopGuardPlugin.js +1 -165
  36. package/dist/version.d.ts +0 -10
  37. package/dist/version.js +1 -63
  38. package/dist/ws-manager.d.ts +0 -95
  39. package/dist/ws-manager.js +1 -392
  40. package/docs/api/image.md +249 -25
  41. package/docs/apicn/image.md +245 -19
  42. package/docs/apipython/image.md +238 -18
  43. package/package.json +3 -2
package/dist/build.js CHANGED
@@ -1,292 +1 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.buildAll = void 0;
40
- const archiver_1 = __importDefault(require("archiver"));
41
- const child_process_1 = require("child_process");
42
- const fsExtra = __importStar(require("fs-extra"));
43
- const os = __importStar(require("os"));
44
- const path = __importStar(require("path"));
45
- const stopGuardPlugin_1 = require("./stopGuardPlugin");
46
- const vite_plugin_bundle_obfuscator_1 = __importDefault(require("vite-plugin-bundle-obfuscator"));
47
- /**
48
- * 压缩目录
49
- * @param source 源目录路径
50
- * @param out 输出文件路径
51
- * @returns 压缩完成后的 Promise
52
- */
53
- async function zipDirectory(source, out) {
54
- const archive = (0, archiver_1.default)("zip", { zlib: { level: 9 } });
55
- const stream = fsExtra.createWriteStream(out);
56
- return new Promise((resolve, reject) => {
57
- archive
58
- .directory(source, false)
59
- .on("error", (err) => reject(err))
60
- .pipe(stream);
61
- stream.on("close", () => resolve());
62
- archive.finalize();
63
- });
64
- }
65
- /**
66
- * 查找入口文件:main.js/main.ts 和所有以 _thread 结尾的 JS/TS 文件
67
- * @param src 源目录路径
68
- * @param baseDir 基础目录路径,用于计算相对路径
69
- * @returns 返回入口文件的相对路径列表
70
- */
71
- async function findEntryFiles(src, baseDir) {
72
- const result = [];
73
- async function walk(dir) {
74
- const entries = await fsExtra.readdir(dir, { withFileTypes: true });
75
- for (const entry of entries) {
76
- const fullPath = path.resolve(dir, entry.name);
77
- if (entry.isDirectory()) {
78
- await walk(fullPath);
79
- }
80
- else if (entry.isFile()) {
81
- // 查找 main.js/main.ts 或 _thread.js/_thread.ts 文件
82
- if (/^main\.(js|ts)$/.test(entry.name) ||
83
- /_thread\.(js|ts)$/.test(entry.name)) {
84
- result.push(path.relative(baseDir, fullPath));
85
- }
86
- }
87
- }
88
- }
89
- await walk(src);
90
- return result;
91
- }
92
- /**
93
- * 检测系统是否存在 Python 3.14
94
- * - 依次尝试 python3.14、python3、py -3.14(Windows)
95
- * - 返回检测结果与版本字符串
96
- */
97
- function detectPython314() {
98
- const candidates = [
99
- {
100
- cmd: path.join(os.homedir(), ".KuaiJSDevloper", "python", "python.exe"),
101
- args: ["--version"],
102
- },
103
- {
104
- cmd: path.join(os.homedir(), ".KuaiJSDevloper", "python", "bin", "python"),
105
- args: ["--version"],
106
- },
107
- { cmd: "python", args: ["--version"] },
108
- { cmd: "python3", args: ["--version"] },
109
- { cmd: "python3.14", args: ["--version"] },
110
- ];
111
- for (const c of candidates) {
112
- try {
113
- const r = (0, child_process_1.spawnSync)(c.cmd, c.args, { encoding: "utf8" });
114
- const out = (r.stdout || r.stderr || "").trim();
115
- if (out && /Python\s+3\.14(\.\d+)?/i.test(out)) {
116
- return { ok: true, path: c.cmd, version: out };
117
- }
118
- }
119
- catch { }
120
- }
121
- return { ok: false };
122
- }
123
- /**
124
- * 处理 Python 构建产物:
125
- * - 将所有 ".cpython-314.pyc" 重命名为 ".pyc"
126
- * - 将 __pycache__/name.cpython-314.pyc 移动到上级目录为 name.pyc
127
- * - 删除所有 ".py" 源文件
128
- */
129
- async function normalizePythonArtifacts(rootDir) {
130
- async function walk(dir) {
131
- const entries = await fsExtra.readdir(dir, { withFileTypes: true });
132
- for (const entry of entries) {
133
- const full = path.join(dir, entry.name);
134
- if (entry.isDirectory()) {
135
- if (entry.name === "__pycache__") {
136
- const cacheEntries = await fsExtra.readdir(full, {
137
- withFileTypes: true,
138
- });
139
- for (const ce of cacheEntries) {
140
- const cacheFull = path.join(full, ce.name);
141
- if (ce.isFile() && ce.name.endsWith(".cpython-314.pyc")) {
142
- const parent = path.dirname(full);
143
- const base = ce.name.replace(/\.cpython-314\.pyc$/, ".pyc");
144
- const target = path.join(parent, base);
145
- await fsExtra.move(cacheFull, target, { overwrite: true });
146
- }
147
- }
148
- // 清理 __pycache__ 目录
149
- try {
150
- await fsExtra.remove(full);
151
- }
152
- catch { }
153
- }
154
- else {
155
- await walk(full);
156
- }
157
- }
158
- else if (entry.isFile()) {
159
- if (entry.name.endsWith(".cpython-314.pyc")) {
160
- const target = full.replace(".cpython-314.pyc", ".pyc");
161
- await fsExtra.move(full, target, { overwrite: true });
162
- }
163
- else if (entry.name.endsWith(".py")) {
164
- await fsExtra.remove(full);
165
- }
166
- }
167
- }
168
- }
169
- await walk(rootDir);
170
- }
171
- const buildAll = async (isDev = true, workspacePath) => {
172
- const isJs = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.js"));
173
- const isPy = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.py"));
174
- if (isJs) {
175
- console.log("🚀 开始构建JavaScript项目...");
176
- const { build } = await import("vite");
177
- const obfuscatorConfigPath = path.join(workspacePath, "obfuscator.json");
178
- if (!(await fsExtra.pathExists(obfuscatorConfigPath))) {
179
- console.error("❌ 错误: 当前目录不是有效的 快点JS 项目");
180
- console.error("请确保目录包含以下文件:");
181
- console.error(" - obfuscator.json");
182
- process.exit(1);
183
- }
184
- const obfuscatorConfig = await fsExtra.readJSON(obfuscatorConfigPath);
185
- const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
186
- const baseDir = path.join(workspacePath, "scripts");
187
- const entryFiles = await findEntryFiles(baseDir, baseDir);
188
- await fsExtra.remove(outputDir);
189
- for (const entry of entryFiles) {
190
- await build({
191
- root: workspacePath,
192
- build: {
193
- lib: {
194
- entry: {
195
- [path.basename(entry, path.extname(entry))]: `./scripts/${entry}`,
196
- },
197
- fileName: () => entry,
198
- formats: ["iife"],
199
- name: "KuaiJS", // IIFE 格式必需的全局变量名
200
- },
201
- outDir: isDev ? "dist/scripts" : "msbundle/scripts",
202
- emptyOutDir: false, // 不要每次清空输出目录
203
- sourcemap: isDev,
204
- minify: !isDev, // 开发环境不压缩变量名
205
- // 目标 JSC 最低兼容 iOS 15,钉死语法降级基线(不超纲到 iOS 15 不支持的语法)
206
- target: "safari15",
207
- },
208
- plugins: [
209
- (0, stopGuardPlugin_1.createStopGuardPlugin)(),
210
- ...(isDev
211
- ? []
212
- : [
213
- (obfuscatorConfig.enabled ?? true)
214
- ? (0, vite_plugin_bundle_obfuscator_1.default)({
215
- autoExcludeNodeModules: true,
216
- threadPool: true,
217
- options: {
218
- ...obfuscatorConfig,
219
- target: "browser",
220
- debugProtection: false,
221
- disableConsoleOutput: false,
222
- domainLock: [],
223
- selfDefending: false,
224
- renameGlobals: false,
225
- renameProperties: false,
226
- },
227
- })
228
- : [],
229
- ]),
230
- ],
231
- });
232
- }
233
- }
234
- if (isDev) {
235
- return;
236
- }
237
- const outPath = path.join(workspacePath, "msbundle");
238
- await fsExtra.ensureDir(outPath);
239
- if (isPy) {
240
- await fsExtra.copy(path.join(workspacePath, "scripts"), path.join(outPath, "scripts"));
241
- }
242
- if (isPy) {
243
- // 获取系统有没有 3.14 版本的 python
244
- const py = detectPython314();
245
- if (py.ok) {
246
- console.log(`✅ 检测到 ${py.version} (${py.path})`);
247
- // python -m compileall scripts
248
- const r = (0, child_process_1.spawnSync)(py.path, ["-m", "compileall", "scripts"], {
249
- encoding: "utf8",
250
- cwd: outPath,
251
- });
252
- if (r.status === 0) {
253
- console.log("✅ 成功编译所有 Python 文件");
254
- // 修改所有 .cpython-314.pyc 为 .pyc,并删除所有 .py 文件
255
- await normalizePythonArtifacts(path.join(outPath, "scripts"));
256
- }
257
- else {
258
- console.error("❌ 编译 Python 文件失败");
259
- console.error(r.stderr);
260
- process.exit(1);
261
- }
262
- }
263
- else {
264
- console.warn("⚠️ 未检测到 Python 3.14,请确保在目标运行环境安装 Python 3.14");
265
- }
266
- }
267
- // 打包完成后执行
268
- await fsExtra.copy(path.join(workspacePath, "res"), path.join(outPath, "res"));
269
- await fsExtra.copy(path.join(workspacePath, "ui"), path.join(outPath, "ui"));
270
- // 如果项目根目录下存在 logo.jpg 或 logo.png,也复制到 outPath
271
- for (const logoName of ["logo.jpg", "logo.png"]) {
272
- const logoSrc = path.join(workspacePath, logoName);
273
- if (await fsExtra.pathExists(logoSrc)) {
274
- await fsExtra.copy(logoSrc, path.join(outPath, logoName));
275
- }
276
- }
277
- const distPath = path.join(workspacePath, "dist");
278
- const src = path.join(workspacePath, "package.json");
279
- const dest = path.join(outPath, "package.json");
280
- const packageJson = await fsExtra.readJSON(src);
281
- delete packageJson.scripts;
282
- delete packageJson.devDependencies;
283
- delete packageJson.dependencies;
284
- await fsExtra.writeJSON(dest, packageJson, { spaces: 2 });
285
- await fsExtra.emptyDir(distPath);
286
- const zipPath = path.join(distPath, "ms.zip");
287
- const msbundlePath = path.join(distPath, "ms.msbundle");
288
- await zipDirectory(outPath, zipPath);
289
- await fsExtra.rename(zipPath, msbundlePath);
290
- await fsExtra.remove(outPath);
291
- };
292
- exports.buildAll = buildAll;
1
+ "use strict";var S=Object.create;var g=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var E=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of J(e))!F.call(t,i)&&i!==n&&g(t,i,{get:()=>e[i],enumerable:!(r=D(e,i))||r.enumerable});return t};var q=(t,e,n)=>(n=t!=null?S(P(t)):{},E(e||!t||!t.__esModule?g(n,"default",{value:t,enumerable:!0}):n,t));var z=exports&&exports.__createBinding||(Object.create?(function(t,e,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}):(function(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]})),M=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),h=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(n){var r=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[r.length]=i);return r},t(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null)for(var r=t(e),i=0;i<r.length;i++)r[i]!=="default"&&z(n,e,r[i]);return M(n,e),n}})(),_=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.buildAll=void 0;const N=_(require("archiver")),A=require("child_process"),a=h(require("fs-extra")),w=h(require("os")),o=h(require("path")),K=require("./stopGuardPlugin"),W=_(require("vite-plugin-bundle-obfuscator"));async function $(t,e){const n=(0,N.default)("zip",{zlib:{level:9}}),r=a.createWriteStream(e);return new Promise((i,s)=>{n.directory(t,!1).on("error",c=>s(c)).pipe(r),r.on("close",()=>i()),n.finalize()})}async function C(t,e){const n=[];async function r(i){const s=await a.readdir(i,{withFileTypes:!0});for(const c of s){const u=o.resolve(i,c.name);c.isDirectory()?await r(u):c.isFile()&&(/^main\.(js|ts)$/.test(c.name)||/_thread\.(js|ts)$/.test(c.name))&&n.push(o.relative(e,u))}}return await r(t),n}function B(){const t=[{cmd:o.join(w.homedir(),".KuaiJSDevloper","python","python.exe"),args:["--version"]},{cmd:o.join(w.homedir(),".KuaiJSDevloper","python","bin","python"),args:["--version"]},{cmd:"python",args:["--version"]},{cmd:"python3",args:["--version"]},{cmd:"python3.14",args:["--version"]}];for(const e of t)try{const n=(0,A.spawnSync)(e.cmd,e.args,{encoding:"utf8"}),r=(n.stdout||n.stderr||"").trim();if(r&&/Python\s+3\.14(\.\d+)?/i.test(r))return{ok:!0,path:e.cmd,version:r}}catch{}return{ok:!1}}async function x(t){async function e(n){const r=await a.readdir(n,{withFileTypes:!0});for(const i of r){const s=o.join(n,i.name);if(i.isDirectory())if(i.name==="__pycache__"){const c=await a.readdir(s,{withFileTypes:!0});for(const u of c){const l=o.join(s,u.name);if(u.isFile()&&u.name.endsWith(".cpython-314.pyc")){const p=o.dirname(s),m=u.name.replace(/\.cpython-314\.pyc$/,".pyc"),f=o.join(p,m);await a.move(l,f,{overwrite:!0})}}try{await a.remove(s)}catch{}}else await e(s);else if(i.isFile())if(i.name.endsWith(".cpython-314.pyc")){const c=s.replace(".cpython-314.pyc",".pyc");await a.move(s,c,{overwrite:!0})}else i.name.endsWith(".py")&&await a.remove(s)}}await e(t)}const G=async(t=!0,e)=>{const n=await a.pathExists(o.join(e,"scripts","main.js")),r=await a.pathExists(o.join(e,"scripts","main.py"));if(n){console.log("\u{1F680} \u5F00\u59CB\u6784\u5EFAJavaScript\u9879\u76EE...");const{build:f}=await import("vite"),d=o.join(e,"obfuscator.json");await a.pathExists(d)||(console.error("\u274C \u9519\u8BEF: \u5F53\u524D\u76EE\u5F55\u4E0D\u662F\u6709\u6548\u7684 \u5FEB\u70B9JS \u9879\u76EE"),console.error("\u8BF7\u786E\u4FDD\u76EE\u5F55\u5305\u542B\u4EE5\u4E0B\u6587\u4EF6:"),console.error(" - obfuscator.json"),process.exit(1));const j=await a.readJSON(d),v=o.join(e,t?"dist":"msbundle"),b=o.join(e,"scripts"),O=await C(b,b);await a.remove(v);for(const y of O)await f({root:e,build:{lib:{entry:{[o.basename(y,o.extname(y))]:`./scripts/${y}`},fileName:()=>y,formats:["iife"],name:"KuaiJS"},outDir:t?"dist/scripts":"msbundle/scripts",emptyOutDir:!1,sourcemap:t,minify:!t,target:"safari15"},plugins:[(0,K.createStopGuardPlugin)(),...t?[]:[j.enabled?(0,W.default)({autoExcludeNodeModules:!0,threadPool:!0,options:{...j,target:"browser",debugProtection:!1,disableConsoleOutput:!1,domainLock:[],selfDefending:!1,renameGlobals:!1,renameProperties:!1}}):[]]]})}if(t)return;const i=o.join(e,"msbundle");await a.ensureDir(i),r&&await a.copy(o.join(e,"scripts"),o.join(i,"scripts")),await a.copy(o.join(e,"res"),o.join(i,"res")),await a.copy(o.join(e,"ui"),o.join(i,"ui"));for(const f of["logo.jpg","logo.png"]){const d=o.join(e,f);await a.pathExists(d)&&await a.copy(d,o.join(i,f))}const s=o.join(e,"dist"),c=o.join(e,"package.json"),u=o.join(i,"package.json"),l=await a.readJSON(c);delete l.scripts,delete l.devDependencies,delete l.dependencies,await a.writeJSON(u,l,{spaces:2}),await a.emptyDir(s);const p=o.join(s,"ms.zip"),m=o.join(s,"ms.msbundle");await $(i,p),await a.rename(p,m),await a.remove(i)};exports.buildAll=G;