node-sys
Universal package installer, get the command for managing packages, or auto install any package, using one command for all platforms. E.g. sudo apt-get install
!@#$software for Debian-based systems, would be node-sys
!@#$software.
This is mainly focused on initial installation of an Node JS packages that needs additional host software installed. This allows pre and post script install routines. Can also automate the installation of macOS Brew, and Windows Chocolatey package managers.
node-sys
will try to find which system packaging is installed for the given process.platform
. If no system package manager is found, 'No package manager found!'
is returned.
A spawning
cross-platform version of Node's child_process.spawn
that returns a Promise, with additions:
- easily execute as administrator, on
Windows
a pop up UAC window will appear. - pass callbacks, for
stderr
and stdout
on data
events, any returns will be the reject/resolve result. fork
another script, a Node Js module instance, for additional sub processing base on stderr
or stdout
events.
- pass additional callback for the
message
event.
A series of general use case strick
type checkers.
Install
npm install node-sys
Usage
import { packager } from 'node-sys';
const sys = packager();
console.log('Do system OS require sudo? ' + sys.sudo);
console.log('The system OS install command: ' + sys.command);
console.log('To fully install a `pandoc` package run: ' + sys.installer + ' pandoc');
Install vim
package onto host, using system's default package manager
import { installer } from 'node-sys';
const onprogress = (object) => {
console.log(object.output);
}
installer('vim', onprogress)
.then(function(data){
console.log(data);
})
.catch(function(err) {
console.log(err);
});
API - spawning
(command, arguments, progressOptions, options)
import { spawning } from 'node-sys';
Spawning
takes an additional argument, progressOptions
, its options
are the same as those of child_process.spawn
plus:
sudo: boolean,
fork: string,
onerror: callable,
onprogress: callable,
onmessage: callable,
Spawning
returns a promise whose result will be any output or any data return in the progress callback.
The progress callback will receive an object with these properties:
-
spawn:
Object - Spawned child process instance handle.
- Access the child process object.
-
output:
String - Output from stdout.
- Output can be altered and if returned will replace the otherwise resolved result.
-
fork:
Object - An additional forked Node Js process handle, IPC communication channel.
- Execute additional processing base off of sub child process output, with module a script.
If there's an error running the child process, received data on stderr, or errors in progress callback, spawning
rejects the returned promise.
General strict
type check
functions
import {
isArray,
isUndefined,
isBuffer,
isArrayBuffer,
isString,
isNumber,
isObject,
isObjectOnly,
isBlob,
isFunction,
isDate,
isStream,
isNull,
isBool,
isWindows,
isLinux,
isMac,
} from 'node-sys';
Find any executable
The sync
from node-which has been exported to where
.
import { where } from 'node-sys';
let found = where('node');
Use CommonJS require
like before in ESM
import { require } from 'node-sys';
const package = require('package');
CLI Usage
npm i -g node-sys
To display your system package manage command.
$ node-sys
brew install
To actually install an system package.
$ node-sys vim
installing...
To install an System OS package manager.
- Will install chocolatey for Windows OS
- Will install brew for Apple macOS
$ node-sys -g | --get # or npm run get-installer
...
Supported package managers
FreeBSD
Linux
OS X
Solaris
Windows