外观
Lint
执行:
全量 lint:
bash
npm run lint1
支持 TASKS 参数
该命令支持通过 TASKS 来指定具体执行哪些任务(不传的话默认执行全部任务)。
该参数支持白名单和黑名单模式,并且支持 * 通配符。注意,白名单和黑名单模式不可混用,以避免歧义。
bash
# 白名单:执行所有 spa: 开头的任务
cross-env TASKS=spa:* npm run <example-command>
# 白名单:混合精确匹配和通配符
cross-env TASKS=clean,ssg:* npm run <example-command>
# 黑名单:排除所有 spa: 开头的任务
cross-env TASKS=-spa:* npm run <example-command>1
2
3
4
5
6
2
3
4
5
6
scripts/lint.mts 源码
typescript
import { joinPath, isPathExists, refreshGitIndex } from "nsuite";
import { runCommandInChildProcess } from "#scripts/utils/child-process";
import { useTask } from "#scripts/utils/use-task";
import { checkEnvFilesConsistency } from "#scripts/utils/check-env";
import {
PATH_APPS_HOME,
STANDALONE_SSG_APPS_NAMES,
STANDALONE_SSR_APPS_NAMES,
SUB_APPS_NAMES,
} from "#utils/ConstantUtils";
const { killAllChildProcessWhenSuitable, addTask, runTasksSequentially, printTaskStatisticsInfo } =
useTask({ allowTasks: process.env.TASKS || "" });
killAllChildProcessWhenSuitable();
addTask("check:env", async () => {
await checkEnvFilesConsistency();
});
addTask("server", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "tsc",
args: `--noEmit --project ./tsconfig.json`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
for (const appName of SUB_APPS_NAMES) {
addTask(`spa:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// vue-tsc
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "vue-tsc",
args: `--noEmit --project ./tsconfig.json`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (vue-tsc) failed: exitCode=${exitCode}`);
}
}
});
}
/**
* 顺序处理所有 SSG APP(静态:Next.js、Nuxt 静态、VitePress 等)
*/
for (const appName of STANDALONE_SSG_APPS_NAMES) {
addTask(`ssg:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps-home/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// 区分应用类型:Next.js、Nuxt 4 应用、VitePress 2 应用
const pathApp = joinPath(PATH_APPS_HOME, appName);
const pathNuxtConfig = joinPath(pathApp, "nuxt.config.ts");
const pathNextConfig = joinPath(pathApp, "next.config.ts");
const isNext = await isPathExists(pathNextConfig);
const isNuxt = await isPathExists(pathNuxtConfig);
if (isNext) {
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "tsc",
args: "--noEmit --project ./tsconfig.json",
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (next) failed: exitCode=${exitCode}`);
}
return;
}
if (!isNuxt) {
// VitePress 项目,执行 ::: 标记格式修复
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "node",
args: `./apps-home/${appName}/scripts/lint.mts`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (vitepress) failed: exitCode=${exitCode}`);
}
return;
}
// Nuxt 项目,执行类型检查
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "cross-env",
args: `APP_NAME=${appName} nuxt typecheck --cwd=./apps-home/${appName}`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (nuxt typecheck) failed: exitCode=${exitCode}`);
}
});
}
/**
* 顺序处理所有 SSR APP(Nuxt SSR,执行类型检查)
*/
for (const appName of STANDALONE_SSR_APPS_NAMES) {
addTask(`ssr:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps-home/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// Nuxt SSR,执行类型检查
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "cross-env",
args: `APP_NAME=${appName} nuxt typecheck --cwd=./apps-home/${appName}`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (nuxt typecheck) failed: exitCode=${exitCode}`);
}
});
}
/**
* Android 壳检查:委托 client/android 子项目自身的 lint 流水线
* (prettier、eslint、markdownlint、tsc、gradlew lint 与 smoke 测试)
*/
addTask("android", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "node",
args: "--run lint",
env: process.env,
cwd: "./client/android",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
/**
* Electron 壳检查:委托 client/electron 子项目自身的 lint 流水线
* (type-check、构建与 node:test)
*/
addTask("electron", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "node",
args: "--run lint",
env: process.env,
cwd: "./client/electron",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
await runTasksSequentially();
printTaskStatisticsInfo();
// 所有检查通过后刷新 git 索引,清除格式化工具重写造成的假差异
const { hasRealChanges, status } = refreshGitIndex();
if (hasRealChanges) {
console.log("刷新完成,剩余真实差异:");
console.log(status);
} else {
console.log("刷新完成,工作区与索引内容一致,无真实差异。");
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317