@vexify-org/yaggs 6.0.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 +41 -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
|
@@ -41,6 +41,7 @@ class ArgumentParser {
|
|
|
41
41
|
hidden: config.hidden || false,
|
|
42
42
|
conflicts: config.conflicts || [],
|
|
43
43
|
implies: config.implies || {},
|
|
44
|
+
global: config.global !== undefined ? config.global : true,
|
|
44
45
|
...config
|
|
45
46
|
};
|
|
46
47
|
|
|
@@ -413,6 +414,18 @@ class ArgumentParser {
|
|
|
413
414
|
this._handleError(`Not a directory: ${fullPath}`);
|
|
414
415
|
}
|
|
415
416
|
result[name] = fullPath;
|
|
417
|
+
} else if (opt.type === 'date') {
|
|
418
|
+
const date = new Date(value);
|
|
419
|
+
if (isNaN(date.getTime())) {
|
|
420
|
+
this._handleError(`Invalid date for option '${name}'`);
|
|
421
|
+
}
|
|
422
|
+
result[name] = date;
|
|
423
|
+
} else if (opt.type === 'regex') {
|
|
424
|
+
try {
|
|
425
|
+
result[name] = new RegExp(value);
|
|
426
|
+
} catch {
|
|
427
|
+
this._handleError(`Invalid regex for option '${name}'`);
|
|
428
|
+
}
|
|
416
429
|
} else if (opt.type === 'custom' && opt._customType) {
|
|
417
430
|
result[name] = opt._customType(value);
|
|
418
431
|
}
|
|
@@ -674,6 +687,34 @@ complete -c ${this.scriptName} `;
|
|
|
674
687
|
return completion;
|
|
675
688
|
}
|
|
676
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
|
+
|
|
677
718
|
getHelp() {
|
|
678
719
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
679
720
|
|