@vexify-org/yaggs 6.1.0 → 6.2.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/index.js +4 -0
- package/lib/parser.js +28 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -109,6 +109,10 @@ class Yaggs {
|
|
|
109
109
|
return this.parser.generateCompletion(shell);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
async checkVersion(packageName, currentVersion) {
|
|
113
|
+
return this.parser.checkVersion(packageName, currentVersion);
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
check(fn) {
|
|
113
117
|
this.middleware(fn);
|
|
114
118
|
return this;
|
package/lib/parser.js
CHANGED
|
@@ -687,6 +687,34 @@ complete -c ${this.scriptName} `;
|
|
|
687
687
|
return completion;
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
+
async checkVersion(packageName, currentVersion) {
|
|
691
|
+
try {
|
|
692
|
+
const https = require('https');
|
|
693
|
+
return new Promise((resolve) => {
|
|
694
|
+
https.get(`https://registry.npmjs.org/${packageName}/latest`, (res) => {
|
|
695
|
+
let data = '';
|
|
696
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
697
|
+
res.on('end', () => {
|
|
698
|
+
try {
|
|
699
|
+
const latest = JSON.parse(data);
|
|
700
|
+
if (latest.version && latest.version !== currentVersion) {
|
|
701
|
+
console.log(`\u001b[33mUpdate available: ${packageName} ${currentVersion} → ${latest.version}\u001b[0m`);
|
|
702
|
+
console.log(`\u001b[36mRun: npm install -g ${packageName}\u001b[0m`);
|
|
703
|
+
}
|
|
704
|
+
resolve(latest.version);
|
|
705
|
+
} catch {
|
|
706
|
+
resolve(null);
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}).on('error', () => {
|
|
710
|
+
resolve(null);
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
} catch {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
690
718
|
getHelp() {
|
|
691
719
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
692
720
|
|