Options
All
  • Public
  • Public/Protected
  • All
Menu

TerminalManager class

see

constructor()

Hierarchy

  • TerminalManager

Index

Constructors

constructor

  • new TerminalManager(workDir?: string, linkSystemWorkDir?: boolean): TerminalManager
  • Class that helps with the process of interacting with command line applications and executions through the OS terminal.

    Parameters

    • Default value workDir: string = ""

      Defines the directory where the class points which will be the base path for all the executed commands. If not specified, The current system work directory will be used. Note that if we specify a work dir that is different than the main application one and linkSystemWorkDir is true, both work directories will be automatically set to the same value.

    • Default value linkSystemWorkDir: boolean = true

      If set to true, any change that is performed on this class workDir will be reflected to the active application work dir. If set to false, this class will handle a totally independent workdir and the main application will have its own one that won't change when this class one is modified. It is true by default

    Returns TerminalManager

    A TerminalManager instance

Properties

Private _linkSystemWorkDir

_linkSystemWorkDir: boolean = true

see class constructor for docs

baseCommand

baseCommand: string = ""

If this value is set, all the executed terminal commands will be appended to it. For example, if we defined baseCommand = 'copy' and we call exec('-a c:/tmp'), the effectively executed command will be 'copy -a c:/tmp'

Private execSync

execSync: any

Stores the NodeJs execSync instance

Private filesManager

filesManager: FilesManager

A files manager instance used by this class

Private path

path: any

Stores the NodeJs path instance

Private workDirHistory

workDirHistory: string[] = []

The list of workdir values that have been defined since the class was constructed. We will be able to navigate this back at any time

Methods

createTempDirectory

  • createTempDirectory(desiredName: string, setWorkDirToIt?: boolean, deleteOnExecutionEnd?: boolean): string
  • Create a new temporary directory on the temporary files location defined by the OS. If folder does not exist, it will be created.

    When the current application exits, the folder will be automatically deleted (if possible).

    Parameters

    • desiredName: string

      see FilesManager.createTempDirectory() method

    • Default value setWorkDirToIt: boolean = true

      If set to true, when the new temporary folder is created it will be defined as the current active terminal working directory. It is true by default

    • Default value deleteOnExecutionEnd: boolean = true

      see FilesManager.createTempDirectory() method

    Returns string

    The full path to the newly created temporary directory

exec

  • exec(command: string, liveOutput?: boolean): { failed: boolean; output: string }
  • Execute an arbitrary terminal cmd command on the currently active work directory and return all relevant data

    Parameters

    • command: string

      Some cmd operation to execute on the current working directory

    • Default value liveOutput: boolean = false

      (false by default) Set it to true to show the execution stdout in real time on the main console

    Returns { failed: boolean; output: string }

    An object with two properties: - failed: False if the command finished successfully, true if any error happened - output: The full terminal output that was generated by the executed command or the full error message if the execution failed

    • failed: boolean
    • output: string

getWorkDir

  • getWorkDir(): string
  • Get the directory that is currently being used by this class as the base path for commands execution

    Returns string

setInitialWorkDir

  • setInitialWorkDir(): string
  • Move the current work dir to the first one that was defined when this class was created

    Returns string

setPreviousWorkDir

  • setPreviousWorkDir(): string
  • Move the current work dir one step backward to the one that was previously defined.

    Returns string

setWorkDir

  • setWorkDir(path: string): string
  • Move the current terminal working directory to the specified path. If linkSystemWorkDir flag has been enabled, the main application work dir will also be pointed to the same path.

    Parameters

    • path: string

      A full file system route to the location where the subsequent terminal commands will be executed

    Returns string

    The new working directory full path

Generated using TypeDoc