UNPKG

node-sys

Version:

Universal package installer, get the command for managing packages, or auto install any package, using one command for all platforms. Automate the installation of macOS Brew, and Windows Chocolatey package managers. A promisify child process of spawn, and

232 lines (231 loc) 8.81 kB
/// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import { SpawnOptionsWithoutStdio, ChildProcess, ChildProcessWithoutNullStreams, Serializable } from 'child_process'; import { Blob } from 'buffer'; import { Stream } from 'stream'; /** * Like the unix `which` utility. * * Finds the first instance of a specified executable in the PATH environment variable. * * @param String executable * * @returns String|Null */ export declare const where: (executable: string) => string | null; declare function Sys(): void; declare namespace Sys { var where: (executable: string) => string | null; var packager: () => object | Error; var installer: (application: string | string[], progress: Function) => Promise<any>; var spawning: (command: string, argument: string[], progressOptions: object | SpawningOnProgress, options?: SpawningOptions | undefined) => Promise<string | string[] | null>; var isArray: (arg: any) => arg is any[]; var isUndefined: (value: any) => value is undefined; var isBuffer: (value: any) => value is Buffer; var isArrayBuffer: (value: any) => value is ArrayBuffer; var isString: (value: any) => value is string; var isNumber: (value: any) => value is number; var isObject: (value: any) => value is object; var isObjectOnly: (value: any) => value is object; var isBlob: (value: any) => value is Blob; var isFunction: (value: any) => value is Function; var isDate: (value: any) => value is Date; var isStream: (value: any) => value is Stream; var isBool: (value: any) => value is boolean; var isNull: (value: any) => value is null; var isWindows: () => boolean; var isLinux: () => boolean; var isMac: () => boolean; } /** * Gets the system package manager install command. * * @returns {Object} *``` * sudo: boolean, // true or false, * command: string, // 'apk-get' - system package manager command, * installer: string, // 'sudo apk-get install' - full install command *``` * - Defaults to 'get os-manager installer' if no package manager is found. * * @throws if `process.platform` is none of darwin, freebsd, linux, sunos or win32. */ export declare const packager: () => object | Error; /** * Install package using the system package manager command. * * @param {String|Array} application package to install. * @param {Function} progress callback for any output doing installation. * - Any value returned in `callback` will be the final resolved result. * * @returns {Promise} Promise Output of spawn command. * - E.g. 'sudo apg-get install' for Debian based systems. * - Defaults to 'get os-manager installer' if no package manager is found. * @rejects On any spawn error, or if `process.platform` is none of * darwin, freebsd, linux, sunos or win32. */ export declare const installer: (application: string | string[], progress: Function) => Promise<any>; export declare type SpawningOnProgress = (args: { spawn: ChildProcessWithoutNullStreams; output: any; fork: ChildProcess | null; }) => string | string[] | null; export declare type SpawningOnError = (err: string) => Error | string; export declare type SpawningOnMessage = (data: Serializable) => void; export declare type SpawningOptions = SpawnOptionsWithoutStdio & { sudo?: boolean; fork?: boolean | null; onerror?: null | SpawningOnError; onprogress?: null | SpawningOnProgress; onmessage?: null | SpawningOnMessage; }; /** * Spawn subprocess with `Promise` features, pass callbacks for `.on('data')` events, with ability to run as admin. * * @param {String} command - platform command * @param {Array} argument - command arguments * @param {Function|Object} progressOptions - either callback for `stdout.on('data')` event or `options`. * - the callback will receive an object: *```js * spawn: object, // child process **spawn** `instance`. * output: string, // any **output** data. * fork: object, // if created, child process **fork** `instance`. *``` * - any `return` is the **`resolve()` .then()** result. * @param {Object} options - Any child process `spawn` options, defaults: stdio: 'pipe'. * - Additionally: *```js * sudo: boolean, // run as administrator. * fork: string, // execute an additional module, a child_process.`fork` IPC communication channel. * onerror: callable, // callback for `stderr.on('data')` event. * onprogress: callable, // callback for `stdout.on('data')` event. * onmessage: callable, // callback for `on('message')` for `fork` event. *``` */ export declare const spawning: (command: string, argument: Array<string>, progressOptions: SpawningOnProgress | object, options?: SpawningOptions | undefined) => Promise<string | string[] | null>; /** * Determine if a value is an Array. * * @param {Object} value The value to test. * @returns {boolean} True if value is an Array, otherwise false. */ export declare const isArray: (arg: any) => arg is any[]; /** * Determine if a value is undefined. * * @param {Object} value The value to test. * @returns {boolean} True if the value is undefined, otherwise false. */ export declare const isUndefined: (value: any) => value is undefined; /** * Determine if a value is a Buffer. * * @param {Object} value The value to test. * @returns {boolean} True if value is a Buffer, otherwise false. */ export declare const isBuffer: (value: any) => value is Buffer; /** * Determine if a value is an ArrayBuffer. * * @param {Object} value The value to test. * @returns {boolean} True if value is an ArrayBuffer, otherwise false */ export declare const isArrayBuffer: (value: any) => value is ArrayBuffer; /** * Determine if a value is a String. * * @param {Object} value The value to test. * @returns {boolean} True if value is a String, otherwise false. */ export declare const isString: (value: any) => value is string; /** * Determine if a value is a Number. * * @param {Object} value The value to test. * @returns {boolean} True if value is a Number, otherwise false. */ export declare const isNumber: (value: any) => value is number; /** * Determine if a value is an Object * * @param {Object} value The value to test. * @returns {boolean} True if value is an Object, otherwise false. */ export declare const isObject: (value: any) => value is object; /** * Determine if a value is only a Object, not an `Array` or `Function`. * * @param {Object} value The value to test. * @return {boolean} True if value is a `Object` only, otherwise false. */ export declare const isObjectOnly: (value: any) => value is object; /** * Determine if a value is a Blob * * @param {Object} value The value to test * @returns {boolean} True if value is a Blob, otherwise false */ export declare const isBlob: (value: any) => value is Blob; /** * Determine if a value is a Function * * @param {Object} value The value to test * @returns {boolean} True if value is a Function, otherwise false */ export declare const isFunction: (value: any) => value is Function; /** * Determine if a value is a Date * * @param {Object} value The value to test * @returns {boolean} True if value is a Date, otherwise false */ export declare const isDate: (value: any) => value is Date; /** * Determine if a value is a Stream * * @param {Object} value The value to test * @returns {boolean} True if value is a Stream, otherwise false */ export declare const isStream: (value: any) => value is Stream; /** * Determine if a value is a boolean * * @param {Object} value The value to test * @returns {boolean} True if value is a boolean, otherwise false */ export declare const isBool: (value: any) => value is boolean; /** * Determine if a value is a null * * @param {Object} value The value to test * @returns {boolean} True if value is a null, otherwise false */ export declare const isNull: (value: any) => value is null; /** * Determine if platform is Windows * * @returns {boolean} True if Windows OS, otherwise false */ export declare const isWindows: () => boolean; /** * Determine if platform is Linux * * @returns {boolean} True if Linux OS, otherwise false */ export declare const isLinux: () => boolean; /** * Determine if platform is Apple Mac * * @returns {boolean} True if Apple macOS, otherwise false */ export declare const isMac: () => boolean; /** * Include an `CommonJS` module the old way. * * @param {string} module */ export declare const require: NodeRequire; export default Sys; export declare const System: typeof Sys;