@lark-apaas/miaoda-cli 0.1.38 → 0.1.39-alpha.4ae5653

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 (35) hide show
  1. package/README.md +10 -0
  2. package/dist/cli/commands/deploy/modern.js +34 -11
  3. package/dist/cli/commands/skills/index.js +1 -1
  4. package/dist/cli/handlers/app/export.js +3 -3
  5. package/dist/cli/handlers/app/migrate.js +4 -1
  6. package/dist/cli/handlers/app/sync.js +2 -2
  7. package/dist/cli/handlers/db/sql.js +8 -6
  8. package/dist/cli/handlers/deploy/modern.js +39 -3
  9. package/dist/cli/handlers/plugin/plugin-local.js +5 -4
  10. package/dist/config/migrate-configs/vite-react-to-nestjs-react-fullstack.js +21 -3
  11. package/dist/config/sync-configs/nestjs-react-fullstack.js +40 -0
  12. package/dist/services/app/init/async-install.js +13 -2
  13. package/dist/services/app/init/install.js +4 -3
  14. package/dist/services/deploy/modern/atoms/build.js +3 -3
  15. package/dist/services/deploy/modern/atoms/local-release.js +3 -0
  16. package/dist/services/deploy/modern/atoms/tosutil.js +6 -8
  17. package/dist/services/deploy/modern/patch/actions.js +7 -1
  18. package/dist/services/deploy/modern/patch/index.js +2 -1
  19. package/dist/services/deploy/modern/pipelines/design-local.js +7 -1
  20. package/dist/services/deploy/modern/pipelines/local.js +7 -1
  21. package/dist/utils/archive.js +103 -0
  22. package/dist/utils/coding-steering.js +30 -2
  23. package/dist/utils/file-ops.js +28 -8
  24. package/dist/utils/http.js +6 -6
  25. package/dist/utils/npm-pack.js +6 -7
  26. package/dist/utils/run-npm.js +102 -0
  27. package/dist/utils/sync-rule.js +10 -1
  28. package/dist/utils/typescript-exclude.js +36 -0
  29. package/dist/utils/which.js +27 -0
  30. package/package.json +8 -4
  31. package/upgrade/templates/nestjs-react-fullstack/templates/nest-cli.json +1 -10
  32. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +25 -0
  33. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/lint.js +188 -41
  34. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/typecheck-mcp-ui.js +32 -0
  35. package/upgrade/templates/nestjs-react-fullstack/templates/tsconfig.mcp-ui.json +33 -0
@@ -1,40 +1,26 @@
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');
5
+ const { spawn } = require('node:child_process');
6
6
 
7
7
  const cwd = process.cwd();
8
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 || 0));
22
- child.on('error', () => resolve(1));
23
- });
24
- }
25
-
26
9
  function normalizeProjectFile(filePath) {
27
10
  const absolutePath = path.isAbsolute(filePath)
28
11
  ? filePath
29
12
  : path.resolve(cwd, filePath);
30
13
 
31
14
  if (!fs.existsSync(absolutePath)) {
32
- console.warn(`[lint] Skip missing file: ${filePath}`);
33
- return null;
15
+ console.log(`[lint] Deleted file: ${filePath}; checking affected projects`);
34
16
  }
35
17
 
36
18
  const relativePath = path.relative(cwd, absolutePath);
37
- if (relativePath.startsWith('..')) {
19
+ if (
20
+ relativePath === '..' ||
21
+ relativePath.startsWith(`..${path.sep}`) ||
22
+ path.isAbsolute(relativePath)
23
+ ) {
38
24
  console.warn(`[lint] Skip file outside project: ${filePath}`);
39
25
  return null;
40
26
  }
@@ -91,25 +77,144 @@ function canRunStylelint() {
91
77
 
92
78
  if (!pkg.scripts || !pkg.scripts.stylelint) return false;
93
79
 
94
- return STYLELINT_CONFIG_FILES.some(file => fs.existsSync(path.join(cwd, file)));
80
+ return STYLELINT_CONFIG_FILES.some(file =>
81
+ fs.existsSync(path.join(cwd, file))
82
+ );
83
+ }
84
+
85
+ function getBinName(name) {
86
+ return process.platform === 'win32' ? `${name}.cmd` : name;
87
+ }
88
+
89
+ function runCommand(command, args) {
90
+ return new Promise(resolve => {
91
+ const child = spawn(command, args, {
92
+ cwd,
93
+ stdio: 'inherit',
94
+ shell: false,
95
+ });
96
+
97
+ child.on('close', code => resolve(code ?? 1));
98
+ child.on('error', () => resolve(1));
99
+ });
100
+ }
101
+
102
+ // 串行依次执行每个任务,全部跑完后再聚合退出码:
103
+ // 降低并发资源占用、让各任务输出按顺序清晰可读,同时保留“一次暴露所有 lint 问题”的行为。
104
+ async function runTasksSerially(taskSpecs) {
105
+ let exitCode = 0;
106
+ for (const [command, args] of taskSpecs) {
107
+ const code = await runCommand(command, args);
108
+ if (code !== 0) {
109
+ exitCode = 1;
110
+ }
111
+ }
112
+ return exitCode;
113
+ }
114
+
115
+ const UI_DIR = 'server/mcp/ui';
116
+
117
+ function uiSourceFiles() {
118
+ const files = [];
119
+ function visit(relative) {
120
+ const absolute = path.join(cwd, relative);
121
+ if (!fs.existsSync(absolute)) return;
122
+ if (fs.lstatSync(absolute).isSymbolicLink()) {
123
+ throw new Error(`MCP UI 检查不支持符号链接: ${relative}`);
124
+ }
125
+ for (const entry of fs.readdirSync(absolute, { withFileTypes: true })) {
126
+ if (['node_modules', 'dist', '.git'].includes(entry.name)) continue;
127
+ const file = `${relative}/${entry.name}`;
128
+ if (entry.isSymbolicLink())
129
+ throw new Error(`MCP UI 检查不支持符号链接: ${file}`);
130
+ if (entry.isDirectory()) visit(file);
131
+ else if (isEslintTarget(file) && !/\.d\.(?:ts|mts|cts)$/.test(file))
132
+ files.push(file);
133
+ }
134
+ }
135
+ visit(UI_DIR);
136
+ return files.sort();
137
+ }
138
+
139
+ function uiTasks({ types = true, eslint = true } = {}) {
140
+ const sources = uiSourceFiles();
141
+ if (!sources.length) return [];
142
+ const tasks = [];
143
+ if (types) tasks.push([getBinName('npm'), ['run', 'type:check:mcp-ui']]);
144
+ if (eslint) {
145
+ const config = [
146
+ 'eslint.mcp-ui.config.js',
147
+ 'eslint.mcp-ui.config.cjs',
148
+ 'eslint.mcp-ui.config.mjs',
149
+ ].find(file => fs.existsSync(path.join(cwd, file)));
150
+ let resolvedConfig = config;
151
+ if (!resolvedConfig) {
152
+ try {
153
+ resolvedConfig =
154
+ require.resolve('@lark-apaas/fullstack-presets/lib/mcp/eslint-ui.js');
155
+ } catch {
156
+ throw new Error(
157
+ '请升级 @lark-apaas/fullstack-presets 以使用 MCP UI 默认 ESLint 配置,或提供 eslint.mcp-ui.config.cjs'
158
+ );
159
+ }
160
+ }
161
+ tasks.push([
162
+ getBinName('npx'),
163
+ [
164
+ '--no-install',
165
+ 'eslint',
166
+ '--config',
167
+ resolvedConfig,
168
+ '--quiet',
169
+ '--max-warnings',
170
+ '0',
171
+ ...sources,
172
+ ],
173
+ ]);
174
+ }
175
+ return tasks;
176
+ }
177
+
178
+ function packageScripts() {
179
+ return (
180
+ JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'))
181
+ .scripts || {}
182
+ );
183
+ }
184
+
185
+ function isUiFile(file) {
186
+ return file.startsWith('server/mcp/ui/');
95
187
  }
96
188
 
97
189
  async function runDefaultLint() {
98
- const commands = ['npm run eslint', 'npm run type:check'];
190
+ const taskSpecs = [
191
+ [getBinName('npm'), ['run', 'eslint']],
192
+ [getBinName('npm'), ['run', 'type:check']],
193
+ ];
194
+
195
+ // 保留用户的 type:check;未聚合 UI 时由 lint 补查。
196
+ taskSpecs.push(
197
+ ...uiTasks({
198
+ types: !/\bnpm\s+run\s+type:check:mcp-ui(?=[\s"';&|)]|$)/.test(
199
+ packageScripts()['type:check'] || ''
200
+ ),
201
+ })
202
+ );
99
203
 
100
204
  if (canRunStylelint()) {
101
- commands.push('npm run stylelint');
205
+ taskSpecs.push([getBinName('npm'), ['run', 'stylelint']]);
102
206
  } else {
103
- console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
207
+ console.warn(
208
+ '[lint] Skip stylelint: missing scripts.stylelint or stylelint config'
209
+ );
104
210
  }
105
211
 
106
- const code = await runCommand(getBinName('npx'), ['concurrently', ...commands]);
107
- process.exit(code);
212
+ process.exit(await runTasksSerially(taskSpecs));
108
213
  }
109
214
 
110
215
  async function runSelectiveLint(inputFiles) {
111
216
  const normalizedFiles = Array.from(
112
- new Set(inputFiles.map(normalizeProjectFile).filter(Boolean)),
217
+ new Set(inputFiles.map(normalizeProjectFile).filter(Boolean))
113
218
  );
114
219
 
115
220
  if (normalizedFiles.length === 0) {
@@ -117,15 +222,41 @@ async function runSelectiveLint(inputFiles) {
117
222
  process.exit(0);
118
223
  }
119
224
 
120
- const eslintFiles = normalizedFiles.filter(isEslintTarget);
121
- const stylelintFiles = normalizedFiles.filter(isStylelintTarget);
225
+ const eslintFiles = normalizedFiles.filter(
226
+ file =>
227
+ fs.existsSync(path.join(cwd, file)) &&
228
+ isEslintTarget(file) &&
229
+ !isUiFile(file) &&
230
+ !file.startsWith('eslint.mcp-ui.config.')
231
+ );
232
+ const stylelintFiles = normalizedFiles.filter(
233
+ file => fs.existsSync(path.join(cwd, file)) && isStylelintTarget(file)
234
+ );
122
235
  const typeCheckFiles = normalizedFiles.filter(isTypeCheckTarget);
123
236
 
124
237
  const clientTypeFiles = [];
125
238
  const serverTypeFiles = [];
239
+ const rootConfigChanged = normalizedFiles.some(file =>
240
+ /^tsconfig(?:\.[^/]*)?\.json$/.test(file)
241
+ );
242
+ if (rootConfigChanged) {
243
+ clientTypeFiles.push('config');
244
+ serverTypeFiles.push('config');
245
+ }
246
+ let checkUi =
247
+ rootConfigChanged ||
248
+ normalizedFiles.some(
249
+ file =>
250
+ isUiFile(file) ||
251
+ file.startsWith('shared/') ||
252
+ file.startsWith('eslint.mcp-ui.config.') ||
253
+ file === 'package.json'
254
+ );
126
255
 
127
256
  for (const filePath of typeCheckFiles) {
128
- if (filePath.startsWith('client/')) {
257
+ if (isUiFile(filePath)) {
258
+ checkUi = true;
259
+ } else if (filePath.startsWith('client/')) {
129
260
  clientTypeFiles.push(filePath);
130
261
  } else if (filePath.startsWith('server/')) {
131
262
  serverTypeFiles.push(filePath);
@@ -135,36 +266,52 @@ async function runSelectiveLint(inputFiles) {
135
266
  }
136
267
  }
137
268
 
138
- const tasks = [];
269
+ const taskSpecs = [];
139
270
 
140
271
  if (eslintFiles.length > 0) {
141
- tasks.push(runCommand(getBinName('npx'), ['eslint', '--quiet', ...eslintFiles]));
272
+ taskSpecs.push([getBinName('npx'), ['eslint', '--quiet', ...eslintFiles]]);
142
273
  }
143
274
 
144
275
  if (stylelintFiles.length > 0 && !canRunStylelint()) {
145
- console.warn('[lint] Skip stylelint: missing scripts.stylelint or stylelint config');
276
+ console.warn(
277
+ '[lint] Skip stylelint: missing scripts.stylelint or stylelint config'
278
+ );
146
279
  } else if (stylelintFiles.length > 0) {
147
- tasks.push(runCommand(getBinName('npx'), ['stylelint', '--quiet', ...stylelintFiles]));
280
+ taskSpecs.push([
281
+ getBinName('npx'),
282
+ ['stylelint', '--quiet', ...stylelintFiles],
283
+ ]);
148
284
  }
149
285
 
150
286
  if (clientTypeFiles.length > 0) {
151
- tasks.push(runCommand(getBinName('npm'), ['run', 'type:check:client']));
287
+ taskSpecs.push([getBinName('npm'), ['run', 'type:check:client']]);
152
288
  }
153
289
 
154
290
  if (serverTypeFiles.length > 0) {
155
- tasks.push(runCommand(getBinName('npm'), ['run', 'type:check:server']));
291
+ taskSpecs.push([getBinName('npm'), ['run', 'type:check:server']]);
156
292
  }
157
293
 
158
- if (tasks.length === 0) {
294
+ if (checkUi) taskSpecs.push(...uiTasks());
295
+
296
+ if (taskSpecs.length === 0) {
159
297
  console.log('[lint] No supported files matched for lint');
160
298
  process.exit(0);
161
299
  }
162
300
 
163
- const results = await Promise.all(tasks);
164
- process.exit(results.some(code => code !== 0) ? 1 : 0);
301
+ process.exit(await runTasksSerially(taskSpecs));
165
302
  }
166
303
 
167
304
  async function main() {
305
+ const args = process.argv.slice(2);
306
+ if (args.length === 1 && args[0] === '--eslint-mcp-ui') {
307
+ process.exit(await runTasksSerially(uiTasks({ types: false })));
308
+ return;
309
+ }
310
+ if (args.length && !(args[0] === '--files' && args.length > 1)) {
311
+ throw new Error('用法: lint.js [--files <paths...>]');
312
+ }
313
+ if (args[0] === '--files' && args.slice(1).some(arg => arg.startsWith('--')))
314
+ throw new Error('--files 不可与其他检查模式混用');
168
315
  const files = parseFilesArg(process.argv.slice(2));
169
316
  if (files === null) {
170
317
  await runDefaultLint();
@@ -179,7 +326,7 @@ async function main() {
179
326
  await runSelectiveLint(files);
180
327
  }
181
328
 
182
- main().catch((error) => {
329
+ main().catch(error => {
183
330
  const message = error instanceof Error ? error.message : String(error);
184
331
  console.error(`[lint] Failed to run lint: ${message}`);
185
332
  process.exit(1);
@@ -0,0 +1,32 @@
1
+ // MCP UI 是可选浏览器工程;没有源码时跳过,否则直接交给 tsc。
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const { spawnSync } = require('node:child_process');
5
+
6
+ function hasSource(dir) {
7
+ if (!fs.existsSync(dir)) return false;
8
+ return fs.readdirSync(dir, { withFileTypes: true }).some(entry => {
9
+ if (['node_modules', 'dist'].includes(entry.name)) return false;
10
+ if (entry.isDirectory()) return hasSource(path.join(dir, entry.name));
11
+ return entry.isFile() && /\.(?:[cm]?[jt]sx?)$/.test(entry.name);
12
+ });
13
+ }
14
+
15
+ if (hasSource('server/mcp/ui')) {
16
+ // 已有应用的独立 UI 配置继续生效,避免升级覆盖自定义 paths/types。
17
+ const config = fs.existsSync('server/mcp/ui/tsconfig.json')
18
+ ? 'server/mcp/ui/tsconfig.json'
19
+ : 'tsconfig.mcp-ui.json';
20
+ const result = spawnSync(
21
+ process.execPath,
22
+ [
23
+ require.resolve('typescript/bin/tsc'),
24
+ '--noEmit',
25
+ '--project',
26
+ config,
27
+ ],
28
+ { stdio: 'inherit' }
29
+ );
30
+ if (result.error) console.error(result.error.message);
31
+ process.exitCode = result.status ?? 1;
32
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "jsx": "react-jsx",
7
+ "types": [],
8
+ "strict": true,
9
+ "checkJs": true,
10
+ "lib": [
11
+ "ES2020",
12
+ "DOM",
13
+ "DOM.Iterable"
14
+ ],
15
+ "allowJs": true,
16
+ "skipLibCheck": true,
17
+ "esModuleInterop": true,
18
+ "noEmit": true,
19
+ "baseUrl": ".",
20
+ "paths": {
21
+ "@shared/*": [
22
+ "shared/*"
23
+ ]
24
+ }
25
+ },
26
+ "include": [
27
+ "server/mcp/ui/**/*"
28
+ ],
29
+ "exclude": [
30
+ "node_modules",
31
+ "dist"
32
+ ]
33
+ }