@h3ravel/shared 0.29.0-alpha.8 → 0.30.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/dist/index.cjs CHANGED
@@ -36,6 +36,8 @@ path = __toESM(path);
36
36
  let inquirer_autocomplete_standalone = require("inquirer-autocomplete-standalone");
37
37
  inquirer_autocomplete_standalone = __toESM(inquirer_autocomplete_standalone);
38
38
  let __inquirer_prompts = require("@inquirer/prompts");
39
+ let ora = require("ora");
40
+ ora = __toESM(ora);
39
41
  let crypto = require("crypto");
40
42
  crypto = __toESM(crypto);
41
43
  let preferred_pm = require("preferred-pm");
@@ -691,39 +693,57 @@ var PathLoader = class {
691
693
  var Prompts = class extends Logger {
692
694
  /**
693
695
  * Allows users to pick from a predefined set of choices when asked a question.
696
+ *
697
+ * @param message Message to display
698
+ * @param choices The choices available to the user
699
+ * @param defaultIndex Item index front of which the cursor will initially appear
700
+ * @param pageSize The number of items to show per page
701
+ * @returns
694
702
  */
695
- static async choice(message, choices, defaultIndex) {
703
+ static async choice(message, choices, defaultIndex, pageSize) {
696
704
  return (0, __inquirer_prompts.select)({
697
705
  message,
698
706
  choices,
699
- default: defaultIndex ? choices.at(defaultIndex) : void 0
707
+ default: defaultIndex ? choices.at(defaultIndex) : void 0,
708
+ pageSize
700
709
  });
701
710
  }
702
711
  /**
703
712
  * Ask the user for a simple "yes or no" confirmation.
704
713
  * By default, this method returns `false`. However, if the user enters y or yes
705
714
  * in response to the prompt, the method would return `true`.
715
+ *
716
+ * @param message Message to display
717
+ * @param defaultValue The default value
706
718
  */
707
- static async confirm(message, def) {
719
+ static async confirm(message, defaultValue) {
708
720
  return (0, __inquirer_prompts.confirm)({
709
721
  message,
710
- default: def
722
+ default: defaultValue
711
723
  });
712
724
  }
713
725
  /**
714
726
  * Prompt the user with the given question, accept their input,
715
727
  * and then return the user's input back to your command.
728
+ *
729
+ * @param message Message to display
730
+ * @param defaultValue The default value
731
+ * @returns
716
732
  */
717
- static async ask(message, def) {
733
+ static async ask(message, defaultValue) {
718
734
  return (0, __inquirer_prompts.input)({
719
735
  message,
720
- default: def
736
+ default: defaultValue
721
737
  });
722
738
  }
723
739
  /**
724
740
  * Prompt the user with the given question, accept their input which
725
741
  * will not be visible to them as they type in the console,
726
742
  * and then return the user's input back to your command.
743
+ *
744
+ * @param message Message to display
745
+ * @param mask Mask the user input
746
+ * @returns
727
747
  */
728
748
  static async secret(message, mask) {
729
749
  return (0, __inquirer_prompts.password)({
@@ -735,14 +755,68 @@ var Prompts = class extends Logger {
735
755
  * Provide auto-completion for possible choices.
736
756
  * The user can still provide any answer, regardless of the auto-completion hints.
737
757
  */
738
- static async anticipate(message, source, def) {
758
+ /**
759
+ *
760
+ * @param message Message to dislpay
761
+ * @param source The source of completions
762
+ * @param defaultValue Set a default value
763
+ * @param pageSize The number of items to show per page
764
+ * @returns
765
+ */
766
+ static async anticipate(message, source, defaultValue, pageSize) {
739
767
  return (0, inquirer_autocomplete_standalone.default)({
740
768
  message,
741
769
  source: Array.isArray(source) ? async (term) => {
742
770
  return (term ? source.filter((e) => e.includes(term)) : source).map((e) => ({ value: e }));
743
771
  } : source,
744
772
  suggestOnly: true,
745
- default: def
773
+ default: defaultValue,
774
+ pageSize
775
+ });
776
+ }
777
+ /**
778
+ * Display a spinner while performing a long task
779
+ *
780
+ * @param options The spinner options
781
+ * @returns
782
+ */
783
+ static spinner(options) {
784
+ return (0, ora.default)(options);
785
+ }
786
+ /**
787
+ * Allows users to select multiple options from a predefined list of choices.
788
+ *
789
+ * @param message Message to display
790
+ * @param choices The choices available to the user
791
+ * @param required Whether at least one choice is required
792
+ * @param prefix Prefix to display before the message
793
+ * @param pageSize The number of items to show per page
794
+ * @returns
795
+ */
796
+ static async checkbox(message, choices, required, prefix, pageSize) {
797
+ return await (0, __inquirer_prompts.checkbox)({
798
+ message,
799
+ choices,
800
+ required,
801
+ prefix,
802
+ pageSize
803
+ });
804
+ }
805
+ /**
806
+ * Open the user's default text editor to accept multi-line input.
807
+ *
808
+ * @param message Message to display
809
+ * @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
810
+ * @param defaultValue The default value to pre-fill in the editor
811
+ * @param validate A function to validate the input text
812
+ * @returns
813
+ */
814
+ static async editor(message, postfix, defaultValue, validate) {
815
+ return await (0, __inquirer_prompts.editor)({
816
+ message: message ?? "Please provide your input in the editor below:",
817
+ postfix,
818
+ default: defaultValue,
819
+ validate
746
820
  });
747
821
  }
748
822
  };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import { Separator } from "@inquirer/prompts";
3
3
  import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
4
4
  import { ChalkInstance } from "chalk";
5
5
  import { ClassConstructor, IPathName } from "@h3ravel/contracts";
6
+ import * as ora0 from "ora";
7
+ import { Options } from "ora";
6
8
 
7
9
  //#region src/Container.d.ts
8
10
  declare const INTERNAL_METHODS: unique symbol;
@@ -423,80 +425,83 @@ declare class PathLoader {
423
425
  declare class Prompts extends Logger {
424
426
  /**
425
427
  * Allows users to pick from a predefined set of choices when asked a question.
428
+ *
429
+ * @param message Message to display
430
+ * @param choices The choices available to the user
431
+ * @param defaultIndex Item index front of which the cursor will initially appear
432
+ * @param pageSize The number of items to show per page
433
+ * @returns
426
434
  */
427
- static choice(
428
- /**
429
- * Message to dislpay
430
- */
431
- message: string,
432
- /**
433
- * The choices available to the user
434
- */
435
- choices: Choices,
436
- /**
437
- * Item index front of which the cursor will initially appear
438
- */
439
- defaultIndex?: number): Promise<string>;
435
+ static choice(message: string, choices: Choices, defaultIndex?: number, pageSize?: number): Promise<string>;
440
436
  /**
441
437
  * Ask the user for a simple "yes or no" confirmation.
442
438
  * By default, this method returns `false`. However, if the user enters y or yes
443
439
  * in response to the prompt, the method would return `true`.
440
+ *
441
+ * @param message Message to display
442
+ * @param defaultValue The default value
444
443
  */
445
- static confirm(
446
- /**
447
- * Message to dislpay
448
- */
449
- message: string,
450
- /**
451
- * The default value
452
- */
453
- def?: boolean | undefined): Promise<boolean>;
444
+ static confirm(message: string, defaultValue?: boolean | undefined): Promise<boolean>;
454
445
  /**
455
446
  * Prompt the user with the given question, accept their input,
456
447
  * and then return the user's input back to your command.
448
+ *
449
+ * @param message Message to display
450
+ * @param defaultValue The default value
451
+ * @returns
457
452
  */
458
- static ask(
459
- /**
460
- * Message to dislpay
461
- */
462
- message: string,
463
- /**
464
- * The default value
465
- */
466
- def?: string | undefined): Promise<string>;
453
+ static ask(message: string, defaultValue?: string | undefined): Promise<string>;
467
454
  /**
468
455
  * Prompt the user with the given question, accept their input which
469
456
  * will not be visible to them as they type in the console,
470
457
  * and then return the user's input back to your command.
471
- */
472
- static secret(
473
- /**
474
- * Message to dislpay
475
- */
476
- message: string,
477
- /**
478
- * Mask the user input
479
458
  *
480
- * @default true
459
+ * @param message Message to display
460
+ * @param mask Mask the user input
461
+ * @returns
481
462
  */
482
- mask?: string | boolean): Promise<string>;
463
+ static secret(message: string, mask?: string | boolean): Promise<string>;
483
464
  /**
484
465
  * Provide auto-completion for possible choices.
485
466
  * The user can still provide any answer, regardless of the auto-completion hints.
486
467
  */
487
- static anticipate(
488
468
  /**
489
- * Message to dislpay
469
+ *
470
+ * @param message Message to dislpay
471
+ * @param source The source of completions
472
+ * @param defaultValue Set a default value
473
+ * @param pageSize The number of items to show per page
474
+ * @returns
490
475
  */
491
- message: string,
476
+ static anticipate(message: string, source: string[] | ((input?: string | undefined) => Promise<ChoiceOrSeparatorArray$1<any>>), defaultValue?: string, pageSize?: number): Promise<any>;
492
477
  /**
493
- * The source of completions
478
+ * Display a spinner while performing a long task
479
+ *
480
+ * @param options The spinner options
481
+ * @returns
482
+ */
483
+ static spinner(options?: string | Options | undefined): ora0.Ora;
484
+ /**
485
+ * Allows users to select multiple options from a predefined list of choices.
486
+ *
487
+ * @param message Message to display
488
+ * @param choices The choices available to the user
489
+ * @param required Whether at least one choice is required
490
+ * @param prefix Prefix to display before the message
491
+ * @param pageSize The number of items to show per page
492
+ * @returns
494
493
  */
495
- source: string[] | ((input?: string | undefined) => Promise<ChoiceOrSeparatorArray$1<any>>),
494
+ static checkbox(message: string, choices: Choices, required?: boolean, prefix?: string, pageSize?: number): Promise<string[]>;
496
495
  /**
497
- * Set a default value
496
+ * Open the user's default text editor to accept multi-line input.
497
+ *
498
+ * @param message Message to display
499
+ * @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
500
+ * @param defaultValue The default value to pre-fill in the editor
501
+ * @param validate A function to validate the input text
502
+ * @returns
498
503
  */
499
- def?: string): Promise<any>;
504
+ static editor(message?: string, postfix?: string, defaultValue?: string, validate?: (text: string) => boolean | string): Promise<string>;
500
505
  }
501
506
  //#endregion
502
507
  //#region src/Utils/Resolver.d.ts
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@ import escalade from "escalade/sync";
4
4
  import { existsSync } from "fs";
5
5
  import path from "path";
6
6
  import autocomplete from "inquirer-autocomplete-standalone";
7
- import { confirm, input, password, select } from "@inquirer/prompts";
7
+ import { checkbox, confirm, editor, input, password, select } from "@inquirer/prompts";
8
+ import ora from "ora";
8
9
  import crypto from "crypto";
9
10
  import preferredPM from "preferred-pm";
10
11
 
@@ -658,39 +659,57 @@ var PathLoader = class {
658
659
  var Prompts = class extends Logger {
659
660
  /**
660
661
  * Allows users to pick from a predefined set of choices when asked a question.
662
+ *
663
+ * @param message Message to display
664
+ * @param choices The choices available to the user
665
+ * @param defaultIndex Item index front of which the cursor will initially appear
666
+ * @param pageSize The number of items to show per page
667
+ * @returns
661
668
  */
662
- static async choice(message, choices, defaultIndex) {
669
+ static async choice(message, choices, defaultIndex, pageSize) {
663
670
  return select({
664
671
  message,
665
672
  choices,
666
- default: defaultIndex ? choices.at(defaultIndex) : void 0
673
+ default: defaultIndex ? choices.at(defaultIndex) : void 0,
674
+ pageSize
667
675
  });
668
676
  }
669
677
  /**
670
678
  * Ask the user for a simple "yes or no" confirmation.
671
679
  * By default, this method returns `false`. However, if the user enters y or yes
672
680
  * in response to the prompt, the method would return `true`.
681
+ *
682
+ * @param message Message to display
683
+ * @param defaultValue The default value
673
684
  */
674
- static async confirm(message, def) {
685
+ static async confirm(message, defaultValue) {
675
686
  return confirm({
676
687
  message,
677
- default: def
688
+ default: defaultValue
678
689
  });
679
690
  }
680
691
  /**
681
692
  * Prompt the user with the given question, accept their input,
682
693
  * and then return the user's input back to your command.
694
+ *
695
+ * @param message Message to display
696
+ * @param defaultValue The default value
697
+ * @returns
683
698
  */
684
- static async ask(message, def) {
699
+ static async ask(message, defaultValue) {
685
700
  return input({
686
701
  message,
687
- default: def
702
+ default: defaultValue
688
703
  });
689
704
  }
690
705
  /**
691
706
  * Prompt the user with the given question, accept their input which
692
707
  * will not be visible to them as they type in the console,
693
708
  * and then return the user's input back to your command.
709
+ *
710
+ * @param message Message to display
711
+ * @param mask Mask the user input
712
+ * @returns
694
713
  */
695
714
  static async secret(message, mask) {
696
715
  return password({
@@ -702,14 +721,68 @@ var Prompts = class extends Logger {
702
721
  * Provide auto-completion for possible choices.
703
722
  * The user can still provide any answer, regardless of the auto-completion hints.
704
723
  */
705
- static async anticipate(message, source, def) {
724
+ /**
725
+ *
726
+ * @param message Message to dislpay
727
+ * @param source The source of completions
728
+ * @param defaultValue Set a default value
729
+ * @param pageSize The number of items to show per page
730
+ * @returns
731
+ */
732
+ static async anticipate(message, source, defaultValue, pageSize) {
706
733
  return autocomplete({
707
734
  message,
708
735
  source: Array.isArray(source) ? async (term) => {
709
736
  return (term ? source.filter((e) => e.includes(term)) : source).map((e) => ({ value: e }));
710
737
  } : source,
711
738
  suggestOnly: true,
712
- default: def
739
+ default: defaultValue,
740
+ pageSize
741
+ });
742
+ }
743
+ /**
744
+ * Display a spinner while performing a long task
745
+ *
746
+ * @param options The spinner options
747
+ * @returns
748
+ */
749
+ static spinner(options) {
750
+ return ora(options);
751
+ }
752
+ /**
753
+ * Allows users to select multiple options from a predefined list of choices.
754
+ *
755
+ * @param message Message to display
756
+ * @param choices The choices available to the user
757
+ * @param required Whether at least one choice is required
758
+ * @param prefix Prefix to display before the message
759
+ * @param pageSize The number of items to show per page
760
+ * @returns
761
+ */
762
+ static async checkbox(message, choices, required, prefix, pageSize) {
763
+ return await checkbox({
764
+ message,
765
+ choices,
766
+ required,
767
+ prefix,
768
+ pageSize
769
+ });
770
+ }
771
+ /**
772
+ * Open the user's default text editor to accept multi-line input.
773
+ *
774
+ * @param message Message to display
775
+ * @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
776
+ * @param defaultValue The default value to pre-fill in the editor
777
+ * @param validate A function to validate the input text
778
+ * @returns
779
+ */
780
+ static async editor(message, postfix, defaultValue, validate) {
781
+ return await editor({
782
+ message: message ?? "Please provide your input in the editor below:",
783
+ postfix,
784
+ default: defaultValue,
785
+ validate
713
786
  });
714
787
  }
715
788
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/shared",
3
- "version": "0.29.0-alpha.8",
3
+ "version": "0.30.0",
4
4
  "description": "Shared Utilities.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,6 +50,7 @@
50
50
  "escalade": "^3.2.0",
51
51
  "h3": "2.0.1-rc.5",
52
52
  "inquirer-autocomplete-standalone": "^0.8.1",
53
+ "ora": "^9.1.0",
53
54
  "preferred-pm": "^4.1.1"
54
55
  },
55
56
  "devDependencies": {