@david_was/nenna 0.1.1 → 0.1.2
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/cli/nenna.js +58 -0
- package/package.json +1 -1
- package/publish/nenna.deps.json +2 -2
- package/publish/nenna.dll +0 -0
- package/publish/nenna.pdb +0 -0
package/cli/nenna.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require('fs');
|
|
6
|
+
const https = require('https');
|
|
6
7
|
const { spawnSync } = require('child_process');
|
|
7
8
|
|
|
8
9
|
const dllPath = path.join(__dirname, '..', 'publish', 'nenna.dll');
|
|
@@ -17,6 +18,55 @@ if (!fs.existsSync(dllPath)) {
|
|
|
17
18
|
process.exit(1);
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
// Check for a newer npm version in the background.
|
|
22
|
+
// Reads the installed version from package.json; fetches the latest published
|
|
23
|
+
// version from the npm registry. Runs after the dotnet process exits so it
|
|
24
|
+
// never blocks or slows down the actual CLI invocation.
|
|
25
|
+
function checkForUpdate(currentVersion) {
|
|
26
|
+
const pkgName = '@david_was/nenna';
|
|
27
|
+
const url = `https://registry.npmjs.org/${encodeURIComponent(pkgName)}/latest`;
|
|
28
|
+
|
|
29
|
+
const req = https.get(url, { timeout: 5000 }, (res) => {
|
|
30
|
+
let body = '';
|
|
31
|
+
res.on('data', (chunk) => { body += chunk; });
|
|
32
|
+
res.on('end', () => {
|
|
33
|
+
try {
|
|
34
|
+
const latest = JSON.parse(body).version;
|
|
35
|
+
if (latest && latest !== currentVersion && isNewer(latest, currentVersion)) {
|
|
36
|
+
process.stderr.write(
|
|
37
|
+
`\n Update available: ${currentVersion} → ${latest}\n` +
|
|
38
|
+
` Run: npm install -g ${pkgName}\n\n`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
// Ignore parse errors – the check is best-effort.
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
req.on('error', () => { /* Ignore network errors – check is best-effort. */ });
|
|
48
|
+
req.on('timeout', () => { req.destroy(); });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Returns true when `a` is strictly greater than `b` using semver ordering.
|
|
52
|
+
function isNewer(a, b) {
|
|
53
|
+
const parse = (v) => String(v).split('.').map((n) => parseInt(n, 10) || 0);
|
|
54
|
+
const [aMaj, aMin, aPat] = parse(a);
|
|
55
|
+
const [bMaj, bMin, bPat] = parse(b);
|
|
56
|
+
if (aMaj !== bMaj) return aMaj > bMaj;
|
|
57
|
+
if (aMin !== bMin) return aMin > bMin;
|
|
58
|
+
return aPat > bPat;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Read the version from the package.json that ships alongside this file.
|
|
62
|
+
let currentVersion = null;
|
|
63
|
+
try {
|
|
64
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
65
|
+
currentVersion = pkg.version || null;
|
|
66
|
+
} catch {
|
|
67
|
+
// If the file is unreadable the update check is simply skipped.
|
|
68
|
+
}
|
|
69
|
+
|
|
20
70
|
const args = process.argv.slice(2);
|
|
21
71
|
const result = spawnSync('dotnet', [dllPath, ...args], { stdio: 'inherit' });
|
|
22
72
|
|
|
@@ -34,4 +84,12 @@ if (result.error) {
|
|
|
34
84
|
process.exit(1);
|
|
35
85
|
}
|
|
36
86
|
|
|
87
|
+
// Start the background update check after the main process finishes.
|
|
88
|
+
// unref() ensures the check does not keep the Node process alive if
|
|
89
|
+
// everything else has already completed.
|
|
90
|
+
if (currentVersion) {
|
|
91
|
+
const handle = setImmediate(() => checkForUpdate(currentVersion));
|
|
92
|
+
if (handle.unref) handle.unref();
|
|
93
|
+
}
|
|
94
|
+
|
|
37
95
|
process.exit(result.status === null ? 1 : result.status);
|
package/package.json
CHANGED
package/publish/nenna.deps.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"compilationOptions": {},
|
|
7
7
|
"targets": {
|
|
8
8
|
".NETCoreApp,Version=v10.0": {
|
|
9
|
-
"nenna/0.1.
|
|
9
|
+
"nenna/0.1.2": {
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"Spectre.Console": "0.57.2"
|
|
12
12
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"libraries": {
|
|
39
|
-
"nenna/0.1.
|
|
39
|
+
"nenna/0.1.2": {
|
|
40
40
|
"type": "project",
|
|
41
41
|
"serviceable": false,
|
|
42
42
|
"sha512": ""
|
package/publish/nenna.dll
CHANGED
|
Binary file
|
package/publish/nenna.pdb
CHANGED
|
Binary file
|