phewsh 0.6.1 → 0.7.0
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/phewsh.js +21 -13
- package/package.json +1 -1
package/bin/phewsh.js
CHANGED
|
@@ -79,10 +79,11 @@ function showHelp() {
|
|
|
79
79
|
console.log('');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// Non-blocking update check
|
|
82
|
+
// Non-blocking update check — resolves true if update found
|
|
83
|
+
let _updateDone = false;
|
|
83
84
|
function checkForUpdates() {
|
|
84
85
|
const pkg = require('../package.json');
|
|
85
|
-
fetch(`https://registry.npmjs.org/${pkg.name}/latest`, { signal: AbortSignal.timeout(3000) })
|
|
86
|
+
return fetch(`https://registry.npmjs.org/${pkg.name}/latest`, { signal: AbortSignal.timeout(3000) })
|
|
86
87
|
.then(r => r.json())
|
|
87
88
|
.then(data => {
|
|
88
89
|
if (data.version && data.version !== pkg.version) {
|
|
@@ -91,25 +92,32 @@ function checkForUpdates() {
|
|
|
91
92
|
const isNewer = newer[0] > current[0] || newer[1] > current[1] || newer[2] > current[2];
|
|
92
93
|
if (isNewer) {
|
|
93
94
|
console.log(g(`\n Update available: ${pkg.version} → ${data.version}`));
|
|
94
|
-
console.log(g(` npm install -g phewsh\n`));
|
|
95
|
+
console.log(g(` Run: npm install -g phewsh\n`));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
})
|
|
98
|
-
.catch(() => {})
|
|
99
|
+
.catch(() => {})
|
|
100
|
+
.finally(() => { _updateDone = true; });
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
process.exit(0);
|
|
104
|
-
}
|
|
103
|
+
// Always check for updates (non-blocking)
|
|
104
|
+
const updatePromise = checkForUpdates();
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
process.exit(
|
|
106
|
+
function exitAfterUpdate(code = 0) {
|
|
107
|
+
// If update check already resolved, exit now
|
|
108
|
+
if (_updateDone) return process.exit(code);
|
|
109
|
+
// Otherwise wait up to 2s for it to finish
|
|
110
|
+
updatePromise.then(() => process.exit(code));
|
|
111
|
+
setTimeout(() => process.exit(code), 2000);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
114
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
115
|
+
showHelp();
|
|
116
|
+
exitAfterUpdate(0);
|
|
117
|
+
} else if (command === 'version' || command === '--version' || command === '-v') {
|
|
118
|
+
showVersion();
|
|
119
|
+
exitAfterUpdate(0);
|
|
120
|
+
} else if (COMMANDS[command]) {
|
|
113
121
|
COMMANDS[command]();
|
|
114
122
|
} else {
|
|
115
123
|
console.error(`\n Unknown command: ${command}\n Run 'phewsh help' for available commands.\n`);
|