@ivanmaxlogiudice/eslint-config 3.0.0-beta.1 → 3.0.0-beta.3
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/LICENSE +2 -2
- package/README.md +22 -214
- package/bin/index.js +1 -1
- package/dist/cli.js +156 -264
- package/dist/index.d.ts +13446 -3
- package/dist/index.js +1375 -32
- package/package.json +109 -144
- package/dist/cli.cjs +0 -579
- package/dist/cli.d.cts +0 -2
- package/dist/index.cjs +0 -80
- package/dist/index.d.cts +0 -5
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
// src/cli/index.ts
|
|
2
2
|
import process5 from "node:process";
|
|
3
|
+
import * as p5 from "@clack/prompts";
|
|
3
4
|
import c6 from "picocolors";
|
|
4
|
-
import { hideBin } from "yargs/helpers";
|
|
5
5
|
import yargs from "yargs";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
// src/cli/run.ts
|
|
9
|
-
import fs3 from "node:fs";
|
|
10
|
-
import path4 from "node:path";
|
|
11
|
-
import process4 from "node:process";
|
|
12
|
-
import c5 from "picocolors";
|
|
13
|
-
import * as p4 from "@clack/prompts";
|
|
6
|
+
import { hideBin } from "yargs/helpers";
|
|
14
7
|
|
|
15
8
|
// src/cli/constants.ts
|
|
16
9
|
import c from "picocolors";
|
|
@@ -18,159 +11,121 @@ import c from "picocolors";
|
|
|
18
11
|
// package.json
|
|
19
12
|
var package_default = {
|
|
20
13
|
name: "@ivanmaxlogiudice/eslint-config",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
packageManager: "pnpm@9.6.0",
|
|
14
|
+
version: "3.0.0-beta.3",
|
|
15
|
+
packageManager: "bun@1.1.24",
|
|
24
16
|
description: "Personal ESLint config",
|
|
25
|
-
|
|
17
|
+
type: "module",
|
|
18
|
+
keywords: ["eslint-config"],
|
|
26
19
|
license: "MIT",
|
|
27
20
|
homepage: "https://github.com/ivanmaxlogiudice/eslint-config#readme",
|
|
21
|
+
bugs: {
|
|
22
|
+
url: "https://github.com/ivanmaxlogiudice/eslint-config/issues"
|
|
23
|
+
},
|
|
28
24
|
repository: {
|
|
29
25
|
type: "git",
|
|
30
26
|
url: "git+https://github.com/ivanmaxlogiudice/eslint-config.git"
|
|
31
27
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
keywords: [
|
|
36
|
-
"eslint",
|
|
37
|
-
"eslint-config"
|
|
38
|
-
],
|
|
28
|
+
files: ["bin", "dist"],
|
|
29
|
+
main: "./dist/index.js",
|
|
30
|
+
types: "./dist/index.d.ts",
|
|
39
31
|
exports: {
|
|
40
32
|
".": {
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
require: "./dist/index.cjs",
|
|
34
|
+
import: "./dist/index.js"
|
|
43
35
|
}
|
|
44
36
|
},
|
|
45
|
-
main: "./dist/index.js",
|
|
46
|
-
types: "./dist/index.d.ts",
|
|
47
37
|
bin: "./bin/index.js",
|
|
48
|
-
files: [
|
|
49
|
-
"bin",
|
|
50
|
-
"dist"
|
|
51
|
-
],
|
|
52
38
|
publishConfig: {
|
|
53
39
|
access: "public"
|
|
54
40
|
},
|
|
55
41
|
scripts: {
|
|
56
42
|
stub: "tsup --format esm",
|
|
57
43
|
dev: "config-inspector --config eslint.config.ts",
|
|
58
|
-
build: "tsup --format esm
|
|
59
|
-
"build:inspector": "pnpm build && config-inspector build",
|
|
60
|
-
lint: "pnpm run stub && eslint . --fix",
|
|
61
|
-
prepack: "pnpm run build",
|
|
62
|
-
release: "bumpp && pnpm publish",
|
|
44
|
+
build: "bun run typegen && tsup --format esm --clean --dts",
|
|
63
45
|
test: "vitest",
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
lint: "eslint . --fix",
|
|
47
|
+
typegen: "bun scripts/typegen.ts",
|
|
48
|
+
prepack: "bun run build",
|
|
49
|
+
release: "bumpp && npm publish",
|
|
50
|
+
typecheck: "tsc --noEmit"
|
|
66
51
|
},
|
|
67
52
|
peerDependencies: {
|
|
68
|
-
"@
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
eslint: "
|
|
73
|
-
"eslint-plugin-
|
|
74
|
-
"eslint-
|
|
75
|
-
"eslint-
|
|
76
|
-
"eslint-plugin-react-refresh": ">=0.4.9",
|
|
77
|
-
"eslint-plugin-solid": ">=0.14.1",
|
|
78
|
-
"eslint-plugin-svelte": ">=2.43.0",
|
|
79
|
-
"prettier-plugin-astro": ">=0.14.1",
|
|
80
|
-
"prettier-plugin-slidev": ">=1.0.5",
|
|
81
|
-
"svelte-eslint-parser": ">=0.41.0"
|
|
53
|
+
"@unocss/eslint-plugin": "^0.61.9",
|
|
54
|
+
eslint: "^9.9.0",
|
|
55
|
+
"eslint-plugin-markdown": "^5.1.0",
|
|
56
|
+
"eslint-plugin-regexp": "^2.6.0",
|
|
57
|
+
"eslint-plugin-vue": "^9.27.0",
|
|
58
|
+
"eslint-plugin-yml": "^1.14.0",
|
|
59
|
+
"vue-eslint-parser": "^9.4.3",
|
|
60
|
+
"yaml-eslint-parser": "^1.2.3"
|
|
82
61
|
},
|
|
83
62
|
peerDependenciesMeta: {
|
|
84
|
-
"@eslint-react/eslint-plugin": {
|
|
85
|
-
optional: true
|
|
86
|
-
},
|
|
87
|
-
"@prettier/plugin-xml": {
|
|
88
|
-
optional: true
|
|
89
|
-
},
|
|
90
63
|
"@unocss/eslint-plugin": {
|
|
91
64
|
optional: true
|
|
92
65
|
},
|
|
93
|
-
"
|
|
94
|
-
optional: true
|
|
95
|
-
},
|
|
96
|
-
"eslint-plugin-astro": {
|
|
97
|
-
optional: true
|
|
98
|
-
},
|
|
99
|
-
"eslint-plugin-format": {
|
|
100
|
-
optional: true
|
|
101
|
-
},
|
|
102
|
-
"eslint-plugin-react-hooks": {
|
|
103
|
-
optional: true
|
|
104
|
-
},
|
|
105
|
-
"eslint-plugin-react-refresh": {
|
|
66
|
+
"eslint-plugin-markdown": {
|
|
106
67
|
optional: true
|
|
107
68
|
},
|
|
108
|
-
"eslint-plugin-
|
|
69
|
+
"eslint-plugin-regexp": {
|
|
109
70
|
optional: true
|
|
110
71
|
},
|
|
111
|
-
"eslint-plugin-
|
|
72
|
+
"eslint-plugin-vue": {
|
|
112
73
|
optional: true
|
|
113
74
|
},
|
|
114
|
-
"
|
|
75
|
+
"eslint-plugin-yml": {
|
|
115
76
|
optional: true
|
|
116
77
|
},
|
|
117
|
-
"
|
|
78
|
+
"vue-eslint-parser": {
|
|
118
79
|
optional: true
|
|
119
80
|
},
|
|
120
|
-
"
|
|
81
|
+
"yaml-eslint-parser": {
|
|
121
82
|
optional: true
|
|
122
83
|
}
|
|
123
84
|
},
|
|
124
85
|
dependencies: {
|
|
125
|
-
"@antfu/eslint-config": "^2.24.0",
|
|
126
86
|
"@clack/prompts": "^0.7.0",
|
|
127
|
-
|
|
128
|
-
"
|
|
87
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
|
|
88
|
+
"@ivanmaxlogiudice/gitignore": "^0.0.2",
|
|
89
|
+
"@stylistic/eslint-plugin": "^2.6.2",
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
91
|
+
"@typescript-eslint/parser": "^8.1.0",
|
|
92
|
+
"@vitest/eslint-plugin": "^1.0.2",
|
|
93
|
+
"eslint-plugin-antfu": "^2.3.5",
|
|
94
|
+
"eslint-plugin-import-x": "^3.1.0",
|
|
95
|
+
"eslint-plugin-jsdoc": "^50.2.2",
|
|
96
|
+
"eslint-plugin-jsonc": "^2.16.0",
|
|
97
|
+
"eslint-plugin-n": "^17.10.2",
|
|
98
|
+
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
99
|
+
"eslint-plugin-perfectionist": "^3.1.3",
|
|
100
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
101
|
+
"eslint-plugin-unused-imports": "^4.1.3",
|
|
102
|
+
globals: "^15.9.0",
|
|
103
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
129
104
|
picocolors: "^1.0.1",
|
|
130
105
|
yargs: "^17.7.2"
|
|
131
106
|
},
|
|
132
107
|
devDependencies: {
|
|
133
|
-
"@eslint-react/eslint-plugin": "^1.6.0",
|
|
134
108
|
"@eslint/config-inspector": "^0.5.2",
|
|
135
|
-
"@
|
|
136
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
109
|
+
"@stylistic/eslint-plugin-migrate": "^2.6.2",
|
|
137
110
|
"@types/eslint": "^9.6.0",
|
|
138
|
-
"@types/
|
|
139
|
-
"@types/
|
|
140
|
-
"@
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
eslint: "
|
|
146
|
-
"eslint-plugin-
|
|
147
|
-
"eslint-plugin-
|
|
148
|
-
"eslint-plugin-
|
|
149
|
-
"eslint-
|
|
150
|
-
|
|
151
|
-
"eslint-plugin-svelte": "^2.43.0",
|
|
152
|
-
"eslint-ts-patch": "9.8.0-1",
|
|
153
|
-
esno: "^4.7.0",
|
|
154
|
-
execa: "^9.3.0",
|
|
155
|
-
"fast-glob": "^3.3.2",
|
|
156
|
-
"fs-extra": "^11.2.0",
|
|
157
|
-
"lint-staged": "^15.2.7",
|
|
158
|
-
"prettier-plugin-astro": "^0.14.1",
|
|
159
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
160
|
-
"simple-git-hooks": "^2.11.1",
|
|
161
|
-
svelte: "^4.2.18",
|
|
162
|
-
"svelte-eslint-parser": "^0.41.0",
|
|
163
|
-
tsup: "^8.2.3",
|
|
164
|
-
tsx: "^4.16.2",
|
|
111
|
+
"@types/node": "^22.3.0",
|
|
112
|
+
"@types/yargs": "^17.0.33",
|
|
113
|
+
"@unocss/eslint-plugin": "^0.62.1",
|
|
114
|
+
bumpp: "^9.5.1",
|
|
115
|
+
"bun-types": "^1.1.24",
|
|
116
|
+
"bundle-require": "^5.0.0",
|
|
117
|
+
eslint: "^9.9.0",
|
|
118
|
+
"eslint-plugin-markdown": "^5.1.0",
|
|
119
|
+
"eslint-plugin-regexp": "^2.6.0",
|
|
120
|
+
"eslint-plugin-vue": "^9.27.0",
|
|
121
|
+
"eslint-plugin-yml": "^1.14.0",
|
|
122
|
+
"eslint-typegen": "^0.3.0",
|
|
123
|
+
tsup: "^8.2.4",
|
|
165
124
|
typescript: "^5.5.4",
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"pre-commit": "pnpm lint-staged"
|
|
171
|
-
},
|
|
172
|
-
"lint-staged": {
|
|
173
|
-
"*": "eslint --fix"
|
|
125
|
+
unbuild: "^2.0.0",
|
|
126
|
+
vitest: "^2.0.5",
|
|
127
|
+
"vue-eslint-parser": "^9.4.3",
|
|
128
|
+
"yaml-eslint-parser": "^1.2.3"
|
|
174
129
|
}
|
|
175
130
|
};
|
|
176
131
|
|
|
@@ -207,56 +162,20 @@ var vscodeSettingsString = `
|
|
|
207
162
|
"typescript",
|
|
208
163
|
"typescriptreact",
|
|
209
164
|
"vue",
|
|
210
|
-
"html",
|
|
211
165
|
"markdown",
|
|
212
166
|
"json",
|
|
213
167
|
"jsonc",
|
|
214
|
-
"yaml"
|
|
215
|
-
"toml",
|
|
216
|
-
"xml",
|
|
217
|
-
"gql",
|
|
218
|
-
"graphql",
|
|
219
|
-
"astro",
|
|
220
|
-
"css",
|
|
221
|
-
"less",
|
|
222
|
-
"scss",
|
|
223
|
-
"pcss",
|
|
224
|
-
"postcss"
|
|
168
|
+
"yaml"
|
|
225
169
|
]
|
|
226
170
|
`;
|
|
227
171
|
var frameworkOptions = [
|
|
228
172
|
{
|
|
229
173
|
label: c.green("Vue"),
|
|
230
174
|
value: "vue"
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
label: c.cyan("React"),
|
|
234
|
-
value: "react"
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
label: c.red("Svelte"),
|
|
238
|
-
value: "svelte"
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
label: c.magenta("Astro"),
|
|
242
|
-
value: "astro"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
label: c.cyan("Solid"),
|
|
246
|
-
value: "solid"
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
label: c.blue("Slidev"),
|
|
250
|
-
value: "slidev"
|
|
251
175
|
}
|
|
252
176
|
];
|
|
253
177
|
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
254
178
|
var extraOptions = [
|
|
255
|
-
{
|
|
256
|
-
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
|
|
257
|
-
label: c.red("Formatter"),
|
|
258
|
-
value: "formatter"
|
|
259
|
-
},
|
|
260
179
|
{
|
|
261
180
|
label: c.cyan("UnoCSS"),
|
|
262
181
|
value: "unocss"
|
|
@@ -264,33 +183,30 @@ var extraOptions = [
|
|
|
264
183
|
];
|
|
265
184
|
var extra = extraOptions.map(({ value }) => value);
|
|
266
185
|
var dependenciesMap = {
|
|
267
|
-
astro: [
|
|
268
|
-
"eslint-plugin-astro",
|
|
269
|
-
"astro-eslint-parser"
|
|
270
|
-
],
|
|
271
|
-
react: [
|
|
272
|
-
"@eslint-react/eslint-plugin",
|
|
273
|
-
"eslint-plugin-react-hooks",
|
|
274
|
-
"eslint-plugin-react-refresh"
|
|
275
|
-
],
|
|
276
|
-
slidev: [
|
|
277
|
-
"prettier-plugin-slidev"
|
|
278
|
-
],
|
|
279
|
-
solid: [
|
|
280
|
-
"eslint-plugin-solid"
|
|
281
|
-
],
|
|
282
|
-
svelte: [
|
|
283
|
-
"eslint-plugin-svelte",
|
|
284
|
-
"svelte-eslint-parser"
|
|
285
|
-
],
|
|
286
186
|
vue: []
|
|
287
187
|
};
|
|
288
188
|
|
|
189
|
+
// src/cli/run.ts
|
|
190
|
+
import fs3 from "node:fs";
|
|
191
|
+
import path4 from "node:path";
|
|
192
|
+
import process4 from "node:process";
|
|
193
|
+
import * as p4 from "@clack/prompts";
|
|
194
|
+
import c5 from "picocolors";
|
|
195
|
+
|
|
196
|
+
// src/cli/stages/update-eslint-files.ts
|
|
197
|
+
import fs from "node:fs";
|
|
198
|
+
import fsp from "node:fs/promises";
|
|
199
|
+
import path from "node:path";
|
|
200
|
+
import process from "node:process";
|
|
201
|
+
import * as p from "@clack/prompts";
|
|
202
|
+
import { parsePath, toFlatConfig } from "@ivanmaxlogiudice/gitignore";
|
|
203
|
+
import c2 from "picocolors";
|
|
204
|
+
|
|
289
205
|
// src/cli/utils.ts
|
|
290
206
|
import { execSync } from "node:child_process";
|
|
291
207
|
function isGitClean() {
|
|
292
208
|
try {
|
|
293
|
-
execSync("git diff-index --quiet HEAD
|
|
209
|
+
execSync("git diff-index --quiet HEAD --");
|
|
294
210
|
return true;
|
|
295
211
|
} catch {
|
|
296
212
|
return false;
|
|
@@ -298,43 +214,72 @@ function isGitClean() {
|
|
|
298
214
|
}
|
|
299
215
|
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
300
216
|
return `
|
|
301
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
217
|
+
import { config } from '@ivanmaxlogiudice/eslint-config'
|
|
302
218
|
|
|
303
219
|
export default config({
|
|
304
220
|
${mainConfig}
|
|
305
|
-
}${additionalConfigs?.map((config) => `,
|
|
221
|
+
}${additionalConfigs?.map((config) => `,{
|
|
306
222
|
${config}
|
|
307
223
|
}`)})
|
|
308
224
|
`.trimStart();
|
|
309
225
|
}
|
|
310
226
|
|
|
311
|
-
// src/cli/stages/update-
|
|
312
|
-
|
|
313
|
-
import fsp from "node:fs/promises";
|
|
314
|
-
import process from "node:process";
|
|
315
|
-
import c2 from "picocolors";
|
|
316
|
-
import * as p from "@clack/prompts";
|
|
317
|
-
async function updatePackageJson(result) {
|
|
227
|
+
// src/cli/stages/update-eslint-files.ts
|
|
228
|
+
async function updateEslintFiles(result) {
|
|
318
229
|
const cwd = process.cwd();
|
|
230
|
+
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
319
231
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
320
|
-
p.log.step(c2.cyan(`Bumping @ivanmaxlogiudice/eslint-config to v${package_default.version}`));
|
|
321
232
|
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
322
233
|
const pkg = JSON.parse(pkgContent);
|
|
234
|
+
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
235
|
+
const pathFlatConfig = path.join(cwd, configFileName);
|
|
236
|
+
const eslintIgnores = [];
|
|
237
|
+
if (fs.existsSync(pathESLintIgnore)) {
|
|
238
|
+
p.log.step(c2.cyan(`Migrating existing .eslintignore`));
|
|
239
|
+
const patterns = parsePath(pathESLintIgnore);
|
|
240
|
+
eslintIgnores.push(...toFlatConfig(patterns).ignores);
|
|
241
|
+
}
|
|
242
|
+
const configLines = [];
|
|
243
|
+
if (eslintIgnores.length)
|
|
244
|
+
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
245
|
+
if (result.extra.includes("unocss"))
|
|
246
|
+
configLines.push(`unocss: true,`);
|
|
247
|
+
for (const framework of result.frameworks)
|
|
248
|
+
configLines.push(`${framework}: true,`);
|
|
249
|
+
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
250
|
+
const additionalConfig = [];
|
|
251
|
+
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
252
|
+
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
253
|
+
p.log.success(c2.green(`Created ${configFileName}`));
|
|
254
|
+
const files = fs.readdirSync(cwd).sort();
|
|
255
|
+
const legacyConfig = [];
|
|
256
|
+
files.forEach((file) => {
|
|
257
|
+
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
258
|
+
legacyConfig.push(file);
|
|
259
|
+
});
|
|
260
|
+
if (legacyConfig.length)
|
|
261
|
+
p.note(`${c2.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/cli/stages/update-package-json.ts
|
|
265
|
+
import fsp2 from "node:fs/promises";
|
|
266
|
+
import path2 from "node:path";
|
|
267
|
+
import process2 from "node:process";
|
|
268
|
+
import * as p2 from "@clack/prompts";
|
|
269
|
+
import c3 from "picocolors";
|
|
270
|
+
async function updatePackageJson(result) {
|
|
271
|
+
const cwd = process2.cwd();
|
|
272
|
+
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
273
|
+
p2.log.step(c3.cyan(`Bumping @ivanmaxlogiudice/eslint-config to v${package_default.version}`));
|
|
274
|
+
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
275
|
+
const pkg = JSON.parse(pkgContent);
|
|
323
276
|
pkg.devDependencies ??= {};
|
|
324
277
|
pkg.devDependencies["@ivanmaxlogiudice/eslint-config"] = `^${package_default.version}`;
|
|
325
|
-
pkg.devDependencies.eslint ??= package_default.devDependencies.eslint
|
|
278
|
+
pkg.devDependencies.eslint ??= package_default.devDependencies.eslint;
|
|
326
279
|
const addedPackages = [];
|
|
327
280
|
if (result.extra.length) {
|
|
328
281
|
result.extra.forEach((item) => {
|
|
329
282
|
switch (item) {
|
|
330
|
-
case "formatter":
|
|
331
|
-
["eslint-plugin-format", result.frameworks.includes("astro") ? "prettier-plugin-astro" : null].forEach((f) => {
|
|
332
|
-
if (!f)
|
|
333
|
-
return;
|
|
334
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
335
|
-
addedPackages.push(f);
|
|
336
|
-
});
|
|
337
|
-
break;
|
|
338
283
|
case "unocss":
|
|
339
284
|
["@unocss/eslint-plugin"].forEach((f) => {
|
|
340
285
|
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
@@ -354,71 +299,18 @@ async function updatePackageJson(result) {
|
|
|
354
299
|
}
|
|
355
300
|
}
|
|
356
301
|
if (addedPackages.length)
|
|
357
|
-
|
|
358
|
-
await
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// src/cli/stages/update-eslint-files.ts
|
|
363
|
-
import fs from "node:fs";
|
|
364
|
-
import fsp2 from "node:fs/promises";
|
|
365
|
-
import process2 from "node:process";
|
|
366
|
-
import path2 from "node:path";
|
|
367
|
-
import c3 from "picocolors";
|
|
368
|
-
import * as p2 from "@clack/prompts";
|
|
369
|
-
import parse from "parse-gitignore";
|
|
370
|
-
async function updateEslintFiles(result) {
|
|
371
|
-
const cwd = process2.cwd();
|
|
372
|
-
const pathESLintIgnore = path2.join(cwd, ".eslintignore");
|
|
373
|
-
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
374
|
-
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
375
|
-
const pkg = JSON.parse(pkgContent);
|
|
376
|
-
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
377
|
-
const pathFlatConfig = path2.join(cwd, configFileName);
|
|
378
|
-
const eslintIgnores = [];
|
|
379
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
380
|
-
p2.log.step(c3.cyan(`Migrating existing .eslintignore`));
|
|
381
|
-
const content = await fsp2.readFile(pathESLintIgnore, "utf-8");
|
|
382
|
-
const parsed = parse(content);
|
|
383
|
-
const globs = parsed.globs();
|
|
384
|
-
for (const glob of globs) {
|
|
385
|
-
if (glob.type === "ignore")
|
|
386
|
-
eslintIgnores.push(...glob.patterns);
|
|
387
|
-
else if (glob.type === "unignore")
|
|
388
|
-
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
const configLines = [];
|
|
392
|
-
if (eslintIgnores.length)
|
|
393
|
-
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
394
|
-
if (result.extra.includes("formatter"))
|
|
395
|
-
configLines.push(`formatters: true,`);
|
|
396
|
-
if (result.extra.includes("unocss"))
|
|
397
|
-
configLines.push(`unocss: true,`);
|
|
398
|
-
for (const framework of result.frameworks)
|
|
399
|
-
configLines.push(`${framework}: true,`);
|
|
400
|
-
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
401
|
-
const additionalConfig = [];
|
|
402
|
-
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
403
|
-
await fsp2.writeFile(pathFlatConfig, eslintConfigContent);
|
|
404
|
-
p2.log.success(c3.green(`Created ${configFileName}`));
|
|
405
|
-
const files = fs.readdirSync(cwd);
|
|
406
|
-
const legacyConfig = [];
|
|
407
|
-
files.forEach((file) => {
|
|
408
|
-
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
409
|
-
legacyConfig.push(file);
|
|
410
|
-
});
|
|
411
|
-
if (legacyConfig.length)
|
|
412
|
-
p2.note(`${c3.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
302
|
+
p2.note(`${c3.dim(addedPackages.join(", "))}`, "Added packages");
|
|
303
|
+
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
304
|
+
p2.log.success(c3.green(`Changes wrote to package.json`));
|
|
413
305
|
}
|
|
414
306
|
|
|
415
307
|
// src/cli/stages/update-vscode-settings.ts
|
|
416
|
-
import path3 from "node:path";
|
|
417
|
-
import fsp3 from "node:fs/promises";
|
|
418
308
|
import fs2 from "node:fs";
|
|
309
|
+
import fsp3 from "node:fs/promises";
|
|
310
|
+
import path3 from "node:path";
|
|
419
311
|
import process3 from "node:process";
|
|
420
|
-
import c4 from "picocolors";
|
|
421
312
|
import * as p3 from "@clack/prompts";
|
|
313
|
+
import c4 from "picocolors";
|
|
422
314
|
async function updateVscodeSettings(result) {
|
|
423
315
|
const cwd = process3.cwd();
|
|
424
316
|
if (!result.updateVscodeSettings)
|
|
@@ -459,12 +351,15 @@ async function run(options = {}) {
|
|
|
459
351
|
};
|
|
460
352
|
if (!argSkipPrompt) {
|
|
461
353
|
result = await p4.group({
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
354
|
+
extra: ({ results }) => {
|
|
355
|
+
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
356
|
+
if (!results.uncommittedConfirmed || isArgExtraValid)
|
|
357
|
+
return;
|
|
358
|
+
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
359
|
+
return p4.multiselect({
|
|
360
|
+
message: c5.reset(message),
|
|
361
|
+
options: extraOptions,
|
|
362
|
+
required: false
|
|
468
363
|
});
|
|
469
364
|
},
|
|
470
365
|
frameworks: ({ results }) => {
|
|
@@ -478,15 +373,12 @@ async function run(options = {}) {
|
|
|
478
373
|
required: false
|
|
479
374
|
});
|
|
480
375
|
},
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
message: c5.reset(message),
|
|
488
|
-
options: extraOptions,
|
|
489
|
-
required: false
|
|
376
|
+
uncommittedConfirmed: () => {
|
|
377
|
+
if (argSkipPrompt || isGitClean())
|
|
378
|
+
return Promise.resolve(true);
|
|
379
|
+
return p4.confirm({
|
|
380
|
+
initialValue: false,
|
|
381
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
490
382
|
});
|
|
491
383
|
},
|
|
492
384
|
updateVscodeSettings: ({ results }) => {
|