@antfu/eslint-config 4.13.0 → 4.13.2
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 +3 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +259 -324
- package/dist/index.d.ts +9155 -9763
- package/dist/index.js +2182 -2695
- package/package.json +30 -30
package/README.md
CHANGED
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
>
|
|
29
29
|
> If you are using this config directly, I suggest you **review the changes every time you update**. Or if you want more control over the rules, always feel free to fork it. Thanks!
|
|
30
30
|
|
|
31
|
+
> [!TIP]
|
|
32
|
+
> If you are interested in the tooling and the philosophy behind this config, I gave a talk about ESLint flat config at [JSNation 2024 - ESLint One for All Made Easy](https://gitnation.com/contents/eslint-one-for-all-made-easy), slides are [here](https://talks.antfu.me/2024/jsnation).
|
|
33
|
+
|
|
31
34
|
## Usage
|
|
32
35
|
|
|
33
36
|
### Starter Wizard
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export { };
|
package/dist/cli.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import * as p$4 from "@clack/prompts";
|
|
3
|
+
import * as p$3 from "@clack/prompts";
|
|
4
|
+
import * as p$2 from "@clack/prompts";
|
|
5
|
+
import * as p$1 from "@clack/prompts";
|
|
6
|
+
import * as p from "@clack/prompts";
|
|
7
|
+
import c, { green } from "ansis";
|
|
5
8
|
import { cac } from "cac";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import fsp from "node:fs/promises";
|
|
12
|
+
import parse from "parse-gitignore";
|
|
13
|
+
import { execSync } from "node:child_process";
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
var version = "4.13.
|
|
9
|
-
|
|
10
|
-
// src/cli/run.ts
|
|
11
|
-
import fs3 from "node:fs";
|
|
12
|
-
import path4 from "node:path";
|
|
13
|
-
import process4 from "node:process";
|
|
14
|
-
import * as p4 from "@clack/prompts";
|
|
15
|
-
import c4 from "ansis";
|
|
15
|
+
//#region package.json
|
|
16
|
+
var version = "4.13.2";
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/cli/constants.ts
|
|
20
|
+
const vscodeSettingsString = `
|
|
20
21
|
// Disable the default formatter, use eslint instead
|
|
21
22
|
"prettier.enable": false,
|
|
22
23
|
"editor.formatOnSave": false,
|
|
@@ -67,345 +68,279 @@ var vscodeSettingsString = `
|
|
|
67
68
|
"postcss"
|
|
68
69
|
]
|
|
69
70
|
`;
|
|
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
|
-
|
|
71
|
+
const frameworkOptions = [
|
|
72
|
+
{
|
|
73
|
+
label: c.green("Vue"),
|
|
74
|
+
value: "vue"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: c.cyan("React"),
|
|
78
|
+
value: "react"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: c.red("Svelte"),
|
|
82
|
+
value: "svelte"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: c.magenta("Astro"),
|
|
86
|
+
value: "astro"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: c.cyan("Solid"),
|
|
90
|
+
value: "solid"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: c.blue("Slidev"),
|
|
94
|
+
value: "slidev"
|
|
95
|
+
}
|
|
95
96
|
];
|
|
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
|
-
react: [
|
|
121
|
-
"@eslint-react/eslint-plugin",
|
|
122
|
-
"eslint-plugin-react-hooks",
|
|
123
|
-
"eslint-plugin-react-refresh"
|
|
124
|
-
],
|
|
125
|
-
slidev: [
|
|
126
|
-
"prettier-plugin-slidev"
|
|
127
|
-
],
|
|
128
|
-
solid: [
|
|
129
|
-
"eslint-plugin-solid"
|
|
130
|
-
],
|
|
131
|
-
svelte: [
|
|
132
|
-
"eslint-plugin-svelte",
|
|
133
|
-
"svelte-eslint-parser"
|
|
134
|
-
],
|
|
135
|
-
unocss: [
|
|
136
|
-
"@unocss/eslint-plugin"
|
|
137
|
-
],
|
|
138
|
-
vue: []
|
|
97
|
+
const frameworks = frameworkOptions.map(({ value }) => value);
|
|
98
|
+
const extraOptions = [{
|
|
99
|
+
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
|
|
100
|
+
label: c.red("Formatter"),
|
|
101
|
+
value: "formatter"
|
|
102
|
+
}, {
|
|
103
|
+
label: c.cyan("UnoCSS"),
|
|
104
|
+
value: "unocss"
|
|
105
|
+
}];
|
|
106
|
+
const extra = extraOptions.map(({ value }) => value);
|
|
107
|
+
const dependenciesMap = {
|
|
108
|
+
astro: ["eslint-plugin-astro", "astro-eslint-parser"],
|
|
109
|
+
formatter: ["eslint-plugin-format"],
|
|
110
|
+
formatterAstro: ["prettier-plugin-astro"],
|
|
111
|
+
react: [
|
|
112
|
+
"@eslint-react/eslint-plugin",
|
|
113
|
+
"eslint-plugin-react-hooks",
|
|
114
|
+
"eslint-plugin-react-refresh"
|
|
115
|
+
],
|
|
116
|
+
slidev: ["prettier-plugin-slidev"],
|
|
117
|
+
solid: ["eslint-plugin-solid"],
|
|
118
|
+
svelte: ["eslint-plugin-svelte", "svelte-eslint-parser"],
|
|
119
|
+
unocss: ["@unocss/eslint-plugin"],
|
|
120
|
+
vue: []
|
|
139
121
|
};
|
|
140
122
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
import fsp from "node:fs/promises";
|
|
144
|
-
import path from "node:path";
|
|
145
|
-
import process from "node:process";
|
|
146
|
-
import * as p from "@clack/prompts";
|
|
147
|
-
import c2 from "ansis";
|
|
148
|
-
import parse from "parse-gitignore";
|
|
149
|
-
|
|
150
|
-
// src/cli/utils.ts
|
|
151
|
-
import { execSync } from "node:child_process";
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/cli/utils.ts
|
|
152
125
|
function isGitClean() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
126
|
+
try {
|
|
127
|
+
execSync("git diff-index --quiet HEAD --");
|
|
128
|
+
return true;
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
159
132
|
}
|
|
160
133
|
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
161
|
-
|
|
134
|
+
return `
|
|
162
135
|
import antfu from '@antfu/eslint-config'
|
|
163
136
|
|
|
164
137
|
export default antfu({
|
|
165
138
|
${mainConfig}
|
|
166
|
-
}${additionalConfigs?.map((config) => `,{
|
|
167
|
-
${config}
|
|
168
|
-
}`)})
|
|
139
|
+
}${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
|
|
169
140
|
`.trimStart();
|
|
170
141
|
}
|
|
171
142
|
|
|
172
|
-
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/cli/stages/update-eslint-files.ts
|
|
173
145
|
async function updateEslintFiles(result) {
|
|
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
|
-
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
207
|
-
p.log.success(c2.green`Created ${configFileName}`);
|
|
208
|
-
const files = fs.readdirSync(cwd);
|
|
209
|
-
const legacyConfig = [];
|
|
210
|
-
files.forEach((file) => {
|
|
211
|
-
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
212
|
-
legacyConfig.push(file);
|
|
213
|
-
});
|
|
214
|
-
if (legacyConfig.length)
|
|
215
|
-
p.note(c2.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
146
|
+
const cwd = process.cwd();
|
|
147
|
+
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
148
|
+
const pathPackageJSON = path.join(cwd, "package.json");
|
|
149
|
+
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
150
|
+
const pkg = JSON.parse(pkgContent);
|
|
151
|
+
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
152
|
+
const pathFlatConfig = path.join(cwd, configFileName);
|
|
153
|
+
const eslintIgnores = [];
|
|
154
|
+
if (fs.existsSync(pathESLintIgnore)) {
|
|
155
|
+
p$4.log.step(c.cyan`Migrating existing .eslintignore`);
|
|
156
|
+
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
157
|
+
const parsed = parse(content);
|
|
158
|
+
const globs = parsed.globs();
|
|
159
|
+
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
160
|
+
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
161
|
+
}
|
|
162
|
+
const configLines = [];
|
|
163
|
+
if (eslintIgnores.length) configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
164
|
+
if (result.extra.includes("formatter")) configLines.push(`formatters: true,`);
|
|
165
|
+
if (result.extra.includes("unocss")) configLines.push(`unocss: true,`);
|
|
166
|
+
for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
|
|
167
|
+
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
168
|
+
const additionalConfig = [];
|
|
169
|
+
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
170
|
+
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
171
|
+
p$4.log.success(c.green`Created ${configFileName}`);
|
|
172
|
+
const files = fs.readdirSync(cwd);
|
|
173
|
+
const legacyConfig = [];
|
|
174
|
+
files.forEach((file) => {
|
|
175
|
+
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) legacyConfig.push(file);
|
|
176
|
+
});
|
|
177
|
+
if (legacyConfig.length) p$4.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
216
178
|
}
|
|
217
179
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
"eslint-plugin-react-refresh": "^0.4.20",
|
|
235
|
-
"eslint-plugin-solid": "^0.14.5",
|
|
236
|
-
"eslint-plugin-svelte": "^3.5.1",
|
|
237
|
-
"prettier-plugin-astro": "^0.14.1",
|
|
238
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
239
|
-
"svelte-eslint-parser": "^1.1.3"
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/cli/constants-generated.ts
|
|
182
|
+
const versionsMap = {
|
|
183
|
+
"@eslint-react/eslint-plugin": "^1.49.0",
|
|
184
|
+
"@unocss/eslint-plugin": "^66.1.2",
|
|
185
|
+
"astro-eslint-parser": "^1.2.2",
|
|
186
|
+
"eslint": "^9.27.0",
|
|
187
|
+
"eslint-plugin-astro": "^1.3.1",
|
|
188
|
+
"eslint-plugin-format": "^1.0.1",
|
|
189
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
190
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
191
|
+
"eslint-plugin-solid": "^0.14.5",
|
|
192
|
+
"eslint-plugin-svelte": "^3.8.2",
|
|
193
|
+
"prettier-plugin-astro": "^0.14.1",
|
|
194
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
195
|
+
"svelte-eslint-parser": "^1.2.0"
|
|
240
196
|
};
|
|
241
197
|
|
|
242
|
-
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/cli/stages/update-package-json.ts
|
|
243
200
|
async function updatePackageJson(result) {
|
|
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
|
-
pkg.devDependencies[f] = versionsMap[f];
|
|
281
|
-
addedPackages.push(f);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (addedPackages.length)
|
|
286
|
-
p2.note(c3.dim(addedPackages.join(", ")), "Added packages");
|
|
287
|
-
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
288
|
-
p2.log.success(c3.green`Changes wrote to package.json`);
|
|
201
|
+
const cwd = process.cwd();
|
|
202
|
+
const pathPackageJSON = path.join(cwd, "package.json");
|
|
203
|
+
p$3.log.step(c.cyan`Bumping @antfu/eslint-config to v${version}`);
|
|
204
|
+
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
205
|
+
const pkg = JSON.parse(pkgContent);
|
|
206
|
+
pkg.devDependencies ??= {};
|
|
207
|
+
pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
|
|
208
|
+
pkg.devDependencies.eslint ??= versionsMap.eslint;
|
|
209
|
+
const addedPackages = [];
|
|
210
|
+
if (result.extra.length) result.extra.forEach((item) => {
|
|
211
|
+
switch (item) {
|
|
212
|
+
case "formatter":
|
|
213
|
+
[...dependenciesMap.formatter, ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []].forEach((f) => {
|
|
214
|
+
if (!f) return;
|
|
215
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
216
|
+
addedPackages.push(f);
|
|
217
|
+
});
|
|
218
|
+
break;
|
|
219
|
+
case "unocss":
|
|
220
|
+
dependenciesMap.unocss.forEach((f) => {
|
|
221
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
222
|
+
addedPackages.push(f);
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
for (const framework of result.frameworks) {
|
|
228
|
+
const deps = dependenciesMap[framework];
|
|
229
|
+
if (deps) deps.forEach((f) => {
|
|
230
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
231
|
+
addedPackages.push(f);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (addedPackages.length) p$3.note(c.dim(addedPackages.join(", ")), "Added packages");
|
|
235
|
+
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
236
|
+
p$3.log.success(c.green`Changes wrote to package.json`);
|
|
289
237
|
}
|
|
290
238
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
import fsp3 from "node:fs/promises";
|
|
294
|
-
import path3 from "node:path";
|
|
295
|
-
import process3 from "node:process";
|
|
296
|
-
import * as p3 from "@clack/prompts";
|
|
297
|
-
import { green } from "ansis";
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/cli/stages/update-vscode-settings.ts
|
|
298
241
|
async function updateVscodeSettings(result) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
`;
|
|
316
|
-
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
317
|
-
p3.log.success(green`Updated .vscode/settings.json`);
|
|
318
|
-
}
|
|
242
|
+
const cwd = process.cwd();
|
|
243
|
+
if (!result.updateVscodeSettings) return;
|
|
244
|
+
const dotVscodePath = path.join(cwd, ".vscode");
|
|
245
|
+
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
246
|
+
if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
|
|
247
|
+
if (!fs.existsSync(settingsPath)) {
|
|
248
|
+
await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
|
|
249
|
+
p$2.log.success(green`Created .vscode/settings.json`);
|
|
250
|
+
} else {
|
|
251
|
+
let settingsContent = await fsp.readFile(settingsPath, "utf8");
|
|
252
|
+
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
253
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
254
|
+
settingsContent += `${vscodeSettingsString}}\n`;
|
|
255
|
+
await fsp.writeFile(settingsPath, settingsContent, "utf-8");
|
|
256
|
+
p$2.log.success(green`Updated .vscode/settings.json`);
|
|
257
|
+
}
|
|
319
258
|
}
|
|
320
259
|
|
|
321
|
-
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/cli/run.ts
|
|
322
262
|
async function run(options = {}) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return process4.exit(1);
|
|
384
|
-
}
|
|
385
|
-
await updatePackageJson(result);
|
|
386
|
-
await updateEslintFiles(result);
|
|
387
|
-
await updateVscodeSettings(result);
|
|
388
|
-
p4.log.success(c4.green`Setup completed`);
|
|
389
|
-
p4.outro(`Now you can update the dependencies by run ${c4.blue("pnpm install")} and run ${c4.blue("eslint --fix")}
|
|
390
|
-
`);
|
|
263
|
+
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
|
|
264
|
+
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
265
|
+
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
266
|
+
if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
267
|
+
p$1.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
268
|
+
return process.exit(1);
|
|
269
|
+
}
|
|
270
|
+
let result = {
|
|
271
|
+
extra: argExtra ?? [],
|
|
272
|
+
frameworks: argTemplate ?? [],
|
|
273
|
+
uncommittedConfirmed: false,
|
|
274
|
+
updateVscodeSettings: true
|
|
275
|
+
};
|
|
276
|
+
if (!argSkipPrompt) {
|
|
277
|
+
result = await p$1.group({
|
|
278
|
+
uncommittedConfirmed: () => {
|
|
279
|
+
if (argSkipPrompt || isGitClean()) return Promise.resolve(true);
|
|
280
|
+
return p$1.confirm({
|
|
281
|
+
initialValue: false,
|
|
282
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
frameworks: ({ results }) => {
|
|
286
|
+
const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
|
|
287
|
+
if (!results.uncommittedConfirmed || isArgTemplateValid) return;
|
|
288
|
+
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
289
|
+
return p$1.multiselect({
|
|
290
|
+
message: c.reset(message),
|
|
291
|
+
options: frameworkOptions,
|
|
292
|
+
required: false
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
extra: ({ results }) => {
|
|
296
|
+
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
297
|
+
if (!results.uncommittedConfirmed || isArgExtraValid) return;
|
|
298
|
+
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
299
|
+
return p$1.multiselect({
|
|
300
|
+
message: c.reset(message),
|
|
301
|
+
options: extraOptions,
|
|
302
|
+
required: false
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
updateVscodeSettings: ({ results }) => {
|
|
306
|
+
if (!results.uncommittedConfirmed) return;
|
|
307
|
+
return p$1.confirm({
|
|
308
|
+
initialValue: true,
|
|
309
|
+
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}, { onCancel: () => {
|
|
313
|
+
p$1.cancel("Operation cancelled.");
|
|
314
|
+
process.exit(0);
|
|
315
|
+
} });
|
|
316
|
+
if (!result.uncommittedConfirmed) return process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
await updatePackageJson(result);
|
|
319
|
+
await updateEslintFiles(result);
|
|
320
|
+
await updateVscodeSettings(result);
|
|
321
|
+
p$1.log.success(c.green`Setup completed`);
|
|
322
|
+
p$1.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
|
|
391
323
|
}
|
|
392
324
|
|
|
393
|
-
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/cli/index.ts
|
|
394
327
|
function header() {
|
|
395
|
-
|
|
396
|
-
|
|
328
|
+
console.log("\n");
|
|
329
|
+
p.intro(`${c.green`@antfu/eslint-config `}${c.dim`v${version}`}`);
|
|
397
330
|
}
|
|
398
|
-
|
|
331
|
+
const cli = cac("@antfu/eslint-config");
|
|
399
332
|
cli.command("", "Run the initialization or migration").option("--yes, -y", "Skip prompts and use default values", { default: false }).option("--template, -t <template>", "Use the framework template for optimal customization: vue / react / svelte / astro", { type: [] }).option("--extra, -e <extra>", "Use the extra utils: formatter / perfectionist / unocss", { type: [] }).action(async (args) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
333
|
+
header();
|
|
334
|
+
try {
|
|
335
|
+
await run(args);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
p.log.error(c.inverse.red(" Failed to migrate "));
|
|
338
|
+
p.log.error(c.red`✘ ${String(error)}`);
|
|
339
|
+
process.exit(1);
|
|
340
|
+
}
|
|
408
341
|
});
|
|
409
342
|
cli.help();
|
|
410
343
|
cli.version(version);
|
|
411
344
|
cli.parse();
|
|
345
|
+
|
|
346
|
+
//#endregion
|