Skip to content

Commit

Permalink
Merge pull request #1 from Eccenux/feat/puppet-freedom
Browse files Browse the repository at this point in the history
v2.0 Puppet Freedom aka Pionkio Is Free aka Puppeteer Is No More
  • Loading branch information
Eccenux authored Feb 10, 2024
2 parents 33dc7d9 + 55fd225 commit d811b0c
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 1,070 deletions.
12 changes: 4 additions & 8 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ You can also run (and debug) each test case directly from a test file. You might
Step 1. Check and update versions.
```bash
php ./check_up.php
# npm up
# npm test
```

Step 2a. Test Puppeteer.
- Open *Chrome Canary* in *debug* mode.
- Run `ploy_test_full.js`.

Step 2b. Test MWN:
Step 2. Test MWN:
- Run `ploy_test_lite.js`.

Step 3. Final commands.
Step 3. Publish.
```bash
# npm up
npm test
npm publish
```
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ See also:

## New capabilities

### Lightweight Dependencies (v2.0)

We had a good run, but it's time to bid farewell to the [Puppeteer](https://pptr.dev/) and free the puppets ;). Obviously, this might be a breaking change if you really need to use it. However, the Wikiploy API doesn't really change...

The only change is that you need to provide bot configuration to Wikiploy (as already described for WikiployLite). It's not nothing, but you only need to follow few steps from the [Botpass configuration section](#botpass-configuration). You only need to do it once and then use in all your user scripts.

`WikiployLite` is now a synonym to `Wikiploy`.

### nowiki (v1.7)

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.
Expand All @@ -34,27 +42,20 @@ Use the `userPrompt` helper function to prompt for a summary in your Wikiploy sc

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)).

## Wikiploy types

### Wikiploy full (deprecated)

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.

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/).
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*).
## Using Wikiploy

### WikiployLite (recommended)
The `Wikiploy` class can be used to help deploy scripts. It is using a bot API to do that, but don't worry, you don't need to be a bot ;).

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.
You do need to setup a bot password though (on [[Special:BotPasswords]]). It's not as hard as it might seem as you can do this on any Wikimedia wiki and it will work for all WMF wikis. You don't need a bot account for this to work. You will just create an alias for your stadnard account and special password just for your scripts.

**WikiployLite** is less memory heavy as it doesn't use a browser (and doesn't use `Puppeteer`). You do need to setup a bot password though (on [[Special:BotPasswords]]). It's not as hard as it might seem as you can do this on any Wikimedia wiki and it will work for all WMF wikis. You don't need a bot account for this to work.
## Botpass configuration
A bot password is just a sub-account. It helps to keep things separated and safe.

Botpass configuration:
* Setup on e.g.: https://test.wikipedia.org/wiki/Special:BotPasswords
* Rights you should setup (if you can): `assets\Bot passwords - Test Wikipedia.png`.
* Example config file in: `assets\public--bot.config.mjs`.
1. Setup your sub-account on e.g.: https://test.wikipedia.org/wiki/Special:BotPasswords
2. Choose a name and rights for your sub-account. Example rights you should setup to deploy gadgets (if you can): [assets\Bot passwords - Test Wikipedia.png](https://github.com/Eccenux/Wikiploy/blob/main/assets/Bot%20passwords%20-%20Test%20Wikipedia.png).
3. Create your `bot.config.mjs` file. You can find an example config file in: `assets\public--bot.config.mjs`.

**Warning!** Never, ever publish your bot password. If you do spill your password, reset/remove the password ASAP (on Special:BotPasswords).
**Warning!** Never, ever publish your bot password. If you do spill your password, reset/remove the password ASAP (on [Special:BotPasswords](https://test.wikipedia.org/wiki/Special:BotPasswords)).


## Different wiki sites
Expand Down
2 changes: 1 addition & 1 deletion assets/test.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
.tavern {
display: block;
}
/* puppeteer 22.0.0 xor mwn 2.0.2 */
/*## Wikiploy v2.0.0 with MWN v2.0.2 ##*/
2 changes: 1 addition & 1 deletion assets/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*/
// test.js
console.log('test');
/* puppeteer 22.0.0 xor mwn 2.0.2 */
/*## Wikiploy v2.0.0 with MWN v2.0.2 ##*/
22 changes: 20 additions & 2 deletions check/UpdateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,28 @@ public function save() {
}
}

/**
* Check current version.
*
* Does a fresh read from JSON.
*
* @return $versionFromNpm Version in package.json.
*/
public function checkMain() {
$content = file_get_contents('package.json');
$this->package = json_decode($content, true);
return $this->package['version'];
}

/**
* Update test assest with current versions.
*
* @param string $path Test asset path.
*/
public function updateAsset($path) {
$content = file_get_contents($path);
$versionInfo = "/* puppeteer {$this->versions['puppeteer']} xor mwn {$this->versions['mwn']} */";
$content = preg_replace('#/\* puppeteer [0-9.x]+ \w+ mwn [0-9.x]+ \*/#', $versionInfo, $content);
$versionInfo = "$1 Wikiploy v{$this->package['version']} with MWN v{$this->versions['mwn']} $2";
$content = preg_replace('@(/\*##).+(##\*/)@', $versionInfo, $content);
file_put_contents($path, $content);
}
}
15 changes: 11 additions & 4 deletions check_up.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@

$versionChecker = new UpdateChecker();
// check and update internals
$versionChecker->checkPackage("puppeteer");
// $versionChecker->checkPackage("puppeteer");
$versionChecker->checkPackage("mwn");
// save
if ($versionChecker->hasChanges) {
if (!$versionChecker->hasChanges) {
echo "\n[INFO] No updates for main deps.\n";
} else {
$versionChecker->save();

echo "\n[INFO] Bump version\n";
runner('npm run bump');

$packageVersion = $versionChecker->checkMain(); // check and update internals
echo "\n[INFO] New version: $packageVersion\n";
// update test.js/css (puppeteer/mwn version)
echo "\n[INFO] Update version in assets\n";
$versionChecker->updateAsset('assets/test.css');
$versionChecker->updateAsset('assets/test.js');

echo "\n[INFO] Bump version\n";
runner('npm run bump');
echo "\n[INFO] Update packages and locks\n";
runner('npm up');
echo "\n[INFO] Test\n";
Expand Down
Loading

0 comments on commit d811b0c

Please sign in to comment.