11'use strict' ;
22
33var spawn = require ( 'cross-spawn' )
4- , shelly = require ( 'shelljs' )
54 , which = require ( 'which' )
65 , path = require ( 'path' )
76 , util = require ( 'util' )
@@ -57,6 +56,20 @@ Object.defineProperty(Hook.prototype, 'colors', {
5756 }
5857} ) ;
5958
59+ /**
60+ * Execute a binary.
61+ *
62+ * @param {String } bin Binary that needs to be executed
63+ * @param {Array } args Arguments for the binary
64+ * @returns {Object }
65+ * @api private
66+ */
67+ Hook . prototype . exec = function exec ( bin , args ) {
68+ return spawn . sync ( bin , args , {
69+ stdio : 'pipe'
70+ } ) ;
71+ } ;
72+
6073/**
6174 * Parse the package.json so we can create an normalize it's contents to
6275 * a usable configuration structure.
@@ -157,19 +170,14 @@ Hook.prototype.initialize = function initialize() {
157170 //
158171 if ( ! this . git ) return this . log ( this . format ( Hook . log . binary , 'git' ) , 0 ) ;
159172
160- this . root = this . shelly . exec ( this . git + ' rev-parse --show-toplevel' , {
161- silent : true
162- } ) ;
163-
164- this . status = this . shelly . exec ( this . git + ' status --porcelain' , {
165- silent : true
166- } ) ;
173+ this . root = this . exec ( this . git , [ 'rev-parse' , '--show-toplevel' ] ) ;
174+ this . status = this . exec ( this . git , [ 'status' , '--porcelain' ] ) ;
167175
168176 if ( this . status . code ) return this . log ( Hook . log . status , 0 ) ;
169177 if ( this . root . code ) return this . log ( Hook . log . root , 0 ) ;
170178
171- this . status = this . status . output . trim ( ) ;
172- this . root = this . root . output . trim ( ) ;
179+ this . status = this . status . stdout . toString ( ) . trim ( ) ;
180+ this . root = this . root . stdout . toString ( ) . trim ( ) ;
173181
174182 try {
175183 this . json = require ( path . join ( this . root , 'package.json' ) ) ;
@@ -190,9 +198,7 @@ Hook.prototype.initialize = function initialize() {
190198 // execute.
191199 //
192200 if ( this . config . template ) {
193- this . shelly . exec ( this . git + ' config commit.template "' + this . config . template + '"' , {
194- silent : true
195- } ) ;
201+ this . exec ( this . git , [ 'config' , 'commit.template' , '"' + this . config . template + '"' ] ) ;
196202 }
197203
198204 if ( ! this . config . run ) return this . log ( Hook . log . run , 0 ) ;
@@ -213,7 +219,7 @@ Hook.prototype.run = function runner() {
213219
214220 //
215221 // There's a reason on why we're using an async `spawn` here instead of the
216- // `shelly .exec`. The sync `exec` is a hack that writes writes a file to
222+ // `shelljs .exec`. The sync `exec` is a hack that writes writes a file to
217223 // disk and they poll with sync fs calls to see for results. The problem is
218224 // that the way they capture the output which us using input redirection and
219225 // this doesn't have the required `isAtty` information that libraries use to
@@ -239,7 +245,6 @@ Hook.prototype.run = function runner() {
239245 * @public
240246 */
241247Hook . prototype . format = util . format ;
242- Hook . prototype . shelly = shelly ;
243248
244249/**
245250 * The various of error and status messages that we can output.
0 commit comments