checkPlugin: Move dependency update logic to a generic function
This will make it possible to reuse the logic for `peerDependencies`.image-example
parent
747f323552
commit
42da976705
|
@ -37,6 +37,8 @@ const autoUpdate = optArgs.indexOf('autoupdate') !== -1;
|
||||||
// Should we automcommit and npm publish?!
|
// Should we automcommit and npm publish?!
|
||||||
const autoCommit = optArgs.indexOf('autocommit') !== -1;
|
const autoCommit = optArgs.indexOf('autocommit') !== -1;
|
||||||
|
|
||||||
|
let hasAutoFixed = false;
|
||||||
|
|
||||||
const execSync = (cmd, opts = {}) => (childProcess.execSync(cmd, {
|
const execSync = (cmd, opts = {}) => (childProcess.execSync(cmd, {
|
||||||
cwd: `${pluginPath}/`,
|
cwd: `${pluginPath}/`,
|
||||||
...opts,
|
...opts,
|
||||||
|
@ -48,6 +50,28 @@ const writePackageJson = (obj) => {
|
||||||
return fs.writeFileSync(`${pluginPath}/package.json`, s);
|
return fs.writeFileSync(`${pluginPath}/package.json`, s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateDeps = (parsedPackageJson, key, wantDeps) => {
|
||||||
|
const {[key]: deps = {}} = parsedPackageJson;
|
||||||
|
let changed = false;
|
||||||
|
for (const [pkg, ver] of Object.entries(wantDeps)) {
|
||||||
|
if (deps[pkg] === ver) continue;
|
||||||
|
if (deps[pkg] == null) {
|
||||||
|
console.warn(`Missing dependency in ${key}: '${pkg}': '${ver}'`);
|
||||||
|
} else {
|
||||||
|
console.warn(`Dependency mismatch in ${key}: '${pkg}': '${ver}' (current: ${deps[pkg]})`);
|
||||||
|
}
|
||||||
|
if (autoFix) {
|
||||||
|
deps[pkg] = ver;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
hasAutoFixed = true;
|
||||||
|
parsedPackageJson[key] = deps;
|
||||||
|
writePackageJson(parsedPackageJson);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const prepareRepo = () => {
|
const prepareRepo = () => {
|
||||||
let branch = execSync('git symbolic-ref HEAD');
|
let branch = execSync('git symbolic-ref HEAD');
|
||||||
if (branch !== 'refs/heads/master' && branch !== 'refs/heads/main') {
|
if (branch !== 'refs/heads/master' && branch !== 'refs/heads/main') {
|
||||||
|
@ -87,7 +111,6 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
// some files we need to know the actual file name. Not compulsory but might help in the future.
|
// some files we need to know the actual file name. Not compulsory but might help in the future.
|
||||||
let readMeFileName;
|
let readMeFileName;
|
||||||
let repository;
|
let repository;
|
||||||
let hasAutoFixed = false;
|
|
||||||
|
|
||||||
for (let i = 0; i < rootFiles.length; i++) {
|
for (let i = 0; i < rootFiles.length; i++) {
|
||||||
if (rootFiles[i].toLowerCase().indexOf('readme') !== -1) readMeFileName = rootFiles[i];
|
if (rootFiles[i].toLowerCase().indexOf('readme') !== -1) readMeFileName = rootFiles[i];
|
||||||
|
@ -213,8 +236,7 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
repository = parsedPackageJSON.repository.url;
|
repository = parsedPackageJSON.repository.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// include lint config
|
updateDeps(parsedPackageJSON, 'devDependencies', {
|
||||||
const lintDeps = {
|
|
||||||
'eslint': '^7.17.0',
|
'eslint': '^7.17.0',
|
||||||
'eslint-config-etherpad': '^1.0.22',
|
'eslint-config-etherpad': '^1.0.22',
|
||||||
'eslint-plugin-eslint-comments': '^3.2.0',
|
'eslint-plugin-eslint-comments': '^3.2.0',
|
||||||
|
@ -223,21 +245,7 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
'eslint-plugin-prefer-arrow': '^1.2.2',
|
'eslint-plugin-prefer-arrow': '^1.2.2',
|
||||||
'eslint-plugin-promise': '^4.2.1',
|
'eslint-plugin-promise': '^4.2.1',
|
||||||
'eslint-plugin-you-dont-need-lodash-underscore': '^6.10.0',
|
'eslint-plugin-you-dont-need-lodash-underscore': '^6.10.0',
|
||||||
};
|
});
|
||||||
const {devDependencies = {}} = parsedPackageJSON;
|
|
||||||
let lintDepsNeedUpdating = false;
|
|
||||||
for (const [pkg, ver] of Object.entries(lintDeps)) {
|
|
||||||
if (devDependencies[pkg] !== ver) {
|
|
||||||
console.warn(`Missing/outdated ESLint dependency: '${pkg}': '${ver}' ` +
|
|
||||||
`(current: ${devDependencies[pkg]})`);
|
|
||||||
lintDepsNeedUpdating = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lintDepsNeedUpdating && autoFix) {
|
|
||||||
hasAutoFixed = true;
|
|
||||||
parsedPackageJSON.devDependencies = Object.assign(devDependencies, lintDeps);
|
|
||||||
writePackageJson(parsedPackageJSON);
|
|
||||||
}
|
|
||||||
|
|
||||||
// include peer deps config
|
// include peer deps config
|
||||||
if (packageJSON.toLowerCase().indexOf('peerdependencies') === -1 || !parsedPackageJSON.peerDependencies) {
|
if (packageJSON.toLowerCase().indexOf('peerdependencies') === -1 || !parsedPackageJSON.peerDependencies) {
|
||||||
|
|
Loading…
Reference in New Issue