Skip to content

Commit

Permalink
v2.0 automatic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Eccenux committed Feb 10, 2024
1 parent cd82e79 commit 55fd225
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 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
```
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

0 comments on commit 55fd225

Please sign in to comment.