-
Notifications
You must be signed in to change notification settings - Fork 183
/
generate-eslint-package-json.mjs
83 lines (77 loc) · 2.19 KB
/
generate-eslint-package-json.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import fs from 'node:fs/promises';
import { dirname, join } from 'path';
import { fileURLToPath } from 'node:url';
const eslintPluginDependencies = [
'@babel/core',
'@babel/eslint-parser',
'@babel/plugin-proposal-decorators',
'@babel/preset-env',
'@babel/preset-flow',
'@babel/preset-react',
'@eslint-community/regexpp',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/utils',
'builtin-modules',
'bytes',
'eslint-plugin-import',
'eslint-plugin-jsx-a11y',
'eslint-plugin-react',
'eslint-plugin-react-hooks',
'eslint-scope',
'functional-red-black-tree',
'jsx-ast-utils',
'minimatch',
'scslre',
'semver',
'typescript',
'vue-eslint-parser',
];
const mainPackageJson = JSON.parse(
await fs.readFile(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8'),
);
const dependencies = {};
let missingDependencies = Array.from(eslintPluginDependencies);
for (const [name, value] of Object.entries(mainPackageJson.dependencies).concat(
Object.entries(mainPackageJson.devDependencies),
)) {
if (eslintPluginDependencies.includes(name)) {
dependencies[name] = value;
const i = missingDependencies.indexOf(name);
missingDependencies.splice(i, 1);
}
}
if (missingDependencies.length > 0) {
throw new Error(
`Some dependencies of the ESLint plugin were not found in the package.json: ${missingDependencies.toString()}`,
);
}
await fs.writeFile(
join(dirname(fileURLToPath(import.meta.url)), 'lib', 'package.json'),
JSON.stringify(
{
name: 'eslint-plugin-sonarjs',
description: 'SonarJS rules for ESLint',
version: '0.0.0-SNAPSHOT',
main: './cjs/plugin.js',
types: './types/plugin.d.ts',
repository: {
type: 'git',
url: 'git+https://github.com/SonarSource/SonarJS.git',
},
author: 'SonarSource',
license: 'LGPL-3.0-only',
keywords: ['sonarjs', 'eslint', 'eslintplugin'],
bugs: {
url: 'https://community.sonarsource.com/',
},
homepage:
'https://github.com/SonarSource/SonarJS/blob/master/packages/jsts/src/rules/README.md',
dependencies,
peerDependencies: {
eslint: '8.0.0 - 9.14',
},
},
null,
2,
),
);