@2030/eslint-config 2.0.3 → 3.0.0
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 +191 -270
- package/bin/index.js +1 -1
- package/bin/index.mjs +2 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +340 -0
- package/dist/index.d.mts +19877 -0
- package/dist/index.mjs +2584 -0
- package/dist/lib-W3aIkNCI.mjs +11156 -0
- package/package.json +125 -103
- package/dist/cli.cjs +0 -614
- package/dist/cli.d.cts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -585
- package/dist/index.cjs +0 -2756
- package/dist/index.d.cts +0 -16074
- package/dist/index.d.ts +0 -16074
- package/dist/index.js +0 -2643
package/dist/cli.js
DELETED
|
@@ -1,585 +0,0 @@
|
|
|
1
|
-
// src/cli/index.ts
|
|
2
|
-
import process5 from "node:process";
|
|
3
|
-
import * as p5 from "@clack/prompts";
|
|
4
|
-
import c6 from "picocolors";
|
|
5
|
-
import yargs from "yargs";
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
7
|
-
|
|
8
|
-
// src/cli/constants.ts
|
|
9
|
-
import c from "picocolors";
|
|
10
|
-
|
|
11
|
-
// package.json
|
|
12
|
-
var package_default = {
|
|
13
|
-
name: "@2030/eslint-config",
|
|
14
|
-
type: "module",
|
|
15
|
-
version: "2.0.3",
|
|
16
|
-
description: "Shareable ESLint config for conventional coding style",
|
|
17
|
-
author: "Dai Jun <zijun2030@163.com>",
|
|
18
|
-
license: "MIT",
|
|
19
|
-
homepage: "https://github.com/Jun2030/eslint-config",
|
|
20
|
-
keywords: [
|
|
21
|
-
"eslint-config"
|
|
22
|
-
],
|
|
23
|
-
exports: {
|
|
24
|
-
".": {
|
|
25
|
-
import: "./dist/index.js",
|
|
26
|
-
require: "./dist/index.cjs"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
main: "./dist/index.js",
|
|
30
|
-
types: "./dist/index.d.ts",
|
|
31
|
-
bin: "./bin/index.js",
|
|
32
|
-
files: [
|
|
33
|
-
"bin",
|
|
34
|
-
"dist"
|
|
35
|
-
],
|
|
36
|
-
scripts: {
|
|
37
|
-
build: "nr typegen && tsup --format esm,cjs --clean --dts",
|
|
38
|
-
stub: "tsup --format esm",
|
|
39
|
-
dev: "npx @eslint/config-inspector --config eslint.config.ts",
|
|
40
|
-
"build:inspector": "pnpm build && npx @eslint/config-inspector build",
|
|
41
|
-
watch: "tsup --format esm,cjs --watch",
|
|
42
|
-
lint: "eslint --flag unstable_ts_config .",
|
|
43
|
-
typegen: "esno scripts/typegen.ts",
|
|
44
|
-
prepack: "nr build",
|
|
45
|
-
release: "bumpp && pnpm publish",
|
|
46
|
-
test: "vitest",
|
|
47
|
-
typecheck: "tsc --noEmit",
|
|
48
|
-
prepare: "simple-git-hooks"
|
|
49
|
-
},
|
|
50
|
-
peerDependencies: {
|
|
51
|
-
"@eslint-react/eslint-plugin": "^1.5.8",
|
|
52
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
53
|
-
"@unocss/eslint-plugin": ">=0.50.0",
|
|
54
|
-
"astro-eslint-parser": "^1.0.2",
|
|
55
|
-
eslint: "^9.10.0",
|
|
56
|
-
"eslint-plugin-astro": "^1.2.0",
|
|
57
|
-
"eslint-plugin-format": ">=0.1.0",
|
|
58
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
59
|
-
"eslint-plugin-react-refresh": "^0.4.4",
|
|
60
|
-
"eslint-plugin-solid": "^0.14.3",
|
|
61
|
-
"eslint-plugin-svelte": ">=2.35.1",
|
|
62
|
-
"prettier-plugin-astro": "^0.13.0",
|
|
63
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
64
|
-
"svelte-eslint-parser": ">=0.37.0"
|
|
65
|
-
},
|
|
66
|
-
peerDependenciesMeta: {
|
|
67
|
-
"@eslint-react/eslint-plugin": {
|
|
68
|
-
optional: true
|
|
69
|
-
},
|
|
70
|
-
"@prettier/plugin-xml": {
|
|
71
|
-
optional: true
|
|
72
|
-
},
|
|
73
|
-
"@unocss/eslint-plugin": {
|
|
74
|
-
optional: true
|
|
75
|
-
},
|
|
76
|
-
"astro-eslint-parser": {
|
|
77
|
-
optional: true
|
|
78
|
-
},
|
|
79
|
-
"eslint-plugin-astro": {
|
|
80
|
-
optional: true
|
|
81
|
-
},
|
|
82
|
-
"eslint-plugin-format": {
|
|
83
|
-
optional: true
|
|
84
|
-
},
|
|
85
|
-
"eslint-plugin-react-hooks": {
|
|
86
|
-
optional: true
|
|
87
|
-
},
|
|
88
|
-
"eslint-plugin-react-refresh": {
|
|
89
|
-
optional: true
|
|
90
|
-
},
|
|
91
|
-
"eslint-plugin-solid": {
|
|
92
|
-
optional: true
|
|
93
|
-
},
|
|
94
|
-
"eslint-plugin-svelte": {
|
|
95
|
-
optional: true
|
|
96
|
-
},
|
|
97
|
-
"prettier-plugin-astro": {
|
|
98
|
-
optional: true
|
|
99
|
-
},
|
|
100
|
-
"prettier-plugin-slidev": {
|
|
101
|
-
optional: true
|
|
102
|
-
},
|
|
103
|
-
"svelte-eslint-parser": {
|
|
104
|
-
optional: true
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
dependencies: {
|
|
108
|
-
"@antfu/install-pkg": "^0.4.1",
|
|
109
|
-
"@clack/prompts": "^0.7.0",
|
|
110
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
111
|
-
"@eslint/markdown": "^6.1.0",
|
|
112
|
-
"@stylistic/eslint-plugin": "^2.8.0",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^8.7.0",
|
|
114
|
-
"@typescript-eslint/parser": "^8.7.0",
|
|
115
|
-
"@vitest/eslint-plugin": "^1.1.4",
|
|
116
|
-
"eslint-config-flat-gitignore": "^0.3.0",
|
|
117
|
-
"eslint-flat-config-utils": "^0.4.0",
|
|
118
|
-
"eslint-merge-processors": "^0.1.0",
|
|
119
|
-
"eslint-plugin-antfu": "^2.7.0",
|
|
120
|
-
"eslint-plugin-command": "^0.2.6",
|
|
121
|
-
"eslint-plugin-import-x": "^4.3.0",
|
|
122
|
-
"eslint-plugin-jsdoc": "^50.3.0",
|
|
123
|
-
"eslint-plugin-jsonc": "^2.16.0",
|
|
124
|
-
"eslint-plugin-n": "^17.10.3",
|
|
125
|
-
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
126
|
-
"eslint-plugin-perfectionist": "^3.7.0",
|
|
127
|
-
"eslint-plugin-regexp": "^2.6.0",
|
|
128
|
-
"eslint-plugin-toml": "^0.11.1",
|
|
129
|
-
"eslint-plugin-unicorn": "^55.0.0",
|
|
130
|
-
"eslint-plugin-unused-imports": "^4.1.4",
|
|
131
|
-
"eslint-plugin-vue": "^9.28.0",
|
|
132
|
-
"eslint-plugin-yml": "^1.14.0",
|
|
133
|
-
"eslint-processor-vue-blocks": "^0.1.2",
|
|
134
|
-
globals: "^15.9.0",
|
|
135
|
-
"jsonc-eslint-parser": "^2.4.0",
|
|
136
|
-
"local-pkg": "^0.5.0",
|
|
137
|
-
"parse-gitignore": "^2.0.0",
|
|
138
|
-
picocolors: "^1.1.0",
|
|
139
|
-
"toml-eslint-parser": "^0.10.0",
|
|
140
|
-
"vue-eslint-parser": "^9.4.3",
|
|
141
|
-
"yaml-eslint-parser": "^1.2.3",
|
|
142
|
-
yargs: "^17.7.2"
|
|
143
|
-
},
|
|
144
|
-
devDependencies: {
|
|
145
|
-
"@2030/eslint-config": "workspace:*",
|
|
146
|
-
"@antfu/ni": "^0.23.0",
|
|
147
|
-
"@eslint-react/eslint-plugin": "^1.14.2",
|
|
148
|
-
"@eslint/config-inspector": "^0.5.4",
|
|
149
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
150
|
-
"@stylistic/eslint-plugin-migrate": "^2.8.0",
|
|
151
|
-
"@types/fs-extra": "^11.0.4",
|
|
152
|
-
"@types/node": "^22.7.3",
|
|
153
|
-
"@types/prompts": "^2.4.9",
|
|
154
|
-
"@types/yargs": "^17.0.33",
|
|
155
|
-
"@unocss/eslint-plugin": "^0.62.4",
|
|
156
|
-
"astro-eslint-parser": "^1.0.3",
|
|
157
|
-
bumpp: "^9.5.2",
|
|
158
|
-
eslint: "^9.11.1",
|
|
159
|
-
"eslint-plugin-astro": "^1.2.4",
|
|
160
|
-
"eslint-plugin-format": "^0.1.2",
|
|
161
|
-
"eslint-plugin-react-hooks": "^4.6.2",
|
|
162
|
-
"eslint-plugin-react-refresh": "^0.4.12",
|
|
163
|
-
"eslint-plugin-solid": "^0.14.3",
|
|
164
|
-
"eslint-plugin-svelte": "^2.44.0",
|
|
165
|
-
"eslint-typegen": "^0.3.2",
|
|
166
|
-
esno: "^4.7.0",
|
|
167
|
-
execa: "^9.4.0",
|
|
168
|
-
"fast-glob": "^3.3.2",
|
|
169
|
-
"fs-extra": "^11.2.0",
|
|
170
|
-
jiti: "^2.0.0",
|
|
171
|
-
"lint-staged": "^15.2.10",
|
|
172
|
-
"prettier-plugin-astro": "^0.14.1",
|
|
173
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
174
|
-
rimraf: "^6.0.1",
|
|
175
|
-
"simple-git-hooks": "^2.11.1",
|
|
176
|
-
svelte: "^4.2.19",
|
|
177
|
-
"svelte-eslint-parser": "^0.41.1",
|
|
178
|
-
tsup: "^8.3.0",
|
|
179
|
-
tsx: "^4.19.1",
|
|
180
|
-
typescript: "^5.6.2",
|
|
181
|
-
vitest: "^2.1.1",
|
|
182
|
-
vue: "^3.5.9"
|
|
183
|
-
},
|
|
184
|
-
resolutions: {
|
|
185
|
-
"@eslint-community/eslint-utils": "^4.4.0",
|
|
186
|
-
"@typescript-eslint/utils": "^8.7.0",
|
|
187
|
-
eslint: "^9.11.1",
|
|
188
|
-
tsx: "^4.19.1"
|
|
189
|
-
},
|
|
190
|
-
"simple-git-hooks": {
|
|
191
|
-
"pre-commit": "npx lint-staged"
|
|
192
|
-
},
|
|
193
|
-
"lint-staged": {
|
|
194
|
-
"*": "eslint --flag unstable_ts_config --fix"
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// src/cli/constants.ts
|
|
199
|
-
var vscodeSettingsString = `
|
|
200
|
-
// Disable the default formatter, use eslint instead
|
|
201
|
-
"prettier.enable": false,
|
|
202
|
-
"editor.formatOnSave": false,
|
|
203
|
-
|
|
204
|
-
// Auto fix
|
|
205
|
-
"editor.codeActionsOnSave": {
|
|
206
|
-
"source.fixAll.eslint": "explicit",
|
|
207
|
-
"source.organizeImports": "never"
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
211
|
-
"eslint.rules.customizations": [
|
|
212
|
-
{ "rule": "style/*", "severity": "off", "fixable": true },
|
|
213
|
-
{ "rule": "format/*", "severity": "off", "fixable": true },
|
|
214
|
-
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
215
|
-
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
216
|
-
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
217
|
-
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
218
|
-
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
219
|
-
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
220
|
-
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
221
|
-
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
222
|
-
],
|
|
223
|
-
|
|
224
|
-
// Enable eslint for all supported languages
|
|
225
|
-
"eslint.validate": [
|
|
226
|
-
"javascript",
|
|
227
|
-
"javascriptreact",
|
|
228
|
-
"typescript",
|
|
229
|
-
"typescriptreact",
|
|
230
|
-
"vue",
|
|
231
|
-
"html",
|
|
232
|
-
"markdown",
|
|
233
|
-
"json",
|
|
234
|
-
"jsonc",
|
|
235
|
-
"yaml",
|
|
236
|
-
"toml",
|
|
237
|
-
"xml",
|
|
238
|
-
"gql",
|
|
239
|
-
"graphql",
|
|
240
|
-
"astro",
|
|
241
|
-
"css",
|
|
242
|
-
"less",
|
|
243
|
-
"scss",
|
|
244
|
-
"pcss",
|
|
245
|
-
"postcss"
|
|
246
|
-
]
|
|
247
|
-
`;
|
|
248
|
-
var frameworkOptions = [
|
|
249
|
-
{
|
|
250
|
-
label: c.green("Vue"),
|
|
251
|
-
value: "vue"
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
label: c.cyan("React"),
|
|
255
|
-
value: "react"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
label: c.red("Svelte"),
|
|
259
|
-
value: "svelte"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
label: c.magenta("Astro"),
|
|
263
|
-
value: "astro"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
label: c.cyan("Solid"),
|
|
267
|
-
value: "solid"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
label: c.blue("Slidev"),
|
|
271
|
-
value: "slidev"
|
|
272
|
-
}
|
|
273
|
-
];
|
|
274
|
-
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
275
|
-
var extraOptions = [
|
|
276
|
-
{
|
|
277
|
-
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
|
|
278
|
-
label: c.red("Formatter"),
|
|
279
|
-
value: "formatter"
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
label: c.cyan("UnoCSS"),
|
|
283
|
-
value: "unocss"
|
|
284
|
-
}
|
|
285
|
-
];
|
|
286
|
-
var extra = extraOptions.map(({ value }) => value);
|
|
287
|
-
var dependenciesMap = {
|
|
288
|
-
astro: [
|
|
289
|
-
"eslint-plugin-astro",
|
|
290
|
-
"astro-eslint-parser"
|
|
291
|
-
],
|
|
292
|
-
react: [
|
|
293
|
-
"@eslint-react/eslint-plugin",
|
|
294
|
-
"eslint-plugin-react-hooks",
|
|
295
|
-
"eslint-plugin-react-refresh"
|
|
296
|
-
],
|
|
297
|
-
slidev: [
|
|
298
|
-
"prettier-plugin-slidev"
|
|
299
|
-
],
|
|
300
|
-
solid: [
|
|
301
|
-
"eslint-plugin-solid"
|
|
302
|
-
],
|
|
303
|
-
svelte: [
|
|
304
|
-
"eslint-plugin-svelte",
|
|
305
|
-
"svelte-eslint-parser"
|
|
306
|
-
],
|
|
307
|
-
vue: []
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// src/cli/run.ts
|
|
311
|
-
import fs3 from "node:fs";
|
|
312
|
-
import path4 from "node:path";
|
|
313
|
-
import process4 from "node:process";
|
|
314
|
-
import * as p4 from "@clack/prompts";
|
|
315
|
-
import c5 from "picocolors";
|
|
316
|
-
|
|
317
|
-
// src/cli/stages/update-eslint-files.ts
|
|
318
|
-
import fs from "node:fs";
|
|
319
|
-
import fsp from "node:fs/promises";
|
|
320
|
-
import path from "node:path";
|
|
321
|
-
import process from "node:process";
|
|
322
|
-
import * as p from "@clack/prompts";
|
|
323
|
-
import parse from "parse-gitignore";
|
|
324
|
-
import c2 from "picocolors";
|
|
325
|
-
|
|
326
|
-
// src/cli/utils.ts
|
|
327
|
-
import { execSync } from "node:child_process";
|
|
328
|
-
function isGitClean() {
|
|
329
|
-
try {
|
|
330
|
-
execSync("git diff-index --quiet HEAD --");
|
|
331
|
-
return true;
|
|
332
|
-
} catch {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
337
|
-
return `
|
|
338
|
-
import jun from '@jun2030/eslint-config'
|
|
339
|
-
|
|
340
|
-
export default jun({
|
|
341
|
-
${mainConfig}
|
|
342
|
-
}${additionalConfigs?.map((config) => `,{
|
|
343
|
-
${config}
|
|
344
|
-
}`)})
|
|
345
|
-
`.trimStart();
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/cli/stages/update-eslint-files.ts
|
|
349
|
-
async function updateEslintFiles(result) {
|
|
350
|
-
const cwd = process.cwd();
|
|
351
|
-
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
352
|
-
const pathPackageJSON = path.join(cwd, "package.json");
|
|
353
|
-
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
354
|
-
const pkg = JSON.parse(pkgContent);
|
|
355
|
-
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
356
|
-
const pathFlatConfig = path.join(cwd, configFileName);
|
|
357
|
-
const eslintIgnores = [];
|
|
358
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
359
|
-
p.log.step(c2.cyan(`Migrating existing .eslintignore`));
|
|
360
|
-
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
361
|
-
const parsed = parse(content);
|
|
362
|
-
const globs = parsed.globs();
|
|
363
|
-
for (const glob of globs) {
|
|
364
|
-
if (glob.type === "ignore")
|
|
365
|
-
eslintIgnores.push(...glob.patterns);
|
|
366
|
-
else if (glob.type === "unignore")
|
|
367
|
-
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const configLines = [];
|
|
371
|
-
if (eslintIgnores.length)
|
|
372
|
-
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
373
|
-
if (result.extra.includes("formatter"))
|
|
374
|
-
configLines.push(`formatters: true,`);
|
|
375
|
-
if (result.extra.includes("unocss"))
|
|
376
|
-
configLines.push(`unocss: true,`);
|
|
377
|
-
for (const framework of result.frameworks)
|
|
378
|
-
configLines.push(`${framework}: true,`);
|
|
379
|
-
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
380
|
-
const additionalConfig = [];
|
|
381
|
-
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
382
|
-
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
383
|
-
p.log.success(c2.green(`Created ${configFileName}`));
|
|
384
|
-
const files = fs.readdirSync(cwd);
|
|
385
|
-
const legacyConfig = [];
|
|
386
|
-
files.forEach((file) => {
|
|
387
|
-
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
388
|
-
legacyConfig.push(file);
|
|
389
|
-
});
|
|
390
|
-
if (legacyConfig.length)
|
|
391
|
-
p.note(`${c2.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// src/cli/stages/update-package-json.ts
|
|
395
|
-
import fsp2 from "node:fs/promises";
|
|
396
|
-
import path2 from "node:path";
|
|
397
|
-
import process2 from "node:process";
|
|
398
|
-
import * as p2 from "@clack/prompts";
|
|
399
|
-
import c3 from "picocolors";
|
|
400
|
-
async function updatePackageJson(result) {
|
|
401
|
-
const cwd = process2.cwd();
|
|
402
|
-
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
403
|
-
p2.log.step(c3.cyan(`Bumping @jun2030/eslint-config to v${package_default.version}`));
|
|
404
|
-
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
405
|
-
const pkg = JSON.parse(pkgContent);
|
|
406
|
-
pkg.devDependencies ??= {};
|
|
407
|
-
pkg.devDependencies["@jun2030/eslint-config"] = `^${package_default.version}`;
|
|
408
|
-
pkg.devDependencies.eslint ??= package_default.devDependencies.eslint.replace("npm:eslint-ts-patch@", "").replace(/-\d+$/, "");
|
|
409
|
-
const addedPackages = [];
|
|
410
|
-
if (result.extra.length) {
|
|
411
|
-
result.extra.forEach((item) => {
|
|
412
|
-
switch (item) {
|
|
413
|
-
case "formatter":
|
|
414
|
-
[
|
|
415
|
-
"eslint-plugin-format",
|
|
416
|
-
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
417
|
-
].forEach((f) => {
|
|
418
|
-
if (!f)
|
|
419
|
-
return;
|
|
420
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
421
|
-
addedPackages.push(f);
|
|
422
|
-
});
|
|
423
|
-
break;
|
|
424
|
-
case "unocss":
|
|
425
|
-
[
|
|
426
|
-
"@unocss/eslint-plugin"
|
|
427
|
-
].forEach((f) => {
|
|
428
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
429
|
-
addedPackages.push(f);
|
|
430
|
-
});
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
for (const framework of result.frameworks) {
|
|
436
|
-
const deps = dependenciesMap[framework];
|
|
437
|
-
if (deps) {
|
|
438
|
-
deps.forEach((f) => {
|
|
439
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
440
|
-
addedPackages.push(f);
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (addedPackages.length)
|
|
445
|
-
p2.note(`${c3.dim(addedPackages.join(", "))}`, "Added packages");
|
|
446
|
-
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
447
|
-
p2.log.success(c3.green(`Changes wrote to package.json`));
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// src/cli/stages/update-vscode-settings.ts
|
|
451
|
-
import fs2 from "node:fs";
|
|
452
|
-
import fsp3 from "node:fs/promises";
|
|
453
|
-
import path3 from "node:path";
|
|
454
|
-
import process3 from "node:process";
|
|
455
|
-
import * as p3 from "@clack/prompts";
|
|
456
|
-
import c4 from "picocolors";
|
|
457
|
-
async function updateVscodeSettings(result) {
|
|
458
|
-
const cwd = process3.cwd();
|
|
459
|
-
if (!result.updateVscodeSettings)
|
|
460
|
-
return;
|
|
461
|
-
const dotVscodePath = path3.join(cwd, ".vscode");
|
|
462
|
-
const settingsPath = path3.join(dotVscodePath, "settings.json");
|
|
463
|
-
if (!fs2.existsSync(dotVscodePath))
|
|
464
|
-
await fsp3.mkdir(dotVscodePath, { recursive: true });
|
|
465
|
-
if (!fs2.existsSync(settingsPath)) {
|
|
466
|
-
await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
467
|
-
`, "utf-8");
|
|
468
|
-
p3.log.success(c4.green(`Created .vscode/settings.json`));
|
|
469
|
-
} else {
|
|
470
|
-
let settingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
471
|
-
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
472
|
-
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
473
|
-
settingsContent += `${vscodeSettingsString}}
|
|
474
|
-
`;
|
|
475
|
-
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
476
|
-
p3.log.success(c4.green(`Updated .vscode/settings.json`));
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// src/cli/run.ts
|
|
481
|
-
async function run(options = {}) {
|
|
482
|
-
const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
|
|
483
|
-
const argTemplate = options.frameworks?.map((m) => m.trim());
|
|
484
|
-
const argExtra = options.extra?.map((m) => m.trim());
|
|
485
|
-
if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
|
|
486
|
-
p4.log.warn(c5.yellow(`eslint.config.js already exists, migration wizard exited.`));
|
|
487
|
-
return process4.exit(1);
|
|
488
|
-
}
|
|
489
|
-
let result = {
|
|
490
|
-
extra: argExtra ?? [],
|
|
491
|
-
frameworks: argTemplate ?? [],
|
|
492
|
-
uncommittedConfirmed: false,
|
|
493
|
-
updateVscodeSettings: true
|
|
494
|
-
};
|
|
495
|
-
if (!argSkipPrompt) {
|
|
496
|
-
result = await p4.group({
|
|
497
|
-
uncommittedConfirmed: () => {
|
|
498
|
-
if (argSkipPrompt || isGitClean())
|
|
499
|
-
return Promise.resolve(true);
|
|
500
|
-
return p4.confirm({
|
|
501
|
-
initialValue: false,
|
|
502
|
-
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
503
|
-
});
|
|
504
|
-
},
|
|
505
|
-
frameworks: ({ results }) => {
|
|
506
|
-
const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
|
|
507
|
-
if (!results.uncommittedConfirmed || isArgTemplateValid)
|
|
508
|
-
return;
|
|
509
|
-
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
510
|
-
return p4.multiselect({
|
|
511
|
-
message: c5.reset(message),
|
|
512
|
-
options: frameworkOptions,
|
|
513
|
-
required: false
|
|
514
|
-
});
|
|
515
|
-
},
|
|
516
|
-
extra: ({ results }) => {
|
|
517
|
-
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
518
|
-
if (!results.uncommittedConfirmed || isArgExtraValid)
|
|
519
|
-
return;
|
|
520
|
-
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
521
|
-
return p4.multiselect({
|
|
522
|
-
message: c5.reset(message),
|
|
523
|
-
options: extraOptions,
|
|
524
|
-
required: false
|
|
525
|
-
});
|
|
526
|
-
},
|
|
527
|
-
updateVscodeSettings: ({ results }) => {
|
|
528
|
-
if (!results.uncommittedConfirmed)
|
|
529
|
-
return;
|
|
530
|
-
return p4.confirm({
|
|
531
|
-
initialValue: true,
|
|
532
|
-
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
}, {
|
|
536
|
-
onCancel: () => {
|
|
537
|
-
p4.cancel("Operation cancelled.");
|
|
538
|
-
process4.exit(0);
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
if (!result.uncommittedConfirmed)
|
|
542
|
-
return process4.exit(1);
|
|
543
|
-
}
|
|
544
|
-
await updatePackageJson(result);
|
|
545
|
-
await updateEslintFiles(result);
|
|
546
|
-
await updateVscodeSettings(result);
|
|
547
|
-
p4.log.success(c5.green(`Setup completed`));
|
|
548
|
-
p4.outro(`Now you can update the dependencies and run ${c5.blue("eslint . --fix")}
|
|
549
|
-
`);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// src/cli/index.ts
|
|
553
|
-
function header() {
|
|
554
|
-
console.log("\n");
|
|
555
|
-
p5.intro(`${c6.green(`@jun2030/eslint-config `)}${c6.dim(`v${package_default.version}`)}`);
|
|
556
|
-
}
|
|
557
|
-
var instance = yargs(hideBin(process5.argv)).scriptName("@jun2030/eslint-config").usage("").command(
|
|
558
|
-
"*",
|
|
559
|
-
"Run the initialization or migration",
|
|
560
|
-
(args) => args.option("yes", {
|
|
561
|
-
alias: "y",
|
|
562
|
-
description: "Skip prompts and use default values",
|
|
563
|
-
type: "boolean"
|
|
564
|
-
}).option("template", {
|
|
565
|
-
alias: "t",
|
|
566
|
-
description: "Use the framework template for optimal customization: vue / react / svelte / astro",
|
|
567
|
-
type: "string"
|
|
568
|
-
}).option("extra", {
|
|
569
|
-
alias: "e",
|
|
570
|
-
array: true,
|
|
571
|
-
description: "Use the extra utils: formatter / perfectionist / unocss",
|
|
572
|
-
type: "string"
|
|
573
|
-
}).help(),
|
|
574
|
-
async (args) => {
|
|
575
|
-
header();
|
|
576
|
-
try {
|
|
577
|
-
await run(args);
|
|
578
|
-
} catch (error) {
|
|
579
|
-
p5.log.error(c6.inverse(c6.red(" Failed to migrate ")));
|
|
580
|
-
p5.log.error(c6.red(`\u2718 ${String(error)}`));
|
|
581
|
-
process5.exit(1);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|
|
585
|
-
instance.help().argv;
|