mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 07:35:05 -04:00
plugins: Various checkPlugins.js and associated file fixes. (#4439)
This PR makes checkPlugins some what more useful for developers. It adds auto npm publish support and various travis improvements among other goodies.
This commit is contained in:
parent
35f4c00dfb
commit
cfc7e47db0
7 changed files with 495 additions and 389 deletions
|
@ -44,3 +44,9 @@ fi
|
||||||
# echo $dir
|
# echo $dir
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Automating update of ether organization plugins
|
||||||
|
```
|
||||||
|
getCorePlugins.sh
|
||||||
|
updateCorePlugins.sh
|
||||||
|
```
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
// pro usage for all your plugins, replace johnmclear with your github username
|
|
||||||
/*
|
|
||||||
cd node_modules
|
|
||||||
GHUSER=johnmclear; curl "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
for dir in `ls node_modules`;
|
|
||||||
do
|
|
||||||
# echo $0
|
|
||||||
if [[ $dir == *"ep_"* ]]; then
|
|
||||||
if [[ $dir != "ep_etherpad-lite" ]]; then
|
|
||||||
node bin/plugins/checkPlugin.js $dir autofix autocommit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# echo $dir
|
|
||||||
done
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Usage
|
* Usage -- see README.md
|
||||||
*
|
*
|
||||||
* Normal usage: node bin/plugins/checkPlugins.js ep_whatever
|
* Normal usage: node bin/plugins/checkPlugins.js ep_whatever
|
||||||
* Auto fix the things it can: node bin/plugins/checkPlugins.js ep_whatever autofix
|
* Auto fix the things it can: node bin/plugins/checkPlugins.js ep_whatever autofix
|
||||||
|
@ -32,6 +14,12 @@ const { exec } = require("child_process");
|
||||||
|
|
||||||
// get plugin name & path from user input
|
// get plugin name & path from user input
|
||||||
const pluginName = process.argv[2];
|
const pluginName = process.argv[2];
|
||||||
|
|
||||||
|
if(!pluginName){
|
||||||
|
console.error("no plugin name specified");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const pluginPath = "node_modules/"+pluginName;
|
const pluginPath = "node_modules/"+pluginName;
|
||||||
|
|
||||||
console.log("Checking the plugin: "+ pluginName)
|
console.log("Checking the plugin: "+ pluginName)
|
||||||
|
@ -69,12 +57,58 @@ fs.readdir(pluginPath, function (err, rootFiles) {
|
||||||
files.push(rootFiles[i].toLowerCase());
|
files.push(rootFiles[i].toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(files.indexOf(".git") === -1){
|
||||||
|
console.error("No .git folder, aborting");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// do a git pull...
|
||||||
|
var child_process = require('child_process');
|
||||||
|
try{
|
||||||
|
child_process.execSync('git pull ',{"cwd":pluginPath+"/"});
|
||||||
|
}catch(e){
|
||||||
|
console.error("Error git pull", e);
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const path = pluginPath + '/.github/workflows/npmpublish.yml';
|
||||||
|
if (!fs.existsSync(path)) {
|
||||||
|
console.log('no .github/workflows/npmpublish.yml, create one and set npm secret to auto publish to npm on commit');
|
||||||
|
if (autoFix) {
|
||||||
|
const npmpublish =
|
||||||
|
fs.readFileSync('bin/plugins/lib/npmpublish.yml', {encoding: 'utf8', flag: 'r'});
|
||||||
|
fs.mkdirSync(pluginPath + '/.github/workflows', {recursive: true});
|
||||||
|
fs.writeFileSync(path, npmpublish);
|
||||||
|
console.log("If you haven't already, setup autopublish for this plugin https://github.com/ether/etherpad-lite/wiki/Plugins:-Automatically-publishing-to-npm-on-commit-to-Github-Repo");
|
||||||
|
} else {
|
||||||
|
console.log('Setup autopublish for this plugin https://github.com/ether/etherpad-lite/wiki/Plugins:-Automatically-publishing-to-npm-on-commit-to-Github-Repo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
if(files.indexOf("package.json") === -1){
|
if(files.indexOf("package.json") === -1){
|
||||||
console.warn("no package.json, please create");
|
console.warn("no package.json, please create");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(files.indexOf("package.json") !== -1){
|
if(files.indexOf("package.json") !== -1){
|
||||||
let packageJSON = fs.readFileSync(pluginPath+"/package.json", {encoding:'utf8', flag:'r'});
|
let packageJSON = fs.readFileSync(pluginPath+"/package.json", {encoding:'utf8', flag:'r'});
|
||||||
|
let parsedPackageJSON = JSON.parse(packageJSON);
|
||||||
|
if(autoFix){
|
||||||
|
var updatedPackageJSON = false;
|
||||||
|
if(!parsedPackageJSON.funding){
|
||||||
|
updatedPackageJSON = true;
|
||||||
|
parsedPackageJSON.funding = {
|
||||||
|
"type": "individual",
|
||||||
|
"url": "http://etherpad.org/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(updatedPackageJSON){
|
||||||
|
hasAutofixed = true;
|
||||||
|
fs.writeFileSync(pluginPath+"/package.json", JSON.stringify(parsedPackageJSON, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
|
@ -83,10 +117,25 @@ fs.readdir(pluginPath, function (err, rootFiles) {
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// useful for creating README later.
|
// useful for creating README later.
|
||||||
repository = JSON.parse(packageJSON).repository.url;
|
repository = parsedPackageJSON.repository.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(files.indexOf("package-lock.json") === -1){
|
||||||
|
console.warn("package-lock.json file not found. Please run npm install in the plugin folder and commit the package-lock.json file.")
|
||||||
|
if(autoFix){
|
||||||
|
var child_process = require('child_process');
|
||||||
|
try{
|
||||||
|
child_process.execSync('npm install',{"cwd":pluginPath+"/"});
|
||||||
|
console.log("Making package-lock.json");
|
||||||
|
hasAutofixed = true;
|
||||||
|
}catch(e){
|
||||||
|
console.error("Failed to create package-lock.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(files.indexOf("readme") === -1 && files.indexOf("readme.md") === -1){
|
if(files.indexOf("readme") === -1 && files.indexOf("readme.md") === -1){
|
||||||
console.warn("README.md file not found, please create");
|
console.warn("README.md file not found, please create");
|
||||||
if(autoFix){
|
if(autoFix){
|
||||||
|
@ -154,11 +203,10 @@ fs.readdir(pluginPath, function (err, rootFiles) {
|
||||||
// checks the file versioning of .travis and updates it to the latest.
|
// checks the file versioning of .travis and updates it to the latest.
|
||||||
let existingConfig = fs.readFileSync(pluginPath + "/.travis.yml", {encoding:'utf8', flag:'r'});
|
let existingConfig = fs.readFileSync(pluginPath + "/.travis.yml", {encoding:'utf8', flag:'r'});
|
||||||
let existingConfigLocation = existingConfig.indexOf("##ETHERPAD_TRAVIS_V=");
|
let existingConfigLocation = existingConfig.indexOf("##ETHERPAD_TRAVIS_V=");
|
||||||
let existingValue = existingConfig.substr(existingConfigLocation+20, existingConfig.length);
|
let existingValue = parseInt(existingConfig.substr(existingConfigLocation+20, existingConfig.length));
|
||||||
|
|
||||||
let newConfigLocation = travisConfig.indexOf("##ETHERPAD_TRAVIS_V=");
|
let newConfigLocation = travisConfig.indexOf("##ETHERPAD_TRAVIS_V=");
|
||||||
let newValue = travisConfig.substr(newConfigLocation+20, travisConfig.length);
|
let newValue = parseInt(travisConfig.substr(newConfigLocation+20, travisConfig.length));
|
||||||
|
|
||||||
if(existingConfigLocation === -1){
|
if(existingConfigLocation === -1){
|
||||||
console.warn("no previous .travis.yml version found so writing new.")
|
console.warn("no previous .travis.yml version found so writing new.")
|
||||||
// we will write the newTravisConfig to the location.
|
// we will write the newTravisConfig to the location.
|
||||||
|
@ -222,7 +270,8 @@ fs.readdir(pluginPath, function (err, rootFiles) {
|
||||||
if(autoCommit){
|
if(autoCommit){
|
||||||
// holy shit you brave.
|
// holy shit you brave.
|
||||||
console.log("Attempting autocommit and auto publish to npm")
|
console.log("Attempting autocommit and auto publish to npm")
|
||||||
exec("cd node_modules/"+ pluginName + " && git add -A && git commit --allow-empty -m 'autofixes from Etherpad checkPlugins.js' && npm version patch && git add package.json && git commit --allow-empty -m 'bump version' && git push && npm publish && cd ../..", (error, name, stderr) => {
|
// github should push to npm for us :)
|
||||||
|
exec("cd node_modules/"+ pluginName + " && git add -A && git commit --allow-empty -m 'autofixes from Etherpad checkPlugins.js' && git push && cd ../..", (error, name, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(`error: ${error.message}`);
|
console.log(`error: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
|
@ -239,9 +288,6 @@ fs.readdir(pluginPath, function (err, rootFiles) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//listing all files using forEach
|
console.log("Finished");
|
||||||
files.forEach(function (file) {
|
|
||||||
// Do whatever you want to do with the file
|
|
||||||
// console.log(file.toLowerCase());
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
2
bin/plugins/getCorePlugins.sh
Executable file
2
bin/plugins/getCorePlugins.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
cd node_modules/
|
||||||
|
GHUSER=ether; curl "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone
|
|
@ -1,4 +1,4 @@
|
||||||
[](https://travis-ci.org/github/[org_name]/[repo_url])
|
[](https://travis-ci.com/github/[org_name]/[repo_url])
|
||||||
|
|
||||||
# My awesome plugin README example
|
# My awesome plugin README example
|
||||||
Explain what your plugin does and who it's useful for.
|
Explain what your plugin does and who it's useful for.
|
||||||
|
|
39
bin/plugins/lib/npmpublish.yml
Normal file
39
bin/plugins/lib/npmpublish.yml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# This workflow will run tests using node and then publish a package to the npm registry when a release is created
|
||||||
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
||||||
|
|
||||||
|
name: Node.js Package
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm test
|
||||||
|
|
||||||
|
publish-npm:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
registry-url: https://registry.npmjs.org/
|
||||||
|
- run: git config user.name 'github-actions[bot]'
|
||||||
|
- run: git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm version patch
|
||||||
|
- run: npm publish
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||||
|
- run: git push --follow-tags
|
30
bin/plugins/lib/travis.yml
Executable file → Normal file
30
bin/plugins/lib/travis.yml
Executable file → Normal file
|
@ -5,24 +5,14 @@ node_js:
|
||||||
|
|
||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
before_install:
|
|
||||||
- sudo add-apt-repository -y ppa:libreoffice/ppa
|
|
||||||
- sudo apt-get update
|
|
||||||
- sudo apt-get -y install libreoffice
|
|
||||||
- sudo apt-get -y install libreoffice-pdfimport
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- "bin/installDeps.sh"
|
|
||||||
- "export GIT_HASH=$(git rev-parse --verify --short HEAD)"
|
- "export GIT_HASH=$(git rev-parse --verify --short HEAD)"
|
||||||
|
|
||||||
before_script:
|
#script:
|
||||||
- "tests/frontend/travis/sauce_tunnel.sh"
|
# - "tests/frontend/travis/runner.sh"
|
||||||
|
|
||||||
script:
|
|
||||||
- "tests/frontend/travis/runner.sh"
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
|
@ -31,7 +21,19 @@ env:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
|
- name: "Lint test package-lock"
|
||||||
|
install:
|
||||||
|
- "npm install lockfile-lint"
|
||||||
|
script:
|
||||||
|
- npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm
|
||||||
- name: "Run the Backend tests"
|
- name: "Run the Backend tests"
|
||||||
|
before_script:
|
||||||
|
- "tests/frontend/travis/sauce_tunnel.sh"
|
||||||
|
before_install:
|
||||||
|
- sudo add-apt-repository -y ppa:libreoffice/ppa
|
||||||
|
- sudo apt-get update
|
||||||
|
- sudo apt-get -y install libreoffice
|
||||||
|
- sudo apt-get -y install libreoffice-pdfimport
|
||||||
install:
|
install:
|
||||||
- "npm install"
|
- "npm install"
|
||||||
- "mkdir [plugin_name]"
|
- "mkdir [plugin_name]"
|
||||||
|
@ -46,6 +48,8 @@ jobs:
|
||||||
script:
|
script:
|
||||||
- "tests/frontend/travis/runnerBackend.sh"
|
- "tests/frontend/travis/runnerBackend.sh"
|
||||||
- name: "Test the Frontend"
|
- name: "Test the Frontend"
|
||||||
|
before_script:
|
||||||
|
- "tests/frontend/travis/sauce_tunnel.sh"
|
||||||
install:
|
install:
|
||||||
- "npm install"
|
- "npm install"
|
||||||
- "mkdir [plugin_name]"
|
- "mkdir [plugin_name]"
|
||||||
|
@ -64,5 +68,5 @@ notifications:
|
||||||
channels:
|
channels:
|
||||||
- "irc.freenode.org#etherpad-lite-dev"
|
- "irc.freenode.org#etherpad-lite-dev"
|
||||||
|
|
||||||
##ETHERPAD_TRAVIS_V=3
|
##ETHERPAD_TRAVIS_V=7
|
||||||
## Travis configuration automatically created using bin/plugins/updateAllPluginsScript.sh
|
## Travis configuration automatically created using bin/plugins/updateAllPluginsScript.sh
|
||||||
|
|
9
bin/plugins/updateCorePlugins.sh
Executable file
9
bin/plugins/updateCorePlugins.sh
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
for dir in node_modules/ep_*; do
|
||||||
|
dir=${dir#node_modules/}
|
||||||
|
[ "$dir" != ep_etherpad-lite ] || continue
|
||||||
|
node bin/plugins/checkPlugin.js "$dir" autofix autocommit autoupdate
|
||||||
|
done
|
Loading…
Add table
Add a link
Reference in a new issue