@mouse_484/eslint-config 3.2.19 → 3.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 (3) hide show
  1. package/README.md +8 -0
  2. package/bin/cli.js +65 -0
  3. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # @mouse_484/eslint-config
2
+
3
+ ESLint Config based on [@antfu/eslint-config](https://github.com/antfu/eslint-config)
4
+
5
+ ## Usage
6
+ ```
7
+ npx @mouse_484/eslint-config@latest
8
+ ```
package/bin/cli.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ import { spawn, exec as _exec } from 'node:child_process'
3
+ import fs from 'node:fs/promises'
4
+ import path from 'node:path'
5
+ import process from 'node:process'
6
+ import { promisify } from 'node:util'
7
+
8
+ const exec = promisify(_exec)
9
+
10
+ const antfu = '@antfu/eslint-config'
11
+ const mouse = '@mouse_484/eslint-config'
12
+
13
+ // Run the original CLI
14
+ const execCLI = () => {
15
+ const child = spawn('npx', [antfu], {
16
+ stdio: 'inherit',
17
+ })
18
+ return new Promise((resolve, reject) => {
19
+ child.on('exit', resolve)
20
+ child.on('error', reject)
21
+ })
22
+ }
23
+
24
+ await execCLI()
25
+
26
+ // Replace the config
27
+ const cwd = process.cwd()
28
+
29
+ const packageJSONPath = path.join(cwd, 'package.json')
30
+ const packageJSON = await fs.readFile(packageJSONPath, 'utf-8')
31
+ /** @type {Record<string,unknown>} */
32
+ const pkg = JSON.parse(packageJSON)
33
+
34
+ // Replace ESLint config
35
+ const eslintConfigPath = path.join(cwd, `eslint.config.${pkg.type === 'module' ? 'js' : 'mjs'}`)
36
+ const eslintConfig = await fs.readFile(eslintConfigPath, 'utf-8')
37
+
38
+ eslintConfig.replace(
39
+ `import antfu from '${antfu}'`,
40
+ `import { mouse } from '${mouse}'`,
41
+ )
42
+ eslintConfig.replace(
43
+ 'antfu',
44
+ 'mouse',
45
+ )
46
+
47
+ await fs.writeFile(eslintConfigPath, eslintConfig)
48
+
49
+ // Replace package.json
50
+ delete pkg.devDependencies[antfu]
51
+
52
+ const version = (await exec(`npm view ${mouse} dist-tags.latest`).catch(() => {
53
+ console.info(`Failed to get the latest version of ${mouse}`)
54
+ return { stdout: 'latest' }
55
+ })).stdout.trim()
56
+
57
+ pkg.devDependencies[mouse] = version
58
+
59
+ pkg.scripts = {
60
+ ...pkg.scripts,
61
+ 'lint': 'eslint .',
62
+ 'lint:fix': 'eslint --fix .',
63
+ }
64
+
65
+ await fs.writeFile(packageJSONPath, JSON.stringify(pkg, null, 2))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mouse_484/eslint-config",
3
3
  "type": "module",
4
- "version": "3.2.19",
4
+ "version": "3.3.0",
5
5
  "author": "mouse_484",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/mouse484/config/tree/main/packages/eslint",
@@ -17,8 +17,9 @@
17
17
  ],
18
18
  "main": "src/index.js",
19
19
  "types": "src/index.d.ts",
20
+ "bin": "bin/cli.js",
20
21
  "dependencies": {
21
- "@antfu/eslint-config": "^3.6.2"
22
+ "@antfu/eslint-config": "^3.7.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@typescript-eslint/eslint-plugin": "^8.6.0"