mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
checkPlugin: Improve eslintConfig
, funding
, scripts
checking
This commit is contained in:
parent
b7dce95802
commit
314b67b7fe
1 changed files with 34 additions and 35 deletions
|
@ -42,6 +42,23 @@ const writePackageJson = (obj) => {
|
||||||
return fs.writeFileSync(`${pluginPath}/package.json`, s);
|
return fs.writeFileSync(`${pluginPath}/package.json`, s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkEntries = (got, want) => {
|
||||||
|
let changed = false;
|
||||||
|
for (const [key, val] of Object.entries(want)) {
|
||||||
|
try {
|
||||||
|
assert.deepEqual(got[key], val);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`${key} possibly outdated.`);
|
||||||
|
console.warn(err.message);
|
||||||
|
if (autoFix) {
|
||||||
|
got[key] = val;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
};
|
||||||
|
|
||||||
const updateDeps = (parsedPackageJson, key, wantDeps) => {
|
const updateDeps = (parsedPackageJson, key, wantDeps) => {
|
||||||
const {[key]: deps = {}} = parsedPackageJson;
|
const {[key]: deps = {}} = parsedPackageJson;
|
||||||
let changed = false;
|
let changed = false;
|
||||||
|
@ -147,19 +164,6 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
const packageJSON =
|
const packageJSON =
|
||||||
fs.readFileSync(`${pluginPath}/package.json`, {encoding: 'utf8', flag: 'r'});
|
fs.readFileSync(`${pluginPath}/package.json`, {encoding: 'utf8', flag: 'r'});
|
||||||
const parsedPackageJSON = JSON.parse(packageJSON);
|
const parsedPackageJSON = JSON.parse(packageJSON);
|
||||||
if (autoFix) {
|
|
||||||
let updatedPackageJSON = false;
|
|
||||||
if (!parsedPackageJSON.funding) {
|
|
||||||
updatedPackageJSON = true;
|
|
||||||
parsedPackageJSON.funding = {
|
|
||||||
type: 'individual',
|
|
||||||
url: 'https://etherpad.org/',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (updatedPackageJSON) {
|
|
||||||
writePackageJson(parsedPackageJSON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packageJSON.toLowerCase().indexOf('repository') === -1) {
|
if (packageJSON.toLowerCase().indexOf('repository') === -1) {
|
||||||
console.warn('No repository in package.json');
|
console.warn('No repository in package.json');
|
||||||
|
@ -192,29 +196,24 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
node: '>=12.13.0',
|
node: '>=12.13.0',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (packageJSON.toLowerCase().indexOf('eslintconfig') === -1) {
|
if (parsedPackageJSON.eslintConfig == null) parsedPackageJSON.eslintConfig = {};
|
||||||
console.warn('No esLintConfig in package.json');
|
if (checkEntries(parsedPackageJSON.eslintConfig, {
|
||||||
if (autoFix) {
|
|
||||||
const eslintConfig = {
|
|
||||||
root: true,
|
root: true,
|
||||||
extends: 'etherpad/plugin',
|
extends: 'etherpad/plugin',
|
||||||
};
|
})) await writePackageJson(parsedPackageJSON);
|
||||||
parsedPackageJSON.eslintConfig = eslintConfig;
|
|
||||||
writePackageJson(parsedPackageJSON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packageJSON.toLowerCase().indexOf('scripts') === -1) {
|
if (checkEntries(parsedPackageJSON, {
|
||||||
console.warn('No scripts in package.json');
|
funding: {
|
||||||
if (autoFix) {
|
type: 'individual',
|
||||||
const scripts = {
|
url: 'https://etherpad.org/',
|
||||||
|
},
|
||||||
|
})) writePackageJson(parsedPackageJSON);
|
||||||
|
|
||||||
|
if (parsedPackageJSON.scripts == null) parsedPackageJSON.scripts = {};
|
||||||
|
if (checkEntries(parsedPackageJSON.scripts, {
|
||||||
'lint': 'eslint .',
|
'lint': 'eslint .',
|
||||||
'lint:fix': 'eslint --fix .',
|
'lint:fix': 'eslint --fix .',
|
||||||
};
|
})) writePackageJson(parsedPackageJSON);
|
||||||
parsedPackageJSON.scripts = scripts;
|
|
||||||
writePackageJson(parsedPackageJSON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (files.indexOf('package-lock.json') === -1) {
|
if (files.indexOf('package-lock.json') === -1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue