wikiploy 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.building your project.md +499 -0
- package/README.md +25 -55
- package/assets/test.css +1 -1
- package/assets/test.js +1 -1
- package/package.json +2 -2
- package/src/index.js +2 -0
- package/src/userPrompt.js +16 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# Building your project
|
|
2
|
+
|
|
3
|
+
There are various ways to build scripts. You can use [browserify](https://browserify.org/), webpack, TypeScript compiler, etc., or even choose not to build at all. Wikiploy doesn't force the use of any specific tool (you are free to choose whatever you are comfortable with). However, not all solutions are equally well-suited for the wiki world, and choosing the right solution takes time.
|
|
4
|
+
|
|
5
|
+
Let me save you some time. Below is a recommended project setup based on some of my real scripts and years of experience building gadgets. If you're interested, you can take a look at a real-world script: [wikibot-jsbot-core](https://github.com/Eccenux/wikibot-jsbot-core) (it's a bit experimental, but you might find some interesting constructs there). For a more stable example, you might want to explore the template repository for Wikiploy: [wikiploy-rollout-example](https://github.com/Eccenux/wikiploy-rollout-example).
|
|
6
|
+
|
|
7
|
+
## Recommended setup for building scripts
|
|
8
|
+
|
|
9
|
+
Example `.gitignore` for your project:
|
|
10
|
+
```
|
|
11
|
+
/node_modules
|
|
12
|
+
*.lnk
|
|
13
|
+
*.priv.*
|
|
14
|
+
bot.config.*
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Your `package.json` (crucial part being `scripts`):
|
|
18
|
+
```js
|
|
19
|
+
{
|
|
20
|
+
"name": "wiki-gadget-yourgadetname",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "mocha",
|
|
24
|
+
"build": "browserify src/main.js -o dist/yourGadetName.js",
|
|
25
|
+
"deploy-dev": "node wikiploy-dev.mjs",
|
|
26
|
+
"deploy": "node wikiploy.mjs",
|
|
27
|
+
"rollout-dev": "npm run build && npm run deploy-dev"
|
|
28
|
+
"rollout": "npm run build && npm run deploy"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"browserify": "17.x",
|
|
32
|
+
"chai": "4.x",
|
|
33
|
+
"eslint": "8.x",
|
|
34
|
+
"mocha": "10.x"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"wikiploy": "1.x"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Your `src/main.js` could look something like this:
|
|
43
|
+
```js
|
|
44
|
+
var { MyGadget } = require("./MyGadget");
|
|
45
|
+
|
|
46
|
+
// instance
|
|
47
|
+
var gadget = new MyGadget();
|
|
48
|
+
|
|
49
|
+
// init elements
|
|
50
|
+
$(function(){
|
|
51
|
+
gadget.init();
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Your `src/MyGadget.js` could look something like this:
|
|
56
|
+
```js
|
|
57
|
+
function MyGadget() {
|
|
58
|
+
/** Initialize things when DOM is ready. */
|
|
59
|
+
this.init = function() {
|
|
60
|
+
console.log("init done");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { MyGadget };
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Remember to install tools after changing `package.json`:
|
|
68
|
+
```bash
|
|
69
|
+
npm i
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
And now you should already be able to build the script:
|
|
73
|
+
```bash
|
|
74
|
+
npm run build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Now we just need to setup things so that we don't have to build and deploy things manually.
|
|
78
|
+
|
|
79
|
+
## Visual Studio Code setup
|
|
80
|
+
|
|
81
|
+
[VSC](https://code.visualstudio.com/) is a free editor that has evolved over the years to become almost like an IDE. It is great for developing JS scripts.
|
|
82
|
+
|
|
83
|
+
Add `.vscode/extensions.json` to help install a set of **extensions**:
|
|
84
|
+
```js
|
|
85
|
+
{
|
|
86
|
+
"recommendations": [
|
|
87
|
+
"gsppvo.vscode-commandbar",
|
|
88
|
+
"hbenl.vscode-test-explorer",
|
|
89
|
+
"hbenl.vscode-mocha-test-adapter"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
VSC **settings** `.vscode/settings.json`:
|
|
95
|
+
```js
|
|
96
|
+
{
|
|
97
|
+
"search.exclude": {
|
|
98
|
+
"package-lock.json": true,
|
|
99
|
+
},
|
|
100
|
+
"editor.detectIndentation": false,
|
|
101
|
+
"editor.useTabStops": true,
|
|
102
|
+
"editor.insertSpaces": false,
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Using tabs vs spaces is obviously your preference. People tend to have conflicting opinions on that. The simple truth is that a tab is one byte, and 4 spaces are 4 bytes, but use whatever works for your project. Just remember to enforce it at the project level so that the style is consistent.
|
|
107
|
+
|
|
108
|
+
VSC **tasks** `.vscode/tasks.json`:
|
|
109
|
+
```js
|
|
110
|
+
{
|
|
111
|
+
"version": "2.0.0",
|
|
112
|
+
"tasks": [
|
|
113
|
+
{
|
|
114
|
+
"type": "npm",
|
|
115
|
+
"script": "test",
|
|
116
|
+
"group": "test",
|
|
117
|
+
"problemMatcher": [],
|
|
118
|
+
"label": "Run tests",
|
|
119
|
+
"detail": "mocha"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"type": "npm",
|
|
123
|
+
"script": "deploy-dev",
|
|
124
|
+
"group": "none",
|
|
125
|
+
"problemMatcher": [],
|
|
126
|
+
"label": "Run dev deploy",
|
|
127
|
+
"detail": "Run deploy script (wikiploy)"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"type": "npm",
|
|
131
|
+
"script": "deploy",
|
|
132
|
+
"group": "none",
|
|
133
|
+
"problemMatcher": [],
|
|
134
|
+
"label": "Run deploy",
|
|
135
|
+
"detail": "Run deploy script (wikiploy)"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"type": "npm",
|
|
139
|
+
"script": "rollout-dev",
|
|
140
|
+
"group": "none",
|
|
141
|
+
"problemMatcher": [],
|
|
142
|
+
"label": "Run dev rollout",
|
|
143
|
+
"detail": "Run rollout script (browserify & wikiploy)"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "npm",
|
|
147
|
+
"script": "rollout",
|
|
148
|
+
"group": "none",
|
|
149
|
+
"problemMatcher": [],
|
|
150
|
+
"label": "Run rollout",
|
|
151
|
+
"detail": "Run rollout script (browserify & wikiploy)"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"type": "npm",
|
|
155
|
+
"script": "install",
|
|
156
|
+
"group": "none",
|
|
157
|
+
"problemMatcher": [],
|
|
158
|
+
"label": "npm install",
|
|
159
|
+
"detail": "install dependencies from package"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
When you use tasks, VSC runs an interactive terminal. This makes some scripts work better:
|
|
166
|
+
- Any scripts that use colors in the terminal will work with tasks.
|
|
167
|
+
- An interactive shell is required for the `userPrompt` helper (see *Deploy script*).
|
|
168
|
+
- Text progress (like in npm install) looks much better with tasks.
|
|
169
|
+
|
|
170
|
+
VCS **commandbar** `.vscode/commandbar.json`:
|
|
171
|
+
```js
|
|
172
|
+
// Remember to change VSC settings (UI): in `files.associations` add `commandbar.json: jsonc`
|
|
173
|
+
{
|
|
174
|
+
"skipTerminateQuickPick": true,
|
|
175
|
+
"skipSwitchToOutput": false,
|
|
176
|
+
"skipErrorMessage": true,
|
|
177
|
+
"commands": [
|
|
178
|
+
// "commandType": "script" runs npm script directly
|
|
179
|
+
{
|
|
180
|
+
"text": "test",
|
|
181
|
+
"tooltip": "Run mocha tests.",
|
|
182
|
+
"color": "lightgreen",
|
|
183
|
+
"commandType": "script",
|
|
184
|
+
"command": "test",
|
|
185
|
+
"priority": 0
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
{
|
|
189
|
+
"text": "build",
|
|
190
|
+
"tooltip": "Run the browserify build.",
|
|
191
|
+
"color": "lightgreen",
|
|
192
|
+
"commandType": "script",
|
|
193
|
+
"command": "build",
|
|
194
|
+
"priority": 0
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
// running deployment as a task (so that prompts work)
|
|
198
|
+
// note that "Run dev deploy" is a label from tasks.json
|
|
199
|
+
{
|
|
200
|
+
"text": "wikiploy-dev",
|
|
201
|
+
"tooltip": "Deploy pre-built script.",
|
|
202
|
+
"color": "lightgreen",
|
|
203
|
+
"commandType": "palette",
|
|
204
|
+
"command": "workbench.action.tasks.runTask|Run dev deploy",
|
|
205
|
+
"priority": 0
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
// this our one-click rollout
|
|
209
|
+
{
|
|
210
|
+
"text": "build & deploy-dev",
|
|
211
|
+
"tooltip": "Build (browserify) and deploy (wikiploy).",
|
|
212
|
+
"color": "lightgreen",
|
|
213
|
+
"commandType": "palette",
|
|
214
|
+
"command": "workbench.action.tasks.runTask|Run dev rollout",
|
|
215
|
+
"priority": 0
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Note: You should also change VSC settings (UI) under `files.associations` to add `commandbar.json: jsonc` (JSON with comments). This allows comments in JSON, making it more understandable. Otherwise, VSC will complain about inline comments.
|
|
222
|
+
|
|
223
|
+
Also, note: Above, we only added dev tasks to the command bar. This is just for brevity. The same commands can be added for other tasks.
|
|
224
|
+
|
|
225
|
+
## Deploy script
|
|
226
|
+
|
|
227
|
+
Your **bot password** configuration `bot.config.mjs`:
|
|
228
|
+
```js
|
|
229
|
+
/**
|
|
230
|
+
Bot with edit&create rights.
|
|
231
|
+
|
|
232
|
+
https://test.wikipedia.org/wiki/Special:BotPasswords/Wikiploy
|
|
233
|
+
|
|
234
|
+
The new password to log in with Nux@Wikiploy.
|
|
235
|
+
Where "Nux" is a Wikipedia username and "Wikiploy" is a bot name choosen in [[Special:BotPasswords]].
|
|
236
|
+
*/
|
|
237
|
+
export const username = 'Nux@Wikiploy';
|
|
238
|
+
export const password = '0abc...fckgw';
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Your minimal **developer deployment script** `wikiploy-dev.mjs`:
|
|
242
|
+
```js
|
|
243
|
+
import {DeployConfig, WikiployLite, userPrompt} from 'wikiploy';
|
|
244
|
+
|
|
245
|
+
import * as botpass from './bot.config.js';
|
|
246
|
+
const ployBot = new WikiployLite(botpass);
|
|
247
|
+
|
|
248
|
+
// default site for DeployConfig
|
|
249
|
+
ployBot.site = "en.wikipedia.org";
|
|
250
|
+
|
|
251
|
+
// run asynchronously to be able to wait for results
|
|
252
|
+
(async () => {
|
|
253
|
+
// custom summary from a prompt
|
|
254
|
+
const summary = await userPrompt('Summary of changes (empty for default summary):');
|
|
255
|
+
if (typeof summary === 'string' && summary.length) {
|
|
256
|
+
ployBot.summary = () => {
|
|
257
|
+
return summary;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// push out file(s) to wiki
|
|
262
|
+
const configs = [];
|
|
263
|
+
configs.push(new DeployConfig({
|
|
264
|
+
src: 'dist/yourGadetName.js',
|
|
265
|
+
dst: '~/yourGadetName.js',
|
|
266
|
+
nowiki: true,
|
|
267
|
+
}));
|
|
268
|
+
configs.push(new DeployConfig({
|
|
269
|
+
src: 'dist/yourGadetName.css',
|
|
270
|
+
dst: '~/yourGadetName.css',
|
|
271
|
+
}));
|
|
272
|
+
|
|
273
|
+
await ployBot.deploy(configs);
|
|
274
|
+
|
|
275
|
+
})().catch(err => {
|
|
276
|
+
console.error(err);
|
|
277
|
+
process.exit(1);
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Note that `~` will be `User:SomeName` so the user space of a currently logged in user (you user space).
|
|
282
|
+
You can omit `dst` and it will default to `dst: '~/${src}'`. More about this basic code and `dst` in the [Wikiploy rollout example](https://github.com/Eccenux/wikiploy-rollout-example/).
|
|
283
|
+
|
|
284
|
+
Config for your **main deployment script** `wikiploy.mjs`:
|
|
285
|
+
```js
|
|
286
|
+
// [...] (same sa -dev)
|
|
287
|
+
|
|
288
|
+
// push out file(s) to wiki
|
|
289
|
+
// dev version
|
|
290
|
+
const configs = [];
|
|
291
|
+
configs.push(new DeployConfig({
|
|
292
|
+
src: 'dist/yourGadetName.js',
|
|
293
|
+
dst: '~/yourGadetName.js',
|
|
294
|
+
nowiki: true,
|
|
295
|
+
}));
|
|
296
|
+
configs.push(new DeployConfig({
|
|
297
|
+
src: 'dist/yourGadetName.css',
|
|
298
|
+
dst: '~/yourGadetName.css',
|
|
299
|
+
}));
|
|
300
|
+
// gadget
|
|
301
|
+
configs.push(new DeployConfig({
|
|
302
|
+
src: 'dist/yourGadetName.js',
|
|
303
|
+
dst: 'MediaWiki:Gadget-yourGadetName.js',
|
|
304
|
+
nowiki: true,
|
|
305
|
+
}));
|
|
306
|
+
configs.push(new DeployConfig({
|
|
307
|
+
src: 'dist/yourGadetName.css',
|
|
308
|
+
dst: 'MediaWiki:Gadget-yourGadetName.css',
|
|
309
|
+
}));
|
|
310
|
+
|
|
311
|
+
await ployBot.deploy(configs);
|
|
312
|
+
|
|
313
|
+
})().catch(err => {
|
|
314
|
+
console.error(err);
|
|
315
|
+
process.exit(1);
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Note: Above is only the config part of the script.
|
|
320
|
+
|
|
321
|
+
We update both dev and release version above. This will make an empty edit in a dev script if you already deployed it.
|
|
322
|
+
|
|
323
|
+
Though we only deploy to `site = "en.wikipedia.org"` you could use other configs to deploy to many wikis:
|
|
324
|
+
```js
|
|
325
|
+
function addConfig(configs, site) {
|
|
326
|
+
configs.push(new DeployConfig({
|
|
327
|
+
src: 'dist/yourGadetName.js',
|
|
328
|
+
dst: 'MediaWiki:Gadget-yourGadetName.js',
|
|
329
|
+
site,
|
|
330
|
+
nowiki: true,
|
|
331
|
+
}));
|
|
332
|
+
configs.push(new DeployConfig({
|
|
333
|
+
src: 'dist/yourGadetName.css',
|
|
334
|
+
dst: 'MediaWiki:Gadget-yourGadetName.css',
|
|
335
|
+
site,
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
338
|
+
addConfig(configs, 'pl.wikipedia.org');
|
|
339
|
+
addConfig(configs, 'pl.wikisource.org');
|
|
340
|
+
```
|
|
341
|
+
The script doesn't have any limits. You do need interface-admin rights to deploy to `MediaWiki:Gadget-` namespace. So you might need to use `~/` instead to deploy to your user-space.
|
|
342
|
+
|
|
343
|
+
## Exporting stuff
|
|
344
|
+
|
|
345
|
+
Note that *browserify* will wrap your code with a function automatically, so you don't have to worry about leaking variables to the global scope (you should still remember to define variables with `var`, `let`, or `const`).
|
|
346
|
+
|
|
347
|
+
If you want to ***intentionally* expose** a variable, there are two ways to do that:
|
|
348
|
+
|
|
349
|
+
1. Use the `window` object (only if you have to).
|
|
350
|
+
2. Use *userjs* hooks (`mw.hook`).
|
|
351
|
+
|
|
352
|
+
Exposing things in `main.js` could look something like this:
|
|
353
|
+
```js
|
|
354
|
+
var { MyGadget } = require("./MyGadget");
|
|
355
|
+
|
|
356
|
+
// bot instance
|
|
357
|
+
var gadget = new MyGadget();
|
|
358
|
+
|
|
359
|
+
// expose for external usage (*not* recommended)
|
|
360
|
+
window.yourGadetName = gadget;
|
|
361
|
+
|
|
362
|
+
// hook when object is ready
|
|
363
|
+
mw.hook('userjs.yourGadetName.loaded').fire(gadget);
|
|
364
|
+
|
|
365
|
+
$(function(){
|
|
366
|
+
// load Mediwiki core dependency
|
|
367
|
+
// (in this case util is for `mw.util.addPortletLink`)
|
|
368
|
+
mw.loader.using(["mediawiki.util"]).then( function() {
|
|
369
|
+
gadget.init();
|
|
370
|
+
|
|
371
|
+
// hook when initial elements are ready
|
|
372
|
+
mw.hook('userjs.yourGadetName.ready').fire(gadget);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
As you can see, hooks are better because you can keep the name of the variable short. It's also much easier to make sure each dependency is loaded so other devs can use your hooks in other gadgets, and your users can customize the script.
|
|
378
|
+
|
|
379
|
+
User options:
|
|
380
|
+
```js
|
|
381
|
+
mw.hook('userjs.yourGadetName.loaded').add(function (gadget) {
|
|
382
|
+
gadget.options.createTool = false;
|
|
383
|
+
});
|
|
384
|
+
importScript('User:Nux/yourGadetName.js');
|
|
385
|
+
```
|
|
386
|
+
A more advanced customization:
|
|
387
|
+
```js
|
|
388
|
+
mw.hook('userjs.yourGadetName.ready').add(function (gadget) {
|
|
389
|
+
var $tool = $('#some-unique-gadet-tool a');
|
|
390
|
+
$tool.text($tool.text() + ' & plugin');
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Using classes
|
|
395
|
+
|
|
396
|
+
JS has classes for a long time. They don't work in IE and you cannot use them in default gadgets on Wikipedia. If you are building a default gadget you might want to add [babeljs](https://babeljs.io/) as a build step.
|
|
397
|
+
```bash
|
|
398
|
+
# install
|
|
399
|
+
npm install --save-dev babelify @babel/core
|
|
400
|
+
# build
|
|
401
|
+
browserify script.js -t babelify --outfile bundle.js
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
If the gadget is intended for advanced users it is safe to assume they won't use IE. So for most scripts you can probably skip babelify. But as of 2023 you will need `requiresES6` option in the gadget definition.
|
|
405
|
+
|
|
406
|
+
```
|
|
407
|
+
yourClassyGadetName [ResourceLoader | requiresES6 | dependencies = mediawiki.util] | yourGadetName.js | yourGadetName.css
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
Example `MyGadget.js` with a link in the toolbar:
|
|
412
|
+
```js
|
|
413
|
+
class MyGadget {
|
|
414
|
+
constructor() {
|
|
415
|
+
this.options = {
|
|
416
|
+
createTool: true,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Initialize things when DOM is ready. */
|
|
421
|
+
init() {
|
|
422
|
+
// Example link in the tools sidebar
|
|
423
|
+
if (this.options.createTool) {
|
|
424
|
+
var portletId = mw.config.get('skin') === 'timeless' ? 'p-pagemisc' : 'p-tb';
|
|
425
|
+
var linkLabel = 'My gadget dialog';
|
|
426
|
+
var itemId = 'some-unique-gadget-tool';
|
|
427
|
+
var item = mw.util.addPortletLink(portletId, '#', linkLabel, itemId);
|
|
428
|
+
$(item).on('click', function (evt) {
|
|
429
|
+
evt.preventDefault();
|
|
430
|
+
gadget.openDialog();
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Open some dialog. */
|
|
436
|
+
openDialog() {
|
|
437
|
+
// Open a dialog window here
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
module.exports = { MyGadget };
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
This MyGadget class will work with the `main.js` example from the section above.
|
|
445
|
+
|
|
446
|
+
## Appendix: Unit testing
|
|
447
|
+
|
|
448
|
+
Unit testing is important for the stability of tools. Not everything needs to be unit tested, but if you perform any kind of parsing or other complicated tasks, it is a good habit to add automatic tests.
|
|
449
|
+
|
|
450
|
+
There are many testing frameworks, but I mostly use Mocha/Chai. This is mainly because the [Chai assert API](https://www.chaijs.com/api/assert/) is very functional.
|
|
451
|
+
|
|
452
|
+
Below is an example test of `imdb.redir()` function. The test file `test/imdb.test.js`:
|
|
453
|
+
```js
|
|
454
|
+
/* global require, describe, it */
|
|
455
|
+
const { assert } = require('chai');
|
|
456
|
+
const imdb = require('../src/imdb');
|
|
457
|
+
|
|
458
|
+
describe('imdb', function () {
|
|
459
|
+
describe('imdb redir', function () {
|
|
460
|
+
// test function specific to *imdb redir*
|
|
461
|
+
function test(text, expected) {
|
|
462
|
+
// wrap
|
|
463
|
+
let result = imdb.redir(text);
|
|
464
|
+
if (result !== expected) {
|
|
465
|
+
console.log({text, result, expected});
|
|
466
|
+
}
|
|
467
|
+
assert.equal(result, expected);
|
|
468
|
+
}
|
|
469
|
+
// actual test
|
|
470
|
+
it('should resolve redirs', function () {
|
|
471
|
+
test(`[[IMDb.com]]`, `[[IMDb]]`);
|
|
472
|
+
test(`[[IMDb.com|abc]]`, `[[IMDb|abc]]`);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
```
|
|
477
|
+
You don't have to define a `test` function, but having a function like that can help test many different cases quickly.
|
|
478
|
+
|
|
479
|
+
Visual Studio Code will let you run or even debug each `it` function separately, thanks to the *Vscode Test Explorer* extension.
|
|
480
|
+
|
|
481
|
+
## Appendix: Wiki2git
|
|
482
|
+
|
|
483
|
+
So now that we have everthing setup we need code right? If you already have a gadget you might to import it from Wikipedia.
|
|
484
|
+
|
|
485
|
+
```bash
|
|
486
|
+
# install
|
|
487
|
+
npm i -g wiki-to-git
|
|
488
|
+
|
|
489
|
+
# get metadata and insert commits to `src/NavFrame.js`
|
|
490
|
+
wiki2git-load --site pl.wikipedia.org -p "MediaWiki:Gadget-NavFrame.js"
|
|
491
|
+
wiki2git-commit --site pl.wikipedia.org --repo "gadget-NavFrame" -o "src/NavFrame.js"
|
|
492
|
+
|
|
493
|
+
# get metadata and insert commits to `src/NavFrame.css`
|
|
494
|
+
wiki2git-load --site pl.wikipedia.org -p "MediaWiki:Gadget-NavFrame.css"
|
|
495
|
+
wiki2git-commit --site pl.wikipedia.org --repo "gadget-NavFrame" -o "src/NavFrame.css"
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
Note that in the example above `gadget-NavFrame` is a repository folder.
|
|
499
|
+
This can be a repo that already exists or something that you've already setup.
|
package/README.md
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
Wikiploy
|
|
2
2
|
==========================
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Wikiploy is a one-click solution to deploy JS and CSS to Wikipedia.
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
After the initial setup, you can quickly build and deploy your user scripts and gadgets. Though this was designed to work with Wikipedia, you should be able to deploy to any [MediaWiki](https://www.mediawiki.org/)-based wiki. You can even deploy to multiple websites with just one click on your commandbar. Your only limitation is your access level to the wikis.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
See also:
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
- [README: building your project](https://github.com/Eccenux/Wikiploy/blob/main/README.building%20your%20project.md) recommendation on how to build JS and CSS for your gadgets (includes unit testing setup).
|
|
11
|
+
- [Wikipedia:Wikiploy on pl.wiki](https://pl.wikipedia.org/wiki/Wikipedia:Wikiploy) for Polish description.
|
|
12
|
+
- (more links on the bottom)
|
|
12
13
|
|
|
13
|
-
## New
|
|
14
|
+
## New capabilities
|
|
14
15
|
|
|
15
16
|
### nowiki (v1.7)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
The `nowiki` property is a new option in `DeployConfig` since Wikiploy v1.7. It is now recommended to use `nowiki: true` for all JS files.
|
|
19
|
+
```js
|
|
20
|
+
configs.push(new DeployConfig({
|
|
21
|
+
src: 'dist/test.js',
|
|
22
|
+
dst: '~/test.js',
|
|
23
|
+
nowiki: true,
|
|
24
|
+
}));
|
|
25
|
+
```
|
|
18
26
|
|
|
19
27
|
JavaScript page is still a wiki page... Kind of. It can be added to a category or link to other pages. To avoid this use the nowiki option.
|
|
20
28
|
|
|
21
29
|
Don't add this option to CSS though. It won't work correctly.
|
|
22
30
|
|
|
23
|
-
###
|
|
31
|
+
### userPrompt (v1.8)
|
|
32
|
+
|
|
33
|
+
Use the `userPrompt` helper function to prompt for a summary in your Wikiploy script. This is only a helper. You can still set up a static summary, but a prompt helps to ensure you don't forget to change the summary.
|
|
34
|
+
|
|
35
|
+
Note that when using `userPrompt` you have to use an interactive terminal. This might be a bit more tricky to set up but can still function as a one-click build from a commandbar (see [README: building your project](https://github.com/Eccenux/Wikiploy/blob/main/README.building%20your%20project.md)).
|
|
36
|
+
|
|
37
|
+
## Wikiploy types
|
|
38
|
+
|
|
39
|
+
### Wikiploy full (deprecated)
|
|
24
40
|
|
|
25
41
|
This is using [Puppeteer](https://pptr.dev/) to control [Chrome Canary](https://www.google.com/chrome/canary/) or similar. You just open Chrome with remote debug enabled and run a script. The idea is that you are logged in in Chrome and so all edits are still your edits. You can keep the Canary running in the background when you are changing and deploying more stuff.
|
|
26
42
|
|
|
27
43
|
Wikiploy will also work with other Chromium based browser. [Instructions for enabling remote debug in MS Edge](https://learn.microsoft.com/en-us/microsoft-edge/devtools-protocol-chromium/).
|
|
28
44
|
Note that to completely close Edge you might need use settings: Continue running in background when Microsoft Edge is closed (pl. *Kontynuuj działanie aplikacji i rozszerzeń w tle po zamknięciu przeglądarki Microsoft Edge*).
|
|
29
45
|
|
|
30
|
-
### WikiployLite
|
|
46
|
+
### WikiployLite (recommended)
|
|
31
47
|
|
|
32
48
|
The `WikiployLite` class is using a bot API to deploy scripts. You can use standard `Wikiploy` and `WikiployLite` interchangeably. The `DeployConfig` is the same. WikiployLite is recommended as long as you can use it.
|
|
33
49
|
|
|
@@ -40,52 +56,6 @@ Botpass configuration:
|
|
|
40
56
|
|
|
41
57
|
**Warning!** Never, ever publish your bot password. If you do spill your password, reset/remove the password ASAP (on Special:BotPasswords).
|
|
42
58
|
|
|
43
|
-
Example `.gitignore` for your project:
|
|
44
|
-
```
|
|
45
|
-
/node_modules
|
|
46
|
-
*.lnk
|
|
47
|
-
*.priv.*
|
|
48
|
-
bot.config.js
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Basic script and dst
|
|
52
|
-
```js
|
|
53
|
-
import {DeployConfig, Wikiploy, WikiployLite, verlib} from 'wikiploy';
|
|
54
|
-
|
|
55
|
-
// full
|
|
56
|
-
//const ployBot = new Wikiploy();
|
|
57
|
-
// lite
|
|
58
|
-
import * as botpass from './bot.config.js';
|
|
59
|
-
const ployBot = new WikiployLite(botpass);
|
|
60
|
-
|
|
61
|
-
// extra if you want to read your version from the package.json
|
|
62
|
-
const version = await verlib.readVersion('./package.json');
|
|
63
|
-
|
|
64
|
-
// custom summary
|
|
65
|
-
ployBot.summary = () => {
|
|
66
|
-
//return 'v2.7.0: adding new test mode';
|
|
67
|
-
return `v${version}: adding new test mode`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// run asynchronously to be able to wait for results
|
|
71
|
-
(async () => {
|
|
72
|
-
const configs = [];
|
|
73
|
-
configs.push(new DeployConfig({
|
|
74
|
-
src: 'test.js',
|
|
75
|
-
dst: '~/test-wikiploy--test.js',
|
|
76
|
-
nowiki: true,
|
|
77
|
-
}));
|
|
78
|
-
await ployBot.deploy(configs);
|
|
79
|
-
})().catch(err => {
|
|
80
|
-
console.error(err);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Note that `~` will be `User:SomeName` so the user space of a currently logged in user (you user space).
|
|
86
|
-
You can omit `dst` and it will default to `dst: '~/${src}'`.
|
|
87
|
-
|
|
88
|
-
More about this basic code and `dst` in the [Wikiploy rollout example](https://github.com/Eccenux/wikiploy-rollout-example/).
|
|
89
59
|
|
|
90
60
|
## Different wiki sites
|
|
91
61
|
Wikiploy defaults to deployments on `pl.wikipedia.org`.
|
package/assets/test.css
CHANGED
package/assets/test.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiploy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "User scripts and gadgets deployment for MediaWiki (Wikipedia).",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"homepage": "https://github.com/Eccenux/Wikiploy#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"mwn": "2.0.x",
|
|
30
|
-
"puppeteer": "21.
|
|
30
|
+
"puppeteer": "21.6.x"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"bump-version": "0.5.0",
|
package/src/index.js
CHANGED
|
@@ -2,10 +2,12 @@ import DeployConfig from './DeployConfig.js';
|
|
|
2
2
|
import Wikiploy from './Wikiploy.js';
|
|
3
3
|
import WikiployLite from './WikiployLite.js';
|
|
4
4
|
import * as verlib from './version.js';
|
|
5
|
+
import { userPrompt } from './userPrompt.js';
|
|
5
6
|
|
|
6
7
|
export {
|
|
7
8
|
DeployConfig,
|
|
8
9
|
verlib,
|
|
10
|
+
userPrompt,
|
|
9
11
|
WikiployLite,
|
|
10
12
|
Wikiploy
|
|
11
13
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import { stdin as input, stdout as output } from 'node:process';
|
|
3
|
+
|
|
4
|
+
const userPrompt = (prompt) => {
|
|
5
|
+
const rl = readline.createInterface({ input, output });
|
|
6
|
+
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
rl.question(prompt, (summary) => {
|
|
9
|
+
rl.close();
|
|
10
|
+
|
|
11
|
+
resolve(summary);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { userPrompt };
|