Options
All
  • Public
  • Public/Protected
  • All
Menu

foy

Index

Type aliases

Callback

Callback: { fn: (args?: any) => void | Promise<void>; namespaces: string[] }

Type declaration

  • fn: (args?: any) => void | Promise<void>
      • (args?: any): void | Promise<void>
      • Parameters

        • Optional args: any

        Returns void | Promise<void>

  • namespaces: string[]

Dependency

Dependency: TaskDep | string | DepBuilder

ListenerNames

ListenerNames: "before" | "after" | "onerror"

LogLevels

LogLevels: keyof typeof LogLevels

OptionDef

OptionDef: [string, string, OptionConfig | undefined]

TaskFn

TaskFn<O, T>: (ctx: TaskContext<O>) => T | Promise<T>

Type parameters

  • O

  • T = any

Type declaration

WatchDirHandler

WatchDirHandler: (event: string, filename: string) => void

Type declaration

    • (event: string, filename: string): void
    • Parameters

      • event: string
      • filename: string

      Returns void

WatchDirOptions

WatchDirOptions: { persistent?: undefined | false | true; threshold?: undefined | number }

Type declaration

  • Optional persistent?: undefined | false | true
  • Optional threshold?: undefined | number

    ms, default 300

Variables

Const DefaultLogFile

DefaultLogFile: string = join(process.cwd(), 'foy.log')

Const EEXIST

EEXIST: "EEXIST" = "EEXIST"

Const ENOENT

ENOENT: "ENOENT" = "ENOENT"

Const TMKey

TMKey: string = `@foy${require('../package.json').version}/taskManager`

Const fs

fs: "fs" & "fs/promises" & { copy: copy; copyFile: __promisify__ | (Anonymous function); watchDir: watchDir; exists: any; isDirectory: any; isFile: any; isSymbolicLink: any; iter: any; lexists: any; mkdirp: any; mkdirpSync: any; outputFile: any; outputFileSync: any; outputJson: any; outputJsonSync: any; readJson: any; readJsonSync: any; rmrf: any } = Object.assign({}, _fs, _fs.promises, fsExtra)

Const logger

logger: Logger = new Logger()

Let objUid

objUid: number = 0

Let objUidMap

objUidMap: WeakMap<object, number> = new WeakMap<object, number>()

Const shellParser

shellParser: any = require('shell-parser')

Const spawn

spawn: { command: any; commandSync: any; node: any; sync: any } = execa

Type declaration

    • (file: string, arguments?: readonly string[], options?: execa.Options): execa.ExecaChildProcess
    • (file: string, arguments?: readonly string[], options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>
    • (file: string, options?: execa.Options): execa.ExecaChildProcess
    • (file: string, options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>
    • Execute a file.

      Think of this as a mix of child_process.execFile and child_process.spawn.

      example
      import execa = require('execa');
      
      (async () => {
      const {stdout} = await execa('echo', ['unicorns']);
      console.log(stdout);
      //=> 'unicorns'
      
      // Cancelling a spawned process
      const subprocess = execa('node');
      setTimeout(() => { spawned.cancel() }, 1000);
      try {
      await subprocess;
      } catch (error) {
      console.log(subprocess.killed); // true
      console.log(error.isCanceled); // true
      }
      })();
      
      // Pipe the child process stdout to the current stdout
      execa('echo', ['unicorns']).stdout.pipe(process.stdout);

      Parameters

      • file: string

        The program/script to execute.

      • Optional arguments: readonly string[]

        Arguments to pass to file on execution.

      • Optional options: execa.Options

      Returns execa.ExecaChildProcess

      A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.

    • Parameters

      • file: string
      • Optional arguments: readonly string[]
      • Optional options: execa.Options<null>

      Returns execa.ExecaChildProcess<Buffer>

    • Parameters

      • file: string
      • Optional options: execa.Options

      Returns execa.ExecaChildProcess

    • Parameters

      • file: string
      • Optional options: execa.Options<null>

      Returns execa.ExecaChildProcess<Buffer>

  • command: function
    • command(command: string, options?: execa.Options): execa.ExecaChildProcess
    • command(command: string, options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>
    • Same as execa() except both file and arguments are specified in a single command string. For example, execa('echo', ['unicorns']) is the same as execa.command('echo unicorns').

      If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if command is not a constant but a variable, for example with __dirname or process.cwd(). Except for spaces, no escaping/quoting is needed.

      The shell option must be used if the command uses shell-specific features, as opposed to being a simple file followed by its arguments.

      example
      import execa = require('execa');
      
      (async () => {
      const {stdout} = await execa.command('echo unicorns');
      console.log(stdout);
      //=> 'unicorns'
      })();

      Parameters

      • command: string

        The program/script to execute and its arguments.

      • Optional options: execa.Options

      Returns execa.ExecaChildProcess

      A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.

    • Parameters

      • command: string
      • Optional options: execa.Options<null>

      Returns execa.ExecaChildProcess<Buffer>

  • commandSync: function
    • commandSync(command: string, options?: execa.SyncOptions): ExecaSyncReturnValue
    • commandSync(command: string, options?: execa.SyncOptions<null>): ExecaSyncReturnValue<Buffer>
    • Same as execa.command() but synchronous.

      Parameters

      • command: string

        The program/script to execute and its arguments.

      • Optional options: execa.SyncOptions

      Returns ExecaSyncReturnValue

      A result Object with stdout and stderr properties.

    • Parameters

      • command: string
      • Optional options: execa.SyncOptions<null>

      Returns ExecaSyncReturnValue<Buffer>

  • node: function
    • node(scriptPath: string, arguments?: readonly string[], options?: execa.NodeOptions): execa.ExecaChildProcess
    • node(scriptPath: string, arguments?: readonly string[], options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>
    • node(scriptPath: string, options?: execa.Options): execa.ExecaChildProcess
    • node(scriptPath: string, options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>
    • Execute a Node.js script as a child process.

      Same as execa('node', [scriptPath, ...arguments], options) except (like child_process#fork()):

      • the current Node version and options are used. This can be overridden using the nodePath and nodeArguments options.
      • the shell option cannot be used
      • an extra channel ipc is passed to stdio

      Parameters

      • scriptPath: string

        Node.js script to execute.

      • Optional arguments: readonly string[]

        Arguments to pass to scriptPath on execution.

      • Optional options: execa.NodeOptions

      Returns execa.ExecaChildProcess

      A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.

    • Parameters

      • scriptPath: string
      • Optional arguments: readonly string[]
      • Optional options: execa.Options<null>

      Returns execa.ExecaChildProcess<Buffer>

    • Parameters

      • scriptPath: string
      • Optional options: execa.Options

      Returns execa.ExecaChildProcess

    • Parameters

      • scriptPath: string
      • Optional options: execa.Options<null>

      Returns execa.ExecaChildProcess<Buffer>

  • sync: function
    • sync(file: string, arguments?: readonly string[], options?: execa.SyncOptions): ExecaSyncReturnValue
    • sync(file: string, arguments?: readonly string[], options?: execa.SyncOptions<null>): ExecaSyncReturnValue<Buffer>
    • sync(file: string, options?: execa.SyncOptions): ExecaSyncReturnValue
    • sync(file: string, options?: execa.SyncOptions<null>): ExecaSyncReturnValue<Buffer>
    • Execute a file synchronously.

      This method throws an Error if the command fails.

      Parameters

      • file: string

        The program/script to execute.

      • Optional arguments: readonly string[]

        Arguments to pass to file on execution.

      • Optional options: execa.SyncOptions

      Returns ExecaSyncReturnValue

      A result Object with stdout and stderr properties.

    • Parameters

      • file: string
      • Optional arguments: readonly string[]
      • Optional options: execa.SyncOptions<null>

      Returns ExecaSyncReturnValue<Buffer>

    • Parameters

      • file: string
      • Optional options: execa.SyncOptions

      Returns ExecaSyncReturnValue

    • Parameters

      • file: string
      • Optional options: execa.SyncOptions<null>

      Returns ExecaSyncReturnValue<Buffer>

Functions

_exec

  • _exec(cmd: string, options?: execa.Options): ExecaChildProcess<string>
  • Parameters

    • cmd: string
    • Optional options: execa.Options

    Returns ExecaChildProcess<string>

Const after

  • after(fn: (t: Task) => void | Promise<void>): void
  • Parameters

    • fn: (t: Task) => void | Promise<void>
        • (t: Task): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    Returns void

appendCallback

  • Type parameters

    • Fn: (...args: any[]) => void | Promise<void>

    Parameters

    Returns void

Const before

  • before(fn: (t: Task) => void | Promise<void>): void
  • Parameters

    • fn: (t: Task) => void | Promise<void>
        • (t: Task): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    Returns void

copy

  • copy(src: string, dist: string, opts?: undefined | { overwrite?: undefined | false | true; skip?: undefined | ((file: string, stat: Stats) => Promise<boolean | void> | boolean | void) }): Promise<void>
  • Parameters

    • src: string
    • dist: string
    • Optional opts: undefined | { overwrite?: undefined | false | true; skip?: undefined | ((file: string, stat: Stats) => Promise<boolean | void> | boolean | void) }

    Returns Promise<void>

debounce

  • debounce<T>(cb: T, ms: number, getArgsKey?: (args: any[]) => string): T
  • Type parameters

    • T: (...args: any[]) => void

    Parameters

    • cb: T
    • ms: number
    • Default value getArgsKey: (args: any[]) => string = (args: any[]) => args.join('|')
        • (args: any[]): string
        • Parameters

          • args: any[]

          Returns string

    Returns T

defaults

  • defaults<T>(val: T | undefined, defaultVal: T): T
  • defaults<T>(val: T | undefined, val1: T | undefined, defaultVal: T): T
  • defaults<T>(val: T | undefined, val1: T | undefined, val2: T | undefined, defaultVal: T): T
  • defaults<T>(val: T | undefined, val1: T | undefined, val2: T | undefined, val3: T | undefined, defaultVal: T): T
  • defaults<T>(val: T | undefined, val1: T | undefined, val2: T | undefined, val3: T | undefined, val4: T | undefined, defaultVal: T): T
  • Type parameters

    • T

    Parameters

    • val: T | undefined
    • defaultVal: T

    Returns T

  • Type parameters

    • T

    Parameters

    • val: T | undefined
    • val1: T | undefined
    • defaultVal: T

    Returns T

  • Type parameters

    • T

    Parameters

    • val: T | undefined
    • val1: T | undefined
    • val2: T | undefined
    • defaultVal: T

    Returns T

  • Type parameters

    • T

    Parameters

    • val: T | undefined
    • val1: T | undefined
    • val2: T | undefined
    • val3: T | undefined
    • defaultVal: T

    Returns T

  • Type parameters

    • T

    Parameters

    • val: T | undefined
    • val1: T | undefined
    • val2: T | undefined
    • val3: T | undefined
    • val4: T | undefined
    • defaultVal: T

    Returns T

dep

desc

  • desc(desc: string): void
  • Define task description

    Parameters

    • desc: string

    Returns void

exec

  • exec(command: string, options?: execa.Options): execa.ExecaChildProcess
  • exec(commands: string[], options?: execa.Options): Promise<ExecaSyncReturnValue<string>[]>
  • Parameters

    • command: string
    • Optional options: execa.Options

    Returns execa.ExecaChildProcess

  • Parameters

    • commands: string[]
    • Optional options: execa.Options

    Returns Promise<ExecaSyncReturnValue<string>[]>

Const formatDate

  • formatDate(d: Date): string

formatDuration

  • formatDuration(ms: number): string

makeLogger

namespace

  • namespace(ns: string, fn: (ns: string) => void): void
  • Create namespace prefix for inner tasks

    example

    namespace('client', ns => { task('run', async ctx => { logger.log(ns) // 'client' await ctx.exec('') }) }) namespace('server', ns => { task('run', async ctx => { logger.log(ns) // 'server' await ctx.exec('') }) })

    ========== $ yarn foy client:run $ yarn foy server:run

    Parameters

    • ns: string

      namespace

    • fn: (ns: string) => void
        • (ns: string): void
        • Parameters

          • ns: string

          Returns void

    Returns void

Const onerror

  • onerror(fn: (err: Error, t: Task) => void | Promise<void>): void
  • Parameters

    • fn: (err: Error, t: Task) => void | Promise<void>
        • (err: Error, t: Task): void | Promise<void>
        • Parameters

          • err: Error
          • t: Task

          Returns void | Promise<void>

    Returns void

option

  • option(rawName: string, description: string, config?: OptionConfig): void
  • Define a task cli option

    Parameters

    • rawName: string
    • description: string
    • Optional config: OptionConfig

    Returns void

promiseQueue

  • promiseQueue<A, R>(cb: (...args: A) => Promise<R> | R): (Anonymous function)
  • Type parameters

    • A: any[]

    • R

    Parameters

    • cb: (...args: A) => Promise<R> | R
        • (...args: A): Promise<R> | R
        • Parameters

          • Rest ...args: A

          Returns Promise<R> | R

    Returns (Anonymous function)

setGlobalOptions

setOption

  • setOption(options: Partial<typeof last>): void
  • Set options for next task.

    Parameters

    • options: Partial<typeof last>

    Returns void

shell

  • shell(callback: (ctx: ShellContext) => Promise<any>): Promise<any>

Const sleep

  • sleep(ms: number): Promise<void>

strict

  • strict(): void
  • Define task cli options are strict, which means it will throw an error if you passed undefined options.

    Returns void

task

watchDir

Object literals

Const Is

Is: object

bool

  • bool(v: any): v is boolean

defed

  • defed<T>(v: T | null | undefined): v is T
  • Type parameters

    • T

    Parameters

    • v: T | null | undefined

    Returns v is T

fn

  • fn(v: any): v is Function

num

  • num(v: any): v is number

obj

  • obj(v: any): v is object

str

  • str(v: any): v is string

Const LogLevels

LogLevels: object

debug

debug: number = 0

error

error: number = 3

info

info: number = 1

warn

warn: number = 2

Const fsExtra

fsExtra: object

copy

copy: copy

copyFile

copyFile: __promisify__ | (Anonymous function) = _fs.copyFile? util.promisify(_fs.copyFile): async (src: _fs.PathLike, dist: _fs.PathLike) => {await _fs.promises.stat(src)return new Promise((res, rej) => {_fs.createReadStream(src, { highWaterMark: 2 * 1024 * 1024 }).pipe(_fs.createWriteStream(dist)).on('error', rej).on('close', res)})}

watchDir

watchDir: watchDir

exists

  • exists(path: _fs.PathLike): Promise<boolean>
  • Parameters

    • path: _fs.PathLike

    Returns Promise<boolean>

isDirectory

  • isDirectory(path: _fs.PathLike): Promise<boolean>
  • Parameters

    • path: _fs.PathLike

    Returns Promise<boolean>

isFile

  • isFile(path: _fs.PathLike): Promise<boolean>
  • Parameters

    • path: _fs.PathLike

    Returns Promise<boolean>

isSymbolicLink

  • isSymbolicLink(path: _fs.PathLike): Promise<boolean>
  • Parameters

    • path: _fs.PathLike

    Returns Promise<boolean>

iter

  • iter(dir: string, skip: (path: string, stat: Stats) => Promise<boolean | void> | boolean | void): Promise<void>
  • Parameters

    • dir: string
    • skip: (path: string, stat: Stats) => Promise<boolean | void> | boolean | void
        • (path: string, stat: Stats): Promise<boolean | void> | boolean | void
        • Parameters

          • path: string
          • stat: Stats

          Returns Promise<boolean | void> | boolean | void

    Returns Promise<void>

lexists

  • lexists(path: _fs.PathLike): Promise<boolean>
  • exists via lstat, if a symbolic link's target file doesn't exists, fs.exists will return false, but fs.lexists will return true.

    Parameters

    • path: _fs.PathLike

    Returns Promise<boolean>

mkdirp

  • mkdirp(dir: string): Promise<void>
  • Make directory with parents, like mkdir -p

    Parameters

    • dir: string

    Returns Promise<void>

mkdirpSync

  • mkdirpSync(dir: string): void
  • Make directory with parents, like mkdir -p

    Parameters

    • dir: string

    Returns void

outputFile

  • outputFile(path: string, data: any, options?: WriteOptions): Promise<void>

outputFileSync

  • outputFileSync(path: string, data: any, options?: WriteOptions): void

outputJson

  • outputJson(path: string, data: object, options?: { replacer?: undefined | ((key: string, value: any) => any); space?: undefined | number } & WriteOptions): Promise<void>
  • Parameters

    • path: string
    • data: object
    • Optional options: { replacer?: undefined | ((key: string, value: any) => any); space?: undefined | number } & WriteOptions

    Returns Promise<void>

outputJsonSync

  • outputJsonSync(path: string, data: any, options?: { replacer?: undefined | ((key: string, value: any) => any); space?: undefined | number } & WriteOptions): void
  • Parameters

    • path: string
    • data: any
    • Optional options: { replacer?: undefined | ((key: string, value: any) => any); space?: undefined | number } & WriteOptions

    Returns void

readJson

  • readJson<T>(path: string, options?: { encoding?: undefined | null; flag?: undefined | string } | null): Promise<T>
  • Type parameters

    • T = any

    Parameters

    • path: string
    • Optional options: { encoding?: undefined | null; flag?: undefined | string } | null

    Returns Promise<T>

readJsonSync

  • readJsonSync<T>(path: string, options?: { encoding?: undefined | null; flag?: undefined | string } | null): T
  • Type parameters

    • T = any

    Parameters

    • path: string
    • Optional options: { encoding?: undefined | null; flag?: undefined | string } | null

    Returns T

rmrf

  • rmrf(path: string): Promise<void>
  • Remove file or directory recursively, like rm -rf

    Parameters

    • path: string

      The path to remove

    Returns Promise<void>

Generated using TypeDoc