Safe PS
Work with processes safely and easily with Node.js
Install
- Use:
require('safeps')
- Install:
npm install --save safeps
Usage
var safeps = require('safeps');
Processes
openProcess(task)
fire a process task, and keep it open until the task's completion callback fires
spawn(command, opts?, next?)
spawn a process, with respect to the maximum amount of processes we can open at once
command
an array of arguments to executeopts={safe:true, read:true, output:false, stdin:null}
options are also sent on to require('child_process').spawn
safe
whether or not we should attempt to get the absolute executable path of the command to execute via require('safeps').getExecPath
read
whether or not we should listen to the child process's stdout and stderr streams for use in the completion callbackoutput
if set to true
will output the child process's stdout to our process's stdoutstdin
if set will be written to the child process's stdin
next(err, stdout, stderr, code, signal)
spawnMultiple(commands, opts?, next?)
spawn multiple processes, forwards on to require('safeps').spawn
commands
an array of commands to executeopts={concurrency:1}
options are also sent on to require('safeps').spawn
concurrency
how many processes should we execute at once?
next(err, results)
results = [result...]
result = [err, stdout, stderr, code, signal]
spawnCommand(command, args, opts?, next?)
alias of require('safeps').spawn
but with the command
prefixed to the args
, e.g. spawnCommand('git', 'status')
spawnCommands(command, multiArgs, opts?, next?
alias of require('safeps').spawnMultiple
but with the command
prefixed to the multiArgs
, e.g. spawnCommands('git', [['status'],['pull']])
exec(command, opts?, next?)
execute a process, with respect to the maximum amount of processes we can open at once
command
a string to executeopts={output:false}
options are also sent on to require('child_process').exec
output
if set to true
will set the stdio
option to inherit
which will output the child process's stdout and stderr to our own
next(err, stdout, stderr)
execMultiple(commands, opts, next)
execute multiple processes, forwards on to require('safeps').exec
commands
is an array of commands to executeopts={concurrency:1}
options are also sent to require('safeps').exec
concurrency
how many processes should we execute at once?
next(err, results)
results = [result...]
result = [err, stdout, stderr]
Paths
determineExecPath(possibleExecPaths, next)
determine an executable path from a list
possibleExecPaths
an array of possible executable paths that we shall evaluatenext(err, execPath)
getEnvironmentPaths()
returns an array of the environment paths for executablesgetStandardExecPaths(execName?)
return an array of the the environment paths for executables with the cwd prepended
execName
if provided, is added onto each of the paths
getExecPath(execName, next)
get the absolute executable path, forwards to get#{execName}Path
when appropriate
getHomePath(next)
get the user's home path
getTmpPath(next)
get the temporary path
getGitPath(next)
get the git path
getNodePath(next)
get the node path
getNpmPath(next)
get the npm path
Modules
initGitRepo(opts, next?)
get the git path, forwards on to require('safeps').spawnCommand
opts={cwd:process.cwd(), url:null, remote:'origin', branch:'master'}
options are also sent on to require('safeps').spawnCommand
cwd
the path to initialize the repo tourl
the url to initializeremote
the remote name to associate the url
tobranch
the branch name to initialize the repo to
next(err, results)
, results = [result...]
, result = [err, stdout, stderr, code, signal]
initOrPullGitRepo(opts, next?)
if the path exists, update it, otherwise initialize it, forwards on to require('safeps').spawnCommand
opts={cwd:process.cwd(), url:null, remote:'origin', branch:'master'}
options are also sent on to require('safeps').spawnCommand
next(err, method, results)
method
is either pull
or init
depending on the method usedresults = [result...]
result = [err, stdout, stderr, code, signal]
initNodeModules(opts, next?)
initialize node modules, forwards on to require('safeps').spawn
opts={cwd:process.cwd(), args:[], force:false}
options are also sent on to require('safeps').spawnCommand
cwd
the path to initialize the repo toargs
an array of arguments to add onto the initialize commandforce
whether or not to still initialize modules if node_modules
already exists
next(err, results)
, results = [result...]
, result = [err, stdout, stderr, code, signal]
Environment
requireFresh(path)
require the file without adding it to the cacheisWindows()
are we running on windows?getLocaleCode(lang?=process.env.LANG)
get the locale code from a language, e.g. en_au
getLanguageCode(localeCode?=getLocaleCode())
get the language code from a locale code, e.g. en
getCountryCode(localeCode?=getLocaleCode())
get the country code from a locale code, e.g. au
History
Discover the change history by heading on over to the HISTORY.md
file.
Contribute
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Backers
Maintainers
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
Contributors
These amazing people have contributed code to this project:
Become a contributor!
License
Licensed under the incredibly permissive MIT license
Copyright © 2013+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
Copyright © 2011-2012 Benjamin Lupton b@lupton.cc (http://balupton.com)