@isentinel/eslint-config 1.1.2 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -45
- package/dist/{chunk-VXR6SE7R.js → chunk-2HV5XKT7.js} +2 -2
- package/dist/cli.js +108 -118
- package/dist/eslint-plugin-simple-import-sort-FWMVSWU4.js +808 -0
- package/dist/index.d.ts +92 -58
- package/dist/index.js +3530 -1042
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Usage
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Starter Wizard
|
|
6
|
+
|
|
7
|
+
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
|
|
8
|
+
|
|
9
|
+
### Example Usage
|
|
6
10
|
|
|
7
11
|
For an existing template that already has this config setup, please refer to the
|
|
8
12
|
[roblox-ts
|
|
@@ -10,10 +14,6 @@ template](https://github.com/christopher-buss/roblox-ts-project-template)
|
|
|
10
14
|
repository. This includes all necessarily files and configurations to get you up
|
|
11
15
|
and running.
|
|
12
16
|
|
|
13
|
-
### Starter Wizard
|
|
14
|
-
|
|
15
|
-
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
|
|
16
|
-
|
|
17
17
|
```bash
|
|
18
18
|
npx @isentinel/eslint-config@latest
|
|
19
19
|
```
|
|
@@ -30,36 +30,56 @@ pnpm i -D eslint @isentinel/eslint-config
|
|
|
30
30
|
|
|
31
31
|
With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
|
|
32
32
|
|
|
33
|
-
```
|
|
33
|
+
```ts
|
|
34
34
|
// eslint.config.ts
|
|
35
35
|
import style from "@isentinel/eslint-config";
|
|
36
36
|
|
|
37
37
|
export default style();
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
> [customization](#customization) for more details.
|
|
40
|
+
#### Optional: TypeScript Config Support
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
> ESLint can support .ts config files, but requires some additional setup. See
|
|
45
|
-
> [here](https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files)
|
|
46
|
-
> for more information.
|
|
42
|
+
If you want to use `eslint.config.ts` instead of `.js`, install `jiti` v2.0.0 or greater:
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
```bash
|
|
45
|
+
pnpm i -D jiti@^2.0.0
|
|
46
|
+
```
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
following content:
|
|
48
|
+
See [ESLint's TypeScript configuration documentation](https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files) for more details.
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
<details>
|
|
51
|
+
<summary>
|
|
52
|
+
Combined with legacy config:
|
|
53
|
+
</summary>
|
|
54
|
+
|
|
55
|
+
If you still use some configs from the legacy eslintrc format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// eslint.config.ts
|
|
59
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
60
|
+
import style from "@isentinel/eslint-config";
|
|
61
|
+
|
|
62
|
+
const compat = new FlatCompat();
|
|
63
|
+
|
|
64
|
+
export default style(
|
|
65
|
+
{
|
|
66
|
+
ignores: [],
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Legacy config
|
|
70
|
+
...compat.config({
|
|
71
|
+
extends: [
|
|
72
|
+
"eslint:recommended",
|
|
73
|
+
// Other extends...
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
|
|
77
|
+
// Other flat configs...
|
|
78
|
+
);
|
|
59
79
|
```
|
|
60
80
|
|
|
61
|
-
|
|
62
|
-
|
|
81
|
+
> Note that `.eslintignore` no longer works in Flat config, see
|
|
82
|
+
> [customization](#customization) for more details.
|
|
63
83
|
|
|
64
84
|
### Add script for package.json
|
|
65
85
|
|
|
@@ -114,9 +134,6 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
114
134
|
|
|
115
135
|
```json
|
|
116
136
|
{
|
|
117
|
-
// Enable the ESlint flat config support
|
|
118
|
-
"eslint.experimental.useFlatConfig": true,
|
|
119
|
-
|
|
120
137
|
"editor.formatOnSave": false,
|
|
121
138
|
|
|
122
139
|
// Auto fix
|
|
@@ -148,10 +165,7 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
148
165
|
"jsonc",
|
|
149
166
|
"yaml",
|
|
150
167
|
"toml"
|
|
151
|
-
]
|
|
152
|
-
|
|
153
|
-
// Currently required to enable .ts config files
|
|
154
|
-
"eslint.options": { "flags": ["unstable_ts_config"] }
|
|
168
|
+
]
|
|
155
169
|
}
|
|
156
170
|
```
|
|
157
171
|
|
|
@@ -183,14 +197,6 @@ export default style({
|
|
|
183
197
|
// Type of the project. `package` for packages, the default is `game`
|
|
184
198
|
type: "package",
|
|
185
199
|
|
|
186
|
-
// Provide TypeScript parser options for access to type checking lints.
|
|
187
|
-
typescript: {
|
|
188
|
-
parserOptions: {
|
|
189
|
-
project: "tsconfig.build.json",
|
|
190
|
-
},
|
|
191
|
-
tsconfigPath: "tsconfig.build.json",
|
|
192
|
-
},
|
|
193
|
-
|
|
194
200
|
// Disable yaml support
|
|
195
201
|
yaml: false,
|
|
196
202
|
});
|
|
@@ -295,14 +301,15 @@ export default style({
|
|
|
295
301
|
"perfectionist/sort-objects": [
|
|
296
302
|
"warn",
|
|
297
303
|
{
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
304
|
+
customGroups: {
|
|
305
|
+
callbacks: ["\b(on[A-Z][a-zA-Z]*)\b"],
|
|
306
|
+
id: "^id$",
|
|
307
|
+
name: "^name$",
|
|
308
|
+
reactProps: ["^children$", "^ref$"],
|
|
302
309
|
},
|
|
303
|
-
groups: ["id", "name", "unknown", "
|
|
310
|
+
groups: ["id", "name", "unknown", "reactProps"],
|
|
304
311
|
order: "asc",
|
|
305
|
-
|
|
312
|
+
partitionByComment: "^Part:\\*\\*(.*)$",
|
|
306
313
|
type: "natural",
|
|
307
314
|
},
|
|
308
315
|
],
|
|
@@ -327,10 +334,23 @@ export default style({
|
|
|
327
334
|
});
|
|
328
335
|
```
|
|
329
336
|
|
|
337
|
+
#### Jest
|
|
338
|
+
|
|
339
|
+
To enable Jest support, you need to explicitly turn it on:
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
// eslint.config.ts
|
|
343
|
+
import style from "@isentinel/eslint-config";
|
|
344
|
+
|
|
345
|
+
export default style({
|
|
346
|
+
test: true,
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
330
350
|
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
331
351
|
|
|
332
352
|
```bash
|
|
333
|
-
pnpm i -D @eslint-react/eslint-plugin eslint-plugin-react-roblox-hooks
|
|
353
|
+
pnpm i -D @eslint-react/eslint-plugin eslint-plugin-react-roblox-hooks eslint-plugin-jest
|
|
334
354
|
```
|
|
335
355
|
|
|
336
356
|
### Lint Staged
|
|
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
|
|
30
|
-
// node_modules/.pnpm/tsup@8.4.0_jiti@2.4.
|
|
30
|
+
// node_modules/.pnpm/tsup@8.4.0_jiti@2.4.2_tsx@4.20.3_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/esm_shims.js
|
|
31
31
|
var init_esm_shims = __esm({
|
|
32
|
-
"node_modules/.pnpm/tsup@8.4.0_jiti@2.4.
|
|
32
|
+
"node_modules/.pnpm/tsup@8.4.0_jiti@2.4.2_tsx@4.20.3_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/esm_shims.js"() {
|
|
33
33
|
"use strict";
|
|
34
34
|
}
|
|
35
35
|
});
|
package/dist/cli.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_esm_shims
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2HV5XKT7.js";
|
|
4
4
|
|
|
5
5
|
// src/cli.ts
|
|
6
6
|
init_esm_shims();
|
|
7
7
|
|
|
8
8
|
// src/cli/index.ts
|
|
9
9
|
init_esm_shims();
|
|
10
|
-
import { intro, log as
|
|
10
|
+
import { intro, log as log5 } from "@clack/prompts";
|
|
11
11
|
import ansis6 from "ansis";
|
|
12
|
-
import
|
|
12
|
+
import process5 from "node:process";
|
|
13
13
|
import yargs from "yargs";
|
|
14
14
|
import { hideBin } from "yargs/helpers";
|
|
15
15
|
|
|
16
16
|
// src/cli/constants.ts
|
|
17
17
|
init_esm_shims();
|
|
18
|
+
import ansis from "ansis";
|
|
18
19
|
|
|
19
20
|
// package.json
|
|
20
|
-
var version = "1.
|
|
21
|
+
var version = "1.2.2";
|
|
21
22
|
var package_default = {
|
|
22
23
|
name: "@isentinel/eslint-config",
|
|
23
24
|
version,
|
|
@@ -53,7 +54,7 @@ var package_default = {
|
|
|
53
54
|
build: "nr gen && tsup --clean --dts",
|
|
54
55
|
"build:inspector": "pnpm build && npx @eslint/config-inspector build",
|
|
55
56
|
dev: "npx @eslint/config-inspector --config eslint.config.ts",
|
|
56
|
-
gen: "tsx scripts/typegen.ts && tsx scripts/versiongen.ts",
|
|
57
|
+
gen: "NODE_OPTIONS='--import ./scripts/register-stylua-loader.mjs' tsx scripts/typegen.ts && NODE_OPTIONS='--import ./scripts/register-stylua-loader.mjs' tsx scripts/versiongen.ts",
|
|
57
58
|
postgen: "echo 'Generation complete!'",
|
|
58
59
|
lint: "eslint",
|
|
59
60
|
prepack: "nr build",
|
|
@@ -102,12 +103,12 @@ var package_default = {
|
|
|
102
103
|
"eslint-plugin-perfectionist": "catalog:prod",
|
|
103
104
|
"eslint-plugin-pnpm": "catalog:prod",
|
|
104
105
|
"eslint-plugin-promise": "catalog:prod",
|
|
106
|
+
"eslint-plugin-roblox-ts-x": "catalog:prod",
|
|
105
107
|
"eslint-plugin-sentinel": "catalog:prod",
|
|
106
108
|
"eslint-plugin-sonarjs": "catalog:prod",
|
|
107
109
|
"eslint-plugin-toml": "catalog:prod",
|
|
108
110
|
"eslint-plugin-unicorn": "catalog:prod",
|
|
109
111
|
"eslint-plugin-yml": "catalog:prod",
|
|
110
|
-
"isentinel-eslint-plugin-roblox-ts": "catalog:prod",
|
|
111
112
|
"jsonc-eslint-parser": "catalog:prod",
|
|
112
113
|
"local-pkg": "catalog:prod",
|
|
113
114
|
"parse-gitignore": "catalog:prod",
|
|
@@ -163,7 +164,7 @@ var package_default = {
|
|
|
163
164
|
optional: true
|
|
164
165
|
}
|
|
165
166
|
},
|
|
166
|
-
packageManager: "pnpm@10.
|
|
167
|
+
packageManager: "pnpm@10.12.1",
|
|
167
168
|
publishConfig: {
|
|
168
169
|
access: "public"
|
|
169
170
|
}
|
|
@@ -171,9 +172,6 @@ var package_default = {
|
|
|
171
172
|
|
|
172
173
|
// src/cli/constants.ts
|
|
173
174
|
var vscodeSettingsString = `
|
|
174
|
-
// Enable the ESlint flat config support
|
|
175
|
-
"eslint.useFlatConfig": true,
|
|
176
|
-
|
|
177
175
|
// Disable the default formatter, use eslint instead
|
|
178
176
|
"prettier.enable": false,
|
|
179
177
|
"editor.formatOnSave": false,
|
|
@@ -210,55 +208,37 @@ var vscodeSettingsString = `
|
|
|
210
208
|
"luau"
|
|
211
209
|
]
|
|
212
210
|
`;
|
|
211
|
+
var frameworkOptions = [
|
|
212
|
+
{
|
|
213
|
+
label: ansis.red("Test"),
|
|
214
|
+
value: "test"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
label: ansis.cyan("React"),
|
|
218
|
+
value: "react"
|
|
219
|
+
}
|
|
220
|
+
];
|
|
221
|
+
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
213
222
|
var dependenciesMap = {
|
|
214
|
-
react: ["@eslint-react/eslint-plugin", "eslint-plugin-react-roblox-hooks"]
|
|
223
|
+
react: ["@eslint-react/eslint-plugin", "eslint-plugin-react-roblox-hooks"],
|
|
224
|
+
test: ["eslint-plugin-jest"]
|
|
215
225
|
};
|
|
216
226
|
|
|
217
227
|
// src/cli/run.ts
|
|
218
228
|
init_esm_shims();
|
|
219
|
-
import { cancel, confirm, group, log as
|
|
229
|
+
import { cancel, confirm, group, log as log4, multiselect, outro } from "@clack/prompts";
|
|
220
230
|
import ansis5 from "ansis";
|
|
221
|
-
import
|
|
222
|
-
import
|
|
223
|
-
import process5 from "node:process";
|
|
224
|
-
|
|
225
|
-
// src/cli/stages/add-tsconfig.build.json.ts
|
|
226
|
-
init_esm_shims();
|
|
227
|
-
import { log } from "@clack/prompts";
|
|
228
|
-
import ansis from "ansis";
|
|
229
|
-
import fs from "node:fs";
|
|
230
|
-
import fsp from "node:fs/promises";
|
|
231
|
-
import path from "path";
|
|
232
|
-
async function addTsconfigBuild() {
|
|
233
|
-
const cwd = process.cwd();
|
|
234
|
-
const pathTsconfigBuild = path.join(cwd, "tsconfig.build.json");
|
|
235
|
-
if (fs.existsSync(pathTsconfigBuild)) {
|
|
236
|
-
log.info(ansis.yellow("tsconfig.build.json already exists"));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
const tsconfigBuildContent = `{
|
|
240
|
-
"extends": "./tsconfig.json",
|
|
241
|
-
"include": ["src/**/*", "eslint.config.ts"],
|
|
242
|
-
"exclude": ["node_modules"]
|
|
243
|
-
}
|
|
244
|
-
`;
|
|
245
|
-
await fsp.writeFile(pathTsconfigBuild, tsconfigBuildContent, "utf-8");
|
|
246
|
-
log.success(ansis.green("Created tsconfig.build.json"));
|
|
247
|
-
log.info(
|
|
248
|
-
ansis.yellow(
|
|
249
|
-
`You must add '"exclude": ["./eslint.config.ts"]' to your tsconfig.json. In the future, this will be done automatically.`
|
|
250
|
-
)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
231
|
+
import fs3 from "node:fs";
|
|
232
|
+
import process4 from "node:process";
|
|
253
233
|
|
|
254
234
|
// src/cli/stages/update-eslint-files.ts
|
|
255
235
|
init_esm_shims();
|
|
256
|
-
import { log
|
|
236
|
+
import { log, note } from "@clack/prompts";
|
|
257
237
|
import ansis2 from "ansis";
|
|
258
|
-
import
|
|
259
|
-
import
|
|
260
|
-
import
|
|
261
|
-
import
|
|
238
|
+
import fs from "node:fs";
|
|
239
|
+
import fsp from "node:fs/promises";
|
|
240
|
+
import path from "node:path";
|
|
241
|
+
import process from "node:process";
|
|
262
242
|
import parse from "parse-gitignore";
|
|
263
243
|
|
|
264
244
|
// src/cli/utils.ts
|
|
@@ -285,18 +265,18 @@ function isGitClean() {
|
|
|
285
265
|
}
|
|
286
266
|
|
|
287
267
|
// src/cli/stages/update-eslint-files.ts
|
|
288
|
-
async function updateEslintFiles() {
|
|
289
|
-
const cwd =
|
|
290
|
-
const pathESLintIgnore =
|
|
291
|
-
const pathPackageJSON =
|
|
292
|
-
const packageContent = await
|
|
293
|
-
const
|
|
294
|
-
const configFileName =
|
|
295
|
-
const pathFlatConfig =
|
|
268
|
+
async function updateEslintFiles(result) {
|
|
269
|
+
const cwd = process.cwd();
|
|
270
|
+
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
271
|
+
const pathPackageJSON = path.join(cwd, "package.json");
|
|
272
|
+
const packageContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
273
|
+
const parsedPackage = JSON.parse(packageContent);
|
|
274
|
+
const configFileName = parsedPackage.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
275
|
+
const pathFlatConfig = path.join(cwd, configFileName);
|
|
296
276
|
const eslintIgnores = [];
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
const content = await
|
|
277
|
+
if (fs.existsSync(pathESLintIgnore)) {
|
|
278
|
+
log.step(ansis2.cyan("Migrating existing .eslintignore"));
|
|
279
|
+
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
300
280
|
const parsed = parse(content);
|
|
301
281
|
const globs = parsed.globs();
|
|
302
282
|
for (const glob of globs) {
|
|
@@ -311,20 +291,15 @@ async function updateEslintFiles() {
|
|
|
311
291
|
if (eslintIgnores.length) {
|
|
312
292
|
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
313
293
|
}
|
|
314
|
-
|
|
315
|
-
`${
|
|
316
|
-
|
|
317
|
-
parserOptions: {
|
|
318
|
-
project: "tsconfig.build.json",
|
|
319
|
-
},
|
|
320
|
-
},`
|
|
321
|
-
);
|
|
294
|
+
for (const framework of result.frameworks) {
|
|
295
|
+
configLines.push(`${framework}: true,`);
|
|
296
|
+
}
|
|
322
297
|
const mainConfig = configLines.map((index) => ` ${index}`).join("\n");
|
|
323
298
|
const additionalConfig = [];
|
|
324
299
|
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
325
|
-
await
|
|
326
|
-
|
|
327
|
-
const files =
|
|
300
|
+
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
301
|
+
log.success(ansis2.green(`Created ${configFileName}`));
|
|
302
|
+
const files = fs.readdirSync(cwd);
|
|
328
303
|
const legacyConfig = [];
|
|
329
304
|
for (const file of files) {
|
|
330
305
|
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) {
|
|
@@ -338,82 +313,84 @@ async function updateEslintFiles() {
|
|
|
338
313
|
|
|
339
314
|
// src/cli/stages/update-package-json.ts
|
|
340
315
|
init_esm_shims();
|
|
341
|
-
import { log as
|
|
316
|
+
import { log as log2, note as note2 } from "@clack/prompts";
|
|
342
317
|
import ansis3 from "ansis";
|
|
343
|
-
import
|
|
344
|
-
import
|
|
345
|
-
import
|
|
318
|
+
import fsp2 from "node:fs/promises";
|
|
319
|
+
import path2 from "node:path";
|
|
320
|
+
import process2 from "node:process";
|
|
346
321
|
|
|
347
322
|
// src/cli/constants-generated.ts
|
|
348
323
|
init_esm_shims();
|
|
349
324
|
var versionsMap = {
|
|
350
325
|
"@eslint-react/eslint-plugin": "1.48.4",
|
|
351
326
|
"eslint": "9.25.1",
|
|
327
|
+
"eslint-plugin-jest": "28.11.0",
|
|
352
328
|
"eslint-plugin-react-roblox-hooks": "5.1.0-rbx.1"
|
|
353
329
|
};
|
|
354
330
|
|
|
355
331
|
// src/cli/stages/update-package-json.ts
|
|
356
332
|
async function updatePackageJson() {
|
|
357
|
-
const cwd =
|
|
358
|
-
const pathPackageJSON =
|
|
359
|
-
|
|
360
|
-
const packageContent = await
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
333
|
+
const cwd = process2.cwd();
|
|
334
|
+
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
335
|
+
log2.step(ansis3.cyan(`Bumping @isentinel/eslint-config to v${version}`));
|
|
336
|
+
const packageContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
337
|
+
const parsedPackage = JSON.parse(packageContent);
|
|
338
|
+
parsedPackage.devDependencies ??= {};
|
|
339
|
+
parsedPackage.devDependencies["@isentinel/eslint-config"] = `^${version}`;
|
|
340
|
+
parsedPackage.devDependencies.eslint ??= versionsMap.eslint;
|
|
365
341
|
const addedPackages = [];
|
|
366
342
|
for (const dep of dependenciesMap["react"]) {
|
|
367
|
-
|
|
343
|
+
parsedPackage.devDependencies[dep] = versionsMap[dep];
|
|
368
344
|
addedPackages.push(dep);
|
|
369
345
|
}
|
|
370
346
|
if (addedPackages.length) {
|
|
371
347
|
note2(`${ansis3.dim(addedPackages.join(", "))}`, "Added packages");
|
|
372
348
|
}
|
|
373
|
-
await
|
|
374
|
-
|
|
349
|
+
await fsp2.writeFile(pathPackageJSON, JSON.stringify(parsedPackage, null, 2));
|
|
350
|
+
log2.success(ansis3.green("Changes wrote to package.json"));
|
|
375
351
|
}
|
|
376
352
|
|
|
377
353
|
// src/cli/stages/update-vscode-settings.ts
|
|
378
354
|
init_esm_shims();
|
|
379
|
-
import { log as
|
|
355
|
+
import { log as log3 } from "@clack/prompts";
|
|
380
356
|
import ansis4 from "ansis";
|
|
381
|
-
import
|
|
382
|
-
import
|
|
383
|
-
import
|
|
384
|
-
import
|
|
357
|
+
import fs2 from "node:fs";
|
|
358
|
+
import fsp3 from "node:fs/promises";
|
|
359
|
+
import path3 from "node:path";
|
|
360
|
+
import process3 from "node:process";
|
|
385
361
|
async function updateVscodeSettings(result) {
|
|
386
|
-
const cwd =
|
|
362
|
+
const cwd = process3.cwd();
|
|
387
363
|
if (!result.updateVscodeSettings) {
|
|
388
364
|
return;
|
|
389
365
|
}
|
|
390
|
-
const dotVscodePath =
|
|
391
|
-
const settingsPath =
|
|
392
|
-
if (!
|
|
393
|
-
await
|
|
366
|
+
const dotVscodePath = path3.join(cwd, ".vscode");
|
|
367
|
+
const settingsPath = path3.join(dotVscodePath, "settings.json");
|
|
368
|
+
if (!fs2.existsSync(dotVscodePath)) {
|
|
369
|
+
await fsp3.mkdir(dotVscodePath, { recursive: true });
|
|
394
370
|
}
|
|
395
|
-
if (!
|
|
396
|
-
await
|
|
371
|
+
if (!fs2.existsSync(settingsPath)) {
|
|
372
|
+
await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
397
373
|
`, "utf-8");
|
|
398
|
-
|
|
374
|
+
log3.success(ansis4.green("Created .vscode/settings.json"));
|
|
399
375
|
return;
|
|
400
376
|
}
|
|
401
|
-
let settingsContent = await
|
|
377
|
+
let settingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
402
378
|
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
403
379
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
404
380
|
settingsContent += `${vscodeSettingsString}}
|
|
405
381
|
`;
|
|
406
|
-
await
|
|
407
|
-
|
|
382
|
+
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
383
|
+
log3.success(ansis4.green("Updated .vscode/settings.json"));
|
|
408
384
|
}
|
|
409
385
|
|
|
410
386
|
// src/cli/run.ts
|
|
411
387
|
async function run(options = {}) {
|
|
412
|
-
const argumentSkipPrompt = !!
|
|
413
|
-
const argumentTemplate =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
388
|
+
const argumentSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
|
|
389
|
+
const argumentTemplate = options.frameworks?.map((framework) => framework?.trim()).filter(Boolean);
|
|
390
|
+
const eslintConfigFiles = fs3.readdirSync(process4.cwd()).filter((file) => file.startsWith("eslint.config."));
|
|
391
|
+
if (eslintConfigFiles.length > 0) {
|
|
392
|
+
log4.warn(ansis5.yellow(`${eslintConfigFiles[0]} already exists, migration wizard exited.`));
|
|
393
|
+
return process4.exit(1);
|
|
417
394
|
}
|
|
418
395
|
let result = {
|
|
419
396
|
frameworks: argumentTemplate,
|
|
@@ -423,6 +400,18 @@ async function run(options = {}) {
|
|
|
423
400
|
if (!argumentSkipPrompt) {
|
|
424
401
|
result = await group(
|
|
425
402
|
{
|
|
403
|
+
frameworks: ({ results }) => {
|
|
404
|
+
const isArgumentTemplateValid = typeof argumentTemplate === "string" && !!frameworks.includes(argumentTemplate);
|
|
405
|
+
if (!results.uncommittedConfirmed || isArgumentTemplateValid) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const message = !isArgumentTemplateValid && argumentTemplate ? `"${argumentTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
409
|
+
return multiselect({
|
|
410
|
+
message: ansis5.reset(message),
|
|
411
|
+
options: frameworkOptions,
|
|
412
|
+
required: false
|
|
413
|
+
});
|
|
414
|
+
},
|
|
426
415
|
uncommittedConfirmed: () => {
|
|
427
416
|
if (argumentSkipPrompt || isGitClean()) {
|
|
428
417
|
return Promise.resolve(true);
|
|
@@ -445,21 +434,22 @@ async function run(options = {}) {
|
|
|
445
434
|
{
|
|
446
435
|
onCancel: () => {
|
|
447
436
|
cancel("Operation cancelled.");
|
|
448
|
-
|
|
437
|
+
process4.exit(0);
|
|
449
438
|
}
|
|
450
439
|
}
|
|
451
440
|
);
|
|
452
441
|
if (!result.uncommittedConfirmed) {
|
|
453
|
-
return
|
|
442
|
+
return process4.exit(1);
|
|
454
443
|
}
|
|
455
444
|
}
|
|
456
445
|
await updatePackageJson();
|
|
457
|
-
await updateEslintFiles();
|
|
446
|
+
await updateEslintFiles(result);
|
|
458
447
|
await updateVscodeSettings(result);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
`
|
|
448
|
+
log4.success(ansis5.green("Setup completed"));
|
|
449
|
+
outro(
|
|
450
|
+
`Now you can update the dependencies by running ${ansis5.blue("pnpm install")} and run ${ansis5.blue("eslint --fix")}
|
|
451
|
+
`
|
|
452
|
+
);
|
|
463
453
|
}
|
|
464
454
|
|
|
465
455
|
// src/cli/index.ts
|
|
@@ -469,7 +459,7 @@ function header() {
|
|
|
469
459
|
const versionText = `v${package_default.version}`;
|
|
470
460
|
intro(introText + ansis6.dim(versionText));
|
|
471
461
|
}
|
|
472
|
-
var instance = yargs(hideBin(
|
|
462
|
+
var instance = yargs(hideBin(process5.argv)).scriptName("@isentinel/eslint-config").usage("").command(
|
|
473
463
|
"*",
|
|
474
464
|
"Run the initialization or migration",
|
|
475
465
|
(args) => {
|
|
@@ -488,9 +478,9 @@ var instance = yargs(hideBin(process6.argv)).scriptName("@isentinel/eslint-confi
|
|
|
488
478
|
try {
|
|
489
479
|
await run(args);
|
|
490
480
|
} catch (err) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
481
|
+
log5.error(ansis6.inverse(ansis6.red(" Failed to migrate ")));
|
|
482
|
+
log5.error(ansis6.red(`\u2718 ${String(err)}`));
|
|
483
|
+
process5.exit(1);
|
|
494
484
|
}
|
|
495
485
|
}
|
|
496
486
|
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|