brain-dev 2.0.5 → 2.0.6
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/bin/lib/commands/upgrade.cjs +20 -2
- package/package.json +1 -1
|
@@ -3,6 +3,22 @@ const fs = require('node:fs');
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const { output, prefix } = require('../core.cjs');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Read installed version from brain.json or package.json fallback.
|
|
8
|
+
* @param {string} brainDir
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
function getInstalledVersion(brainDir) {
|
|
12
|
+
try {
|
|
13
|
+
const state = JSON.parse(fs.readFileSync(path.join(brainDir, 'brain.json'), 'utf8'));
|
|
14
|
+
if (state.version && state.version !== 'unknown') return state.version;
|
|
15
|
+
} catch {}
|
|
16
|
+
try {
|
|
17
|
+
return require(path.join(__dirname, '..', '..', '..', 'package.json')).version;
|
|
18
|
+
} catch {}
|
|
19
|
+
return 'unknown';
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
async function run(args = [], opts = {}) {
|
|
7
23
|
const brainDir = opts.brainDir || path.join(process.cwd(), '.brain');
|
|
8
24
|
|
|
@@ -13,12 +29,14 @@ async function run(args = [], opts = {}) {
|
|
|
13
29
|
cache = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
|
|
14
30
|
} catch {}
|
|
15
31
|
|
|
32
|
+
const installed = cache?.installed || getInstalledVersion(brainDir);
|
|
33
|
+
|
|
16
34
|
if (!cache || !cache.update_available) {
|
|
17
35
|
const lines = [
|
|
18
36
|
prefix('You are on the latest version.'),
|
|
19
|
-
prefix(`Installed: ${
|
|
37
|
+
prefix(`Installed: ${installed}`)
|
|
20
38
|
];
|
|
21
|
-
output({ action: 'up-to-date', installed
|
|
39
|
+
output({ action: 'up-to-date', installed }, lines.join('\n'));
|
|
22
40
|
return { action: 'up-to-date' };
|
|
23
41
|
}
|
|
24
42
|
|