turbodepot-node
Version:
General purpose multi storage library (ORM, Logs, Users, Files, Objects)
109 lines (108 loc) • 5.23 kB
TypeScript
/**
* TurboDepot is a general purpose multi storage library (ORM, Logs, Users, Files, Objects)
*
* Website : -> https://turboframework.org/en/libs/turbodepot
* License : -> Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License.
* License Url : -> http://www.apache.org/licenses/LICENSE-2.0
* CopyRight : -> Copyright 2019 Edertone Advanded Solutions (08211 Castellar del Vallès, Barcelona). http://www.edertone.com
*/
/**
* TerminalManager class
*
* @see constructor()
*/
export declare class TerminalManager {
/**
* see class constructor for docs
*/
private _linkSystemWorkDir;
/**
* 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'
*/
baseCommand: 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
*/
private workDirHistory;
/**
* A files manager instance used by this class
*/
private filesManager;
/**
* Stores the NodeJs path instance
*/
private path;
/**
* Stores the NodeJs execSync instance
*/
private execSync;
/**
* Class that helps with the process of interacting with command line applications and executions through the OS terminal.
*
* @param workDir 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.
*
* @param linkSystemWorkDir 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
*
* @return A TerminalManager instance
*/
constructor(workDir?: string, linkSystemWorkDir?: boolean);
/**
* 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.
*
* @param path A full file system route to the location where the subsequent terminal commands will be executed
*
* @return The new working directory full path
*/
setWorkDir(path: string): string;
/**
* Get the directory that is currently being used by this class as the base path for commands execution
*/
getWorkDir(): string;
/**
* Move the current work dir one step backward to the one that was previously defined.
*/
setPreviousWorkDir(): string;
/**
* Move the current work dir to the first one that was defined when this class was created
*/
setInitialWorkDir(): 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).
*
* @param desiredName see FilesManager.createTempDirectory() method
* @param setWorkDirToIt 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
*
* @param deleteOnExecutionEnd see FilesManager.createTempDirectory() method
*
* @return The full path to the newly created temporary directory
*/
createTempDirectory(desiredName: string, setWorkDirToIt?: boolean, deleteOnExecutionEnd?: boolean): string;
/**
* Execute an arbitrary terminal cmd command on the currently active work directory and return all relevant data
*
* @param command Some cmd operation to execute on the current working directory
* @param liveOutput (false by default) Set it to true to show the execution stdout in real time on the main console
* @param environmentVars An object with key pair values containing the name and value for environment variables to pass to the command
* Notice that both keys and values must be in string format, like: { 'ENV_VAR': 'value', ... }
*
* @return 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
*/
exec(command: string, liveOutput?: boolean, environmentVars?: any): {
failed: boolean;
output: string;
};
}