Skip to content

Commit

Permalink
Bump Node version and dependencies, compile assets
Browse files Browse the repository at this point in the history
Adopt Wikimedia eslint config

Add .editorconfig

Prepare 5.2.0 release
  • Loading branch information
MusikAnimal committed Feb 24, 2024
1 parent 404e33c commit eb30720
Show file tree
Hide file tree
Showing 17 changed files with 8,871 additions and 11,166 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Want to add custom links? See [[meta:MoreMenu#Customization]].",
"",
"Script: MoreMenu.js",
"Version: 5.1.24",
"Version: 5.2.0",
"Author: MusikAnimal",
"License: MIT",
"Documentation: [[meta:MoreMenu]]",
Expand Down
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://EditorConfig.org

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# 4-char tab indentation
[*.{js,json}]
indent_style = tab
indent_size = 4
55 changes: 22 additions & 33 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"airbnb-base"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"$": "readonly",
"mw": "readonly",
"MoreMenu": "writable"
},
"parserOptions": {
"ecmaVersion": 9
},
"overrides": [
{
"files": "src/*.js"
}
],
"rules": {
"indent": ["error", 4],
"max-len": ["error", {"code": 120}],
"no-bitwise": "off",
"no-param-reassign": "off",
"arrow-parens": ["error", "as-needed"],
"newline-per-chained-call": "off",
"yoda": ["error", "always", {"onlyEquality": true}],
"comma-dangle": ["error", "always-multiline"],
"func-names": "off"
}
"env": {
"browser": true,
"es6": true
},
"extends": [
"wikimedia/client/es6",
"wikimedia/mediawiki",
"wikimedia/jquery"
],
"globals": {
"MoreMenu": "writable",
"process": "readonly"
},
"parserOptions": {
"ecmaVersion": 9
},
"rules": {
"es-x/no-rest-spread-properties": "off",
"mediawiki/class-doc": "off",
"no-bitwise": "off",
"no-jquery/no-global-selector": "off"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.20.0]
node-version: [18.17.0]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.20.0
18.17.0
61 changes: 33 additions & 28 deletions bin/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,45 @@
* You must have interface-admin rights to use this.
* Use [[Special:BotPasswords]] to get credentials.
*
* To use, run:
* node bin/deploy.js [username] [password] "[edit summary]"
* To use, copy credentials.example.json to credentials.json
* and fill in the username and password.
*
* Then:
* node bin/deploy.js "[edit summary]"
*
* The edit summary is transformed to "v5.5.5 at abcd1234: [edit summary]"
*/

const dir = './dist/';
const fs = require('fs');
const { execSync } = require('child_process');
const MWBot = require('mwbot');
const client = new MWBot();
const [summary] = process.argv.slice(2);
const fs = require( 'fs' );
const { execSync } = require( 'child_process' );
const { Mwn } = require( 'mwn' );
const [ summary ] = process.argv.slice( 2 );

// Version info for edit summary.
const sha = execSync('git rev-parse --short HEAD').toString('utf-8');
const message = summary || execSync('git log -2 --pretty=%B').toString('utf-8').split('\n')[2];
const version = require('../package.json').version;
const credentials = require('../credentials.json');
const sha = execSync( 'git rev-parse --short HEAD' ).toString( 'utf-8' );
const message = summary || execSync( 'git log -2 --pretty=%B' ).toString( 'utf-8' ).split( '\n' )[ 2 ];
const version = require( '../package.json' ).version;
const credentials = require( '../credentials.json' );

const bot = new Mwn( {
apiUrl: 'https://meta.wikimedia.org/w/api.php',
username: credentials.username,
password: credentials.password
} );

fs.readdir(dir, (err, files) => {
client.loginGetEditToken({
apiUrl: 'https://meta.wikimedia.org/w/api.php',
username: credentials.username,
password: credentials.password
}).then(() => {
files.forEach(file => {
if ('unversioned' === file) {
return;
}
bot.login().then( () => {
fs.readdir( dir, ( err, files ) => {
files.forEach( ( file ) => {
if ( file === 'unversioned' ) {
return;
}

fs.readFile(`${dir}${file}`, 'utf-8', (err, content) => {
const title = `MediaWiki:Gadget-${file}`;
client.edit(title, content, `v${version} at ${sha.trim()}: ${message}`);
});
});
});
});
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile( `${ dir }${ file }`, 'utf-8', ( _err, content ) => {
const title = `MediaWiki:Gadget-${ file }`;
bot.save( title, content, `v${ version } at ${ sha.trim() }: ${ message }` );
} );
} );
} );
} );
71 changes: 37 additions & 34 deletions bin/server.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
/* eslint-disable max-len */

/**
* Based on https://github.com/wikimedia-gadgets/twinkle/blob/master/scripts/server.js (CC BY-SA 3.0)
*
* Starts a local server so you can test your code by importing the src/ directory from your local.
* Starts a local server, so you can test your code by importing the src/ directory from your local.
* To use, run "node bin/server.js", then in your https://meta.wikimedia.org/wiki/Special:MyPage/global.js,
* add the following:
* mw.loader.using(['mediawiki.user', 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title'], function () {
* mw.loader.load('http://localhost:5501/dist/MoreMenu.messages.en.js');
* mw.loader.load('http://localhost:5501/src/MoreMenu.user.js');
* mw.loader.load('http://localhost:5501/src/MoreMenu.page.js');
* mw.loader.load('http://localhost:5501/src/MoreMenu.js');
* });
* mw.loader.using( [ 'mediawiki.user', 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title' ], () => {
* mw.loader.load( 'http://localhost:5501/dist/MoreMenu.messages.en.js' );
* mw.loader.load( 'http://localhost:5501/src/MoreMenu.user.js' );
* mw.loader.load( 'http://localhost:5501/src/MoreMenu.page.js' );
* mw.loader.load( 'http://localhost:5501/src/MoreMenu.js' );
* } );
*/

const http = require('http');
const fs = require('fs');
const http = require( 'http' );
const fs = require( 'fs' );

const server = http.createServer((request, response) => {
const filePath = `.${request.url}`;
let contentType;
if (request.url.endsWith('.js')) {
contentType = 'text/javascript';
} else if (request.url.endsWith('.css')) {
contentType = 'text/css';
} else {
contentType = 'text/plain';
}
fs.readFile(filePath, (error, content) => {
if (error) {
response.end(`Oops, something went wrong: ${error.code} ..\n`);
} else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
});
const server = http.createServer( ( request, response ) => {
const filePath = `.${ request.url }`;
let contentType;
if ( request.url.endsWith( '.js' ) ) {
contentType = 'text/javascript';
} else if ( request.url.endsWith( '.css' ) ) {
contentType = 'text/css';
} else {
contentType = 'text/plain';
}
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile( filePath, ( error, content ) => {
if ( error ) {
response.end( `Oops, something went wrong: ${ error.code } ..\n` );
} else {
response.writeHead( 200, { 'Content-Type': contentType } );
response.end( content, 'utf-8' );
}
} );
} );

const hostname = '127.0.0.1';
// eslint-disable-next-line no-restricted-globals
const port = isNaN(Number(process.argv[2])) ? '5501' : process.argv[2];

server.listen(port, hostname, () => {
// eslint-disable-next-line no-console
console.log(`Server running at http://${hostname}:${port}/`);
});
const port = isNaN( Number( process.argv[ 2 ] ) ) ? '5501' : process.argv[ 2 ];

server.listen( port, hostname, () => {
// eslint-disable-next-line no-console
console.log( `Server running at http://${ hostname }:${ port }/` );
} );
Loading

0 comments on commit eb30720

Please sign in to comment.