2021-01-08 03:52:45 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-02 17:13:24 +01:00
|
|
|
/*
|
2021-01-11 00:35:50 +01:00
|
|
|
* Usage -- see README.md
|
|
|
|
*
|
2021-02-05 00:43:27 +01:00
|
|
|
* Normal usage: node src/bin/plugins/checkPlugin.js ep_whatever
|
|
|
|
* Auto fix the things it can: node src/bin/plugins/checkPlugin.js ep_whatever autofix
|
2021-01-11 00:35:50 +01:00
|
|
|
* Auto commit, push and publish to npm (highly dangerous):
|
2021-02-05 00:43:27 +01:00
|
|
|
* node src/bin/plugins/checkPlugin.js ep_whatever autocommit
|
2021-01-11 00:35:50 +01:00
|
|
|
*/
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2021-01-18 09:53:15 +01:00
|
|
|
// As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an
|
|
|
|
// unhandled rejection into an uncaught exception, which does cause Node.js to exit.
|
|
|
|
process.on('unhandledRejection', (err) => { throw err; });
|
|
|
|
|
2021-06-15 01:23:04 +02:00
|
|
|
const assert = require('assert').strict;
|
2020-11-23 19:21:51 +01:00
|
|
|
const fs = require('fs');
|
2021-01-08 03:52:45 +01:00
|
|
|
const childProcess = require('child_process');
|
2021-06-15 01:23:04 +02:00
|
|
|
const path = require('path');
|
2020-11-02 17:13:24 +01:00
|
|
|
|
|
|
|
// get plugin name & path from user input
|
|
|
|
const pluginName = process.argv[2];
|
|
|
|
|
2021-01-18 09:53:15 +01:00
|
|
|
if (!pluginName) throw new Error('no plugin name specified');
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
const pluginPath = `node_modules/${pluginName}`;
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
console.log(`Checking the plugin: ${pluginName}`);
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2021-01-09 00:07:55 +01:00
|
|
|
const optArgs = process.argv.slice(3);
|
2021-01-08 03:52:45 +01:00
|
|
|
const autoCommit = optArgs.indexOf('autocommit') !== -1;
|
2021-01-11 01:22:59 +01:00
|
|
|
const autoFix = autoCommit || optArgs.indexOf('autofix') !== -1;
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2021-01-09 05:04:11 +01:00
|
|
|
const execSync = (cmd, opts = {}) => (childProcess.execSync(cmd, {
|
|
|
|
cwd: `${pluginPath}/`,
|
|
|
|
...opts,
|
|
|
|
}) || '').toString().replace(/\n+$/, '');
|
|
|
|
|
2021-01-10 00:28:11 +01:00
|
|
|
const writePackageJson = (obj) => {
|
|
|
|
let s = JSON.stringify(obj, null, 2);
|
|
|
|
if (s.length && s.slice(s.length - 1) !== '\n') s += '\n';
|
|
|
|
return fs.writeFileSync(`${pluginPath}/package.json`, s);
|
|
|
|
};
|
2021-01-10 00:27:37 +01:00
|
|
|
|
2021-01-10 00:51:31 +01:00
|
|
|
const updateDeps = (parsedPackageJson, key, wantDeps) => {
|
|
|
|
const {[key]: deps = {}} = parsedPackageJson;
|
|
|
|
let changed = false;
|
2021-01-10 22:23:04 +01:00
|
|
|
for (const [pkg, verInfo] of Object.entries(wantDeps)) {
|
|
|
|
const {ver, overwrite = true} = typeof verInfo === 'string' ? {ver: verInfo} : verInfo;
|
2021-01-10 00:51:31 +01:00
|
|
|
if (deps[pkg] === ver) continue;
|
|
|
|
if (deps[pkg] == null) {
|
|
|
|
console.warn(`Missing dependency in ${key}: '${pkg}': '${ver}'`);
|
|
|
|
} else {
|
2021-01-10 22:23:04 +01:00
|
|
|
if (!overwrite) continue;
|
2021-01-10 00:51:31 +01:00
|
|
|
console.warn(`Dependency mismatch in ${key}: '${pkg}': '${ver}' (current: ${deps[pkg]})`);
|
|
|
|
}
|
|
|
|
if (autoFix) {
|
|
|
|
deps[pkg] = ver;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
parsedPackageJson[key] = deps;
|
|
|
|
writePackageJson(parsedPackageJson);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-09 06:08:43 +01:00
|
|
|
const prepareRepo = () => {
|
|
|
|
let branch = execSync('git symbolic-ref HEAD');
|
|
|
|
if (branch !== 'refs/heads/master' && branch !== 'refs/heads/main') {
|
|
|
|
throw new Error('master/main must be checked out');
|
|
|
|
}
|
|
|
|
branch = branch.replace(/^refs\/heads\//, '');
|
|
|
|
execSync('git rev-parse --verify -q HEAD^0 || ' +
|
|
|
|
`{ echo "Error: no commits on ${branch}" >&2; exit 1; }`);
|
|
|
|
execSync('git rev-parse --verify @{u}'); // Make sure there's a remote tracking branch.
|
2021-01-09 23:30:41 +01:00
|
|
|
const modified = execSync('git diff-files --name-status');
|
|
|
|
if (modified !== '') throw new Error(`working directory has modifications:\n${modified}`);
|
|
|
|
const untracked = execSync('git ls-files -o --exclude-standard');
|
|
|
|
if (untracked !== '') throw new Error(`working directory has untracked files:\n${untracked}`);
|
2021-01-09 23:27:51 +01:00
|
|
|
const indexStatus = execSync('git diff-index --cached --name-status HEAD');
|
2021-01-09 06:08:43 +01:00
|
|
|
if (indexStatus !== '') throw new Error(`uncommitted staged changes to files:\n${indexStatus}`);
|
|
|
|
execSync('git pull --ff-only', {stdio: 'inherit'});
|
|
|
|
if (execSync('git rev-list @{u}...') !== '') throw new Error('repo contains unpushed commits');
|
|
|
|
if (autoCommit) {
|
|
|
|
execSync('git config --get user.name');
|
|
|
|
execSync('git config --get user.email');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-15 01:23:04 +02:00
|
|
|
const checkFile = (srcFn, dstFn) => {
|
|
|
|
const outFn = path.join(pluginPath, dstFn);
|
|
|
|
const verRegEx = /^##ETHERPAD_NPM_V=(\d+)$/;
|
|
|
|
const wantContents = fs.readFileSync(srcFn, {encoding: 'utf8'});
|
|
|
|
const [, wantVer] = verRegEx.exec(wantContents) || [];
|
|
|
|
let gotContents = null;
|
|
|
|
try {
|
|
|
|
gotContents = fs.readFileSync(outFn, {encoding: 'utf8'});
|
|
|
|
} catch (err) { /* treat as if the file doesn't exist */ }
|
|
|
|
const [, gotVer] = verRegEx.exec(gotContents || '') || [];
|
|
|
|
try {
|
|
|
|
assert.equal(gotVer, wantVer);
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(`File ${dstFn} is out of date`);
|
|
|
|
console.warn(err.message);
|
|
|
|
if (autoFix) {
|
|
|
|
fs.mkdirSync(path.dirname(outFn), {recursive: true});
|
|
|
|
fs.writeFileSync(outFn, wantContents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (autoCommit) {
|
|
|
|
console.warn('Auto commit is enabled, I hope you know what you are doing...');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
fs.readdir(pluginPath, (err, rootFiles) => {
|
|
|
|
// handling error
|
2020-11-02 17:13:24 +01:00
|
|
|
if (err) {
|
2020-11-23 19:21:51 +01:00
|
|
|
return console.log(`Unable to scan directory: ${err}`);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// rewriting files to lower case
|
2020-11-23 19:21:51 +01:00
|
|
|
const files = [];
|
2020-11-02 17:13:24 +01:00
|
|
|
|
|
|
|
// some files we need to know the actual file name. Not compulsory but might help in the future.
|
2020-11-23 19:21:51 +01:00
|
|
|
let readMeFileName;
|
|
|
|
let repository;
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
for (let i = 0; i < rootFiles.length; i++) {
|
|
|
|
if (rootFiles[i].toLowerCase().indexOf('readme') !== -1) readMeFileName = rootFiles[i];
|
2020-11-02 17:13:24 +01:00
|
|
|
files.push(rootFiles[i].toLowerCase());
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:53:15 +01:00
|
|
|
if (files.indexOf('.git') === -1) throw new Error('No .git folder, aborting');
|
2021-01-09 06:08:43 +01:00
|
|
|
prepareRepo();
|
2020-11-02 17:13:24 +01:00
|
|
|
|
2021-06-15 01:23:04 +02:00
|
|
|
for (const fn of ['backend-tests.yml', 'npmpublish.yml']) {
|
|
|
|
checkFile(`src/bin/plugins/lib/${fn}`, `.github/workflows/${fn}`);
|
2020-11-30 18:22:52 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('package.json') === -1) {
|
|
|
|
console.warn('no package.json, please create');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('package.json') !== -1) {
|
2021-01-08 03:52:45 +01:00
|
|
|
const packageJSON =
|
|
|
|
fs.readFileSync(`${pluginPath}/package.json`, {encoding: 'utf8', flag: 'r'});
|
2020-11-23 19:21:51 +01:00
|
|
|
const parsedPackageJSON = JSON.parse(packageJSON);
|
|
|
|
if (autoFix) {
|
|
|
|
let updatedPackageJSON = false;
|
|
|
|
if (!parsedPackageJSON.funding) {
|
2020-11-02 17:13:24 +01:00
|
|
|
updatedPackageJSON = true;
|
|
|
|
parsedPackageJSON.funding = {
|
2020-11-23 19:21:51 +01:00
|
|
|
type: 'individual',
|
2020-11-27 20:55:51 +01:00
|
|
|
url: 'https://etherpad.org/',
|
2020-11-23 19:21:51 +01:00
|
|
|
};
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
2020-11-23 19:21:51 +01:00
|
|
|
if (updatedPackageJSON) {
|
2021-01-10 00:27:37 +01:00
|
|
|
writePackageJson(parsedPackageJSON);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (packageJSON.toLowerCase().indexOf('repository') === -1) {
|
|
|
|
console.warn('No repository in package.json');
|
|
|
|
if (autoFix) {
|
2021-01-08 03:52:45 +01:00
|
|
|
console.warn('Repository not detected in package.json. Add repository section.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
2020-11-23 19:21:51 +01:00
|
|
|
} else {
|
2020-11-02 17:13:24 +01:00
|
|
|
// useful for creating README later.
|
|
|
|
repository = parsedPackageJSON.repository.url;
|
|
|
|
}
|
|
|
|
|
2021-01-10 00:51:31 +01:00
|
|
|
updateDeps(parsedPackageJSON, 'devDependencies', {
|
2021-06-14 20:36:17 +02:00
|
|
|
'eslint': '^7.28.0',
|
|
|
|
'eslint-config-etherpad': '^2.0.0',
|
|
|
|
'eslint-plugin-cypress': '^2.11.3',
|
2021-01-09 00:45:27 +01:00
|
|
|
'eslint-plugin-eslint-comments': '^3.2.0',
|
2021-06-14 20:36:17 +02:00
|
|
|
'eslint-plugin-mocha': '^9.0.0',
|
2021-01-09 00:45:27 +01:00
|
|
|
'eslint-plugin-node': '^11.1.0',
|
2021-01-29 07:00:33 +01:00
|
|
|
'eslint-plugin-prefer-arrow': '^1.2.3',
|
2021-06-14 20:36:17 +02:00
|
|
|
'eslint-plugin-promise': '^5.1.0',
|
|
|
|
'eslint-plugin-you-dont-need-lodash-underscore': '^6.12.0',
|
2021-01-10 00:51:31 +01:00
|
|
|
});
|
2020-11-22 15:58:11 +01:00
|
|
|
|
2021-01-10 22:23:04 +01:00
|
|
|
updateDeps(parsedPackageJSON, 'peerDependencies', {
|
|
|
|
// Some plugins require a newer version of Etherpad so don't overwrite if already set.
|
|
|
|
'ep_etherpad-lite': {ver: '>=1.8.6', overwrite: false},
|
|
|
|
});
|
2020-11-27 22:43:23 +01:00
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (packageJSON.toLowerCase().indexOf('eslintconfig') === -1) {
|
|
|
|
console.warn('No esLintConfig in package.json');
|
|
|
|
if (autoFix) {
|
|
|
|
const eslintConfig = {
|
|
|
|
root: true,
|
|
|
|
extends: 'etherpad/plugin',
|
|
|
|
};
|
2020-11-22 15:58:11 +01:00
|
|
|
parsedPackageJSON.eslintConfig = eslintConfig;
|
2021-01-10 00:27:37 +01:00
|
|
|
writePackageJson(parsedPackageJSON);
|
2020-11-22 15:58:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (packageJSON.toLowerCase().indexOf('scripts') === -1) {
|
|
|
|
console.warn('No scripts in package.json');
|
|
|
|
if (autoFix) {
|
|
|
|
const scripts = {
|
|
|
|
'lint': 'eslint .',
|
|
|
|
'lint:fix': 'eslint --fix .',
|
|
|
|
};
|
2020-11-22 15:58:11 +01:00
|
|
|
parsedPackageJSON.scripts = scripts;
|
2021-01-10 00:27:37 +01:00
|
|
|
writePackageJson(parsedPackageJSON);
|
2020-11-22 15:58:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:51:43 +01:00
|
|
|
if ((packageJSON.toLowerCase().indexOf('engines') === -1) || !parsedPackageJSON.engines.node) {
|
2020-11-27 22:43:23 +01:00
|
|
|
console.warn('No engines or node engine in package.json');
|
2020-11-23 19:21:51 +01:00
|
|
|
if (autoFix) {
|
|
|
|
const engines = {
|
2021-06-14 19:43:42 +02:00
|
|
|
node: '>=12.13.0',
|
2020-11-23 19:21:51 +01:00
|
|
|
};
|
2020-11-22 15:58:11 +01:00
|
|
|
parsedPackageJSON.engines = engines;
|
2021-01-10 00:27:37 +01:00
|
|
|
writePackageJson(parsedPackageJSON);
|
2020-11-22 15:58:11 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('package-lock.json') === -1) {
|
2021-01-10 00:50:06 +01:00
|
|
|
console.warn('package-lock.json not found');
|
|
|
|
if (!autoFix) {
|
|
|
|
console.warn('Run npm install in the plugin folder and commit the package-lock.json file.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('readme') === -1 && files.indexOf('readme.md') === -1) {
|
|
|
|
console.warn('README.md file not found, please create');
|
|
|
|
if (autoFix) {
|
2021-01-08 03:52:45 +01:00
|
|
|
console.log('Autofixing missing README.md file');
|
|
|
|
console.log('please edit the README.md file further to include plugin specific details.');
|
2021-02-05 00:43:27 +01:00
|
|
|
let readme = fs.readFileSync('src/bin/plugins/lib/README.md', {encoding: 'utf8', flag: 'r'});
|
2020-11-02 17:13:24 +01:00
|
|
|
readme = readme.replace(/\[plugin_name\]/g, pluginName);
|
2020-11-23 19:21:51 +01:00
|
|
|
if (repository) {
|
|
|
|
const org = repository.split('/')[3];
|
|
|
|
const name = repository.split('/')[4];
|
2020-11-02 17:13:24 +01:00
|
|
|
readme = readme.replace(/\[org_name\]/g, org);
|
|
|
|
readme = readme.replace(/\[repo_url\]/g, name);
|
2020-11-23 19:21:51 +01:00
|
|
|
fs.writeFileSync(`${pluginPath}/README.md`, readme);
|
|
|
|
} else {
|
|
|
|
console.warn('Unable to find repository in package.json, aborting.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 08:47:13 +01:00
|
|
|
if (files.indexOf('contributing') === -1 && files.indexOf('contributing.md') === -1) {
|
|
|
|
console.warn('CONTRIBUTING.md file not found, please create');
|
|
|
|
if (autoFix) {
|
2021-01-18 09:53:15 +01:00
|
|
|
console.log('Autofixing missing CONTRIBUTING.md file, please edit the CONTRIBUTING.md ' +
|
|
|
|
'file further to include plugin specific details.');
|
|
|
|
let contributing =
|
2021-02-05 00:43:27 +01:00
|
|
|
fs.readFileSync('src/bin/plugins/lib/CONTRIBUTING.md', {encoding: 'utf8', flag: 'r'});
|
2020-12-05 08:47:13 +01:00
|
|
|
contributing = contributing.replace(/\[plugin_name\]/g, pluginName);
|
|
|
|
fs.writeFileSync(`${pluginPath}/CONTRIBUTING.md`, contributing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-09 10:41:41 +01:00
|
|
|
if (readMeFileName) {
|
|
|
|
let readme =
|
2021-01-18 09:53:15 +01:00
|
|
|
fs.readFileSync(`${pluginPath}/${readMeFileName}`, {encoding: 'utf8', flag: 'r'});
|
2020-11-23 19:21:51 +01:00
|
|
|
if (readme.toLowerCase().indexOf('license') === -1) {
|
|
|
|
console.warn('No license section in README');
|
|
|
|
if (autoFix) {
|
|
|
|
console.warn('Please add License section to README manually.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-09 10:41:41 +01:00
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
const publishBadge = `![Publish Status](https://github.com/ether/${pluginName}/workflows/Node.js%20Package/badge.svg)`;
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
const testBadge = `![Backend Tests Status](https://github.com/ether/${pluginName}/workflows/Backend%20tests/badge.svg)`;
|
|
|
|
if (readme.toLowerCase().indexOf('travis') !== -1) {
|
|
|
|
console.warn('Remove Travis badges');
|
|
|
|
}
|
|
|
|
if (readme.indexOf('workflows/Node.js%20Package/badge.svg') === -1) {
|
|
|
|
console.warn('No Github workflow badge detected');
|
|
|
|
if (autoFix) {
|
|
|
|
readme = `${publishBadge} ${testBadge}\n\n${readme}`;
|
|
|
|
// write readme to file system
|
|
|
|
fs.writeFileSync(`${pluginPath}/${readMeFileName}`, readme);
|
|
|
|
console.log('Wrote Github workflow badges to README');
|
|
|
|
}
|
|
|
|
}
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('license') === -1 && files.indexOf('license.md') === -1) {
|
|
|
|
console.warn('LICENSE.md file not found, please create');
|
|
|
|
if (autoFix) {
|
|
|
|
console.log('Autofixing missing LICENSE.md file, including Apache 2 license.');
|
2021-02-05 00:43:27 +01:00
|
|
|
let license =
|
|
|
|
fs.readFileSync('src/bin/plugins/lib/LICENSE.md', {encoding: 'utf8', flag: 'r'});
|
2021-01-09 05:04:11 +01:00
|
|
|
license = license.replace('[yyyy]', new Date().getFullYear());
|
|
|
|
license = license.replace('[name of copyright owner]', execSync('git config user.name'));
|
|
|
|
fs.writeFileSync(`${pluginPath}/LICENSE.md`, license);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('.gitignore') === -1) {
|
2021-01-18 09:53:15 +01:00
|
|
|
console.warn('.gitignore file not found, please create. .gitignore files are useful to ' +
|
|
|
|
"ensure files aren't incorrectly commited to a repository.");
|
2020-11-23 19:21:51 +01:00
|
|
|
if (autoFix) {
|
|
|
|
console.log('Autofixing missing .gitignore file');
|
2021-02-05 00:43:27 +01:00
|
|
|
const gitignore =
|
|
|
|
fs.readFileSync('src/bin/plugins/lib/gitignore', {encoding: 'utf8', flag: 'r'});
|
2020-11-23 19:21:51 +01:00
|
|
|
fs.writeFileSync(`${pluginPath}/.gitignore`, gitignore);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
2020-12-16 22:51:43 +01:00
|
|
|
} else {
|
2020-11-28 14:13:14 +01:00
|
|
|
let gitignore =
|
|
|
|
fs.readFileSync(`${pluginPath}/.gitignore`, {encoding: 'utf8', flag: 'r'});
|
2020-12-16 22:51:43 +01:00
|
|
|
if (gitignore.indexOf('node_modules/') === -1) {
|
|
|
|
console.warn('node_modules/ missing from .gitignore');
|
|
|
|
if (autoFix) {
|
|
|
|
gitignore += 'node_modules/';
|
|
|
|
fs.writeFileSync(`${pluginPath}/.gitignore`, gitignore);
|
|
|
|
}
|
|
|
|
}
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we include templates but don't have translations...
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('templates') !== -1 && files.indexOf('locales') === -1) {
|
2021-01-18 09:53:15 +01:00
|
|
|
console.warn('Translations not found, please create. ' +
|
|
|
|
'Translation files help with Etherpad accessibility.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('.ep_initialized') !== -1) {
|
2021-01-18 09:53:15 +01:00
|
|
|
console.warn(
|
|
|
|
'.ep_initialized found, please remove. .ep_initialized should never be commited to git ' +
|
|
|
|
'and should only exist once the plugin has been executed one time.');
|
2020-11-23 19:21:51 +01:00
|
|
|
if (autoFix) {
|
|
|
|
console.log('Autofixing incorrectly existing .ep_initialized file');
|
|
|
|
fs.unlinkSync(`${pluginPath}/.ep_initialized`);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('npm-debug.log') !== -1) {
|
2021-01-18 09:53:15 +01:00
|
|
|
console.warn('npm-debug.log found, please remove. npm-debug.log should never be commited to ' +
|
|
|
|
'your repository.');
|
2020-11-23 19:21:51 +01:00
|
|
|
if (autoFix) {
|
|
|
|
console.log('Autofixing incorrectly existing npm-debug.log file');
|
|
|
|
fs.unlinkSync(`${pluginPath}/npm-debug.log`);
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
if (files.indexOf('static') !== -1) {
|
|
|
|
fs.readdir(`${pluginPath}/static`, (errRead, staticFiles) => {
|
|
|
|
if (staticFiles.indexOf('tests') === -1) {
|
|
|
|
console.warn('Test files not found, please create tests. https://github.com/ether/etherpad-lite/wiki/Creating-a-plugin#writing-and-running-front-end-tests-for-your-plugin');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
2020-11-23 19:21:51 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.warn('Test files not found, please create tests. https://github.com/ether/etherpad-lite/wiki/Creating-a-plugin#writing-and-running-front-end-tests-for-your-plugin');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 00:50:06 +01:00
|
|
|
// Install dependencies so we can run ESLint. This should also create or update package-lock.json
|
|
|
|
// if autoFix is enabled.
|
|
|
|
const npmInstall = `npm install${autoFix ? '' : ' --no-package-lock'}`;
|
|
|
|
execSync(npmInstall, {stdio: 'inherit'});
|
2021-01-10 01:29:30 +01:00
|
|
|
// The ep_etherpad-lite peer dep must be installed last otherwise `npm install` will nuke it. An
|
|
|
|
// absolute path to etherpad-lite/src is used here so that pluginPath can be a symlink.
|
|
|
|
execSync(
|
2021-02-03 13:08:43 +01:00
|
|
|
`${npmInstall} --no-save ep_etherpad-lite@file:${__dirname}/../../`, {stdio: 'inherit'});
|
2020-11-22 15:58:11 +01:00
|
|
|
// linting begins
|
2020-11-23 19:21:51 +01:00
|
|
|
try {
|
2021-01-09 06:59:20 +01:00
|
|
|
console.log('Linting...');
|
2021-01-08 03:52:45 +01:00
|
|
|
const lintCmd = autoFix ? 'npx eslint --fix .' : 'npx eslint';
|
2021-01-09 06:59:56 +01:00
|
|
|
execSync(lintCmd, {stdio: 'inherit'});
|
2020-11-23 19:21:51 +01:00
|
|
|
} catch (e) {
|
2020-11-22 15:58:11 +01:00
|
|
|
// it is gonna throw an error anyway
|
2020-11-23 19:21:51 +01:00
|
|
|
console.log('Manual linting probably required, check with: npm run lint');
|
2020-11-22 15:58:11 +01:00
|
|
|
}
|
|
|
|
// linting ends.
|
|
|
|
|
2021-01-10 01:16:56 +01:00
|
|
|
if (autoFix) {
|
|
|
|
const unchanged = JSON.parse(execSync(
|
|
|
|
'untracked=$(git ls-files -o --exclude-standard) || exit 1; ' +
|
|
|
|
'git diff-files --quiet && [ -z "$untracked" ] && echo true || echo false'));
|
|
|
|
if (!unchanged) {
|
2021-01-11 00:28:32 +01:00
|
|
|
// Display a diff of changes. Git doesn't diff untracked files, so they must be added to the
|
|
|
|
// index. Use a temporary index file to avoid modifying Git's default index file.
|
|
|
|
execSync('git read-tree HEAD; git add -A && git diff-index -p --cached HEAD && echo ""', {
|
|
|
|
env: {...process.env, GIT_INDEX_FILE: '.git/checkPlugin.index'},
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
|
|
|
fs.unlinkSync(`${pluginPath}/.git/checkPlugin.index`);
|
|
|
|
|
2021-01-10 01:16:56 +01:00
|
|
|
const cmd = [
|
|
|
|
'git add -A',
|
|
|
|
'git commit -m "autofixes from Etherpad checkPlugin.js"',
|
|
|
|
'git push',
|
|
|
|
].join(' && ');
|
|
|
|
if (autoCommit) {
|
|
|
|
console.log('Attempting autocommit and auto publish to npm');
|
|
|
|
execSync(cmd, {stdio: 'inherit'});
|
|
|
|
} else {
|
2021-01-11 00:28:32 +01:00
|
|
|
console.log('Fixes applied. Check the above git diff then run the following command:');
|
2021-01-10 01:16:56 +01:00
|
|
|
console.log(`(cd node_modules/${pluginName} && ${cmd})`);
|
|
|
|
}
|
2020-11-23 19:21:51 +01:00
|
|
|
} else {
|
2021-01-10 01:16:56 +01:00
|
|
|
console.log('No changes.');
|
2020-11-02 17:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:51 +01:00
|
|
|
console.log('Finished');
|
2020-11-02 17:13:24 +01:00
|
|
|
});
|