@vexify-org/yaggs 6.1.0 → 6.3.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 CHANGED
@@ -109,6 +109,14 @@ 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
+
116
+ async prompt(questions) {
117
+ return this.parser.prompt(questions);
118
+ }
119
+
112
120
  check(fn) {
113
121
  this.middleware(fn);
114
122
  return this;
package/lib/parser.js CHANGED
@@ -687,6 +687,90 @@ 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
+
718
+ async prompt(questions) {
719
+ const readline = require('readline');
720
+ const rl = readline.createInterface({
721
+ input: process.stdin,
722
+ output: process.stdout
723
+ });
724
+
725
+ const answers = {};
726
+
727
+ for (const question of questions) {
728
+ const answer = await new Promise((resolve) => {
729
+ const defaultVal = question.default !== undefined ? ` (${question.default})` : '';
730
+ const choices = question.choices ? ` [${question.choices.join('/')}]` : '';
731
+ const required = question.required ? '*' : '';
732
+
733
+ rl.question(`\u001b[34m${question.name}${required}${choices}${defaultVal}:\u001b[0m `, (input) => {
734
+ const value = input.trim() || question.default;
735
+
736
+ if (question.required && !value) {
737
+ console.log('\u001b[31mThis field is required!\u001b[0m');
738
+ rl.emit('close');
739
+ resolve(null);
740
+ return;
741
+ }
742
+
743
+ if (question.choices && value && !question.choices.includes(value)) {
744
+ console.log(`\u001b[31mInvalid choice. Must be one of: ${question.choices.join(', ')}\u001b[0m`);
745
+ rl.emit('close');
746
+ resolve(null);
747
+ return;
748
+ }
749
+
750
+ if (question.type === 'number') {
751
+ resolve(parseFloat(value));
752
+ } else if (question.type === 'integer') {
753
+ resolve(parseInt(value, 10));
754
+ } else if (question.type === 'boolean') {
755
+ resolve(['true', '1', 'yes', 'y'].includes(value.toLowerCase()));
756
+ } else {
757
+ resolve(value);
758
+ }
759
+ });
760
+ });
761
+
762
+ if (answer === null) {
763
+ rl.close();
764
+ return null;
765
+ }
766
+
767
+ answers[question.name] = answer;
768
+ }
769
+
770
+ rl.close();
771
+ return answers;
772
+ }
773
+
690
774
  getHelp() {
691
775
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
692
776
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {