@waron97/prbot 3.0.3 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waron97/prbot",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -150,9 +150,11 @@ function scoreSections(sections, candidates) {
150
150
  continue;
151
151
  }
152
152
  // Token fallback
153
- const tokens = lc.split(/[\s|_\-.]+/).filter((t) => t.length > 2);
153
+ const tokens = lc.split(/[\s|_\-.]+/).filter((t) => t.length > 1);
154
154
  for (const token of tokens) {
155
- if (heading.includes(token)) score++;
155
+ if (heading.includes(token)) {
156
+ score += /^\d+$/.test(token) ? 5 : 1;
157
+ }
156
158
  }
157
159
  }
158
160
  if (score > 0) results.push({ ...section, score });
package/src/index.js CHANGED
@@ -10,9 +10,19 @@ import { init } from './commands/init.js';
10
10
  import { main as prMain } from './commands/pr.js';
11
11
  import { verbot } from './commands/ver.js';
12
12
  import { CONFIG_FILE } from './config.js';
13
+ import { checkForUpdate, currentVersion } from './lib/updateCheck.js';
13
14
 
14
15
  configDotenv({ path: CONFIG_FILE, quiet: true });
15
16
 
17
+ let _updateAvailable = null;
18
+ checkForUpdate().then((v) => { _updateAvailable = v; });
19
+
20
+ process.on('exit', () => {
21
+ if (_updateAvailable) {
22
+ console.log(`\nUpdate available: ${currentVersion} → ${_updateAvailable}\nRun: prbot update`);
23
+ }
24
+ });
25
+
16
26
  program
17
27
  .command('pr <module>')
18
28
  .option('-b, --bump <level>')
@@ -0,0 +1,60 @@
1
+ import { execFile } from 'child_process';
2
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { CONFIG_DIR } from '../config.js';
6
+
7
+ const CACHE_FILE = path.join(CONFIG_DIR, '.update-check');
8
+ const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const pkg = JSON.parse(readFileSync(path.join(__dirname, '../../package.json'), 'utf8'));
12
+
13
+ export const currentVersion = pkg.version;
14
+
15
+ function semverGt(a, b) {
16
+ const pa = a.split('.').map(Number);
17
+ const pb = b.split('.').map(Number);
18
+ for (let i = 0; i < 3; i++) {
19
+ if (pa[i] > pb[i]) return true;
20
+ if (pa[i] < pb[i]) return false;
21
+ }
22
+ return false;
23
+ }
24
+
25
+ function readCache() {
26
+ try {
27
+ if (!existsSync(CACHE_FILE)) return null;
28
+ const data = JSON.parse(readFileSync(CACHE_FILE, 'utf8'));
29
+ if (Date.now() - new Date(data.checkedAt).getTime() > CACHE_TTL_MS) return null;
30
+ return data.latestVersion;
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ function writeCache(latestVersion) {
37
+ try {
38
+ mkdirSync(CONFIG_DIR, { recursive: true });
39
+ writeFileSync(CACHE_FILE, JSON.stringify({ checkedAt: new Date().toISOString(), latestVersion }));
40
+ } catch {
41
+ // non-critical
42
+ }
43
+ }
44
+
45
+ function fetchLatest() {
46
+ return new Promise((resolve) => {
47
+ execFile('npm', ['view', '@waron97/prbot', 'version'], { timeout: 5000 }, (err, stdout) => {
48
+ if (err) resolve(null);
49
+ else resolve(stdout.trim());
50
+ });
51
+ });
52
+ }
53
+
54
+ export async function checkForUpdate() {
55
+ const cached = readCache();
56
+ const latest = cached ?? (await fetchLatest());
57
+ if (latest && !cached) writeCache(latest);
58
+ if (latest && semverGt(latest, currentVersion)) return latest;
59
+ return null;
60
+ }