@eienjs/eslint-config 1.2.2 → 1.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.
Files changed (76) hide show
  1. package/dist/cli/constants.js +74 -0
  2. package/dist/cli/constants_generated.js +13 -0
  3. package/dist/cli/index.d.ts +1 -1
  4. package/dist/cli/index.js +3 -268
  5. package/dist/cli/run.js +77 -0
  6. package/dist/cli/stages/update_eslint_files.js +41 -0
  7. package/dist/cli/stages/update_package_json.js +46 -0
  8. package/dist/cli/stages/update_vscode_settings.js +30 -0
  9. package/dist/cli/utils.js +23 -0
  10. package/dist/configs/adonisjs.d.ts +6 -0
  11. package/dist/configs/adonisjs.js +115 -0
  12. package/dist/configs/astro.d.ts +6 -0
  13. package/dist/configs/astro.js +52 -0
  14. package/dist/configs/command.d.ts +6 -0
  15. package/dist/configs/command.js +12 -0
  16. package/dist/configs/comments.d.ts +6 -0
  17. package/dist/configs/comments.js +19 -0
  18. package/dist/configs/disables.d.ts +6 -0
  19. package/dist/configs/disables.js +85 -0
  20. package/dist/configs/formatters.d.ts +6 -0
  21. package/dist/configs/formatters.js +134 -0
  22. package/dist/configs/ignores.d.ts +6 -0
  23. package/dist/configs/ignores.js +12 -0
  24. package/dist/configs/imports.d.ts +6 -0
  25. package/dist/configs/imports.js +28 -0
  26. package/dist/configs/index.d.ts +25 -95
  27. package/dist/configs/index.js +25 -1
  28. package/dist/configs/javascript.d.ts +6 -0
  29. package/dist/configs/javascript.js +289 -0
  30. package/dist/configs/jsdoc.d.ts +6 -0
  31. package/dist/configs/jsdoc.js +34 -0
  32. package/dist/configs/jsonc.d.ts +6 -0
  33. package/dist/configs/jsonc.js +71 -0
  34. package/dist/configs/markdown.d.ts +6 -0
  35. package/dist/configs/markdown.js +67 -0
  36. package/dist/configs/node.d.ts +6 -0
  37. package/dist/configs/node.js +22 -0
  38. package/dist/configs/nuxt.d.ts +6 -0
  39. package/dist/configs/nuxt.js +137 -0
  40. package/dist/configs/perfectionist.d.ts +12 -0
  41. package/dist/configs/perfectionist.js +56 -0
  42. package/dist/configs/pnpm.d.ts +6 -0
  43. package/dist/configs/pnpm.js +33 -0
  44. package/dist/configs/regexp.d.ts +6 -0
  45. package/dist/configs/regexp.js +21 -0
  46. package/dist/configs/sort.d.ts +18 -0
  47. package/dist/configs/sort.js +239 -0
  48. package/dist/configs/stylistic.d.ts +8 -0
  49. package/dist/configs/stylistic.js +76 -0
  50. package/dist/configs/test.d.ts +6 -0
  51. package/dist/configs/test.js +42 -0
  52. package/dist/configs/toml.d.ts +6 -0
  53. package/dist/configs/toml.js +45 -0
  54. package/dist/configs/typescript.d.ts +6 -0
  55. package/dist/configs/typescript.js +213 -0
  56. package/dist/configs/unicorn.d.ts +6 -0
  57. package/dist/configs/unicorn.js +42 -0
  58. package/dist/configs/vue.d.ts +6 -0
  59. package/dist/configs/vue.js +206 -0
  60. package/dist/configs/yaml.d.ts +6 -0
  61. package/dist/configs/yaml.js +83 -0
  62. package/dist/factory.d.ts +17 -0
  63. package/dist/factory.js +161 -0
  64. package/dist/globs.d.ts +32 -0
  65. package/dist/globs.js +89 -0
  66. package/dist/index.d.ts +5 -85
  67. package/dist/index.js +3 -133
  68. package/dist/package.js +5 -0
  69. package/dist/plugins.js +9 -0
  70. package/dist/{types-ClRJcxpY.d.ts → typegen.d.ts} +379 -745
  71. package/dist/types.d.ts +404 -0
  72. package/dist/utils.d.ts +42 -0
  73. package/dist/utils.js +62 -0
  74. package/dist/vendored/prettier_types.d.ts +121 -0
  75. package/package.json +31 -24
  76. package/dist/configs-D_4UWxl6.js +0 -2192
@@ -0,0 +1,74 @@
1
+ import c from "ansis";
2
+
3
+ //#region src/cli/constants.ts
4
+ const vscodeSettingsString = `
5
+ // Disable the default formatter, use eslint instead
6
+ "prettier.enable": false,
7
+ "editor.formatOnSave": false,
8
+ "eslint.format.enable": true,
9
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint",
10
+
11
+ // Auto fix
12
+ "editor.codeActionsOnSave": {
13
+ "source.organizeImports": "never"
14
+ },
15
+
16
+ "eslint.runtime": "node",
17
+
18
+ // Enable eslint for all supported languages
19
+ "eslint.validate": [
20
+ "javascript",
21
+ "typescript",
22
+ "vue",
23
+ "html",
24
+ "markdown",
25
+ "json",
26
+ "json5",
27
+ "jsonc",
28
+ "yaml",
29
+ "toml",
30
+ "xml",
31
+ "astro",
32
+ "css",
33
+ "less",
34
+ "scss",
35
+ "pcss",
36
+ "postcss"
37
+ ],
38
+ `;
39
+ const frameworkOptions = [
40
+ {
41
+ label: c.green("Vue"),
42
+ value: "vue"
43
+ },
44
+ {
45
+ label: c.magenta("Astro"),
46
+ value: "astro"
47
+ },
48
+ {
49
+ label: c.blueBright("AdonisJS"),
50
+ value: "adonisjs"
51
+ },
52
+ {
53
+ label: c.greenBright("Nuxt"),
54
+ value: "nuxt"
55
+ }
56
+ ];
57
+ const frameworks = frameworkOptions.map(({ value }) => value);
58
+ const extraOptions = [{
59
+ hint: "Use external formatters (Prettier) to format files that ESLint cannot handle yet (.css, .html, etc)",
60
+ label: c.red("Formatter"),
61
+ value: "formatter"
62
+ }];
63
+ const extra = extraOptions.map(({ value }) => value);
64
+ const dependenciesMap = {
65
+ astro: ["eslint-plugin-astro", "astro-eslint-parser"],
66
+ formatter: ["eslint-plugin-format"],
67
+ formatterAstro: ["prettier-plugin-astro"],
68
+ vue: [],
69
+ adonisjs: ["@adonisjs/eslint-plugin"],
70
+ nuxt: ["@nuxt/eslint-plugin"]
71
+ };
72
+
73
+ //#endregion
74
+ export { dependenciesMap, extra, extraOptions, frameworkOptions, frameworks, vscodeSettingsString };
@@ -0,0 +1,13 @@
1
+ //#region src/cli/constants_generated.ts
2
+ const versionsMap = {
3
+ "@adonisjs/eslint-plugin": "^2.0.1",
4
+ "@nuxt/eslint-plugin": "^1.9.0",
5
+ "astro-eslint-parser": "^1.2.2",
6
+ "eslint": "^9.36.0",
7
+ "eslint-plugin-astro": "^1.3.1",
8
+ "eslint-plugin-format": "^1.0.2",
9
+ "prettier-plugin-astro": "^0.14.1"
10
+ };
11
+
12
+ //#endregion
13
+ export { versionsMap };
@@ -1 +1 @@
1
- export {};
1
+ export { };
package/dist/cli/index.js CHANGED
@@ -1,275 +1,10 @@
1
+ import { version } from "../package.js";
2
+ import { run } from "./run.js";
1
3
  import process from "node:process";
2
4
  import * as p from "@clack/prompts";
3
- import c, { green } from "ansis";
5
+ import c from "ansis";
4
6
  import { cac } from "cac";
5
- import fs from "node:fs";
6
- import path from "node:path";
7
- import fsp from "node:fs/promises";
8
- import parse from "parse-gitignore";
9
- import { execSync } from "node:child_process";
10
7
 
11
- //#region package.json
12
- var version = "1.2.2";
13
-
14
- //#endregion
15
- //#region src/cli/constants.ts
16
- const vscodeSettingsString = `
17
- // Disable the default formatter, use eslint instead
18
- "prettier.enable": false,
19
- "editor.formatOnSave": false,
20
- "eslint.format.enable": true,
21
- "editor.defaultFormatter": "dbaeumer.vscode-eslint",
22
-
23
- // Auto fix
24
- "editor.codeActionsOnSave": {
25
- "source.organizeImports": "never"
26
- },
27
-
28
- "eslint.runtime": "node",
29
-
30
- // Enable eslint for all supported languages
31
- "eslint.validate": [
32
- "javascript",
33
- "typescript",
34
- "vue",
35
- "html",
36
- "markdown",
37
- "json",
38
- "json5",
39
- "jsonc",
40
- "yaml",
41
- "toml",
42
- "xml",
43
- "astro",
44
- "css",
45
- "less",
46
- "scss",
47
- "pcss",
48
- "postcss"
49
- ],
50
- `;
51
- const frameworkOptions = [
52
- {
53
- label: c.green("Vue"),
54
- value: "vue"
55
- },
56
- {
57
- label: c.magenta("Astro"),
58
- value: "astro"
59
- },
60
- {
61
- label: c.blueBright("AdonisJS"),
62
- value: "adonisjs"
63
- },
64
- {
65
- label: c.greenBright("Nuxt"),
66
- value: "nuxt"
67
- }
68
- ];
69
- const frameworks = frameworkOptions.map(({ value }) => value);
70
- const extraOptions = [{
71
- hint: "Use external formatters (Prettier) to format files that ESLint cannot handle yet (.css, .html, etc)",
72
- label: c.red("Formatter"),
73
- value: "formatter"
74
- }];
75
- const extra = extraOptions.map(({ value }) => value);
76
- const dependenciesMap = {
77
- astro: ["eslint-plugin-astro", "astro-eslint-parser"],
78
- formatter: ["eslint-plugin-format"],
79
- formatterAstro: ["prettier-plugin-astro"],
80
- vue: [],
81
- adonisjs: ["@adonisjs/eslint-plugin"],
82
- nuxt: ["@nuxt/eslint-plugin"]
83
- };
84
-
85
- //#endregion
86
- //#region src/cli/utils.ts
87
- function isGitClean() {
88
- try {
89
- execSync("git diff-index --quiet HEAD --");
90
- return true;
91
- } catch {
92
- return false;
93
- }
94
- }
95
- function getEslintConfigContent(mainConfig) {
96
- return `
97
- import eienjs from '@eienjs/eslint-config';
98
-
99
- export default eienjs({
100
- ${mainConfig}
101
- });
102
- `.trimStart();
103
- }
104
-
105
- //#endregion
106
- //#region src/cli/stages/update_eslint_files.ts
107
- async function updateEslintFiles(result) {
108
- const cwd = process.cwd();
109
- const pathESLintIgnore = path.join(cwd, ".eslintignore");
110
- const pathPackageJSON = path.join(cwd, "package.json");
111
- const pkgContent = await fsp.readFile(pathPackageJSON, "utf8");
112
- const pkg = JSON.parse(pkgContent);
113
- const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
114
- const pathFlatConfig = path.join(cwd, configFileName);
115
- const eslintIgnores = [];
116
- if (fs.existsSync(pathESLintIgnore)) {
117
- p.log.step(c.cyan`Migrating existing .eslintignore`);
118
- const content = await fsp.readFile(pathESLintIgnore, "utf8");
119
- const parsed = parse(content);
120
- const globs = parsed.globs();
121
- for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
122
- else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
123
- }
124
- const configLines = [];
125
- if (eslintIgnores.length > 0) configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
126
- if (result.extra.includes("formatter")) configLines.push("formatters: true,");
127
- for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
128
- const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
129
- const eslintConfigContent = getEslintConfigContent(mainConfig);
130
- await fsp.writeFile(pathFlatConfig, eslintConfigContent);
131
- p.log.success(c.green`Created ${configFileName}`);
132
- const files = fs.readdirSync(cwd);
133
- const legacyConfig = [];
134
- for (const file of files) if (/eslint|prettier/.test(file) && !file.includes("eslint.config.")) legacyConfig.push(file);
135
- if (legacyConfig.length > 0) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
136
- }
137
-
138
- //#endregion
139
- //#region src/cli/constants_generated.ts
140
- const versionsMap = {
141
- "@adonisjs/eslint-plugin": "^2.0.1",
142
- "@nuxt/eslint-plugin": "^1.8.0",
143
- "astro-eslint-parser": "^1.2.2",
144
- "eslint": "^9.32.0",
145
- "eslint-plugin-astro": "^1.3.1",
146
- "eslint-plugin-format": "^1.0.1",
147
- "prettier-plugin-astro": "^0.14.1"
148
- };
149
-
150
- //#endregion
151
- //#region src/cli/stages/update_package_json.ts
152
- async function updatePackageJson(result) {
153
- const cwd = process.cwd();
154
- const pathPackageJSON = path.join(cwd, "package.json");
155
- p.log.step(c.cyan`Bumping @eienjs/eslint-config to v${version}`);
156
- const pkgContent = await fsp.readFile(pathPackageJSON, "utf8");
157
- const pkg = JSON.parse(pkgContent);
158
- pkg.devDependencies = pkg.devDependencies ?? {};
159
- pkg.devDependencies["@eienjs/eslint-config"] = `^${version}`;
160
- pkg.devDependencies.eslint = pkg.devDependencies.eslint ?? versionsMap.eslint;
161
- const addedPackages = [];
162
- if (result.extra.length > 0) {
163
- const extraPackages = result.extra;
164
- for (const item of extraPackages) switch (item) {
165
- case "formatter":
166
- for (const f of [...dependenciesMap.formatter, ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []]) {
167
- if (!f) continue;
168
- pkg.devDependencies[f] = versionsMap[f];
169
- addedPackages.push(f);
170
- }
171
- break;
172
- }
173
- }
174
- for (const framework of result.frameworks) {
175
- const deps = dependenciesMap[framework];
176
- if (deps.length > 0) for (const f of deps) {
177
- pkg.devDependencies[f] = versionsMap[f];
178
- addedPackages.push(f);
179
- }
180
- }
181
- if (addedPackages.length > 0) p.note(c.dim(addedPackages.join(", ")), "Added packages");
182
- await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
183
- p.log.success(c.green`Changes wrote to package.json`);
184
- }
185
-
186
- //#endregion
187
- //#region src/cli/stages/update_vscode_settings.ts
188
- async function updateVscodeSettings(result) {
189
- const cwd = process.cwd();
190
- if (!result.updateVscodeSettings) return;
191
- const dotVscodePath = path.join(cwd, ".vscode");
192
- const settingsPath = path.join(dotVscodePath, "settings.json");
193
- if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
194
- if (fs.existsSync(settingsPath)) {
195
- let settingsContent = await fsp.readFile(settingsPath, "utf8");
196
- settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
197
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
198
- settingsContent += `${vscodeSettingsString}}\n`;
199
- await fsp.writeFile(settingsPath, settingsContent, "utf8");
200
- p.log.success(green`Updated .vscode/settings.json`);
201
- } else {
202
- await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf8");
203
- p.log.success(green`Created .vscode/settings.json`);
204
- }
205
- }
206
-
207
- //#endregion
208
- //#region src/cli/run.ts
209
- async function run(options = {}) {
210
- const argSkipPrompt = Boolean(process.env.SKIP_PROMPT) || options.yes;
211
- const argTemplate = options.frameworks?.map((m) => m.trim()).filter(Boolean);
212
- const argExtra = options.extra?.map((m) => m.trim()).filter(Boolean);
213
- if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
214
- p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
215
- return process.exit(1);
216
- }
217
- let result = {
218
- extra: argExtra ?? [],
219
- frameworks: argTemplate ?? [],
220
- uncommittedConfirmed: false,
221
- updateVscodeSettings: true
222
- };
223
- if (!argSkipPrompt) {
224
- result = await p.group({
225
- uncommittedConfirmed: async () => {
226
- if (isGitClean()) return true;
227
- return p.confirm({
228
- initialValue: false,
229
- message: "There are uncommitted changes in the current repository, are you sure to continue?"
230
- });
231
- },
232
- frameworks: async ({ results }) => {
233
- const isArgTemplateValid = typeof argTemplate === "string" && frameworks.includes(argTemplate);
234
- if (!results.uncommittedConfirmed || isArgTemplateValid) return;
235
- const message = argTemplate ? `"${argTemplate.toString()}" isn't a valid template. Please choose from below: ` : "Select a framework:";
236
- return p.multiselect({
237
- message: c.reset(message),
238
- options: frameworkOptions,
239
- required: false
240
- });
241
- },
242
- extra: async ({ results }) => {
243
- const isArgExtraValid = argExtra?.length && argExtra.filter((element) => !extra.includes(element)).length === 0;
244
- if (!results.uncommittedConfirmed || isArgExtraValid) return;
245
- const message = argExtra ? `"${argExtra.toString()}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
246
- return p.multiselect({
247
- message: c.reset(message),
248
- options: extraOptions,
249
- required: false
250
- });
251
- },
252
- updateVscodeSettings: async ({ results }) => {
253
- if (!results.uncommittedConfirmed) return;
254
- return p.confirm({
255
- initialValue: true,
256
- message: "Update .vscode/settings.json for better VS Code experience?"
257
- });
258
- }
259
- }, { onCancel: () => {
260
- p.cancel("Operation cancelled.");
261
- process.exit(0);
262
- } });
263
- if (!result.uncommittedConfirmed) return process.exit(1);
264
- }
265
- await updatePackageJson(result);
266
- await updateEslintFiles(result);
267
- await updateVscodeSettings(result);
268
- p.log.success(c.green`Setup completed`);
269
- p.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
270
- }
271
-
272
- //#endregion
273
8
  //#region src/cli/index.ts
274
9
  function header() {
275
10
  console.log("\n");
@@ -0,0 +1,77 @@
1
+ import { extra, extraOptions, frameworkOptions, frameworks } from "./constants.js";
2
+ import { isGitClean } from "./utils.js";
3
+ import { updateEslintFiles } from "./stages/update_eslint_files.js";
4
+ import { updatePackageJson } from "./stages/update_package_json.js";
5
+ import { updateVscodeSettings } from "./stages/update_vscode_settings.js";
6
+ import process from "node:process";
7
+ import * as p from "@clack/prompts";
8
+ import c from "ansis";
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+
12
+ //#region src/cli/run.ts
13
+ async function run(options = {}) {
14
+ const argSkipPrompt = Boolean(process.env.SKIP_PROMPT) || options.yes;
15
+ const argTemplate = options.frameworks?.map((m) => m.trim()).filter(Boolean);
16
+ const argExtra = options.extra?.map((m) => m.trim()).filter(Boolean);
17
+ if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
18
+ p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
19
+ return process.exit(1);
20
+ }
21
+ let result = {
22
+ extra: argExtra ?? [],
23
+ frameworks: argTemplate ?? [],
24
+ uncommittedConfirmed: false,
25
+ updateVscodeSettings: true
26
+ };
27
+ if (!argSkipPrompt) {
28
+ result = await p.group({
29
+ uncommittedConfirmed: async () => {
30
+ if (isGitClean()) return true;
31
+ return p.confirm({
32
+ initialValue: false,
33
+ message: "There are uncommitted changes in the current repository, are you sure to continue?"
34
+ });
35
+ },
36
+ frameworks: async ({ results }) => {
37
+ const isArgTemplateValid = typeof argTemplate === "string" && frameworks.includes(argTemplate);
38
+ if (!results.uncommittedConfirmed || isArgTemplateValid) return;
39
+ const message = argTemplate ? `"${argTemplate.toString()}" isn't a valid template. Please choose from below: ` : "Select a framework:";
40
+ return p.multiselect({
41
+ message: c.reset(message),
42
+ options: frameworkOptions,
43
+ required: false
44
+ });
45
+ },
46
+ extra: async ({ results }) => {
47
+ const isArgExtraValid = argExtra?.length && argExtra.filter((element) => !extra.includes(element)).length === 0;
48
+ if (!results.uncommittedConfirmed || isArgExtraValid) return;
49
+ const message = argExtra ? `"${argExtra.toString()}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
50
+ return p.multiselect({
51
+ message: c.reset(message),
52
+ options: extraOptions,
53
+ required: false
54
+ });
55
+ },
56
+ updateVscodeSettings: async ({ results }) => {
57
+ if (!results.uncommittedConfirmed) return;
58
+ return p.confirm({
59
+ initialValue: true,
60
+ message: "Update .vscode/settings.json for better VS Code experience?"
61
+ });
62
+ }
63
+ }, { onCancel: () => {
64
+ p.cancel("Operation cancelled.");
65
+ process.exit(0);
66
+ } });
67
+ if (!result.uncommittedConfirmed) return process.exit(1);
68
+ }
69
+ await updatePackageJson(result);
70
+ await updateEslintFiles(result);
71
+ await updateVscodeSettings(result);
72
+ p.log.success(c.green`Setup completed`);
73
+ p.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
74
+ }
75
+
76
+ //#endregion
77
+ export { run };
@@ -0,0 +1,41 @@
1
+ import { getEslintConfigContent } from "../utils.js";
2
+ import process from "node:process";
3
+ import * as p from "@clack/prompts";
4
+ import c from "ansis";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import fsp from "node:fs/promises";
8
+ import parse from "parse-gitignore";
9
+
10
+ //#region src/cli/stages/update_eslint_files.ts
11
+ async function updateEslintFiles(result) {
12
+ const cwd = process.cwd();
13
+ const pathESLintIgnore = path.join(cwd, ".eslintignore");
14
+ const pathPackageJSON = path.join(cwd, "package.json");
15
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf8");
16
+ const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
17
+ const pathFlatConfig = path.join(cwd, configFileName);
18
+ const eslintIgnores = [];
19
+ if (fs.existsSync(pathESLintIgnore)) {
20
+ p.log.step(c.cyan`Migrating existing .eslintignore`);
21
+ const content = await fsp.readFile(pathESLintIgnore, "utf8");
22
+ const globs = parse(content).globs();
23
+ for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
24
+ else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
25
+ }
26
+ const configLines = [];
27
+ if (eslintIgnores.length > 0) configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
28
+ if (result.extra.includes("formatter")) configLines.push("formatters: true,");
29
+ for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
30
+ const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
31
+ const eslintConfigContent = getEslintConfigContent(mainConfig);
32
+ await fsp.writeFile(pathFlatConfig, eslintConfigContent);
33
+ p.log.success(c.green`Created ${configFileName}`);
34
+ const files = fs.readdirSync(cwd);
35
+ const legacyConfig = [];
36
+ for (const file of files) if (/eslint|prettier/.test(file) && !file.includes("eslint.config.")) legacyConfig.push(file);
37
+ if (legacyConfig.length > 0) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
38
+ }
39
+
40
+ //#endregion
41
+ export { updateEslintFiles };
@@ -0,0 +1,46 @@
1
+ import { version } from "../../package.js";
2
+ import { dependenciesMap } from "../constants.js";
3
+ import { versionsMap } from "../constants_generated.js";
4
+ import process from "node:process";
5
+ import * as p from "@clack/prompts";
6
+ import c from "ansis";
7
+ import path from "node:path";
8
+ import fsp from "node:fs/promises";
9
+
10
+ //#region src/cli/stages/update_package_json.ts
11
+ async function updatePackageJson(result) {
12
+ const cwd = process.cwd();
13
+ const pathPackageJSON = path.join(cwd, "package.json");
14
+ p.log.step(c.cyan`Bumping @eienjs/eslint-config to v${version}`);
15
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf8");
16
+ const pkg = JSON.parse(pkgContent);
17
+ pkg.devDependencies = pkg.devDependencies ?? {};
18
+ pkg.devDependencies["@eienjs/eslint-config"] = `^${version}`;
19
+ pkg.devDependencies.eslint = pkg.devDependencies.eslint ?? versionsMap.eslint;
20
+ const addedPackages = [];
21
+ if (result.extra.length > 0) {
22
+ const extraPackages = result.extra;
23
+ for (const item of extraPackages) switch (item) {
24
+ case "formatter":
25
+ for (const f of [...dependenciesMap.formatter, ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []]) {
26
+ if (!f) continue;
27
+ pkg.devDependencies[f] = versionsMap[f];
28
+ addedPackages.push(f);
29
+ }
30
+ break;
31
+ }
32
+ }
33
+ for (const framework of result.frameworks) {
34
+ const deps = dependenciesMap[framework];
35
+ if (deps.length > 0) for (const f of deps) {
36
+ pkg.devDependencies[f] = versionsMap[f];
37
+ addedPackages.push(f);
38
+ }
39
+ }
40
+ if (addedPackages.length > 0) p.note(c.dim(addedPackages.join(", ")), "Added packages");
41
+ await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
42
+ p.log.success(c.green`Changes wrote to package.json`);
43
+ }
44
+
45
+ //#endregion
46
+ export { updatePackageJson };
@@ -0,0 +1,30 @@
1
+ import { vscodeSettingsString } from "../constants.js";
2
+ import process from "node:process";
3
+ import * as p from "@clack/prompts";
4
+ import { green } from "ansis";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import fsp from "node:fs/promises";
8
+
9
+ //#region src/cli/stages/update_vscode_settings.ts
10
+ async function updateVscodeSettings(result) {
11
+ const cwd = process.cwd();
12
+ if (!result.updateVscodeSettings) return;
13
+ const dotVscodePath = path.join(cwd, ".vscode");
14
+ const settingsPath = path.join(dotVscodePath, "settings.json");
15
+ if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
16
+ if (fs.existsSync(settingsPath)) {
17
+ let settingsContent = await fsp.readFile(settingsPath, "utf8");
18
+ settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
19
+ settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
20
+ settingsContent += `${vscodeSettingsString}}\n`;
21
+ await fsp.writeFile(settingsPath, settingsContent, "utf8");
22
+ p.log.success(green`Updated .vscode/settings.json`);
23
+ } else {
24
+ await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf8");
25
+ p.log.success(green`Created .vscode/settings.json`);
26
+ }
27
+ }
28
+
29
+ //#endregion
30
+ export { updateVscodeSettings };
@@ -0,0 +1,23 @@
1
+ import { execSync } from "node:child_process";
2
+
3
+ //#region src/cli/utils.ts
4
+ function isGitClean() {
5
+ try {
6
+ execSync("git diff-index --quiet HEAD --");
7
+ return true;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+ function getEslintConfigContent(mainConfig) {
13
+ return `
14
+ import eienjs from '@eienjs/eslint-config';
15
+
16
+ export default eienjs({
17
+ ${mainConfig}
18
+ });
19
+ `.trimStart();
20
+ }
21
+
22
+ //#endregion
23
+ export { getEslintConfigContent, isGitClean };
@@ -0,0 +1,6 @@
1
+ import { OptionsAdonisJS, TypedFlatConfigItem } from "../types.js";
2
+
3
+ //#region src/configs/adonisjs.d.ts
4
+ declare function adonisjs(options?: OptionsAdonisJS): Promise<TypedFlatConfigItem[]>;
5
+ //#endregion
6
+ export { adonisjs };