Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Generator

Logic for generating aggregated typings for NPM module

Hierarchy

  • Cli
    • Generator

Index

Constructors

constructor

  • new Generator(injectedArguments?: INpmDtsArgs, enableLog?: boolean | null, throwErrors?: boolean): Generator
  • Auto-launches generation based on command line arguments

    Parameters

    • Optional injectedArguments: INpmDtsArgs

      generation arguments (same as CLI)

    • Default value enableLog: boolean | null = null

      enables logging when true, null allows application to decide

    • Default value throwErrors: boolean = false

      makes generation throw errors when true

    Returns Generator

Properties

Private cacheContentEmptied

cacheContentEmptied: boolean = true

Protected launched

launched: boolean = false

Stores whether module was successfully launched

Private moduleNames

moduleNames: string[]

Private packageInfo

packageInfo: any

Private throwErrors

throwErrors: boolean

Protected tmpPassed

tmpPassed: boolean = false

Stores whether TMP directory location was passed

Methods

Private _generate

  • _generate(): Promise<void>

Private addAlias

  • addAlias(source: string): string
  • Adds alias for main NPM package file to generated .d.ts source

    Parameters

    • source: string

      generated .d.ts declaration source so far

    Returns string

Private clearTempDir

  • clearTempDir(): Promise<void>

Private combineTypings

  • combineTypings(): Promise<string>
  • Combines typings into a single declaration source

    Returns Promise<string>

Private convertPathToModule

  • convertPathToModule(path: string, rootType?: IBasePathType, noPrefix?: boolean): string
  • Generates module name based on file path

    Parameters

    • path: string

      path to be converted to module name

    • Default value rootType: IBasePathType = IBasePathType.tmp
    • Default value noPrefix: boolean = false

      disables addition of module name as prefix for module name

    Returns string

generate

  • generate(): Promise<void>
  • Executes generation of single declaration file

    Returns Promise<void>

Private generateTypings

  • generateTypings(): Promise<void>

Protected getArgument

Private getDeclarationFiles

  • getDeclarationFiles(dir?: string, files?: string[]): string[]
  • Gathers a list of created per-file declaration files

    Parameters

    • Default value dir: string = this.getTempDir()

      directory to be scanned for files (called during recursion)

    • Default value files: string[] = []

      discovered array of files (called during recursion)

    Returns string[]

Private getEntry

  • getEntry(): string
  • Gathers entry file address (relative to project root path)

    Returns string

Private getLogLevel

Private getOutput

  • getOutput(): string

Private getPackageDetails

  • getPackageDetails(): any

Private getRoot

  • getRoot(): string

Private getTempDir

  • getTempDir(): string
  • Gathers TMP directory to be used for TSC operations

    Returns string

Private loadTypings

Private makeTempDir

  • makeTempDir(retries?: number): Promise<void>
  • Creates TMP directory to be used for TSC operations

    Parameters

    • Default value retries: number = MKDIR_RETRIES

      amount of times to retry on failure

    Returns Promise<void>

Private moduleExists

  • moduleExists(moduleName: string): boolean
  • Verifies if module specified exists among known modules

    Parameters

    • moduleName: string

      name of module to be checked

    Returns boolean

Private resetCacheDir

  • resetCacheDir(): Promise<unknown>
  • Re-creates empty TMP directory to be used for TSC operations

    Returns Promise<unknown>

Private resolveImportSources

  • resolveImportSources(source: string, moduleName: string): string
  • Alters import sources to avoid relative addresses and default index usage

    Parameters

    • source: string

      import source to be resolved

    • moduleName: string

      name of module containing import

    Returns string

Private resolveImportSourcesAtLine

  • resolveImportSourcesAtLine(regexp: RegExp, line: string, moduleName: string): string
  • Parameters

    • regexp: RegExp
    • line: string
    • moduleName: string

    Returns string

Protected setArgument

  • setArgument(arg: ECliArgument, value: string | boolean): void
  • Dynamically overrides value of stored argument

    Parameters

    • arg: ECliArgument

      argument name

    • value: string | boolean

      argument value

    Returns void

Private showDebugError

  • showDebugError(e: any): void
  • Logs serialized error if it exists

    Parameters

    • e: any

      error to be shown

    Returns void

Private storeResult

  • storeResult(source: string): Promise<void>
  • Stores generated .d.ts declaration source into file

    Parameters

    • source: string

      generated .d.ts source

    Returns Promise<void>

Private useForce

  • useForce(): boolean
  • Checks if script is forced to attempt generation despite errors

    Returns boolean

Private useTestMode

  • useTestMode(): boolean
  • Checks if script is forced to use its built-in TSC

    Returns boolean

Generated using TypeDoc