Options
All
  • Public
  • Public/Protected
  • All
Menu

Package @tscmono/utils

Index

References

CacheDescriptor

Re-exports CacheDescriptor

TreeNode

Re-exports TreeNode

config

Re-exports config

excludeFromPathNormalization

Re-exports excludeFromPathNormalization

execPromised

Re-exports execPromised

extendLoggingNaming

Re-exports extendLoggingNaming

findPackageJson

Re-exports findPackageJson

findRoot

Re-exports findRoot

getLoggingNamingFromPackageName

Re-exports getLoggingNamingFromPackageName

getPackageJson

Re-exports getPackageJson

hasPackageJson

Re-exports hasPackageJson

makeLogger

Re-exports makeLogger

normalizeLoggingNaming

Re-exports normalizeLoggingNaming

normalizePath

Re-exports normalizePath

parseLoggerName

Re-exports parseLoggerName

parseLoggingNameByFileName

Re-exports parseLoggingNameByFileName

parseLoggingNameByName

Re-exports parseLoggingNameByName

parseLoggingNameByPackageName

Re-exports parseLoggingNameByPackageName

parseWorkspaces

Re-exports parseWorkspaces

pathToTree

Re-exports pathToTree

pathsToTree

Re-exports pathsToTree

registerCache

Re-exports registerCache

root

Re-exports root

rootString

Re-exports rootString

workspaces

Re-exports workspaces

Type aliases

CacheDescriptor

CacheDescriptor<T, K>: { refresh: (...args: K) => Promise<T>; value: Promise<T> }

Proxy for working with caches

Type parameters

  • T

  • K: any[]

Type declaration

  • refresh: (...args: K) => Promise<T>
      • (...args: K): Promise<T>
      • Parameters

        • Rest ...args: K

        Returns Promise<T>

  • value: Promise<T>

ExecOptions

ExecOptions: { cwd?: undefined | string; exitOnSTDERR?: undefined | false | true }

Type declaration

  • Optional cwd?: undefined | string

    CWD to run the process into

  • Optional exitOnSTDERR?: undefined | false | true

    Should exit when STDERR is not empty

LoggingNaming

LoggingNaming: { name: string; prefix?: undefined | string }

Type declaration

  • name: string
  • Optional prefix?: undefined | string

LoggingNamingParser

LoggingNamingParser<T>: (...args: T) => LoggingNaming

Type parameters

  • T: any[]

Type declaration

LoggingNamingParserBinding

LoggingNamingParserBinding: () => LoggingNaming

Type declaration

LoggingNamingParserValidator

LoggingNamingParserValidator: () => string | undefined

Type declaration

    • (): string | undefined
    • Returns string | undefined

LoggingNamingParsers

LoggingNamingParsers: "name" | "file" | "package"

TreeNode

TreeNode: { children: Record<string, TreeNode | string>; path: string }

Type declaration

  • children: Record<string, TreeNode | string>
  • path: string

WorkspaceConfig

WorkspaceConfig: { location: string } & WorkspaceDependencies

WorkspaceDependencies

WorkspaceDependencies: { mismatchedWorkspaceDependencies: string[]; workspaceDependencies: string[] }

Type declaration

  • mismatchedWorkspaceDependencies: string[]
  • workspaceDependencies: string[]

WorkspacesConfig

WorkspacesConfig: Record<string, WorkspaceConfig>

YarnV2WorkspaceConfig

YarnV2WorkspaceConfig: { name: string } & WorkspaceConfig

Cache Variables

Const root

root: { refresh: (...args: K) => Promise<T>; value: Promise<T> } = registerCache('repoRoot',findRoot,)

Cached version of the Find Root function

Type declaration

  • refresh: (...args: K) => Promise<T>
      • (...args: K): Promise<T>
      • Parameters

        • Rest ...args: K

        Returns Promise<T>

  • value: Promise<T>

Const workspaces

workspaces: { refresh: (...args: K) => Promise<T>; value: Promise<T> } = registerCache('workspaces',parseWorkspaces,)

Cached version of the Parse Workspaces function

Type declaration

  • refresh: (...args: K) => Promise<T>
      • (...args: K): Promise<T>
      • Parameters

        • Rest ...args: K

        Returns Promise<T>

  • value: Promise<T>

Logging Variables

Const excludeFromPathNormalization

excludeFromPathNormalization: string[] = ['src', 'dist', 'types']

Paths to be excluded from Path Normalization

Other Variables

Const rootString

rootString: "<root>" = "<root>"

Logging Functions

Const extendLoggingNaming

  • Extend a logging naming with an extension string

    Parameters

    • loggingNaming: LoggingNaming

      The Logging Naming

    • input: string

      The extension string

    Returns LoggingNaming

Const normalizeLoggingNaming

  • Normalize a Logging Naming by applying the prefix to the name, if possible

    Parameters

    Returns LoggingNaming

Const normalizePath

  • normalizePath(filePath: string, exclude?: string[]): string
  • Normalize path by replacing slashes with naming separator stripping excluded path segments and removing extensions

    Parameters

    • filePath: string

      Path to be normalized

    • Default value exclude: string[] = excludeFromPathNormalization

    Returns string

Const parseLoggerName

  • Generate a logging name based on user input

    Parameters

    • parser: LoggingNamingParsers

      The parser to use when generating a logging name

    • input: { fileName: string; name?: undefined | string }

      The input used for generation

      • fileName: string
      • Optional name?: undefined | string

    Returns LoggingNaming

Const parseLoggingNameByFileName

  • parseLoggingNameByFileName(fileName: string): { name: string; prefix?: undefined | string }
  • Generate a Logger Naming Convention based on the current file and package name

    Parameters

    • fileName: string

      The __filename of the current script

    Returns { name: string; prefix?: undefined | string }

    • name: string
    • Optional prefix?: undefined | string

Const parseLoggingNameByName

  • parseLoggingNameByName(dirName: string, name: string): { name: string; prefix?: undefined | string }
  • Generate a Logger Naming Convention based on a name and current package

    Parameters

    • dirName: string

      The __dirname of the current script

    • name: string

      The name to be attributed

    Returns { name: string; prefix?: undefined | string }

    • name: string
    • Optional prefix?: undefined | string

Const parseLoggingNameByPackageName

  • parseLoggingNameByPackageName(rootDir: string): { name: string; prefix?: undefined | string }
  • Generate a Logger Naming Convention based on the current package name

    Parameters

    • rootDir: string

      The __dirname of the current script

    Returns { name: string; prefix?: undefined | string }

    • name: string
    • Optional prefix?: undefined | string

Other Functions

Const makeLogger

  • makeLogger(fileName: string, parser?: LoggingNamingParsers, loggerName?: undefined | string): Debugger
  • Create a logger to be used in the app

    Parameters

    • fileName: string

      The filename from which to generate the logger name

    • Default value parser: LoggingNamingParsers = "file"

      The parser to use for generating the logger name

    • Optional loggerName: undefined | string

      Optional name to be used when generating the logger name

    Returns Debugger

Const pathToTree

  • pathToTree(input: string, prev?: undefined | string): TreeNode | undefined
  • Parameters

    • input: string
    • Optional prev: undefined | string

    Returns TreeNode | undefined

Const pathsToTree

  • pathsToTree(input: string[]): TreeNode
  • Parameters

    • input: string[]

    Returns TreeNode

Const registerCache

  • registerCache<T, K>(name: string, setter: (...args: K) => Promise<T>, defaultArguments?: K): CacheDescriptor<T, K>
  • Register a cache key

    Type parameters

    • T

    • K: any[]

    Parameters

    • name: string

      The name of the property to save under

    • setter: (...args: K) => Promise<T>

      A setter to be used in obtaining the values

        • (...args: K): Promise<T>
        • Parameters

          • Rest ...args: K

          Returns Promise<T>

    • Optional defaultArguments: K

    Returns CacheDescriptor<T, K>

Util Functions

Const execPromised

  • execPromised(cmd: string, options?: ExecOptions): Promise<string[]>
  • Will execute a process and return a Promise that would resolve to the STDOUT split by lines

    Parameters

    • cmd: string

      Command to be executed

    • Default value options: ExecOptions = {}

      Options

    Returns Promise<string[]>

Const extractWorkspaces

  • extractWorkspaces(json: any): string[]
  • Extracts an array of workspaces from a package.json

    Parameters

    • json: any

      The contents of a package.json

    Returns string[]

Const findPackageJson

  • findPackageJson(pwd: string, prev?: undefined | string): string
  • Find a directory containing a package.json file, crawling from the starting path, and moving towards the OS root dir, using hasPackageJson

    Parameters

    • pwd: string

      Starting point for finding a package.json

    • Optional prev: undefined | string

      Previous visited directory (used for determining OS root dir)

    Returns string

Const fixV2Path

  • fixV2Path(pwd: string, p: string): any
  • Fixes Yarn V2 Output to conform to V1 Standards

    Parameters

    • pwd: string

      Root path

    • p: string

      Package path

    Returns any

Const getLoggingNamingFromPackageName

  • getLoggingNamingFromPackageName(packageName: string): LoggingNaming

Const getPackageJson

  • getPackageJson(pwd: string): any
  • Load a package.json file from a path

    Parameters

    • pwd: string

      The path

    Returns any

Const hasPackageJson

  • hasPackageJson(pwd: string): boolean
  • Determine if path contains a package.json file

    Parameters

    • pwd: string

      Path

    Returns boolean

Const hasWorkspaces

  • hasWorkspaces(json: any): boolean
  • Determines if a package.json has workspaces

    Parameters

    • json: any

      The contents of a package.json

    Returns boolean

Const isRoot

  • isRoot(pwd: string, relative: string): boolean
  • Checks if the current folder (pwd) contains a package.json with workspaces and then checks a relative path against workspaces to determine if the relative path belongs to the current monorepo

    Parameters

    • pwd: string

      The path to check if it is the monorepo root

    • relative: string

      Relative path to be checked against workspaces

    Returns boolean

Workspace Root Finder Functions

Const findRoot

  • findRoot(cwd?: string): Promise<string>
  • Finds the monorepo root, either via the Workspace Finder or the Git Finder

    Parameters

    • Default value cwd: string = process.cwd()

    Returns Promise<string>

Const findWithGit

  • findWithGit(root?: string): Promise<string>
  • Determines the root of a project based on git

    Parameters

    • Default value root: string = __dirname

      The root directory to start searching from

    Returns Promise<string>

Const findWithWorkspaces

  • findWithWorkspaces(root?: string): Promise<string>
  • Crawl directory structure to find root workspaces dir

    Parameters

    • Default value root: string = __dirname

      Root dir to begin crawling

    Returns Promise<string>

Yarn Workspace Parsers Functions

Const parseWorkspaces

  • Attempt to parse repo workspaces from a certain path. It will attempt to parse by using parsers made for Yarn V1 and V2

    Parameters

    • Optional rootDir: undefined | string

      Path to be used when parsing

    Returns Promise<WorkspacesConfig>

Const runParser

  • Invoke a Workspace Parser in a certain path

    Parameters

    • parser: WorkspaceParser

      Parser to be invoked on the path

    • cwd: string

      Path to be used when parsing

    Returns Promise<WorkspacesConfig>

Logging Object literals

Const config

config: object

Configure the Logger

setSeparator

  • setSeparator(value: string): string
  • Set the separator to be used when generating logger names

    Parameters

    • value: string

      The new separator

    Returns string

separator

  • get separator(): string
  • set separator(_: string): void
  • The separator to be used when generating logger names

    Returns string

  • NOOP Setting the separator through dot notation (TS)

    Parameters

    • _: string

    Returns void

Yarn Workspace Parsers Object literals

Const YarnV1Parser

YarnV1Parser: object

Yarn V1 Workspace List Parser

call

  • call(cwd: string): Promise<string[]>
  • Obtain an Yarn V1 workspace list output

    Parameters

    • cwd: string

      The cwd of execution

    Returns Promise<string[]>

parse

  • Parse a Yarn V1 workspace list output

    Parameters

    • input: string[]

      The input to parse

    Returns Promise<WorkspacesConfig>

Const YarnV2Parser

YarnV2Parser: object

Yarn V2 Workspace List Parser

call

  • call(cwd: string): Promise<string[]>
  • Parameters

    • cwd: string

    Returns Promise<string[]>

parse

  • parse(input: string[], pwd: string): Promise<{}>
  • Parameters

    • input: string[]
    • pwd: string

    Returns Promise<{}>

Generated using TypeDoc