thepopebot 1.2.41 → 1.2.42
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/lib/cron.js +16 -10
- package/package.json +1 -1
package/lib/cron.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import cron from 'node-cron';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
4
|
-
import { dirname, join } from 'path';
|
|
3
|
+
import path from 'path';
|
|
5
4
|
import { cronsFile, cronDir } from './paths.js';
|
|
6
5
|
import { executeAction } from './actions.js';
|
|
7
6
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
7
|
+
// Installed version — resolved lazily on first version check.
|
|
8
|
+
// Can't read at module scope because webpack bakes in the build-time path
|
|
9
|
+
// (e.g. /Users/dev/project/...) which doesn't exist at runtime in Docker.
|
|
10
|
+
let _installedVersion = null;
|
|
11
|
+
|
|
12
|
+
function getInstalledVersion() {
|
|
13
|
+
if (!_installedVersion) {
|
|
14
|
+
const pkgPath = path.join(process.cwd(), 'node_modules', 'thepopebot', 'package.json');
|
|
15
|
+
_installedVersion = JSON.parse(fs.readFileSync(pkgPath, 'utf8')).version;
|
|
16
|
+
}
|
|
17
|
+
return _installedVersion;
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
// In-memory flag for available update (read by sidebar, written by cron)
|
|
16
21
|
let _updateAvailable = null;
|
|
@@ -62,8 +67,9 @@ async function runVersionCheck() {
|
|
|
62
67
|
const data = await res.json();
|
|
63
68
|
const latest = data.version;
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const installed = getInstalledVersion();
|
|
71
|
+
if (isVersionNewer(latest, installed)) {
|
|
72
|
+
console.log(`[version check] update available: ${installed} → ${latest}`);
|
|
67
73
|
setUpdateAvailable(latest);
|
|
68
74
|
// Persist to DB
|
|
69
75
|
const { setAvailableVersion } = await import('./db/update-check.js');
|