mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-08-14 12:31:01 +01:00
Reintroduce HackMyCore, dropping the interim submodule, and reorganize and improve tests.
29 lines
767 B
CoffeeScript
29 lines
767 B
CoffeeScript
###*
|
|
Safe spawn utility for HackMyResume / FluentCV.
|
|
@module utils/safe-spawn
|
|
@license MIT. See LICENSE.md for details.
|
|
###
|
|
|
|
module.exports = ( cmd, args, isSync, callback ) ->
|
|
|
|
try
|
|
|
|
# .spawnSync not available on earlier Node.js, so default to .spawn
|
|
spawn = require('child_process')[ if isSync then 'spawnSync' else 'spawn'];
|
|
info = spawn cmd, args
|
|
|
|
# Check for error depending on whether we're sync or async
|
|
if !isSync
|
|
info.on 'error', (err) ->
|
|
if callback? then callback err; return
|
|
else throw cmd: cmd, inner: err
|
|
return
|
|
else
|
|
if info.error
|
|
if callback? then callback err; return
|
|
else throw cmd: cmd, inner: info.error
|
|
|
|
catch
|
|
if callback? then callback _error
|
|
else throw _error
|