Variable UtilsConst

Utils: {
    Hook: typeof Hook;
    _: LoDashStatic;
    chalk: Chalk & ChalkFunction & {};
    clearConsole: (() => void);
    color: Colors & {};
    config: ((key?, defaultValue?) => any);
    consoleReader: ((content, opts?) => string | true);
    day: typeof dayjs;
    debug: Debug & {};
    debugCore: ((...args) => any);
    delay: ((ms) => Promise<unknown>);
    envinfo: __module;
    error: ((message, exit?, errorCode?) => void);
    exec: ((command, options?) => any);
    extendConfig: ((extendRcPath, prefix?) => any);
    extendSubCommand: ((command, moduleName, yargs, basePath) => void);
    fileExistsSyncCache: ((filePath) => any);
    formatRcOptions: ((opts) => object);
    fs: __module;
    getAbsolutePath: ((filePath) => string);
    getAllPluginsMapping: ((argv?) => {
        [propName: string]: string;
    });
    getApplicationConfig: ((opts?) => any);
    getCache: ((namespace) => NodeCache);
    getCombinedConfig: ((argv?) => {
        [propName: string]: any;
    });
    getInternalCache: (() => NodeCache);
    getNodeEnv: ((argv?) => string);
    importPackage: ((name, location?, home?, force?) => string);
    info: ((message, exit?, errorCode?) => void);
    installPackage: ((name, location?, home?, force?) => void);
    invokeHook: (<T>(hook?, options?, argv?) => Promise<T>);
    isDevelopment: (() => boolean);
    isProduction: (() => boolean);
    isPromise: ((obj) => boolean);
    launchDispatcher: ((opts?) => Promise<void>);
    loadCorePackageInfo: (() => any);
    loadPackageInfo: ((pkg?, paths?) => any);
    loadPluginRc: ((name, location?, home?) => any);
    log: ((message) => void);
    md5: ((s) => string);
    outputTable: ((columns, caption?, borderOptions?) => void);
    parsePackageNames: ((input) => string[]);
    pluginConfig: ((key, defaultValue?) => any);
    replHistory: ((repl, file) => void);
    resolvePackage: ((name, location?, home?) => string);
    run: ((func, getPath?, ...args) => Promise<any>);
    shell: __module;
    sleep: ((ms) => Promise<unknown>);
    splitByChar: ((input, char) => string[]);
    splitComma: ((input) => string[]);
    success: ((message, exit?, errorCode?) => void);
    uninstallPackage: ((name, location?, home?) => void);
    useDotEnv: ((expand, options?) => void);
    warn: ((message, exit?, errorCode?) => void);
    yaml: __module;
    yargs: Argv<{}>;
} = ...

Type declaration

  • Hook: typeof Hook
  • _: LoDashStatic
  • chalk: Chalk & ChalkFunction & {}
  • clearConsole: (() => void)
      • (): void
      • Clear console

        Returns void

  • color: Colors & {}

    picocolors reference

  • config: ((key?, defaultValue?) => any)
      • (key?, defaultValue?): any
      • Get current argv config

        Parameters

        • key: any = undefined
        • defaultValue: any = undefined

        Returns any

  • consoleReader: ((content, opts?) => string | true)
      • (content, opts?): string | true
      • Console Reader

        Mostly use less mode, if HOME can not be detected, it will fallback to console.log

        Parameters

        • content: string

          The content to read

        • opts: {
              identifier?: string;
              plugin?: string;
              tmpPathOnly?: boolean;
          } = {}
          • Optional identifier?: string
          • Optional plugin?: string
          • Optional tmpPathOnly?: boolean

        Returns string | true

  • day: typeof dayjs
  • debug: Debug & {}
  • debugCore: ((...args) => any)
      • (...args): any
      • debug core

        Parameters

        • Rest ...args: any[]

        Returns any

  • delay: ((ms) => Promise<unknown>)
      • (ms): Promise<unknown>
      • Sleep a while of ms

        Parameters

        • ms: number

        Returns Promise<unknown>

  • envinfo: __module
  • error: ((message, exit?, errorCode?) => void)
      • (message, exit?, errorCode?): void
      • Print error message, and exit process.

        Parameters

        • message: any

          Error message to log

        • exit: boolean = true
        • errorCode: number = 1

          Error code

        Returns void

  • exec: ((command, options?) => any)
      • (command, options?): any
      • Execute command, because npm install running info can not be catched by shelljs, temporarily use this one

        Parameters

        • command: string

          Command to exec

        • options: any = {}

          Options stdio default is [0, 1, 2]

        Returns any

  • extendConfig: ((extendRcPath, prefix?) => any)
      • (extendRcPath, prefix?): any
      • Attach config info in another file to argv config

        This is often for Application usage

        Parameters

        • extendRcPath: string | string[]
        • prefix: any = undefined

        Returns any

  • extendSubCommand: ((command, moduleName, yargs, basePath) => void)
      • (command, moduleName, yargs, basePath): void
      • Extend command's sub command, it give other plugins an opportunity to extend it's sub command. So if you want other plugins to extend your sub commands, you can use this util function to replace default yargs.commandDir

        Parameters

        • command: string

          Current command name.

        • moduleName: string
        • yargs: any

          Yargs reference.

        • basePath: string

          Often set to __dirname.

        Returns void

        Example

        exports.builder = function (yargs) {
        // The first param could be a/b/c if you want to extend subcommand's subcommand
        Utils.extendSubCommand('make', 'semo', yargs, __dirname)
        }
  • fileExistsSyncCache: ((filePath) => any)
      • (filePath): any
      • Parameters

        • filePath: any

        Returns any

  • formatRcOptions: ((opts) => object)
      • (opts): object
      • Format options keys

        Make compatible of param cases and camel cases

        Parameters

        • opts: any

        Returns object

  • fs: __module
  • getAbsolutePath: ((filePath) => string)
      • (filePath): string
      • Get absolute path or dir, this func will not judge if exist

        Parameters

        • filePath: string

        Returns string

  • getAllPluginsMapping: ((argv?) => {
        [propName: string]: string;
    })
      • (argv?): {
            [propName: string]: string;
        }
      • Parameters

        • argv: any = {}

        Returns {
            [propName: string]: string;
        }

        • [propName: string]: string
  • getApplicationConfig: ((opts?) => any)
      • (opts?): any
      • Get application semo config only.

        Parameters

        • opts: any = {}

          opts.scriptName: set scriptName

        Returns any

  • getCache: ((namespace) => NodeCache)
      • (namespace): NodeCache
      • Get Semo cache instance by namespace

        Parameters

        • namespace: string

        Returns NodeCache

  • getCombinedConfig: ((argv?) => {
        [propName: string]: any;
    })
      • (argv?): {
            [propName: string]: any;
        }
      • Get commbined config from whole environment.

        Parameters

        • argv: any = {}

        Returns {
            [propName: string]: any;
        }

        • [propName: string]: any
  • getInternalCache: (() => NodeCache)
      • (): NodeCache
      • Get Semo internal cache instance

        Returns NodeCache

  • getNodeEnv: ((argv?) => string)
      • (argv?): string
      • Get current node env setting

        You can change the node-env-key in command args or semo rc file

        Parameters

        • argv: any = null

        Returns string

  • importPackage: ((name, location?, home?, force?) => string)
      • (name, location?, home?, force?): string
      • Import a package on runtime

        If not exist, will install first,

        Parameters

        • name: any

          Package name

        • location: string = ''

          node_module directory by location

        • home: boolean = true

          if true save modules to .semo, if false, save to cwd

        • force: boolean = false

          Force install again

        Returns string

  • info: ((message, exit?, errorCode?) => void)
      • (message, exit?, errorCode?): void
      • Print info message with green color.

        Parameters

        • message: any

          Error message to log

        • exit: boolean = false
        • errorCode: number = 0

        Returns void

  • installPackage: ((name, location?, home?, force?) => void)
      • (name, location?, home?, force?): void
      • Parameters

        • name: any
        • location: string = ''
        • home: boolean = true
        • force: boolean = false

        Returns void

  • invokeHook: (<T>(hook?, options?, argv?) => Promise<T>)
      • <T>(hook?, options?, argv?): Promise<T>
      • Run hook in all valid plugins and return the combined results. Plugins implement hook in module.exports, could be generator function or promise function or non-function For non-function, it will be used as hook data directly, likely to be returned by function

        Type Parameters

        • T

        Parameters

        • hook: any = null

          Hook name, suggest plugin defined hook include a prefix, e.g. prefix:hook

        • options: IHookOption = ...

          Options

        • argv: any = null

        Returns Promise<T>

        Example

        const hookReturn = await Utils.invokeHook('semo:hook')
        
  • isDevelopment: (() => boolean)
      • (): boolean
      • Shortcut for checking if or not current env is development

        Returns boolean

  • isProduction: (() => boolean)
      • (): boolean
      • Shortcut for checking if or not current env is production

        Returns boolean

  • isPromise: ((obj) => boolean)
      • (obj): boolean
      • Check if obj is a Promise

        Copy from is-promise npm module

        Parameters

        • obj: any

        Returns boolean

  • launchDispatcher: ((opts?) => Promise<void>)
      • (opts?): Promise<void>
      • Launch dispatcher

        Parameters

        • opts: any = {}

        Returns Promise<void>

  • loadCorePackageInfo: (() => any)
      • (): any
      • Load core package.json

        Returns any

  • loadPackageInfo: ((pkg?, paths?) => any)
      • (pkg?, paths?): any
      • Load any package's package.json

        Parameters

        • pkg: undefined | string = undefined

          package name

        • paths: any = []

          search paths

        Returns any

  • loadPluginRc: ((name, location?, home?) => any)
      • (name, location?, home?): any
      • Load plugin rc config

        Parameters

        • name: any

          Plugin name

        • location: string = ''

          plugin installed directory name under ~/.semo

        • home: boolean = true

          if load from HOME directory

        Returns any

  • log: ((message) => void)
      • (message): void
      • Print message with format and color.

        Parameters

        • message: any

          Message to log

        Returns void

  • md5: ((s) => string)
      • (s): string
      • Compute md5.

        Parameters

        • s: string

        Returns string

  • outputTable: ((columns, caption?, borderOptions?) => void)
      • (columns, caption?, borderOptions?): void
      • Print a simple table. A table style for semo status, if you don't like this style, can use Utils.table

        Parameters

        • columns: string[][]

          Table columns

        • caption: string = ''

          Table caption

        • borderOptions: {} = {}

          Border options

          Returns void

    • parsePackageNames: ((input) => string[])
        • (input): string[]
        • Parse packages from yargs option

          Parameters

          • input: string | string[]

            yarns option input, could be string or array

          Returns string[]

          Package list

    • pluginConfig: ((key, defaultValue?) => any)
        • (key, defaultValue?): any
        • Get final config value

          Only work in command handler, use top level config first than use plugin config

          Parameters

          • key: string

            config key

          • defaultValue: any = undefined

            default value

          Returns any

    • replHistory: ((repl, file) => void)
        • (repl, file): void
        • Keep repl history

          repl.history 0.1.4 not compatile with node v12, so find other solution.

          Parameters

          • repl: any
          • file: any

          Returns void

    • resolvePackage: ((name, location?, home?) => string)
        • (name, location?, home?): string
        • Parameters

          • name: any
          • location: string = ''
          • home: boolean = true

          Returns string

    • run: ((func, getPath?, ...args) => Promise<any>)
        • (func, getPath?, ...args): Promise<any>
        • Used for get deep value from a object or function or Promise

          Parameters

          • func: any

            a Promise, a Function or a literal object

          • getPath: string = ''

            a key path

          • Rest ...args: any[]

          Returns Promise<any>

    • shell: __module
    • sleep: ((ms) => Promise<unknown>)
        • (ms): Promise<unknown>
        • Sleep a while of ms

          Parameters

          • ms: number

          Returns Promise<unknown>

    • splitByChar: ((input, char) => string[])
        • (input, char): string[]
        • Split input by a specific char and blank.

          Parameters

          • input: string
          • char: string

          Returns string[]

          input separated by comma

          Example

          const = Utils.splitByChar('a, b , c=d', '=')
          
    • splitComma: ((input) => string[])
        • (input): string[]
        • Split input by comma and blank.

          Parameters

          • input: string

          Returns string[]

          input separated by comma

          Example

          const = Utils.splitComma('a, b , c,d')
          
    • success: ((message, exit?, errorCode?) => void)
        • (message, exit?, errorCode?): void
        • Print success message with green color.

          Parameters

          • message: any

            Error message to log

          • exit: boolean = false
          • errorCode: number = 0

          Returns void

    • uninstallPackage: ((name, location?, home?) => void)
        • (name, location?, home?): void
        • Parameters

          • name: any
          • location: string = ''
          • home: boolean = true

          Returns void

    • useDotEnv: ((expand, options?) => void)
        • (expand, options?): void
        • Use dotenv style

          Parameters

          • expand: true

            expand dotenv

          • options: DotenvConfigOptions = {}

            dotenv options

          Returns void

    • warn: ((message, exit?, errorCode?) => void)
        • (message, exit?, errorCode?): void
        • Print warn message with yellow color.

          Parameters

          • message: any

            Error message to log

          • exit: boolean = false
          • errorCode: number = 0

          Returns void

    • yaml: __module
    • yargs: Argv<{}>

    Generated using TypeDoc