gluegun

  • Version 5.2.0
  • Published
  • 390 kB
  • 30 dependencies
  • MIT license

Install

npm i gluegun
yarn add gluegun
pnpm add gluegun

Overview

A delightful toolkit for building Node-powered CLIs.

Index

Variables

variable filesystem

const filesystem: GluegunFilesystem;

    variable http

    const http: GluegunHttp;

      variable packageManager

      const packageManager: GluegunPackageManager;

        variable patching

        const patching: GluegunPatching;

          variable print

          const print: GluegunPrint;

            variable prompt

            const prompt: GluegunPrompt;
            • We're replicating the interface of Enquirer in order to "lazy load" the package only if and when we actually are asked for it. This results in a significant speed increase.

            variable semver

            const semver: GluegunSemver;
            • We're replicating the interface of semver in order to "lazy load" the package only if and when we actually are asked for it. This results in a significant speed increase.

            variable strings

            const strings: GluegunStrings;

              variable system

              const system: GluegunSystem;

                Functions

                function build

                build: (brand?: string) => Builder;
                • Export it as a factory function.

                Interfaces

                interface GluegunCommand

                interface GluegunCommand<TContext extends Toolbox = Toolbox> {}

                  property alias

                  alias?: string | string[];
                  • Potential other names for this command

                  property commandPath

                  commandPath?: string[];
                  • The command path, an array that describes how to get to this command

                  property dashed

                  dashed?: boolean;
                  • Lets you run the command as a dashed command, like --version or -v.

                  property description

                  description?: string;
                  • A tweet-sized summary of your command

                  property file

                  file?: string;
                  • The path to the file name for this command.

                  property hidden

                  hidden?: boolean;
                  • Should your command be shown in the listings

                  property name

                  name?: string;
                  • The name of your command

                  property plugin

                  plugin?: Plugin;
                  • A reference to the plugin that contains this command.

                  property run

                  run: (toolbox: TContext) => void;
                  • The function for running your command, can be async

                  interface GluegunFilesystem

                  interface GluegunFilesystem extends FSJetpack {}

                    property chmodSync

                    chmodSync: typeof import('fs').chmodSync;
                    • The right-most parameter is considered {to}. Other parameters are considered an array of {from}.

                      Starting from leftmost {from} parameter, resolves {to} to an absolute path.

                      If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

                      Parameter pathSegments

                      string paths to join. Non-string arguments are ignored.

                    property eol

                    eol: string;
                    • Convenience property for os.EOL.

                    property homedir

                    homedir: () => string;
                    • Convenience property for os.homedir function

                    property resolve

                    resolve: typeof import('path').resolve;
                    • The right-most parameter is considered {to}. Other parameters are considered an array of {from}.

                      Starting from leftmost {from} parameter, resolves {to} to an absolute path.

                      If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

                      Parameter pathSegments

                      string paths to join. Non-string arguments are ignored.

                    property separator

                    separator: string;
                    • Convenience property for path.sep.

                    method isDirectory

                    isDirectory: (path: string) => boolean;
                    • Is this a directory?

                    method isFile

                    isFile: (path: string) => boolean;
                    • Is this a file?

                    method isNotDirectory

                    isNotDirectory: (path: string) => boolean;
                    • Is this not a directory?

                    method isNotFile

                    isNotFile: (path: string) => boolean;
                    • Is this not a file?

                    method subdirectories

                    subdirectories: (
                    path: string,
                    isRelative?: boolean,
                    matching?: string
                    ) => string[];
                    • Retrieves a list of subdirectories for a given path.

                    interface GluegunHttp

                    interface GluegunHttp {}

                      method create

                      create: (options: ApisauceConfig) => ApisauceInstance;

                        interface GluegunMeta

                        interface GluegunMeta {}

                          property checkForUpdate

                          checkForUpdate: () => Promise<boolean | string>;

                            property commandInfo

                            commandInfo: () => string[][];

                              property onAbort

                              onAbort: typeof onAbort;

                                property packageJSON

                                packageJSON: () => PackageJSON;

                                  property src

                                  src: string | void;

                                    property version

                                    version: () => string;

                                      interface GluegunParameters

                                      interface GluegunParameters {}

                                        property argv

                                        argv?: any;

                                          property array

                                          array?: string[];

                                            property command

                                            command?: string;

                                              property first

                                              first?: string;

                                                property options

                                                options: Options;
                                                • Any optional parameters. Typically coming from command-line arguments like this: --force -p tsconfig.json.

                                                property plugin

                                                plugin?: string;

                                                  property raw

                                                  raw?: any;

                                                    property second

                                                    second?: string;

                                                      property string

                                                      string?: string;

                                                        property third

                                                        third?: string;

                                                          interface GluegunPatching

                                                          interface GluegunPatching {}

                                                            method append

                                                            append: (filename: string, contents: string) => Promise<string | boolean>;
                                                            • Appends to the end of a file.

                                                            method exists

                                                            exists: (filename: string, findPattern: string | RegExp) => Promise<boolean>;
                                                            • Checks if a string or pattern exists in a file.

                                                            method patch

                                                            patch: (
                                                            filename: string,
                                                            ...options: GluegunPatchingPatchOptions[]
                                                            ) => Promise<string | boolean>;
                                                            • Makes a patch inside file.

                                                            method prepend

                                                            prepend: (filename: string, contents: string) => Promise<string | boolean>;
                                                            • Prepends to the start of a files.

                                                            method replace

                                                            replace: (
                                                            filename: string,
                                                            searchFor: string,
                                                            replaceWith: string
                                                            ) => Promise<string | boolean>;
                                                            • Replaces part of a file.

                                                            method update

                                                            update: (
                                                            filename: string,
                                                            callback: (contents: any) => any
                                                            ) => Promise<string | object | boolean>;
                                                            • Updates a file.

                                                            interface GluegunPatchingPatchOptions

                                                            interface GluegunPatchingPatchOptions {}

                                                              property after

                                                              after?: string | RegExp;

                                                                property before

                                                                before?: string | RegExp;

                                                                  property delete

                                                                  delete?: string | RegExp;

                                                                    property force

                                                                    force?: boolean;

                                                                      property insert

                                                                      insert?: string;

                                                                        property replace

                                                                        replace?: string | RegExp;

                                                                          interface GluegunPrint

                                                                          interface GluegunPrint {}

                                                                            property checkmark

                                                                            checkmark: string;

                                                                              property colors

                                                                              colors: GluegunPrintColors;

                                                                                property columnHeaderDivider

                                                                                columnHeaderDivider: (cliTable: CLITable, style: TableStyle) => string[];

                                                                                  property debug

                                                                                  debug: (value: any, title?: string) => void;

                                                                                    property divider

                                                                                    divider: () => void;

                                                                                      property error

                                                                                      error: (message: any) => void;

                                                                                        property fancy

                                                                                        fancy: (value: string) => void;

                                                                                          property findWidths

                                                                                          findWidths: (cliTable: CLITable) => number[];

                                                                                            property highlight

                                                                                            highlight: (message: any) => void;

                                                                                              property info

                                                                                              info: (message: any) => void;

                                                                                                property muted

                                                                                                muted: (message: any) => void;

                                                                                                  property newline

                                                                                                  newline: () => void;

                                                                                                    property success

                                                                                                    success: (message: any) => void;

                                                                                                      property table

                                                                                                      table: (data: string[][], options?: GluegunPrintTableOptions) => void;

                                                                                                        property warning

                                                                                                        warning: (message: any) => void;

                                                                                                          property xmark

                                                                                                          xmark: string;

                                                                                                            method printCommands

                                                                                                            printCommands: (toolbox: Toolbox, commandRoot?: string[]) => void;

                                                                                                              method printHelp

                                                                                                              printHelp: (toolbox: GluegunToolbox) => void;

                                                                                                                method spin

                                                                                                                spin: (options?: ora.Options | string) => ora.Ora;

                                                                                                                  interface GluegunPrompt

                                                                                                                  interface GluegunPrompt {}

                                                                                                                    method ask

                                                                                                                    ask: <T = GluegunAskResponse>(
                                                                                                                    questions:
                                                                                                                    | PromptOptions
                                                                                                                    | ((this: GluegunEnquirer) => PromptOptions)
                                                                                                                    | (PromptOptions | ((this: GluegunEnquirer) => PromptOptions))[]
                                                                                                                    ) => Promise<T>;

                                                                                                                      method confirm

                                                                                                                      confirm: (message: string, initial?: boolean) => Promise<boolean>;

                                                                                                                        method separator

                                                                                                                        separator: () => string;

                                                                                                                          interface GluegunSemver

                                                                                                                          interface GluegunSemver {}

                                                                                                                            method clean

                                                                                                                            clean: (version: string) => string | null;

                                                                                                                              method gt

                                                                                                                              gt: (version: string, isGreaterThanVersion: string) => boolean;

                                                                                                                                method lt

                                                                                                                                lt: (version: string, isLessThanVersion: string) => boolean;

                                                                                                                                  method satisfies

                                                                                                                                  satisfies: (version: string, inVersion: string) => boolean;

                                                                                                                                    method valid

                                                                                                                                    valid: (version: string) => string | null;

                                                                                                                                      method validRange

                                                                                                                                      validRange: (range: string) => boolean | null;

                                                                                                                                        interface GluegunStrings

                                                                                                                                        interface GluegunStrings {}

                                                                                                                                          method addIrregularRule

                                                                                                                                          addIrregularRule: (single: string, plural: string) => void;
                                                                                                                                          • Add an irregular word definition.

                                                                                                                                          method addPluralRule

                                                                                                                                          addPluralRule: (rule: string | RegExp, replacement: string) => void;
                                                                                                                                          • Add a pluralization rule to the collection.

                                                                                                                                          method addSingularRule

                                                                                                                                          addSingularRule: (rule: string | RegExp, replacement: string) => void;
                                                                                                                                          • Add a singularization rule to the collection.

                                                                                                                                          method addUncountableRule

                                                                                                                                          addUncountableRule: (word: string | RegExp) => void;
                                                                                                                                          • Add an uncountable word rule.

                                                                                                                                          method camelCase

                                                                                                                                          camelCase: (value: string) => string;
                                                                                                                                          • Converts a string toCamelCase.

                                                                                                                                          method identity

                                                                                                                                          identity: (value: string) => string;
                                                                                                                                          • Returns itself.

                                                                                                                                          method isBlank

                                                                                                                                          isBlank: (value: string) => boolean;
                                                                                                                                          • Is this string blank, null, or otherwise empty?

                                                                                                                                          method isNotString

                                                                                                                                          isNotString: (value: any) => boolean;
                                                                                                                                          • This is not a string? Are you not entertained?

                                                                                                                                          method isPlural

                                                                                                                                          isPlural: (word: string) => boolean;
                                                                                                                                          • Test if provided word is plural.

                                                                                                                                          method isSingular

                                                                                                                                          isSingular: (word: string) => boolean;
                                                                                                                                          • Test if provided word is singular.

                                                                                                                                          method kebabCase

                                                                                                                                          kebabCase: (value: string) => string;
                                                                                                                                          • Converts a string to-kebab-case.

                                                                                                                                          method lowerCase

                                                                                                                                          lowerCase: (value: string) => string;
                                                                                                                                          • Converts a string to lower case.

                                                                                                                                          method lowerFirst

                                                                                                                                          lowerFirst: (value: string) => string;
                                                                                                                                          • Converts the first character oF eVERY wORD tO lOWER.

                                                                                                                                          method pad

                                                                                                                                          pad: (sourceString: string, length: number, chars?: string) => string;
                                                                                                                                          • Pads a string with chars (spaces default) to length characters long, effectively centering the string.

                                                                                                                                          method padEnd

                                                                                                                                          padEnd: (sourceString: string, length: number, chars?: string) => string;
                                                                                                                                          • Pads the end of string with chars (spaces default) to length characters.

                                                                                                                                          method padStart

                                                                                                                                          padStart: (sourceString: string, length: number, chars?: string) => string;
                                                                                                                                          • Pads the start of string with chars (spaces default) to length characters.

                                                                                                                                          method pascalCase

                                                                                                                                          pascalCase: (value: string) => string;
                                                                                                                                          • Converts a string ToPascalCase.

                                                                                                                                          method plural

                                                                                                                                          plural: (word: string) => string;
                                                                                                                                          • Pluralize a word based.

                                                                                                                                          method pluralize

                                                                                                                                          pluralize: (word: string, count?: number, inclusive?: boolean) => string;
                                                                                                                                          • Pluralize or singularize a word based on the passed in count.

                                                                                                                                          method repeat

                                                                                                                                          repeat: (sourceString: string, numberOfTimes: number) => string;
                                                                                                                                          • Repeats a string a numberOfTimes.

                                                                                                                                          method singular

                                                                                                                                          singular: (word: string) => string;
                                                                                                                                          • Singularize a word based.

                                                                                                                                          method snakeCase

                                                                                                                                          snakeCase: (value: string) => string;
                                                                                                                                          • Converts a string to_snake_case.

                                                                                                                                          method startCase

                                                                                                                                          startCase: (value: string) => string;
                                                                                                                                          • Converts a string To start case.

                                                                                                                                          method trim

                                                                                                                                          trim: (sourceString: string, chars?: string) => string;
                                                                                                                                          • Strips whitespace from a string.

                                                                                                                                          method trimEnd

                                                                                                                                          trimEnd: (sourceString: string, chars?: string) => string;
                                                                                                                                          • Strips whitespace from the end of a string.

                                                                                                                                          method trimStart

                                                                                                                                          trimStart: (sourceString: string, chars?: string) => string;
                                                                                                                                          • Strips whitespace from the start of a string.

                                                                                                                                          method upperCase

                                                                                                                                          upperCase: (value: string) => string;
                                                                                                                                          • Converts a string TO UPPER CASE.

                                                                                                                                          method upperFirst

                                                                                                                                          upperFirst: (value: string) => string;
                                                                                                                                          • Converts the first character Of Every Word To Upper.

                                                                                                                                          interface GluegunSystem

                                                                                                                                          interface GluegunSystem {}

                                                                                                                                            method exec

                                                                                                                                            exec: (command: string, options?: any) => Promise<any>;
                                                                                                                                            • Executes a command via execa.

                                                                                                                                            method run

                                                                                                                                            run: (command: string, options?: any) => Promise<string>;
                                                                                                                                            • Runs a command and returns stdout as a trimmed string.

                                                                                                                                            method spawn

                                                                                                                                            spawn: (command: string, options?: any) => Promise<any>;
                                                                                                                                            • Spawns a command via crosspawn.

                                                                                                                                            method startTimer

                                                                                                                                            startTimer: () => GluegunTimer;
                                                                                                                                            • Returns a timer function that starts from this moment. Calling this function will return the number of milliseconds from when it was started.

                                                                                                                                            method which

                                                                                                                                            which: (command: string) => string | void;
                                                                                                                                            • Uses node-which to find out where the command lines.

                                                                                                                                            interface GluegunTemplate

                                                                                                                                            interface GluegunTemplate {}

                                                                                                                                              method generate

                                                                                                                                              generate: (options: GluegunTemplateGenerateOptions) => Promise<string>;

                                                                                                                                                interface GluegunToolbox

                                                                                                                                                interface GluegunToolbox extends GluegunEmptyToolbox {}

                                                                                                                                                  property command

                                                                                                                                                  command?: Command;

                                                                                                                                                    property commandName

                                                                                                                                                    commandName?: string;

                                                                                                                                                      property config

                                                                                                                                                      config: Options;

                                                                                                                                                        property filesystem

                                                                                                                                                        filesystem: GluegunFilesystem;

                                                                                                                                                          property generate

                                                                                                                                                          generate: any;

                                                                                                                                                            property http

                                                                                                                                                            http: GluegunHttp;

                                                                                                                                                              property meta

                                                                                                                                                              meta: GluegunMeta;

                                                                                                                                                                property packageManager

                                                                                                                                                                packageManager: GluegunPackageManager;

                                                                                                                                                                  property parameters

                                                                                                                                                                  parameters: GluegunParameters;

                                                                                                                                                                    property patching

                                                                                                                                                                    patching: GluegunPatching;

                                                                                                                                                                      property plugin

                                                                                                                                                                      plugin?: Plugin;

                                                                                                                                                                        property pluginName

                                                                                                                                                                        pluginName?: string;

                                                                                                                                                                          property print

                                                                                                                                                                          print: GluegunPrint;

                                                                                                                                                                            property prompt

                                                                                                                                                                            prompt: GluegunPrompt;

                                                                                                                                                                              property result

                                                                                                                                                                              result?: any;

                                                                                                                                                                                property runtime

                                                                                                                                                                                runtime?: Runtime;

                                                                                                                                                                                  property semver

                                                                                                                                                                                  semver: GluegunSemver;

                                                                                                                                                                                    property strings

                                                                                                                                                                                    strings: GluegunStrings;

                                                                                                                                                                                      property system

                                                                                                                                                                                      system: GluegunSystem;

                                                                                                                                                                                        property template

                                                                                                                                                                                        template: GluegunTemplate;

                                                                                                                                                                                          Type Aliases

                                                                                                                                                                                          type GluegunPackageManager

                                                                                                                                                                                          type GluegunPackageManager = {
                                                                                                                                                                                          add: (
                                                                                                                                                                                          packageName: string | string[],
                                                                                                                                                                                          options: GluegunPackageManagerOptions
                                                                                                                                                                                          ) => Promise<GluegunPackageManagerResult>;
                                                                                                                                                                                          remove: (
                                                                                                                                                                                          packageName: string | string[],
                                                                                                                                                                                          options: GluegunPackageManagerOptions
                                                                                                                                                                                          ) => Promise<GluegunPackageManagerResult>;
                                                                                                                                                                                          hasYarn: () => boolean;
                                                                                                                                                                                          };

                                                                                                                                                                                            type GluegunRunContext

                                                                                                                                                                                            type GluegunRunContext = GluegunToolbox;

                                                                                                                                                                                              Package Files (24)

                                                                                                                                                                                              Dependencies (30)

                                                                                                                                                                                              Dev Dependencies (33)

                                                                                                                                                                                              Peer Dependencies (0)

                                                                                                                                                                                              No peer dependencies.

                                                                                                                                                                                              Badge

                                                                                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/gluegun.

                                                                                                                                                                                              • Markdown
                                                                                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/gluegun)
                                                                                                                                                                                              • HTML
                                                                                                                                                                                                <a href="https://www.jsdocs.io/package/gluegun"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>