@kirklin/eslint-config 2.0.0 → 2.2.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 +29 -2
- package/README.zh-cn.md +1 -1
- package/bin/index.js +0 -0
- package/dist/cli.cjs +457 -145
- package/dist/cli.js +457 -145
- package/dist/index.cjs +190 -37
- package/dist/index.d.cts +39 -3
- package/dist/index.d.ts +39 -3
- package/dist/index.js +188 -37
- package/package.json +76 -57
package/dist/cli.cjs
CHANGED
|
@@ -28,65 +28,196 @@ var cli_exports = {};
|
|
|
28
28
|
module.exports = __toCommonJS(cli_exports);
|
|
29
29
|
|
|
30
30
|
// src/cli/index.ts
|
|
31
|
-
var
|
|
32
|
-
var
|
|
31
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
32
|
+
var import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
33
33
|
var import_helpers = require("yargs/helpers");
|
|
34
34
|
var import_yargs = __toESM(require("yargs"), 1);
|
|
35
|
+
var p5 = __toESM(require("@clack/prompts"), 1);
|
|
35
36
|
|
|
36
37
|
// src/cli/run.ts
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
43
|
-
var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
38
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
39
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
40
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
41
|
+
var import_picocolors5 = __toESM(require("picocolors"), 1);
|
|
42
|
+
var p4 = __toESM(require("@clack/prompts"), 1);
|
|
44
43
|
|
|
45
44
|
// src/cli/constants.ts
|
|
46
45
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
47
46
|
|
|
48
47
|
// package.json
|
|
49
|
-
var
|
|
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
|
-
|
|
48
|
+
var package_default = {
|
|
49
|
+
name: "@kirklin/eslint-config",
|
|
50
|
+
type: "module",
|
|
51
|
+
version: "2.2.0",
|
|
52
|
+
packageManager: "pnpm@8.15.5",
|
|
53
|
+
description: "Kirk Lin's ESLint config",
|
|
54
|
+
author: "Kirk Lin (https://github.com/kirklin/)",
|
|
55
|
+
license: "MIT",
|
|
56
|
+
funding: "https://www.buymeacoffee.com/linkirk",
|
|
57
|
+
homepage: "https://github.com/kirklin/eslint-config",
|
|
58
|
+
keywords: [
|
|
59
|
+
"eslint-config"
|
|
60
|
+
],
|
|
61
|
+
exports: {
|
|
62
|
+
".": {
|
|
63
|
+
import: "./dist/index.js",
|
|
64
|
+
require: "./dist/index.cjs"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
main: "./dist/index.js",
|
|
68
|
+
types: "./dist/index.d.ts",
|
|
69
|
+
bin: "./bin/index.js",
|
|
70
|
+
files: [
|
|
71
|
+
"bin",
|
|
72
|
+
"dist"
|
|
73
|
+
],
|
|
74
|
+
scripts: {
|
|
75
|
+
build: "tsup --format esm,cjs --clean --dts",
|
|
76
|
+
stub: "tsup --format esm",
|
|
77
|
+
dev: "tsup --format esm,cjs --watch & eslint-flat-config-viewer",
|
|
78
|
+
watch: "tsup --format esm,cjs --watch",
|
|
79
|
+
lint: "eslint .",
|
|
80
|
+
"lint:fix": "eslint . --fix",
|
|
81
|
+
prepack: "nr build",
|
|
82
|
+
release: "bumpp && pnpm publish",
|
|
83
|
+
test: "vitest",
|
|
84
|
+
typecheck: "tsc --noEmit",
|
|
85
|
+
prepare: "simple-git-hooks"
|
|
86
|
+
},
|
|
87
|
+
peerDependencies: {
|
|
88
|
+
"@unocss/eslint-plugin": ">=0.50.0",
|
|
89
|
+
"astro-eslint-parser": "^0.16.3",
|
|
90
|
+
eslint: ">=8.40.0",
|
|
91
|
+
"eslint-plugin-astro": "^0.31.4",
|
|
92
|
+
"eslint-plugin-format": ">=0.1.0",
|
|
93
|
+
"eslint-plugin-react": "^7.33.2",
|
|
94
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
95
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
96
|
+
"eslint-plugin-svelte": "^2.34.1",
|
|
97
|
+
"prettier-plugin-astro": "^0.13.0",
|
|
98
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
99
|
+
"svelte-eslint-parser": "^0.33.1"
|
|
100
|
+
},
|
|
101
|
+
peerDependenciesMeta: {
|
|
102
|
+
"@unocss/eslint-plugin": {
|
|
103
|
+
optional: true
|
|
104
|
+
},
|
|
105
|
+
"astro-eslint-parser": {
|
|
106
|
+
optional: true
|
|
107
|
+
},
|
|
108
|
+
"eslint-plugin-astro": {
|
|
109
|
+
optional: true
|
|
110
|
+
},
|
|
111
|
+
"eslint-plugin-format": {
|
|
112
|
+
optional: true
|
|
113
|
+
},
|
|
114
|
+
"eslint-plugin-react": {
|
|
115
|
+
optional: true
|
|
116
|
+
},
|
|
117
|
+
"eslint-plugin-react-hooks": {
|
|
118
|
+
optional: true
|
|
119
|
+
},
|
|
120
|
+
"eslint-plugin-react-refresh": {
|
|
121
|
+
optional: true
|
|
122
|
+
},
|
|
123
|
+
"eslint-plugin-svelte": {
|
|
124
|
+
optional: true
|
|
125
|
+
},
|
|
126
|
+
"prettier-plugin-astro": {
|
|
127
|
+
optional: true
|
|
128
|
+
},
|
|
129
|
+
"prettier-plugin-slidev": {
|
|
130
|
+
optional: true
|
|
131
|
+
},
|
|
132
|
+
"svelte-eslint-parser": {
|
|
133
|
+
optional: true
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
dependencies: {
|
|
137
|
+
"@antfu/eslint-define-config": "1.23.0-2",
|
|
138
|
+
"@antfu/install-pkg": "^0.3.1",
|
|
139
|
+
"@clack/prompts": "^0.7.0",
|
|
140
|
+
"@eslint-types/jsdoc": "48.2.1",
|
|
141
|
+
"@eslint-types/typescript-eslint": "^7.2.0",
|
|
142
|
+
"@eslint-types/unicorn": "^51.0.1",
|
|
143
|
+
"@stylistic/eslint-plugin": "^1.7.0",
|
|
144
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
145
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
146
|
+
"eslint-config-flat-gitignore": "^0.1.3",
|
|
147
|
+
"eslint-merge-processors": "^0.1.0",
|
|
148
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
149
|
+
"eslint-plugin-i": "^2.29.1",
|
|
150
|
+
"eslint-plugin-jsdoc": "^48.2.1",
|
|
151
|
+
"eslint-plugin-jsonc": "^2.14.1",
|
|
152
|
+
"eslint-plugin-kirklin": "^1.1.0",
|
|
153
|
+
"eslint-plugin-markdown": "^4.0.1",
|
|
154
|
+
"eslint-plugin-n": "^16.6.2",
|
|
155
|
+
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
156
|
+
"eslint-plugin-perfectionist": "^2.7.0",
|
|
157
|
+
"eslint-plugin-toml": "^0.10.0",
|
|
158
|
+
"eslint-plugin-unicorn": "^51.0.1",
|
|
159
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
160
|
+
"eslint-plugin-vitest": "^0.3.26",
|
|
161
|
+
"eslint-plugin-vue": "^9.23.0",
|
|
162
|
+
"eslint-plugin-yml": "^1.13.1",
|
|
163
|
+
"eslint-processor-vue-blocks": "^0.1.1",
|
|
164
|
+
globals: "^14.0.0",
|
|
165
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
166
|
+
"local-pkg": "^0.5.0",
|
|
167
|
+
"parse-gitignore": "^2.0.0",
|
|
168
|
+
picocolors: "^1.0.0",
|
|
169
|
+
"toml-eslint-parser": "^0.9.3",
|
|
170
|
+
"vue-eslint-parser": "^9.4.2",
|
|
171
|
+
"yaml-eslint-parser": "^1.2.2",
|
|
172
|
+
yargs: "^17.7.2"
|
|
173
|
+
},
|
|
174
|
+
devDependencies: {
|
|
175
|
+
"@antfu/eslint-plugin-prettier": "5.0.1-1",
|
|
176
|
+
"@antfu/ni": "^0.21.12",
|
|
177
|
+
"@kirklin/eslint-config": "workspace:*",
|
|
178
|
+
"@stylistic/eslint-plugin-migrate": "^1.7.0",
|
|
179
|
+
"@types/eslint": "^8.56.6",
|
|
180
|
+
"@types/fs-extra": "^11.0.4",
|
|
181
|
+
"@types/node": "^20.11.30",
|
|
182
|
+
"@types/prompts": "^2.4.9",
|
|
183
|
+
"@types/yargs": "^17.0.32",
|
|
184
|
+
"@unocss/eslint-plugin": "^0.58.6",
|
|
185
|
+
"astro-eslint-parser": "^0.16.3",
|
|
186
|
+
bumpp: "^9.4.0",
|
|
187
|
+
eslint: "npm:eslint-ts-patch@8.57.0-0",
|
|
188
|
+
"eslint-flat-config-viewer": "^0.1.11",
|
|
189
|
+
"eslint-plugin-astro": "^0.32.0",
|
|
190
|
+
"eslint-plugin-format": "^0.1.0",
|
|
191
|
+
"eslint-plugin-react": "^7.34.1",
|
|
192
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
193
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
194
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
195
|
+
"eslint-ts-patch": "8.57.0-0",
|
|
196
|
+
esno: "^4.7.0",
|
|
197
|
+
execa: "^8.0.1",
|
|
198
|
+
"fast-glob": "^3.3.2",
|
|
199
|
+
"fs-extra": "^11.2.0",
|
|
200
|
+
"lint-staged": "^15.2.2",
|
|
201
|
+
"prettier-plugin-astro": "^0.13.0",
|
|
202
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
203
|
+
rimraf: "^5.0.5",
|
|
204
|
+
"simple-git-hooks": "^2.11.0",
|
|
205
|
+
svelte: "^4.2.12",
|
|
206
|
+
"svelte-eslint-parser": "^0.33.1",
|
|
207
|
+
tsup: "^8.0.2",
|
|
208
|
+
typescript: "^5.4.2",
|
|
209
|
+
vitest: "^1.4.0",
|
|
210
|
+
vue: "^3.4.21"
|
|
211
|
+
},
|
|
212
|
+
"simple-git-hooks": {
|
|
213
|
+
"pre-commit": "pnpm lint-staged"
|
|
214
|
+
},
|
|
215
|
+
"lint-staged": {
|
|
216
|
+
"*": "eslint --fix"
|
|
217
|
+
}
|
|
82
218
|
};
|
|
83
219
|
|
|
84
220
|
// src/cli/constants.ts
|
|
85
|
-
var ARROW = import_picocolors.default.cyan("\u2192");
|
|
86
|
-
var CHECK = import_picocolors.default.green("\u2714");
|
|
87
|
-
var CROSS = import_picocolors.default.red("\u2718");
|
|
88
|
-
var WARN = import_picocolors.default.yellow("\u2139");
|
|
89
|
-
var eslintVersion = devDependencies.eslint;
|
|
90
221
|
var vscodeSettingsString = `
|
|
91
222
|
// Enable the ESlint flat config support
|
|
92
223
|
"eslint.experimental.useFlatConfig": true,
|
|
@@ -127,9 +258,64 @@ var vscodeSettingsString = `
|
|
|
127
258
|
"json",
|
|
128
259
|
"jsonc",
|
|
129
260
|
"yaml",
|
|
130
|
-
"toml"
|
|
261
|
+
"toml",
|
|
262
|
+
"astro",
|
|
131
263
|
]
|
|
132
264
|
`;
|
|
265
|
+
var frameworkOptions = [
|
|
266
|
+
{
|
|
267
|
+
label: import_picocolors.default.green("Vue"),
|
|
268
|
+
value: "vue"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
label: import_picocolors.default.cyan("React"),
|
|
272
|
+
value: "react"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
label: import_picocolors.default.red("Svelte"),
|
|
276
|
+
value: "svelte"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
label: import_picocolors.default.magenta("Astro"),
|
|
280
|
+
value: "astro"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
label: import_picocolors.default.blue("Slidev"),
|
|
284
|
+
value: "slidev"
|
|
285
|
+
}
|
|
286
|
+
];
|
|
287
|
+
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
288
|
+
var extraOptions = [
|
|
289
|
+
{
|
|
290
|
+
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
|
|
291
|
+
label: import_picocolors.default.red("Formatter"),
|
|
292
|
+
value: "formatter"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
label: import_picocolors.default.cyan("UnoCSS"),
|
|
296
|
+
value: "unocss"
|
|
297
|
+
}
|
|
298
|
+
];
|
|
299
|
+
var extra = extraOptions.map(({ value }) => value);
|
|
300
|
+
var dependenciesMap = {
|
|
301
|
+
astro: [
|
|
302
|
+
"eslint-plugin-astro",
|
|
303
|
+
"astro-eslint-parser"
|
|
304
|
+
],
|
|
305
|
+
react: [
|
|
306
|
+
"eslint-plugin-react",
|
|
307
|
+
"eslint-plugin-react-hooks",
|
|
308
|
+
"eslint-plugin-react-refresh"
|
|
309
|
+
],
|
|
310
|
+
slidev: [
|
|
311
|
+
"prettier-plugin-slidev"
|
|
312
|
+
],
|
|
313
|
+
svelte: [
|
|
314
|
+
"eslint-plugin-svelte",
|
|
315
|
+
"svelte-eslint-parser"
|
|
316
|
+
],
|
|
317
|
+
vue: []
|
|
318
|
+
};
|
|
133
319
|
|
|
134
320
|
// src/cli/utils.ts
|
|
135
321
|
var import_node_child_process = require("child_process");
|
|
@@ -141,44 +327,97 @@ function isGitClean() {
|
|
|
141
327
|
return false;
|
|
142
328
|
}
|
|
143
329
|
}
|
|
330
|
+
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
331
|
+
return `
|
|
332
|
+
import kirklin from '@kirklin/eslint-config'
|
|
144
333
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
334
|
+
export default kirklin({
|
|
335
|
+
${mainConfig}
|
|
336
|
+
}${additionalConfigs?.map((config) => `,{
|
|
337
|
+
${config}
|
|
338
|
+
}`)})
|
|
339
|
+
`.trimStart();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/cli/stages/update-package-json.ts
|
|
343
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
344
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
345
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
346
|
+
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
347
|
+
var p = __toESM(require("@clack/prompts"), 1);
|
|
348
|
+
async function updatePackageJson(result) {
|
|
349
|
+
var _a;
|
|
149
350
|
const cwd = import_node_process.default.cwd();
|
|
150
|
-
const pathFlatConfig = import_node_path.default.join(cwd, "eslint.config.js");
|
|
151
351
|
const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
|
|
152
|
-
|
|
153
|
-
if (import_node_fs.default.existsSync(pathFlatConfig)) {
|
|
154
|
-
console.log(import_picocolors2.default.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
|
|
155
|
-
return import_node_process.default.exit(1);
|
|
156
|
-
}
|
|
157
|
-
if (!SKIP_GIT_CHECK && !isGitClean()) {
|
|
158
|
-
const { confirmed } = await (0, import_prompts.default)({
|
|
159
|
-
initial: false,
|
|
160
|
-
message: "There are uncommitted changes in the current repository, are you sure to continue?",
|
|
161
|
-
name: "confirmed",
|
|
162
|
-
type: "confirm"
|
|
163
|
-
});
|
|
164
|
-
if (!confirmed) {
|
|
165
|
-
return import_node_process.default.exit(1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
console.log(import_picocolors2.default.cyan(`${ARROW} bumping @kirklin/eslint-config to v${version}`));
|
|
352
|
+
p.log.step(import_picocolors2.default.cyan(`Bumping @kirklin/eslint-config to v${package_default.version}`));
|
|
169
353
|
const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf-8");
|
|
170
354
|
const pkg = JSON.parse(pkgContent);
|
|
171
355
|
pkg.devDependencies ?? (pkg.devDependencies = {});
|
|
172
|
-
pkg.devDependencies["@kirklin/eslint-config"] = `^${version}`;
|
|
173
|
-
|
|
174
|
-
|
|
356
|
+
pkg.devDependencies["@kirklin/eslint-config"] = `^${package_default.version}`;
|
|
357
|
+
(_a = pkg.devDependencies).eslint ?? (_a.eslint = package_default.devDependencies.eslint.replace("npm:eslint-ts-patch@", "").replace(/-\d+$/, ""));
|
|
358
|
+
const addedPackages = [];
|
|
359
|
+
if (result.extra.length) {
|
|
360
|
+
result.extra.forEach((item) => {
|
|
361
|
+
switch (item) {
|
|
362
|
+
case "formatter":
|
|
363
|
+
[
|
|
364
|
+
"eslint-plugin-format",
|
|
365
|
+
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
366
|
+
].forEach((f) => {
|
|
367
|
+
if (!f) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
371
|
+
addedPackages.push(f);
|
|
372
|
+
});
|
|
373
|
+
break;
|
|
374
|
+
case "unocss":
|
|
375
|
+
[
|
|
376
|
+
"@unocss/eslint-plugin"
|
|
377
|
+
].forEach((f) => {
|
|
378
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
379
|
+
addedPackages.push(f);
|
|
380
|
+
});
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
for (const framework of result.frameworks) {
|
|
386
|
+
const deps = dependenciesMap[framework];
|
|
387
|
+
if (deps) {
|
|
388
|
+
deps.forEach((f) => {
|
|
389
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
390
|
+
addedPackages.push(f);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (addedPackages.length) {
|
|
395
|
+
p.note(`${import_picocolors2.default.dim(addedPackages.join(", "))}`, "Added packages");
|
|
175
396
|
}
|
|
176
397
|
await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
177
|
-
|
|
398
|
+
p.log.success(import_picocolors2.default.green(`Changes wrote to package.json`));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/cli/stages/update-eslint-files.ts
|
|
402
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
403
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
404
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
405
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
406
|
+
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
407
|
+
var p2 = __toESM(require("@clack/prompts"), 1);
|
|
408
|
+
var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
409
|
+
async function updateEslintFiles(result) {
|
|
410
|
+
const cwd = import_node_process2.default.cwd();
|
|
411
|
+
const pathESLintIgnore = import_node_path2.default.join(cwd, ".eslintignore");
|
|
412
|
+
const pathPackageJSON = import_node_path2.default.join(cwd, "package.json");
|
|
413
|
+
const pkgContent = await import_promises2.default.readFile(pathPackageJSON, "utf-8");
|
|
414
|
+
const pkg = JSON.parse(pkgContent);
|
|
415
|
+
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
416
|
+
const pathFlatConfig = import_node_path2.default.join(cwd, configFileName);
|
|
178
417
|
const eslintIgnores = [];
|
|
179
418
|
if (import_node_fs.default.existsSync(pathESLintIgnore)) {
|
|
180
|
-
|
|
181
|
-
const content = await
|
|
419
|
+
p2.log.step(import_picocolors3.default.cyan(`Migrating existing .eslintignore`));
|
|
420
|
+
const content = await import_promises2.default.readFile(pathESLintIgnore, "utf-8");
|
|
182
421
|
const parsed = (0, import_parse_gitignore.default)(content);
|
|
183
422
|
const globs = parsed.globs();
|
|
184
423
|
for (const glob of globs) {
|
|
@@ -189,102 +428,175 @@ async function run(options = {}) {
|
|
|
189
428
|
}
|
|
190
429
|
}
|
|
191
430
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
`.trimStart();
|
|
202
|
-
} else {
|
|
203
|
-
eslintConfigContent = `
|
|
204
|
-
const kirklin = require('@kirklin/eslint-config').default
|
|
205
|
-
|
|
206
|
-
module.exports = kirklin({
|
|
207
|
-
${kirklinConfig}
|
|
208
|
-
})
|
|
209
|
-
`.trimStart();
|
|
431
|
+
const configLines = [];
|
|
432
|
+
if (eslintIgnores.length) {
|
|
433
|
+
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
434
|
+
}
|
|
435
|
+
if (result.extra.includes("formatter")) {
|
|
436
|
+
configLines.push(`formatters: true,`);
|
|
437
|
+
}
|
|
438
|
+
if (result.extra.includes("unocss")) {
|
|
439
|
+
configLines.push(`unocss: true,`);
|
|
210
440
|
}
|
|
211
|
-
|
|
212
|
-
|
|
441
|
+
for (const framework of result.frameworks) {
|
|
442
|
+
configLines.push(`${framework}: true,`);
|
|
443
|
+
}
|
|
444
|
+
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
445
|
+
const additionalConfig = [];
|
|
446
|
+
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
447
|
+
await import_promises2.default.writeFile(pathFlatConfig, eslintConfigContent);
|
|
448
|
+
p2.log.success(import_picocolors3.default.green(`Created ${configFileName}`));
|
|
213
449
|
const files = import_node_fs.default.readdirSync(cwd);
|
|
214
450
|
const legacyConfig = [];
|
|
215
451
|
files.forEach((file) => {
|
|
216
|
-
if (file
|
|
452
|
+
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) {
|
|
217
453
|
legacyConfig.push(file);
|
|
218
454
|
}
|
|
219
455
|
});
|
|
220
456
|
if (legacyConfig.length) {
|
|
221
|
-
|
|
222
|
-
console.log(` ${import_picocolors2.default.dim(legacyConfig.join(", "))}`);
|
|
457
|
+
p2.note(`${import_picocolors3.default.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
223
458
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
} catch (cancelled) {
|
|
240
|
-
console.log(cancelled.message);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/cli/stages/update-vscode-settings.ts
|
|
462
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
463
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
464
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
465
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
466
|
+
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
467
|
+
var p3 = __toESM(require("@clack/prompts"), 1);
|
|
468
|
+
async function updateVscodeSettings(result) {
|
|
469
|
+
const cwd = import_node_process3.default.cwd();
|
|
470
|
+
if (!result.updateVscodeSettings) {
|
|
471
|
+
return;
|
|
243
472
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
await import_promises.default.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
473
|
+
const dotVscodePath = import_node_path3.default.join(cwd, ".vscode");
|
|
474
|
+
const settingsPath = import_node_path3.default.join(dotVscodePath, "settings.json");
|
|
475
|
+
if (!import_node_fs2.default.existsSync(dotVscodePath)) {
|
|
476
|
+
await import_promises3.default.mkdir(dotVscodePath, { recursive: true });
|
|
477
|
+
}
|
|
478
|
+
if (!import_node_fs2.default.existsSync(settingsPath)) {
|
|
479
|
+
await import_promises3.default.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
252
480
|
`, "utf-8");
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
481
|
+
p3.log.success(import_picocolors4.default.green(`Created .vscode/settings.json`));
|
|
482
|
+
} else {
|
|
483
|
+
let settingsContent = await import_promises3.default.readFile(settingsPath, "utf8");
|
|
484
|
+
settingsContent = settingsContent.trim().replace(/\s*}$/, "");
|
|
485
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
486
|
+
settingsContent += `${vscodeSettingsString}}
|
|
259
487
|
`;
|
|
260
|
-
|
|
261
|
-
|
|
488
|
+
await import_promises3.default.writeFile(settingsPath, settingsContent, "utf-8");
|
|
489
|
+
p3.log.success(import_picocolors4.default.green(`Updated .vscode/settings.json`));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/cli/run.ts
|
|
494
|
+
async function run(options = {}) {
|
|
495
|
+
const argSkipPrompt = !!import_node_process4.default.env.SKIP_PROMPT || options.yes;
|
|
496
|
+
const argTemplate = options.frameworks?.map((m) => m.trim());
|
|
497
|
+
const argExtra = options.extra?.map((m) => m.trim());
|
|
498
|
+
if (import_node_fs3.default.existsSync(import_node_path4.default.join(import_node_process4.default.cwd(), "eslint.config.js"))) {
|
|
499
|
+
p4.log.warn(import_picocolors5.default.yellow(`eslint.config.js already exists, migration wizard exited.`));
|
|
500
|
+
return import_node_process4.default.exit(1);
|
|
501
|
+
}
|
|
502
|
+
let result = {
|
|
503
|
+
extra: argExtra ?? [],
|
|
504
|
+
frameworks: argTemplate ?? [],
|
|
505
|
+
uncommittedConfirmed: false,
|
|
506
|
+
updateVscodeSettings: true
|
|
507
|
+
};
|
|
508
|
+
if (!argSkipPrompt) {
|
|
509
|
+
result = await p4.group({
|
|
510
|
+
uncommittedConfirmed: () => {
|
|
511
|
+
if (argSkipPrompt || isGitClean()) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
return p4.confirm({
|
|
515
|
+
initialValue: false,
|
|
516
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
517
|
+
});
|
|
518
|
+
},
|
|
519
|
+
frameworks: ({ results }) => {
|
|
520
|
+
const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
|
|
521
|
+
if (!results.uncommittedConfirmed || isArgTemplateValid) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
525
|
+
return p4.multiselect({
|
|
526
|
+
message: import_picocolors5.default.reset(message),
|
|
527
|
+
options: frameworkOptions
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
extra: ({ results }) => {
|
|
531
|
+
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
532
|
+
if (!results.uncommittedConfirmed || isArgExtraValid) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
536
|
+
return p4.multiselect({
|
|
537
|
+
message: import_picocolors5.default.reset(message),
|
|
538
|
+
options: extraOptions,
|
|
539
|
+
required: false
|
|
540
|
+
});
|
|
541
|
+
},
|
|
542
|
+
updateVscodeSettings: ({ results }) => {
|
|
543
|
+
if (!results.uncommittedConfirmed) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
return p4.confirm({
|
|
547
|
+
initialValue: true,
|
|
548
|
+
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}, {
|
|
552
|
+
onCancel: () => {
|
|
553
|
+
p4.cancel("Operation cancelled.");
|
|
554
|
+
import_node_process4.default.exit(0);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
if (!result.uncommittedConfirmed) {
|
|
558
|
+
return import_node_process4.default.exit(1);
|
|
262
559
|
}
|
|
263
560
|
}
|
|
264
|
-
|
|
265
|
-
|
|
561
|
+
await updatePackageJson(result);
|
|
562
|
+
await updateEslintFiles(result);
|
|
563
|
+
await updateVscodeSettings(result);
|
|
564
|
+
p4.log.success(import_picocolors5.default.green(`Setup completed`));
|
|
565
|
+
p4.outro(`Now you can update the dependencies and run ${import_picocolors5.default.blue("eslint . --fix")}
|
|
266
566
|
`);
|
|
267
567
|
}
|
|
268
568
|
|
|
269
569
|
// src/cli/index.ts
|
|
270
570
|
function header() {
|
|
271
|
-
console.log(
|
|
272
|
-
|
|
571
|
+
console.log("\n");
|
|
572
|
+
p5.intro(`${import_picocolors6.default.green(`@kirklin/eslint-config `)}${import_picocolors6.default.dim(`v${package_default.version}`)}`);
|
|
273
573
|
}
|
|
274
|
-
var instance = (0, import_yargs.default)((0, import_helpers.hideBin)(
|
|
574
|
+
var instance = (0, import_yargs.default)((0, import_helpers.hideBin)(import_node_process5.default.argv)).scriptName("@kirklin/eslint-config").usage("").command(
|
|
275
575
|
"*",
|
|
276
576
|
"Run the initialization or migration",
|
|
277
|
-
(args) => args.option("yes", {
|
|
577
|
+
(args) => args.option("yes", {
|
|
578
|
+
alias: "y",
|
|
579
|
+
description: "Skip prompts and use default values",
|
|
580
|
+
type: "boolean"
|
|
581
|
+
}).option("template", {
|
|
582
|
+
alias: "t",
|
|
583
|
+
description: "Use the framework template for optimal customization: vue / react / svelte / astro",
|
|
584
|
+
type: "string"
|
|
585
|
+
}).option("extra", {
|
|
586
|
+
alias: "e",
|
|
587
|
+
array: true,
|
|
588
|
+
description: "Use the extra utils: formatter / perfectionist / unocss",
|
|
589
|
+
type: "string"
|
|
590
|
+
}).help(),
|
|
278
591
|
async (args) => {
|
|
279
592
|
header();
|
|
280
|
-
console.log();
|
|
281
593
|
try {
|
|
282
594
|
await run(args);
|
|
283
595
|
} catch (error) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
596
|
+
p5.log.error(import_picocolors6.default.inverse(import_picocolors6.default.red(" Failed to migrate ")));
|
|
597
|
+
p5.log.error(import_picocolors6.default.red(`\u2718 ${String(error)}`));
|
|
598
|
+
import_node_process5.default.exit(1);
|
|
287
599
|
}
|
|
288
600
|
}
|
|
289
|
-
).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
601
|
+
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|
|
290
602
|
instance.help().argv;
|