@tyyyho/treg 0.1.18 → 0.1.19
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.
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { writeFile } from "./shared.js";
|
|
4
|
+
export const DEFAULT_ESLINT_CONFIG = `export default [
|
|
5
|
+
{
|
|
6
|
+
ignores: ["node_modules/**", "dist/**", "coverage/**"],
|
|
7
|
+
},
|
|
8
|
+
]
|
|
9
|
+
`;
|
|
10
|
+
const ESLINT_CONFIG_FILES = [
|
|
11
|
+
"eslint.config.js",
|
|
12
|
+
"eslint.config.mjs",
|
|
13
|
+
"eslint.config.cjs",
|
|
14
|
+
"eslint.config.ts",
|
|
15
|
+
"eslint.config.mts",
|
|
16
|
+
"eslint.config.cts",
|
|
17
|
+
".eslintrc",
|
|
18
|
+
".eslintrc.js",
|
|
19
|
+
".eslintrc.cjs",
|
|
20
|
+
".eslintrc.json",
|
|
21
|
+
".eslintrc.yaml",
|
|
22
|
+
".eslintrc.yml",
|
|
23
|
+
];
|
|
24
|
+
export function findExistingEslintConfig(projectDir) {
|
|
25
|
+
for (const fileName of ESLINT_CONFIG_FILES) {
|
|
26
|
+
if (existsSync(path.join(projectDir, fileName))) {
|
|
27
|
+
return fileName;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export async function ensureEslintConfig(projectDir, dryRun) {
|
|
33
|
+
const existing = findExistingEslintConfig(projectDir);
|
|
34
|
+
if (existing) {
|
|
35
|
+
console.log(`Skip eslint config creation (${existing} already exists)`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await writeFile(projectDir, "eslint.config.mjs", DEFAULT_ESLINT_CONFIG, false, dryRun);
|
|
39
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { packageJson } from "../mrm-core.js";
|
|
2
2
|
import { installPackages, withProjectCwd } from "./shared.js";
|
|
3
|
+
import { ensureEslintConfig } from "./lint-config.js";
|
|
3
4
|
export async function runLintRule(context) {
|
|
4
5
|
const { projectDir, pm, dryRun } = context;
|
|
5
6
|
installPackages(projectDir, pm, ["eslint"], true, dryRun);
|
|
7
|
+
await ensureEslintConfig(projectDir, dryRun);
|
|
6
8
|
withProjectCwd(projectDir, () => {
|
|
7
9
|
if (dryRun) {
|
|
8
10
|
console.log("[dry-run] Would set package scripts: lint, lint:check");
|