@whoj/eslint-config 2.2.1 → 2.3.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 +21 -21
- package/dist/cli.js +213 -102
- package/dist/index.d.ts +290 -283
- package/dist/index.js +709 -757
- package/package.json +8 -4
- package/dist/chunk-3P3JBQLJ.js +0 -5191
- package/dist/chunk-5NT2OOQW.js +0 -29719
- package/dist/chunk-7F5ASJF4.js +0 -1962
- package/dist/chunk-DLJMV7EV.js +0 -626
- package/dist/chunk-G5WGJHBR.js +0 -149
- package/dist/chunk-IDB36RF3.js +0 -353
- package/dist/chunk-IKAXXATW.js +0 -6400
- package/dist/chunk-MKKAXXPL.js +0 -5769
- package/dist/chunk-MKNYKNDN.js +0 -65
- package/dist/chunk-PVCENCBM.js +0 -1053
- package/dist/chunk-QT5XME2Q.js +0 -209134
- package/dist/chunk-THBKBMVU.js +0 -8352
- package/dist/chunk-VSLGWZT6.js +0 -115
- package/dist/chunk-XZGWRL6X.js +0 -1520
- package/dist/dist-MYXPM6TG.js +0 -4953
- package/dist/dist-ZJ2E2ITJ.js +0 -26233
- package/dist/eslint-plugin-react-hooks-BV2CYKDG.js +0 -2559
- package/dist/eslint-plugin-react-refresh-N5P3A37Z.js +0 -272
- package/dist/lib-C6BFP32Q.js +0 -24437
- package/dist/lib-FENTQ4WJ.js +0 -10106
- package/dist/lib-WKUBBNE4.js +0 -26
- package/dist/lib-XQB7MXK6.js +0 -9
- package/dist/sass.node-L3JPZGSW.js +0 -125580
- package/dist/typescript-LG2A6BNW.js +0 -5
package/README.md
CHANGED
|
@@ -45,16 +45,16 @@ const compat = new FlatCompat();
|
|
|
45
45
|
|
|
46
46
|
export default whoj(
|
|
47
47
|
{
|
|
48
|
-
ignores: []
|
|
48
|
+
ignores: [],
|
|
49
49
|
},
|
|
50
50
|
|
|
51
51
|
// Legacy config
|
|
52
52
|
...compat.config({
|
|
53
53
|
extends: [
|
|
54
|
-
'eslint:recommended'
|
|
54
|
+
'eslint:recommended',
|
|
55
55
|
// Other extends...
|
|
56
|
-
]
|
|
57
|
-
})
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
58
|
|
|
59
59
|
// Other flat configs...
|
|
60
60
|
);
|
|
@@ -152,31 +152,31 @@ You can configure each integration individually, for example:
|
|
|
152
152
|
import whoj from '@whoj/eslint-config';
|
|
153
153
|
|
|
154
154
|
export default whoj({
|
|
155
|
-
|
|
156
|
-
type: 'lib',
|
|
155
|
+
vue: true,
|
|
157
156
|
|
|
158
157
|
// Enable stylistic formatting rules
|
|
159
158
|
// stylistic: true,
|
|
160
159
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
indent: 2, // 4, or 'tab'
|
|
164
|
-
quotes: 'single' // or 'double'
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
// TypeScript and Vue are autodetected, you can also explicitly enable them:
|
|
168
|
-
typescript: true,
|
|
169
|
-
vue: true,
|
|
160
|
+
// Type of the project. 'lib' for libraries, the default is 'app'
|
|
161
|
+
type: 'lib',
|
|
170
162
|
|
|
163
|
+
yaml: false,
|
|
171
164
|
// Disable jsonc and yaml support
|
|
172
165
|
jsonc: false,
|
|
173
|
-
yaml: false,
|
|
174
166
|
|
|
167
|
+
// TypeScript and Vue are autodetected, you can also explicitly enable them:
|
|
168
|
+
typescript: true,
|
|
175
169
|
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
176
170
|
ignores: [
|
|
177
|
-
'**/fixtures'
|
|
171
|
+
'**/fixtures',
|
|
178
172
|
// ...globs
|
|
179
|
-
]
|
|
173
|
+
],
|
|
174
|
+
|
|
175
|
+
// Or customize the stylistic rules
|
|
176
|
+
stylistic: {
|
|
177
|
+
indent: 2, // 4, or 'tab'
|
|
178
|
+
quotes: 'single', // or 'double'
|
|
179
|
+
},
|
|
180
180
|
});
|
|
181
181
|
```
|
|
182
182
|
|
|
@@ -194,12 +194,12 @@ export default whoj(
|
|
|
194
194
|
// From the second arguments they are ESLint Flat Configs
|
|
195
195
|
// you can have multiple configs
|
|
196
196
|
{
|
|
197
|
+
rules: {},
|
|
197
198
|
files: ['**/*.ts'],
|
|
198
|
-
rules: {}
|
|
199
199
|
},
|
|
200
200
|
{
|
|
201
|
-
rules: {}
|
|
202
|
-
}
|
|
201
|
+
rules: {},
|
|
202
|
+
},
|
|
203
203
|
);
|
|
204
204
|
```
|
|
205
205
|
|
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_esm_shims
|
|
3
|
-
} from "./chunk-MKNYKNDN.js";
|
|
4
|
-
|
|
5
|
-
// src/cli.ts
|
|
6
|
-
init_esm_shims();
|
|
7
|
-
|
|
8
1
|
// src/cli/index.ts
|
|
9
|
-
init_esm_shims();
|
|
10
2
|
import yargs from "yargs";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import * as
|
|
3
|
+
import c7 from "picocolors";
|
|
4
|
+
import process6 from "node:process";
|
|
5
|
+
import * as p6 from "@clack/prompts";
|
|
14
6
|
import { hideBin } from "yargs/helpers";
|
|
15
7
|
|
|
16
8
|
// src/cli/run.ts
|
|
17
|
-
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import * as p4 from "@clack/prompts";
|
|
9
|
+
import fs4 from "node:fs";
|
|
10
|
+
import c6 from "picocolors";
|
|
11
|
+
import path5 from "node:path";
|
|
12
|
+
import process5 from "node:process";
|
|
13
|
+
import * as p5 from "@clack/prompts";
|
|
23
14
|
|
|
24
15
|
// src/cli/utils.ts
|
|
25
|
-
init_esm_shims();
|
|
26
16
|
import { execSync } from "node:child_process";
|
|
27
17
|
function isGitClean() {
|
|
28
18
|
try {
|
|
@@ -32,20 +22,29 @@ function isGitClean() {
|
|
|
32
22
|
return false;
|
|
33
23
|
}
|
|
34
24
|
}
|
|
25
|
+
function getJetbrainsEslintConfigContent(configFrom) {
|
|
26
|
+
return `
|
|
27
|
+
import { whoj } from '@whoj/eslint-config';
|
|
28
|
+
import _defaults from "${configFrom}";
|
|
29
|
+
|
|
30
|
+
export default whoj({
|
|
31
|
+
isInEditor: true
|
|
32
|
+
}).append(_defaults);
|
|
33
|
+
`.trimStart();
|
|
34
|
+
}
|
|
35
35
|
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
36
36
|
return `
|
|
37
|
-
import whoj from '@whoj/eslint-config'
|
|
37
|
+
import whoj from '@whoj/eslint-config';
|
|
38
38
|
|
|
39
39
|
export default whoj({
|
|
40
40
|
${mainConfig}
|
|
41
41
|
}${additionalConfigs?.map((config) => `,{
|
|
42
42
|
${config}
|
|
43
|
-
}`)})
|
|
43
|
+
}`)});
|
|
44
44
|
`.trimStart();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// src/cli/stages/update-eslint-files.ts
|
|
48
|
-
init_esm_shims();
|
|
49
48
|
import fs from "node:fs";
|
|
50
49
|
import c from "picocolors";
|
|
51
50
|
import path from "node:path";
|
|
@@ -96,10 +95,10 @@ async function updateEslintFiles(result) {
|
|
|
96
95
|
});
|
|
97
96
|
if (legacyConfig.length)
|
|
98
97
|
p.note(`${c.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
98
|
+
return pathFlatConfig;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// src/cli/stages/update-package-json.ts
|
|
102
|
-
init_esm_shims();
|
|
103
102
|
import c3 from "picocolors";
|
|
104
103
|
import path2 from "node:path";
|
|
105
104
|
import fsp2 from "node:fs/promises";
|
|
@@ -107,14 +106,13 @@ import process2 from "node:process";
|
|
|
107
106
|
import * as p2 from "@clack/prompts";
|
|
108
107
|
|
|
109
108
|
// src/cli/constants.ts
|
|
110
|
-
init_esm_shims();
|
|
111
109
|
import c2 from "picocolors";
|
|
112
110
|
|
|
113
111
|
// package.json
|
|
114
112
|
var package_default = {
|
|
115
113
|
name: "@whoj/eslint-config",
|
|
116
114
|
type: "module",
|
|
117
|
-
version: "2.
|
|
115
|
+
version: "2.3.0",
|
|
118
116
|
packageManager: "pnpm@10.2.1",
|
|
119
117
|
description: "ESLint config",
|
|
120
118
|
license: "MIT",
|
|
@@ -148,12 +146,16 @@ var package_default = {
|
|
|
148
146
|
prepare: "simple-git-hooks"
|
|
149
147
|
},
|
|
150
148
|
peerDependencies: {
|
|
149
|
+
"@nuxt/eslint-config": "^1.0.1",
|
|
151
150
|
"@prettier/plugin-xml": "^3.4.1",
|
|
152
151
|
"@unocss/eslint-plugin": ">=0.50.0",
|
|
153
152
|
eslint: "^9.19.0",
|
|
154
153
|
"eslint-plugin-format": ">=0.1.0"
|
|
155
154
|
},
|
|
156
155
|
peerDependenciesMeta: {
|
|
156
|
+
"@nuxt/eslint-config": {
|
|
157
|
+
optional: true
|
|
158
|
+
},
|
|
157
159
|
"@prettier/plugin-xml": {
|
|
158
160
|
optional: true
|
|
159
161
|
},
|
|
@@ -172,7 +174,6 @@ var package_default = {
|
|
|
172
174
|
"@clack/prompts": "^0.9.1",
|
|
173
175
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
|
174
176
|
"@eslint/markdown": "^6.2.2",
|
|
175
|
-
"@nuxt/eslint-config": "^1.0.1",
|
|
176
177
|
"@stylistic/eslint-plugin": "^3.0.1",
|
|
177
178
|
"@typescript-eslint/eslint-plugin": "^8.22.0",
|
|
178
179
|
"@typescript-eslint/parser": "^8.22.0",
|
|
@@ -195,6 +196,7 @@ var package_default = {
|
|
|
195
196
|
"eslint-plugin-vue": "^9.32.0",
|
|
196
197
|
"eslint-plugin-yml": "^1.16.0",
|
|
197
198
|
"eslint-processor-vue-blocks": "^1.0.0",
|
|
199
|
+
"fast-xml-parser": "^4.5.1",
|
|
198
200
|
globals: "^15.14.0",
|
|
199
201
|
"jsonc-eslint-parser": "^2.4.0",
|
|
200
202
|
"local-pkg": "^1.0.0",
|
|
@@ -209,6 +211,7 @@ var package_default = {
|
|
|
209
211
|
"@antfu/ni": "^23.3.1",
|
|
210
212
|
"@eslint-react/eslint-plugin": "^1.26.2",
|
|
211
213
|
"@eslint/config-inspector": "^1.0.0",
|
|
214
|
+
"@nuxt/eslint-config": "^1.0.1",
|
|
212
215
|
"@prettier/plugin-xml": "^3.4.1",
|
|
213
216
|
"@stylistic/eslint-plugin-migrate": "^3.0.1",
|
|
214
217
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -235,7 +238,6 @@ var package_default = {
|
|
|
235
238
|
"prettier-plugin-astro": "^0.14.1",
|
|
236
239
|
"prettier-plugin-slidev": "^1.0.5",
|
|
237
240
|
rimraf: "^6.0.1",
|
|
238
|
-
sass: "^1.84.0",
|
|
239
241
|
"simple-git-hooks": "^2.11.1",
|
|
240
242
|
svelte: "^5.19.9",
|
|
241
243
|
"svelte-eslint-parser": "^0.43.0",
|
|
@@ -266,6 +268,15 @@ var package_default = {
|
|
|
266
268
|
};
|
|
267
269
|
|
|
268
270
|
// src/cli/constants.ts
|
|
271
|
+
var jetbrainsSettingsObj = {
|
|
272
|
+
"?xml": { version: "1.0", encoding: "UTF-8" },
|
|
273
|
+
"project": { version: "4", component: {
|
|
274
|
+
"name": "EslintConfiguration",
|
|
275
|
+
"extra-options": { value: "--cache" },
|
|
276
|
+
"option": { value: "true", name: "fix-on-save" },
|
|
277
|
+
"custom-configuration-file": { used: "true", path: "$PROJECT_DIR$/eslint.config.js" }
|
|
278
|
+
} }
|
|
279
|
+
};
|
|
269
280
|
var vscodeSettingsString = `
|
|
270
281
|
// Disable the default formatter, use eslint instead
|
|
271
282
|
"prettier.enable": false,
|
|
@@ -319,64 +330,71 @@ var vscodeSettingsString = `
|
|
|
319
330
|
`;
|
|
320
331
|
var frameworkOptions = [
|
|
321
332
|
{
|
|
322
|
-
|
|
323
|
-
|
|
333
|
+
value: "vue",
|
|
334
|
+
label: c2.green("Vue")
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
value: "nuxt",
|
|
338
|
+
label: c2.green("Nuxt")
|
|
324
339
|
},
|
|
325
340
|
{
|
|
326
|
-
|
|
327
|
-
|
|
341
|
+
value: "react",
|
|
342
|
+
label: c2.cyan("React")
|
|
328
343
|
},
|
|
329
344
|
{
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
value: "svelte",
|
|
346
|
+
label: c2.red("Svelte")
|
|
332
347
|
},
|
|
333
348
|
{
|
|
334
|
-
|
|
335
|
-
|
|
349
|
+
value: "astro",
|
|
350
|
+
label: c2.magenta("Astro")
|
|
336
351
|
},
|
|
337
352
|
{
|
|
338
|
-
|
|
339
|
-
|
|
353
|
+
value: "solid",
|
|
354
|
+
label: c2.cyan("Solid")
|
|
340
355
|
},
|
|
341
356
|
{
|
|
342
|
-
|
|
343
|
-
|
|
357
|
+
value: "slidev",
|
|
358
|
+
label: c2.blue("Slidev")
|
|
344
359
|
}
|
|
345
360
|
];
|
|
346
361
|
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
347
362
|
var extraOptions = [
|
|
348
363
|
{
|
|
349
|
-
|
|
364
|
+
value: "formatter",
|
|
350
365
|
label: c2.red("Formatter"),
|
|
351
|
-
|
|
366
|
+
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)"
|
|
352
367
|
},
|
|
353
368
|
{
|
|
354
|
-
|
|
355
|
-
|
|
369
|
+
value: "unocss",
|
|
370
|
+
label: c2.cyan("UnoCSS")
|
|
356
371
|
}
|
|
357
372
|
];
|
|
358
373
|
var extra = extraOptions.map(({ value }) => value);
|
|
359
374
|
var dependenciesMap = {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
"
|
|
375
|
+
vue: [],
|
|
376
|
+
nuxt: [
|
|
377
|
+
"@nuxt/eslint-config"
|
|
363
378
|
],
|
|
364
|
-
|
|
365
|
-
"
|
|
366
|
-
"eslint-plugin-react-hooks",
|
|
367
|
-
"eslint-plugin-react-refresh"
|
|
379
|
+
solid: [
|
|
380
|
+
"eslint-plugin-solid"
|
|
368
381
|
],
|
|
369
382
|
slidev: [
|
|
370
383
|
"prettier-plugin-slidev"
|
|
371
384
|
],
|
|
372
|
-
|
|
373
|
-
"eslint-plugin-
|
|
385
|
+
astro: [
|
|
386
|
+
"eslint-plugin-astro",
|
|
387
|
+
"astro-eslint-parser"
|
|
374
388
|
],
|
|
375
389
|
svelte: [
|
|
376
390
|
"eslint-plugin-svelte",
|
|
377
391
|
"svelte-eslint-parser"
|
|
378
392
|
],
|
|
379
|
-
|
|
393
|
+
react: [
|
|
394
|
+
"@eslint-react/eslint-plugin",
|
|
395
|
+
"eslint-plugin-react-hooks",
|
|
396
|
+
"eslint-plugin-react-refresh"
|
|
397
|
+
]
|
|
380
398
|
};
|
|
381
399
|
|
|
382
400
|
// src/cli/stages/update-package-json.ts
|
|
@@ -393,21 +411,21 @@ async function updatePackageJson(result) {
|
|
|
393
411
|
if (result.extra.length) {
|
|
394
412
|
result.extra.forEach((item) => {
|
|
395
413
|
switch (item) {
|
|
396
|
-
case "
|
|
414
|
+
case "unocss":
|
|
397
415
|
[
|
|
398
|
-
"eslint-plugin
|
|
399
|
-
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
416
|
+
"@unocss/eslint-plugin"
|
|
400
417
|
].forEach((f) => {
|
|
401
|
-
if (!f)
|
|
402
|
-
return;
|
|
403
418
|
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
404
419
|
addedPackages.push(f);
|
|
405
420
|
});
|
|
406
421
|
break;
|
|
407
|
-
case "
|
|
422
|
+
case "formatter":
|
|
408
423
|
[
|
|
409
|
-
"
|
|
424
|
+
"eslint-plugin-format",
|
|
425
|
+
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
410
426
|
].forEach((f) => {
|
|
427
|
+
if (!f)
|
|
428
|
+
return;
|
|
411
429
|
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
412
430
|
addedPackages.push(f);
|
|
413
431
|
});
|
|
@@ -430,58 +448,129 @@ async function updatePackageJson(result) {
|
|
|
430
448
|
p2.log.success(c3.green("Changes wrote to package.json"));
|
|
431
449
|
}
|
|
432
450
|
|
|
433
|
-
// src/cli/stages/update-
|
|
434
|
-
init_esm_shims();
|
|
451
|
+
// src/cli/stages/update-jetbrains-idea.ts
|
|
435
452
|
import fs2 from "node:fs";
|
|
436
453
|
import c4 from "picocolors";
|
|
437
454
|
import path3 from "node:path";
|
|
438
455
|
import fsp3 from "node:fs/promises";
|
|
439
456
|
import process3 from "node:process";
|
|
440
457
|
import * as p3 from "@clack/prompts";
|
|
441
|
-
|
|
458
|
+
import { deepMergeWithArray } from "@antfu/utils";
|
|
459
|
+
import { XMLParser, XMLBuilder } from "fast-xml-parser";
|
|
460
|
+
async function updateJetbrainsIdea(result, flatConfigPath) {
|
|
442
461
|
const cwd = process3.cwd();
|
|
443
|
-
if (!result.
|
|
462
|
+
if (!result.updateJetbrainsIdea)
|
|
444
463
|
return;
|
|
445
|
-
const
|
|
446
|
-
const settingsPath = path3.join(
|
|
447
|
-
|
|
448
|
-
|
|
464
|
+
const dotIdeaPath = path3.join(cwd, ".idea/jsLinters");
|
|
465
|
+
const settingsPath = path3.join(dotIdeaPath, "eslint.xml");
|
|
466
|
+
const ideaFlatConfigPath = path3.join(dotIdeaPath, path3.basename(flatConfigPath));
|
|
467
|
+
const xmlParserOptions = {
|
|
468
|
+
attributeNamePrefix: "",
|
|
469
|
+
ignoreAttributes: false,
|
|
470
|
+
unpairedTags: [
|
|
471
|
+
"option",
|
|
472
|
+
"extra-options",
|
|
473
|
+
"work-dir-patterns",
|
|
474
|
+
"additional-rules-dir",
|
|
475
|
+
"custom-configuration-file"
|
|
476
|
+
]
|
|
477
|
+
};
|
|
478
|
+
const xmlBuilderOptions = {
|
|
479
|
+
format: true,
|
|
480
|
+
...xmlParserOptions,
|
|
481
|
+
suppressUnpairedNode: false,
|
|
482
|
+
suppressBooleanAttributes: false
|
|
483
|
+
};
|
|
484
|
+
const builder = new XMLBuilder(xmlBuilderOptions);
|
|
485
|
+
if (!fs2.existsSync(dotIdeaPath)) {
|
|
486
|
+
await fsp3.mkdir(dotIdeaPath, { recursive: true });
|
|
487
|
+
}
|
|
488
|
+
await fsp3.writeFile(
|
|
489
|
+
ideaFlatConfigPath,
|
|
490
|
+
getJetbrainsEslintConfigContent(flatConfigPath),
|
|
491
|
+
"utf8"
|
|
492
|
+
);
|
|
493
|
+
p3.log.success(c4.green(`Created ${path3.relative(cwd, ideaFlatConfigPath)}`));
|
|
494
|
+
const ideaSettingsObject = deepMergeWithArray(
|
|
495
|
+
jetbrainsSettingsObj,
|
|
496
|
+
{
|
|
497
|
+
project: {
|
|
498
|
+
component: {
|
|
499
|
+
"custom-configuration-file": {
|
|
500
|
+
used: "true",
|
|
501
|
+
path: `$PROJECT_DIR$/.idea/jsLinters/${path3.basename(flatConfigPath)}`
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
);
|
|
449
507
|
if (!fs2.existsSync(settingsPath)) {
|
|
450
|
-
await fsp3.writeFile(settingsPath,
|
|
508
|
+
await fsp3.writeFile(settingsPath, builder.build(ideaSettingsObject), "utf8");
|
|
509
|
+
p3.log.success(c4.green("Created .idea/jsLinters/eslint.xml"));
|
|
510
|
+
} else {
|
|
511
|
+
const ideaSettingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
512
|
+
const parser = new XMLParser(xmlParserOptions);
|
|
513
|
+
const ideaXml = deepMergeWithArray(
|
|
514
|
+
parser.parse(ideaSettingsContent),
|
|
515
|
+
jetbrainsSettingsObj
|
|
516
|
+
);
|
|
517
|
+
await fsp3.writeFile(settingsPath, builder.build(ideaXml), "utf8");
|
|
518
|
+
p3.log.success(c4.green("Updated .idea/jsLinters/eslint.xml"));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/cli/stages/update-vscode-settings.ts
|
|
523
|
+
import fs3 from "node:fs";
|
|
524
|
+
import c5 from "picocolors";
|
|
525
|
+
import path4 from "node:path";
|
|
526
|
+
import fsp4 from "node:fs/promises";
|
|
527
|
+
import process4 from "node:process";
|
|
528
|
+
import * as p4 from "@clack/prompts";
|
|
529
|
+
async function updateVscodeSettings(result) {
|
|
530
|
+
const cwd = process4.cwd();
|
|
531
|
+
if (!result.updateVscodeSettings)
|
|
532
|
+
return;
|
|
533
|
+
const dotVscodePath = path4.join(cwd, ".vscode");
|
|
534
|
+
const settingsPath = path4.join(dotVscodePath, "settings.json");
|
|
535
|
+
if (!fs3.existsSync(dotVscodePath))
|
|
536
|
+
await fsp4.mkdir(dotVscodePath, { recursive: true });
|
|
537
|
+
if (!fs3.existsSync(settingsPath)) {
|
|
538
|
+
await fsp4.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
451
539
|
`, "utf-8");
|
|
452
|
-
|
|
540
|
+
p4.log.success(c5.green("Created .vscode/settings.json"));
|
|
453
541
|
} else {
|
|
454
|
-
let settingsContent = await
|
|
542
|
+
let settingsContent = await fsp4.readFile(settingsPath, "utf8");
|
|
455
543
|
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
456
544
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
457
545
|
settingsContent += `${vscodeSettingsString}}
|
|
458
546
|
`;
|
|
459
|
-
await
|
|
460
|
-
|
|
547
|
+
await fsp4.writeFile(settingsPath, settingsContent, "utf-8");
|
|
548
|
+
p4.log.success(c5.green("Updated .vscode/settings.json"));
|
|
461
549
|
}
|
|
462
550
|
}
|
|
463
551
|
|
|
464
552
|
// src/cli/run.ts
|
|
465
|
-
async function run(options = {}) {
|
|
466
|
-
const argSkipPrompt = !!
|
|
553
|
+
async function run({ jetbrains, vscode, ...options } = {}) {
|
|
554
|
+
const argSkipPrompt = !!process5.env.SKIP_PROMPT || options.yes;
|
|
467
555
|
const argTemplate = options.frameworks?.map((m) => m.trim());
|
|
468
556
|
const argExtra = options.extra?.map((m) => m.trim());
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
return
|
|
557
|
+
if (fs4.existsSync(path5.join(process5.cwd(), "eslint.config.js"))) {
|
|
558
|
+
p5.log.warn(c6.yellow("eslint.config.js already exists, migration wizard exited."));
|
|
559
|
+
return process5.exit(1);
|
|
472
560
|
}
|
|
473
561
|
let result = {
|
|
474
562
|
extra: argExtra ?? [],
|
|
475
563
|
frameworks: argTemplate ?? [],
|
|
476
564
|
uncommittedConfirmed: false,
|
|
477
|
-
updateVscodeSettings: true
|
|
565
|
+
updateVscodeSettings: vscode ?? true,
|
|
566
|
+
updateJetbrainsIdea: jetbrains ?? true
|
|
478
567
|
};
|
|
479
568
|
if (!argSkipPrompt) {
|
|
480
|
-
result = await
|
|
569
|
+
result = await p5.group({
|
|
481
570
|
uncommittedConfirmed: () => {
|
|
482
571
|
if (argSkipPrompt || isGitClean())
|
|
483
572
|
return Promise.resolve(true);
|
|
484
|
-
return
|
|
573
|
+
return p5.confirm({
|
|
485
574
|
initialValue: false,
|
|
486
575
|
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
487
576
|
});
|
|
@@ -491,8 +580,8 @@ async function run(options = {}) {
|
|
|
491
580
|
if (!results.uncommittedConfirmed || isArgTemplateValid)
|
|
492
581
|
return;
|
|
493
582
|
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
494
|
-
return
|
|
495
|
-
message:
|
|
583
|
+
return p5.multiselect({
|
|
584
|
+
message: c6.reset(message),
|
|
496
585
|
options: frameworkOptions,
|
|
497
586
|
required: false
|
|
498
587
|
});
|
|
@@ -502,67 +591,89 @@ async function run(options = {}) {
|
|
|
502
591
|
if (!results.uncommittedConfirmed || isArgExtraValid)
|
|
503
592
|
return;
|
|
504
593
|
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
505
|
-
return
|
|
506
|
-
message:
|
|
594
|
+
return p5.multiselect({
|
|
595
|
+
message: c6.reset(message),
|
|
507
596
|
options: extraOptions,
|
|
508
597
|
required: false
|
|
509
598
|
});
|
|
510
599
|
},
|
|
600
|
+
updateJetbrainsIdea: ({ results }) => {
|
|
601
|
+
if (!results.uncommittedConfirmed)
|
|
602
|
+
return;
|
|
603
|
+
return p5.confirm({
|
|
604
|
+
initialValue: true,
|
|
605
|
+
message: "Update JetBrain IDE's eslint configuration for better experience WebStorm / PhpStorm?"
|
|
606
|
+
});
|
|
607
|
+
},
|
|
511
608
|
updateVscodeSettings: ({ results }) => {
|
|
512
609
|
if (!results.uncommittedConfirmed)
|
|
513
610
|
return;
|
|
514
|
-
return
|
|
611
|
+
return p5.confirm({
|
|
515
612
|
initialValue: true,
|
|
516
613
|
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
517
614
|
});
|
|
518
615
|
}
|
|
519
616
|
}, {
|
|
520
617
|
onCancel: () => {
|
|
521
|
-
|
|
522
|
-
|
|
618
|
+
p5.cancel("Operation cancelled.");
|
|
619
|
+
process5.exit(0);
|
|
523
620
|
}
|
|
524
621
|
});
|
|
525
622
|
if (!result.uncommittedConfirmed)
|
|
526
|
-
return
|
|
623
|
+
return process5.exit(1);
|
|
527
624
|
}
|
|
528
625
|
await updatePackageJson(result);
|
|
529
|
-
await updateEslintFiles(result);
|
|
626
|
+
const configFileName = await updateEslintFiles(result);
|
|
627
|
+
await updateJetbrainsIdea(
|
|
628
|
+
result,
|
|
629
|
+
configFileName
|
|
630
|
+
);
|
|
530
631
|
await updateVscodeSettings(result);
|
|
531
|
-
|
|
532
|
-
|
|
632
|
+
p5.log.success(c6.green("Setup completed"));
|
|
633
|
+
p5.outro(`Now you can update the dependencies by run ${c6.blue("pnpm install")} and run ${c6.blue("eslint . --fix")}
|
|
533
634
|
`);
|
|
534
635
|
}
|
|
535
636
|
|
|
536
637
|
// src/cli/index.ts
|
|
537
638
|
function header() {
|
|
538
639
|
console.log("\n");
|
|
539
|
-
|
|
640
|
+
p6.intro(`${c7.green("@whoj/eslint-config ")}${c7.dim(`v${package_default.version}`)}`);
|
|
540
641
|
}
|
|
541
|
-
var instance = yargs(hideBin(
|
|
642
|
+
var instance = yargs(hideBin(process6.argv)).scriptName("@whoj/eslint-config").usage("").command(
|
|
542
643
|
"*",
|
|
543
644
|
"Run the initialization or migration",
|
|
544
645
|
(args) => args.option("yes", {
|
|
545
646
|
alias: "y",
|
|
546
|
-
|
|
547
|
-
|
|
647
|
+
type: "boolean",
|
|
648
|
+
description: "Skip prompts and use default values"
|
|
649
|
+
}).option("jetbrains", {
|
|
650
|
+
default: true,
|
|
651
|
+
type: "boolean",
|
|
652
|
+
alias: ["idea", "j"],
|
|
653
|
+
description: "Configure eslint settings for better Jetbrains IDE. (WebStorm / PhpStorm) experience."
|
|
654
|
+
}).option("vscode", {
|
|
655
|
+
default: true,
|
|
656
|
+
type: "boolean",
|
|
657
|
+
alias: ["c", "code"],
|
|
658
|
+
description: "Add/Update .vscode/settings.json for better VS Code experience."
|
|
548
659
|
}).option("template", {
|
|
549
660
|
alias: "t",
|
|
550
|
-
|
|
551
|
-
|
|
661
|
+
type: "string",
|
|
662
|
+
description: "Use the framework template for optimal customization: vue / nuxt / react / svelte / astro"
|
|
552
663
|
}).option("extra", {
|
|
553
664
|
alias: "e",
|
|
554
665
|
array: true,
|
|
555
|
-
|
|
556
|
-
|
|
666
|
+
type: "string",
|
|
667
|
+
description: "Use the extra utils: formatter / perfectionist / unocss"
|
|
557
668
|
}).help(),
|
|
558
669
|
async (args) => {
|
|
559
670
|
header();
|
|
560
671
|
try {
|
|
561
672
|
await run(args);
|
|
562
673
|
} catch (error) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
674
|
+
p6.log.error(c7.inverse(c7.red(" Failed to migrate ")));
|
|
675
|
+
p6.log.error(c7.red(`\u2718 ${String(error)}`));
|
|
676
|
+
process6.exit(1);
|
|
566
677
|
}
|
|
567
678
|
}
|
|
568
679
|
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|