@lark-apaas/miaoda-cli 0.1.38 → 0.1.39-alpha.44e04b8
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/README.md +17 -0
- package/dist/cli/commands/deploy/modern.js +34 -11
- package/dist/cli/commands/skills/index.js +1 -1
- package/dist/cli/handlers/app/export.js +3 -3
- package/dist/cli/handlers/app/migrate.js +4 -1
- package/dist/cli/handlers/app/sync.js +2 -2
- package/dist/cli/handlers/db/sql.js +8 -6
- package/dist/cli/handlers/deploy/modern.js +39 -3
- package/dist/cli/handlers/plugin/plugin-local.js +5 -4
- package/dist/config/migrate-configs/vite-react-to-nestjs-react-fullstack.js +13 -2
- package/dist/config/sync-configs/nestjs-react-fullstack.js +50 -0
- package/dist/services/app/init/async-install.js +13 -2
- package/dist/services/app/init/install.js +4 -3
- package/dist/services/deploy/modern/atoms/build.js +3 -3
- package/dist/services/deploy/modern/atoms/local-release.js +3 -0
- package/dist/services/deploy/modern/atoms/tosutil.js +6 -8
- package/dist/services/deploy/modern/patch/actions.js +7 -1
- package/dist/services/deploy/modern/patch/index.js +2 -1
- package/dist/services/deploy/modern/pipelines/design-local.js +7 -1
- package/dist/services/deploy/modern/pipelines/local.js +7 -1
- package/dist/utils/archive.js +103 -0
- package/dist/utils/coding-steering.js +30 -2
- package/dist/utils/eslint-ignore.js +169 -0
- package/dist/utils/file-ops.js +28 -8
- package/dist/utils/http.js +6 -6
- package/dist/utils/npm-pack.js +6 -7
- package/dist/utils/run-npm.js +102 -0
- package/dist/utils/sync-rule.js +24 -1
- package/dist/utils/typescript-exclude.js +62 -0
- package/dist/utils/which.js +27 -0
- package/package.json +7 -3
- package/upgrade/templates/nestjs-react-fullstack/templates/nest-cli.json +1 -10
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +25 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/check.cjs +123 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/lint.js +39 -35
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.excludeTypeScriptPath = excludeTypeScriptPath;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
11
|
+
const error_1 = require("./error");
|
|
12
|
+
/** 追加排除项,保留 JSONC 注释和继承的排除路径;不创建缺失的配置。 */
|
|
13
|
+
function excludeTypeScriptPath(filename, excludedPath) {
|
|
14
|
+
if (!node_fs_1.default.existsSync(filename))
|
|
15
|
+
return false;
|
|
16
|
+
const source = node_fs_1.default.readFileSync(filename, 'utf8');
|
|
17
|
+
const errors = [];
|
|
18
|
+
const raw = (0, jsonc_parser_1.parse)(source, errors, { allowTrailingComma: true });
|
|
19
|
+
if (errors.length || !raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
20
|
+
throw new error_1.AppError('INVALID_CONFIG', `Invalid TypeScript configuration: ${filename}`);
|
|
21
|
+
}
|
|
22
|
+
const parsed = typescript_1.default.getParsedCommandLineOfConfigFile(filename, {}, {
|
|
23
|
+
...typescript_1.default.sys,
|
|
24
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
25
|
+
throw new error_1.AppError('INVALID_CONFIG', typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
// 初始化中的空工程允许迁移,其他错误不能被静默忽略。
|
|
29
|
+
const diagnostics = parsed?.errors.filter((d) => d.code !== 18003 && d.code !== 18002) ?? [];
|
|
30
|
+
if (!parsed || diagnostics.length) {
|
|
31
|
+
throw new error_1.AppError('INVALID_CONFIG', `Cannot migrate ${filename}: ${diagnostics.map((d) => typescript_1.default.flattenDiagnosticMessageText(d.messageText, '\n')).join('; ')}`);
|
|
32
|
+
}
|
|
33
|
+
const effective = parsed.raw;
|
|
34
|
+
const excludes = effective.exclude ?? [
|
|
35
|
+
'node_modules',
|
|
36
|
+
'bower_components',
|
|
37
|
+
'jspm_packages',
|
|
38
|
+
...[parsed.options.outDir, parsed.options.declarationDir]
|
|
39
|
+
.filter((p) => Boolean(p))
|
|
40
|
+
.map((p) => node_path_1.default.relative(node_path_1.default.dirname(filename), p).split(node_path_1.default.sep).join('/')),
|
|
41
|
+
];
|
|
42
|
+
if (!Array.isArray(excludes) || excludes.some((p) => typeof p !== 'string')) {
|
|
43
|
+
throw new error_1.AppError('INVALID_CONFIG', `Invalid exclude array: ${filename}`);
|
|
44
|
+
}
|
|
45
|
+
const paths = excludes;
|
|
46
|
+
if (paths.includes(excludedPath))
|
|
47
|
+
return false;
|
|
48
|
+
const ownExclude = raw.exclude;
|
|
49
|
+
const formattingOptions = {
|
|
50
|
+
insertSpaces: true,
|
|
51
|
+
tabSize: 2,
|
|
52
|
+
eol: source.includes('\r\n') ? '\r\n' : '\n',
|
|
53
|
+
};
|
|
54
|
+
const edits = Array.isArray(ownExclude)
|
|
55
|
+
? (0, jsonc_parser_1.modify)(source, ['exclude', ownExclude.length], excludedPath, {
|
|
56
|
+
formattingOptions,
|
|
57
|
+
isArrayInsertion: true,
|
|
58
|
+
})
|
|
59
|
+
: (0, jsonc_parser_1.modify)(source, ['exclude'], [...paths, excludedPath], { formattingOptions });
|
|
60
|
+
node_fs_1.default.writeFileSync(filename, (0, jsonc_parser_1.applyEdits)(source, edits));
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.whichSync = whichSync;
|
|
7
|
+
const which_1 = __importDefault(require("which"));
|
|
8
|
+
/**
|
|
9
|
+
* 跨平台可执行文件查找 —— 仓库内查 PATH 的唯一入口,禁止 shell out `which`。
|
|
10
|
+
*
|
|
11
|
+
* 为什么不 shell out:`which` 在 Windows 上不存在(对应的是 `where`),而 `where`
|
|
12
|
+
* 的输出格式与退出码语义又跟 `which` 不同。
|
|
13
|
+
*
|
|
14
|
+
* 为什么用社区 `which` 包而不是自己遍历 PATH:Windows 要按 PATHEXT 逐个后缀试探
|
|
15
|
+
* (`npm` 实际是 `npm.cmd`),POSIX 要看执行位,还有 all / delimiter 这些边角。
|
|
16
|
+
* 这些是 npm 官方维护的 `which` 已经做完并被全生态验证过的事,自己写只会漏。
|
|
17
|
+
*
|
|
18
|
+
* 保留这层薄封装而不是让各处直接 `import which`,是为了:
|
|
19
|
+
* 1. 把 `null`(社区库的「没找到」)归一成仓库内统一的 `undefined` optional 语义;
|
|
20
|
+
* 2. 留一个收口点 —— 换实现、加缓存、加平台特例都只改这里;
|
|
21
|
+
* 3. 配合 ESLint no-restricted-imports,保证不会有人绕过去直接用。
|
|
22
|
+
*/
|
|
23
|
+
function whichSync(name) {
|
|
24
|
+
if (name === '')
|
|
25
|
+
return undefined;
|
|
26
|
+
return which_1.default.sync(name, { nothrow: true }) ?? undefined;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/miaoda-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39-alpha.44e04b8",
|
|
4
4
|
"description": "Miaoda 平台命令行工具,面向 Agent 调用",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -29,12 +29,17 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@lark-apaas/http-client": "^0.1.5",
|
|
31
31
|
"commander": "^13.1.0",
|
|
32
|
+
"cross-spawn": "^7.0.6",
|
|
32
33
|
"jsonc-parser": "^3.3.1",
|
|
33
34
|
"ora": "^5.4.1",
|
|
34
|
-
"picocolors": "^1.1.1"
|
|
35
|
+
"picocolors": "^1.1.1",
|
|
36
|
+
"which": "^7.0.0",
|
|
37
|
+
"typescript": "^5.8.3"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@types/cross-spawn": "^6.0.6",
|
|
37
41
|
"@types/node": "^22.15.3",
|
|
42
|
+
"@types/which": "^3.0.4",
|
|
38
43
|
"@typescript-eslint/eslint-plugin": "^8.58.2",
|
|
39
44
|
"@typescript-eslint/parser": "^8.58.2",
|
|
40
45
|
"@vitest/coverage-v8": "^4.1.4",
|
|
@@ -47,7 +52,6 @@
|
|
|
47
52
|
"prettier": "^3.8.3",
|
|
48
53
|
"tsc-alias": "^1.8.11",
|
|
49
54
|
"tsx": "^4.19.4",
|
|
50
|
-
"typescript": "^5.8.3",
|
|
51
55
|
"vitest": "^4.1.4",
|
|
52
56
|
"xml2js": "^0.6.2"
|
|
53
57
|
},
|
|
@@ -210,3 +210,28 @@ else
|
|
|
210
210
|
echo " node_modules: $NODE_MODULES_SIZE"
|
|
211
211
|
echo ""
|
|
212
212
|
fi
|
|
213
|
+
|
|
214
|
+
# 仅成功的全构建生成 backendBuildID;必须在构建、产物准备和依赖裁剪之后。
|
|
215
|
+
# UI/Skill 内容由 SDK 独立计入总 hash;纯前端发布不替换已部署的 backendBuildID。
|
|
216
|
+
if [[ "${only_frontend_change:-false}" != "true" ]]; then
|
|
217
|
+
node - "$ROOT_DIR/dist" <<'NODE'
|
|
218
|
+
const fs = require('node:fs');
|
|
219
|
+
const path = require('node:path');
|
|
220
|
+
const { randomUUID } = require('node:crypto');
|
|
221
|
+
const dist = process.argv[2];
|
|
222
|
+
// 防止 build:server 空跑成功、却没有可交付的服务端入口。
|
|
223
|
+
if (!fs.statSync(path.join(dist, 'server/main.js')).isFile()) {
|
|
224
|
+
throw new Error('Missing server build output: dist/server/main.js');
|
|
225
|
+
}
|
|
226
|
+
// runtime cwd 分别为工程根、dist/(或整包解压到 dist-server/)、旧版 dist/server/。
|
|
227
|
+
// 与 MCP UI/Skill 的交付布局一致:复制产物时保留同一个 UUID,不在启动时生成。
|
|
228
|
+
const files = [
|
|
229
|
+
path.join(dist, 'mcp-build-id'),
|
|
230
|
+
path.join(dist, 'dist/mcp-build-id'),
|
|
231
|
+
path.join(dist, 'server/dist/mcp-build-id'),
|
|
232
|
+
];
|
|
233
|
+
for (const file of files) fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
234
|
+
const buildID = randomUUID();
|
|
235
|
+
for (const file of files) fs.writeFileSync(file, buildID, 'utf8');
|
|
236
|
+
NODE
|
|
237
|
+
fi
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// 叶子检查入口:不得调用 lint 或聚合 type:check npm script。
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { spawn } = require('node:child_process');
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
|
|
9
|
+
function getBinName(name) {
|
|
10
|
+
return process.platform === 'win32' ? `${name}.cmd` : name;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function runCommand(command, args) {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const child = spawn(command, args, {
|
|
16
|
+
cwd,
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
shell: false,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
child.on('close', (code) => resolve(code ?? 1));
|
|
22
|
+
child.on('error', () => resolve(1));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 串行依次执行每个任务,全部跑完后再聚合退出码:
|
|
27
|
+
// 降低并发资源占用、让各任务输出按顺序清晰可读,同时保留“一次暴露所有 lint 问题”的行为。
|
|
28
|
+
async function runTasksSerially(taskSpecs) {
|
|
29
|
+
let exitCode = 0;
|
|
30
|
+
for (const [command, args] of taskSpecs) {
|
|
31
|
+
const code = await runCommand(command, args);
|
|
32
|
+
if (code !== 0) {
|
|
33
|
+
exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return exitCode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isEslintTarget(filePath) { return /\.(c|m)?(j|t)sx?$/.test(filePath); }
|
|
40
|
+
|
|
41
|
+
const UI_DIR = 'server/mcp/ui';
|
|
42
|
+
|
|
43
|
+
function uiSourceFiles() {
|
|
44
|
+
const files = [];
|
|
45
|
+
function visit(relative) {
|
|
46
|
+
const absolute = path.join(cwd, relative);
|
|
47
|
+
if (!fs.existsSync(absolute)) return;
|
|
48
|
+
if (fs.lstatSync(absolute).isSymbolicLink()) {
|
|
49
|
+
throw new Error(`MCP UI 检查不支持符号链接: ${relative}`);
|
|
50
|
+
}
|
|
51
|
+
for (const entry of fs.readdirSync(absolute, { withFileTypes: true })) {
|
|
52
|
+
if (['node_modules', 'dist', '.git'].includes(entry.name)) continue;
|
|
53
|
+
const file = `${relative}/${entry.name}`;
|
|
54
|
+
if (entry.isSymbolicLink()) throw new Error(`MCP UI 检查不支持符号链接: ${file}`);
|
|
55
|
+
if (entry.isDirectory()) visit(file);
|
|
56
|
+
else if (isEslintTarget(file) && !/\.d\.(?:ts|mts|cts)$/.test(file)) files.push(file);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
visit(UI_DIR);
|
|
60
|
+
return files.sort();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function uiTasks({ types = true, eslint = true } = {}) {
|
|
64
|
+
const sources = uiSourceFiles();
|
|
65
|
+
if (!sources.length) return [];
|
|
66
|
+
const tasks = [];
|
|
67
|
+
if (types) {
|
|
68
|
+
const config = `${UI_DIR}/tsconfig.json`;
|
|
69
|
+
if (!fs.existsSync(path.join(cwd, config))) {
|
|
70
|
+
throw new Error(`MCP UI 缺少 ${config},请按 mcp-guide 补齐独立浏览器 TypeScript 配置。`);
|
|
71
|
+
}
|
|
72
|
+
const ts = require('typescript');
|
|
73
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(path.join(cwd, config), {}, {
|
|
74
|
+
...ts.sys,
|
|
75
|
+
onUnRecoverableConfigFileDiagnostic: d => { throw new Error(ts.flattenDiagnosticMessageText(d.messageText, '\n')); },
|
|
76
|
+
});
|
|
77
|
+
if (!parsed || parsed.errors.length) throw new Error(`MCP UI TypeScript 配置无效: ${config}`);
|
|
78
|
+
const included = new Set(parsed.fileNames.map(file => path.resolve(file)));
|
|
79
|
+
const missing = sources.filter(file => !included.has(path.resolve(cwd, file)));
|
|
80
|
+
if (missing.length) throw new Error(`MCP UI TypeScript 配置未覆盖源码: ${missing.join(', ')};请检查 include/exclude,JS 源码需开启 allowJs。`);
|
|
81
|
+
tasks.push([getBinName('npx'), ['--no-install', 'tsc', '--noEmit', '-p', config]]);
|
|
82
|
+
}
|
|
83
|
+
if (eslint) {
|
|
84
|
+
const config = ['eslint.mcp-ui.config.js', 'eslint.mcp-ui.config.cjs', 'eslint.mcp-ui.config.mjs']
|
|
85
|
+
.find(file => fs.existsSync(path.join(cwd, file)));
|
|
86
|
+
if (!config) throw new Error('MCP UI 缺少独立 ESLint 配置,请按 mcp-guide 创建 eslint.mcp-ui.config.cjs。');
|
|
87
|
+
tasks.push([getBinName('npx'), ['--no-install', 'eslint', '--config', config, '--quiet', '--max-warnings', '0', ...sources]]);
|
|
88
|
+
}
|
|
89
|
+
return tasks;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function packageScripts() {
|
|
93
|
+
return JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')).scripts || {};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function runTypeCheck() {
|
|
97
|
+
const scripts = packageScripts();
|
|
98
|
+
const tasks = ['type:check:server', 'type:check:client'].map(name => {
|
|
99
|
+
if (!scripts[name]) throw new Error(`缺少 scripts.${name},请保留应用原有类型检查命令。`);
|
|
100
|
+
return [getBinName('npm'), ['run', name]];
|
|
101
|
+
});
|
|
102
|
+
tasks.push(...uiTasks({ eslint: false }));
|
|
103
|
+
process.exit(await runTasksSerially(tasks));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function main(args = process.argv.slice(2)) {
|
|
107
|
+
const modes = ['--typecheck', '--typecheck-mcp-ui', '--eslint-mcp-ui'];
|
|
108
|
+
if (args.length !== 1 || !modes.includes(args[0])) {
|
|
109
|
+
throw new Error('用法: check.cjs --typecheck | --typecheck-mcp-ui | --eslint-mcp-ui');
|
|
110
|
+
}
|
|
111
|
+
// 自定义 leaf script 意外回到聚合入口时立即失败,避免生成递归进程树。
|
|
112
|
+
if (process.env.MIAODA_TYPECHECK_ACTIVE === '1') {
|
|
113
|
+
throw new Error('检测到检查命令递归,请检查 type:check:server/client,不能回调 lint 或 type:check。');
|
|
114
|
+
}
|
|
115
|
+
process.env.MIAODA_TYPECHECK_ACTIVE = '1';
|
|
116
|
+
if (args[0] === '--typecheck') return runTypeCheck();
|
|
117
|
+
process.exit(await runTasksSerially(uiTasks(args[0] === '--typecheck-mcp-ui' ? { eslint: false } : { types: false })));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { getBinName, runTasksSerially, uiTasks, packageScripts, main };
|
|
121
|
+
if (require.main === module) {
|
|
122
|
+
main().catch(error => { console.error(`[check] ${error.message}`); process.exit(1); });
|
|
123
|
+
}
|
|
@@ -1,36 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const path = require('node:path');
|
|
4
|
-
const { spawn } = require('node:child_process');
|
|
5
4
|
const fs = require('node:fs');
|
|
6
5
|
|
|
7
6
|
const cwd = process.cwd();
|
|
8
7
|
|
|
9
|
-
function getBinName(name) {
|
|
10
|
-
return process.platform === 'win32' ? `${name}.cmd` : name;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function runCommand(command, args) {
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
const child = spawn(command, args, {
|
|
16
|
-
cwd,
|
|
17
|
-
stdio: 'inherit',
|
|
18
|
-
shell: false,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
child.on('close', (code) => resolve(code || 0));
|
|
22
|
-
child.on('error', () => resolve(1));
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
8
|
function normalizeProjectFile(filePath) {
|
|
27
9
|
const absolutePath = path.isAbsolute(filePath)
|
|
28
10
|
? filePath
|
|
29
11
|
: path.resolve(cwd, filePath);
|
|
30
12
|
|
|
31
13
|
if (!fs.existsSync(absolutePath)) {
|
|
32
|
-
console.
|
|
33
|
-
return null;
|
|
14
|
+
console.log(`[lint] Deleted file: ${filePath}; checking affected projects`);
|
|
34
15
|
}
|
|
35
16
|
|
|
36
17
|
const relativePath = path.relative(cwd, absolutePath);
|
|
@@ -94,17 +75,26 @@ function canRunStylelint() {
|
|
|
94
75
|
return STYLELINT_CONFIG_FILES.some(file => fs.existsSync(path.join(cwd, file)));
|
|
95
76
|
}
|
|
96
77
|
|
|
78
|
+
const { getBinName, runTasksSerially, uiTasks, packageScripts, main: runChecks } = require('./check.cjs');
|
|
79
|
+
const UI_TYPECHECKS = ['node ./scripts/check.cjs --typecheck', 'node ./scripts/lint.js --typecheck'];
|
|
80
|
+
function isUiFile(file) { return file.startsWith('server/mcp/ui/'); }
|
|
81
|
+
|
|
97
82
|
async function runDefaultLint() {
|
|
98
|
-
const
|
|
83
|
+
const taskSpecs = [
|
|
84
|
+
[getBinName('npm'), ['run', 'eslint']],
|
|
85
|
+
[getBinName('npm'), ['run', 'type:check']],
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
// Customized type:check remains untouched; ensure full lint still checks UI.
|
|
89
|
+
taskSpecs.push(...uiTasks({ types: !UI_TYPECHECKS.includes(packageScripts()['type:check']) }));
|
|
99
90
|
|
|
100
91
|
if (canRunStylelint()) {
|
|
101
|
-
|
|
92
|
+
taskSpecs.push([getBinName('npm'), ['run', 'stylelint']]);
|
|
102
93
|
} else {
|
|
103
94
|
console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
|
|
104
95
|
}
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
process.exit(code);
|
|
97
|
+
process.exit(await runTasksSerially(taskSpecs));
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
async function runSelectiveLint(inputFiles) {
|
|
@@ -117,15 +107,20 @@ async function runSelectiveLint(inputFiles) {
|
|
|
117
107
|
process.exit(0);
|
|
118
108
|
}
|
|
119
109
|
|
|
120
|
-
const eslintFiles = normalizedFiles.filter(isEslintTarget);
|
|
121
|
-
const stylelintFiles = normalizedFiles.filter(isStylelintTarget);
|
|
110
|
+
const eslintFiles = normalizedFiles.filter(file => fs.existsSync(path.join(cwd, file)) && isEslintTarget(file) && !isUiFile(file) && !file.startsWith('eslint.mcp-ui.config.'));
|
|
111
|
+
const stylelintFiles = normalizedFiles.filter(file => fs.existsSync(path.join(cwd, file)) && isStylelintTarget(file));
|
|
122
112
|
const typeCheckFiles = normalizedFiles.filter(isTypeCheckTarget);
|
|
123
113
|
|
|
124
114
|
const clientTypeFiles = [];
|
|
125
115
|
const serverTypeFiles = [];
|
|
116
|
+
const rootConfigChanged = normalizedFiles.some(file => /^tsconfig(?:\.[^/]*)?\.json$/.test(file));
|
|
117
|
+
if (rootConfigChanged) { clientTypeFiles.push('config'); serverTypeFiles.push('config'); }
|
|
118
|
+
let checkUi = rootConfigChanged || normalizedFiles.some(file => isUiFile(file) || file.startsWith('shared/') || file.startsWith('eslint.mcp-ui.config.'));
|
|
126
119
|
|
|
127
120
|
for (const filePath of typeCheckFiles) {
|
|
128
|
-
if (filePath
|
|
121
|
+
if (isUiFile(filePath)) {
|
|
122
|
+
checkUi = true;
|
|
123
|
+
} else if (filePath.startsWith('client/')) {
|
|
129
124
|
clientTypeFiles.push(filePath);
|
|
130
125
|
} else if (filePath.startsWith('server/')) {
|
|
131
126
|
serverTypeFiles.push(filePath);
|
|
@@ -135,36 +130,45 @@ async function runSelectiveLint(inputFiles) {
|
|
|
135
130
|
}
|
|
136
131
|
}
|
|
137
132
|
|
|
138
|
-
const
|
|
133
|
+
const taskSpecs = [];
|
|
139
134
|
|
|
140
135
|
if (eslintFiles.length > 0) {
|
|
141
|
-
|
|
136
|
+
taskSpecs.push([getBinName('npx'), ['eslint', '--quiet', ...eslintFiles]]);
|
|
142
137
|
}
|
|
143
138
|
|
|
144
139
|
if (stylelintFiles.length > 0 && !canRunStylelint()) {
|
|
145
140
|
console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
|
|
146
141
|
} else if (stylelintFiles.length > 0) {
|
|
147
|
-
|
|
142
|
+
taskSpecs.push([getBinName('npx'), ['stylelint', '--quiet', ...stylelintFiles]]);
|
|
148
143
|
}
|
|
149
144
|
|
|
150
145
|
if (clientTypeFiles.length > 0) {
|
|
151
|
-
|
|
146
|
+
taskSpecs.push([getBinName('npm'), ['run', 'type:check:client']]);
|
|
152
147
|
}
|
|
153
148
|
|
|
154
149
|
if (serverTypeFiles.length > 0) {
|
|
155
|
-
|
|
150
|
+
taskSpecs.push([getBinName('npm'), ['run', 'type:check:server']]);
|
|
156
151
|
}
|
|
157
152
|
|
|
158
|
-
if (
|
|
153
|
+
if (checkUi) taskSpecs.push(...uiTasks());
|
|
154
|
+
|
|
155
|
+
if (taskSpecs.length === 0) {
|
|
159
156
|
console.log('[lint] No supported files matched for lint');
|
|
160
157
|
process.exit(0);
|
|
161
158
|
}
|
|
162
159
|
|
|
163
|
-
|
|
164
|
-
process.exit(results.some(code => code !== 0) ? 1 : 0);
|
|
160
|
+
process.exit(await runTasksSerially(taskSpecs));
|
|
165
161
|
}
|
|
166
162
|
|
|
167
163
|
async function main() {
|
|
164
|
+
const args = process.argv.slice(2);
|
|
165
|
+
const modes = ['--typecheck', '--typecheck-mcp-ui', '--eslint-mcp-ui'];
|
|
166
|
+
if (args.length && !(args[0] === '--files' && args.length > 1) && !(args.length === 1 && modes.includes(args[0]))) {
|
|
167
|
+
throw new Error('用法: lint.js [--files <paths...> | --typecheck | --typecheck-mcp-ui | --eslint-mcp-ui]');
|
|
168
|
+
}
|
|
169
|
+
if (args[0] === '--files' && args.slice(1).some(arg => arg.startsWith('--'))) throw new Error('--files 不可与其他检查模式混用');
|
|
170
|
+
// 兼容旧入口,只向独立检查器转发;新的 npm scripts 不再指向 lint.js。
|
|
171
|
+
if (modes.includes(args[0])) return runChecks(args);
|
|
168
172
|
const files = parseFilesArg(process.argv.slice(2));
|
|
169
173
|
if (files === null) {
|
|
170
174
|
await runDefaultLint();
|