wikiploy 1.5.1 → 1.5.4

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.
@@ -0,0 +1,25 @@
1
+ // Requires `gsppvo.vscode-commandbar`.
2
+ // Also: in settings (UI), `files.associations`, add `commandbar.json: jsonc` (json with comments).
3
+ {
4
+ "skipTerminateQuickPick": true,
5
+ "skipSwitchToOutput": false,
6
+ "skipErrorMessage": true,
7
+ "commands": [
8
+ {
9
+ "text": "test",
10
+ "tooltip": "Run mocha tests.",
11
+ "color": "lightgreen",
12
+ "commandType": "script",
13
+ "command": "test",
14
+ "priority": 0
15
+ },
16
+ {
17
+ "text": "check_up",
18
+ "tooltip": "Check update of main deps.",
19
+ "color": "lightgreen",
20
+ "commandType": "exec",
21
+ "command": "php ./check_up.php",
22
+ "priority": 0
23
+ }
24
+ ]
25
+ }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "recommendations": [
3
+ "gsppvo.vscode-commandbar",
3
4
  "hbenl.vscode-test-explorer",
4
5
  "hbenl.vscode-mocha-test-adapter"
5
6
  ]
@@ -13,6 +13,24 @@
13
13
  ],
14
14
  "program": "${workspaceFolder}\\${file}"
15
15
  },
16
+ {
17
+ "name": "Run current PHP",
18
+ "type": "php",
19
+ "request": "launch",
20
+ "program": "${file}",
21
+ "cwd": "${fileDirname}",
22
+ "externalConsole": false,
23
+ "port": 9003
24
+ },
25
+ {
26
+ "name": "Run check_up",
27
+ "type": "php",
28
+ "request": "launch",
29
+ "program": "${workspaceFolder}\\check_up.php",
30
+ "cwd": "${workspaceFolder}",
31
+ "externalConsole": false,
32
+ "port": 9003
33
+ },
16
34
  {
17
35
  "type": "node",
18
36
  "request": "launch",
package/DEV.md CHANGED
@@ -35,24 +35,21 @@ You can also run (and debug) each test case directly from a test file. You might
35
35
 
36
36
  ## Publishing
37
37
 
38
- Step. 1. Check.
38
+ Step 1. Check and update versions.
39
39
  ```bash
40
- git pull
41
- npm up
42
- npm test
40
+ php ./check_up.php
43
41
  ```
44
- If updating Puppeteer, the also:
45
- - Change `assets/test.js` and/or css.
46
- - Run `src/ploy_test_full.js`.
47
- If updating MWN, the also:
48
- - Change `assets/test.js` and/or css.
49
- - Run `src/ploy_test_lite.js`.
50
42
 
51
- Step. 2. Change version in the package.
43
+ Step 2a. Test Puppeteer.
44
+ - Open *Chrome Canary* in *debug* mode.
45
+ - Run `ploy_test_full.js`.
46
+
47
+ Step 2b. Test MWN:
48
+ - Run `ploy_test_lite.js`.
52
49
 
53
- Step. 3. Final commands.
50
+ Step 3. Final commands.
54
51
  ```bash
55
- npm up
52
+ # npm up
56
53
  npm test
57
54
  npm publish
58
55
  ```
package/assets/test.css CHANGED
@@ -5,4 +5,4 @@
5
5
  .tavern {
6
6
  display: block;
7
7
  }
8
- /* puppeteer 21.1.x xor mwn 1.11.x */
8
+ /* puppeteer 21.2.1 xor mwn 1.11.5 */
package/assets/test.js CHANGED
@@ -5,4 +5,4 @@
5
5
  */
6
6
  // test.js
7
7
  console.log('test');
8
- /* puppeteer 21.1.x xor mwn 1.11.x */
8
+ /* puppeteer 21.2.1 xor mwn 1.11.5 */
@@ -0,0 +1,78 @@
1
+ <?php
2
+ /**
3
+ * Check for updates.
4
+ */
5
+ class UpdateChecker {
6
+ private $nodeLocks;
7
+ private $package;
8
+ private $cacheNpm;
9
+ public $hasChanges = false;
10
+ /** modified/checked versions */
11
+ public $versions = array();
12
+
13
+ public function __construct() {
14
+ // Read and decode package-lock.json
15
+ $content = file_get_contents('package-lock.json');
16
+ $this->nodeLocks = json_decode($content, true);
17
+ $content = file_get_contents('package.json');
18
+ $this->package = json_decode($content, true);
19
+
20
+ }
21
+
22
+ /** Get latest version from npm site (cached). */
23
+ private function getNpmVersion($package) {
24
+ if (empty($this->cacheNpm[$package])) {
25
+ $version = exec("npm view $package version");
26
+ $this->cacheNpm[$package] = trim($version);
27
+ }
28
+ return $this->cacheNpm[$package];
29
+ }
30
+
31
+ /**
32
+ * Check package version.
33
+ *
34
+ * @param [type] $package
35
+ * @return $versionFromNpm when updated.
36
+ */
37
+ public function checkPackage($package) {
38
+ if (!isset($this->nodeLocks['packages']['node_modules/'.$package]['version'])) {
39
+ echo "[ERROR] Package $package not found in package-lock.json.\n";
40
+ // throw new Exception("Unexpected: All packages should be there");
41
+ return -1;
42
+ }
43
+
44
+ // Get version from package-lock.json
45
+ $versionFromLock = $this->nodeLocks['packages']['node_modules/'.$package]['version'];
46
+ $this->versions[$package] = $versionFromLock;
47
+
48
+ // Get version from npm site
49
+ $versionFromNpm = $this->getNpmVersion($package);
50
+
51
+ if ($versionFromLock === $versionFromNpm) {
52
+ echo "[INFO] Versions match for $package (no updates).\n";
53
+ return true;
54
+ } else {
55
+ echo "[INFO] Versions differ for $package: $versionFromLock -> $versionFromNpm\n";
56
+ $this->package['dependencies'][$package] = preg_replace("#[0-9]+$#", "x", $versionFromNpm);
57
+ $this->versions[$package] = $versionFromNpm;
58
+ $this->hasChanges = true;
59
+ return $versionFromNpm;
60
+ }
61
+ }
62
+
63
+ /** Update */
64
+ public function save() {
65
+ if ($this->hasChanges) {
66
+ echo "[INFO] Saving changes.\n";
67
+ $data = json_encode($this->package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
68
+ file_put_contents('package.json', $data);
69
+ }
70
+ }
71
+
72
+ public function updateAsset($path) {
73
+ $content = file_get_contents($path);
74
+ $versionInfo = "/* puppeteer {$this->versions['puppeteer']} xor mwn {$this->versions['mwn']} */";
75
+ $content = preg_replace('#/\* puppeteer [0-9.x]+ \w+ mwn [0-9.x]+ \*/#', $versionInfo, $content);
76
+ file_put_contents($path, $content);
77
+ }
78
+ }
@@ -0,0 +1,24 @@
1
+ <?php
2
+ /**
3
+ * Simple executioner.
4
+ *
5
+ * @param string $command
6
+ * @param integer $tail
7
+ * @return void
8
+ */
9
+ function runner($command, $tail=10) {
10
+ exec($command, $output, $retval);
11
+ if ($retval !== 0) {
12
+ echo "[ERROR] Failed to run command ($command) (returned with status $retval)\n";
13
+ } else {
14
+ echo "[INFO] Command ($command) seems OK\n";
15
+ }
16
+ if ($tail > 0) {
17
+ $output = array_slice($output, -$tail);
18
+ }
19
+ foreach($output as $line) {
20
+ echo $line;
21
+ echo "\n";
22
+ }
23
+ echo "\n";
24
+ }
package/check_up.php ADDED
@@ -0,0 +1,27 @@
1
+ <?php
2
+ /**
3
+ * Automated check for updates.
4
+ */
5
+ require_once "./check/UpdateChecker.php";
6
+ require_once "./check/runner.php";
7
+
8
+ runner('git pull', -1);
9
+
10
+ $versionChecker = new UpdateChecker();
11
+ // check and update internals
12
+ $versionChecker->checkPackage("puppeteer");
13
+ $versionChecker->checkPackage("mwn");
14
+ // save
15
+ if ($versionChecker->hasChanges) {
16
+ $versionChecker->save();
17
+ // update test.js/css (puppeteer/mwn version)
18
+ $versionChecker->updateAsset('assets/test.css');
19
+ $versionChecker->updateAsset('assets/test.js');
20
+
21
+ echo "\n[INFO] Bump version\n";
22
+ runner('npm run bump');
23
+ echo "\n[INFO] Update packages and locks\n";
24
+ runner('npm up');
25
+ echo "\n[INFO] Test\n";
26
+ runner('npm test', 3);
27
+ }
package/package.json CHANGED
@@ -1,36 +1,38 @@
1
1
  {
2
- "name": "wikiploy",
3
- "version": "1.5.1",
4
- "description": "User scripts and gadgets deployment for MediaWiki (Wikipedia).",
5
- "main": "src/index.js",
6
- "type": "module",
7
- "scripts": {
8
- "test": "mocha"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/Eccenux/Wikiploy.git"
13
- },
14
- "keywords": [
15
- "Mediawiki",
16
- "Wikipedia",
17
- "deploy",
18
- "rollout",
19
- "gadgets"
20
- ],
21
- "author": "Maciej Nux Jaros",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/Eccenux/Wikiploy/issues"
25
- },
26
- "homepage": "https://github.com/Eccenux/Wikiploy#readme",
27
- "dependencies": {
28
- "mwn": "1.11.x",
29
- "puppeteer": "21.1.x"
30
- },
31
- "devDependencies": {
32
- "chai": "4.x",
33
- "eslint": "8.x",
34
- "mocha": "10.x"
35
- }
2
+ "name": "wikiploy",
3
+ "version": "1.5.4",
4
+ "description": "User scripts and gadgets deployment for MediaWiki (Wikipedia).",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "bump": "bump patch",
9
+ "test": "mocha"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/Eccenux/Wikiploy.git"
14
+ },
15
+ "keywords": [
16
+ "Mediawiki",
17
+ "Wikipedia",
18
+ "deploy",
19
+ "rollout",
20
+ "gadgets"
21
+ ],
22
+ "author": "Maciej Nux Jaros",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/Eccenux/Wikiploy/issues"
26
+ },
27
+ "homepage": "https://github.com/Eccenux/Wikiploy#readme",
28
+ "dependencies": {
29
+ "mwn": "1.11.x",
30
+ "puppeteer": "21.2.x"
31
+ },
32
+ "devDependencies": {
33
+ "bump-version": "0.5.0",
34
+ "chai": "4.x",
35
+ "eslint": "8.x",
36
+ "mocha": "10.x"
37
+ }
36
38
  }