@@ -57,16 +57,23 @@ function structureScripts(scripts) {
5757 // start out by giving every script a `default`
5858 const defaultedScripts = Object . keys ( scripts ) . reduce ( ( obj , key ) => {
5959 const keyParts = key . split ( ':' )
60- let deepKey = [ ...keyParts , 'default' ] . join ( '.' )
60+ const isKeyScriptHook = isScriptHook ( keyParts [ 0 ] ) ;
61+ let deepKey = keyParts . map ( key => camelCase ( key ) ) . join ( '.' )
62+ let defaultDeepKey = `${ deepKey } .default`
6163 if ( key . indexOf ( 'start' ) === 0 ) {
62- deepKey = [
64+ defaultDeepKey = [
6365 'default' ,
6466 ...keyParts . slice ( 1 , keyParts . length ) ,
6567 'default' ,
6668 ] . join ( '.' )
6769 }
68- const script = scripts [ key ]
69- set ( obj , deepKey , script )
70+ let script = scripts [ key ]
71+ if ( ! isKeyScriptHook ) {
72+ const preHook = scripts [ `pre${ key } ` ] ? `nps pre${ deepKey } && ` : ''
73+ const postHook = scripts [ `post${ key } ` ] ? ` && nps post${ deepKey } ` : ''
74+ script = `${ preHook } ${ script } ${ postHook } `
75+ }
76+ set ( obj , defaultDeepKey , script )
7077 return obj
7178 } , { } )
7279 // traverse the object and replace all objects that
@@ -102,9 +109,8 @@ function jsObjectStringify(object, indent) {
102109 } else {
103110 value = `'${ escapeSingleQuote ( script ) } '`
104111 }
105- const camelKey = camelCase ( key )
106112 const comma = isLast ( object , index ) ? '' : ','
107- return `${ string } \n${ indent } ${ camelKey } : ${ value } ${ comma } `
113+ return `${ string } \n${ indent } ${ key } : ${ value } ${ comma } `
108114 } ,
109115 '' ,
110116 )
@@ -123,3 +129,7 @@ function escapeSingleQuote(string) {
123129function isLast ( object , index ) {
124130 return Object . keys ( object ) . length - 1 === index
125131}
132+
133+ function isScriptHook ( script ) {
134+ return script . indexOf ( 'pre' ) === 0 || script . indexOf ( 'post' ) === 0
135+ }
0 commit comments