generated from wikimedia-gadgets/modular-wiki-userscript-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
49 lines (41 loc) · 1.6 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-env node */
const fs = require('fs');
const mwn = require('mwn');
const {exec} = require('child_process');
// JSON file with your username and bot password. Set up a bot password from [[Special:BotPasswords]]
const credentials = require('./credentials.json');
// name of the on-wiki script page name
const SCRIPT_PAGE = 'User:Evad37/livenotifications/core.js';
const SCRIPT_SANDBOX_PAGE = 'User:Evad37/livenotifications/core/sandbox.js';
const sandboxOnly = process.argv[2] === '--sandbox';
const site = new mwn({
apiUrl: 'https://en.wikipedia.org/w/api.php',
username: credentials.username,
password: credentials.password
});
const version = require('./package.json').version;
exec('git log -1 --pretty=%B', (err, stdout) => {
let editSummary;
if (err) {
editSummary = `v${version}: updating`;
} else {
let last_commit_summary = stdout.trim();
editSummary = `v${version}: ${last_commit_summary}`;
}
site.loginGetToken().then(() => {
let outjs = fs.readFileSync(__dirname + '/dist/out.js').toString();
site.save(SCRIPT_SANDBOX_PAGE, outjs, editSummary).then(() => {
console.log(`Successfully saved dist/out.js to ${SCRIPT_SANDBOX_PAGE}`);
if (!sandboxOnly) {
let outminjs = fs.readFileSync(__dirname + '/dist/out.min.js').toString();
site.save(SCRIPT_PAGE, outminjs, editSummary).then(() => {
console.log(`Successfully saved dist/out.min.js to ${SCRIPT_PAGE}`);
}, () => {
console.log(`Failed to edit ${SCRIPT_PAGE} :(`);
});
}
}, () => {
console.log(`Failed to edit ${SCRIPT_SANDBOX_PAGE} :(`);
});
});
});