@@ -7,6 +7,8 @@ const is = require('check-more-types')
7
7
const os = require ( 'os' )
8
8
const execa = require ( 'execa' )
9
9
10
+ const prop = name => object => object [ name ]
11
+
10
12
function getMessage ( ) {
11
13
return ggit . lastCommitId ( ) . then ( ggit . commitMessage )
12
14
}
@@ -68,11 +70,36 @@ const isNpmInstall = is.schema({
68
70
packages : is . unemptyString
69
71
} )
70
72
73
+ const isRunIf = is . schema ( {
74
+ platform : is . maybe . unemptyString ,
75
+ env : is . maybe . object
76
+ } )
77
+
71
78
function isPlatformAllowed ( platform ) {
72
79
la ( is . unemptyString ( platform ) , 'invalid allowed platform' , platform )
73
80
return platform === '*' || platform . indexOf ( os . platform ( ) ) !== - 1
74
81
}
75
82
83
+ function getCommand ( args ) {
84
+ la ( is . array ( args ) , 'expected arguments' , args )
85
+ const cloned = [ ...args ]
86
+ const flags = [ '-f' , '--file' ]
87
+ if ( flags . includes ( cloned [ 0 ] ) ) {
88
+ debug ( 'found flag' , cloned [ 0 ] )
89
+ cloned . shift ( )
90
+ cloned . shift ( )
91
+ }
92
+ const command = cloned . join ( ' ' )
93
+ debug ( 'found command' , command )
94
+ return command
95
+ }
96
+
97
+ function runIf ( command , json ) {
98
+ la ( is . unemptyString ( command ) , 'missing command to run' , command )
99
+ la ( isRunIf ( json ) , 'invalid runIf json' , json )
100
+ return execa . shell ( command , { env : json . env } ) . then ( prop ( 'stdout' ) )
101
+ }
102
+
76
103
function npmInstall ( json ) {
77
104
if ( ! json ) {
78
105
debug ( 'missing json for npm install' )
@@ -100,7 +127,14 @@ function npmInstall (json) {
100
127
return execa ( 'npm' , [ 'install' , json . packages ] , {
101
128
env,
102
129
stdio : 'inherit'
103
- } ) . then ( x => x . stdout )
130
+ } ) . then ( prop ( ' stdout' ) )
104
131
}
105
132
106
- module . exports = { getMessage, isPlatformAllowed, getJsonBlock, npmInstall }
133
+ module . exports = {
134
+ getMessage,
135
+ getCommand,
136
+ runIf,
137
+ isPlatformAllowed,
138
+ getJsonBlock,
139
+ npmInstall
140
+ }
0 commit comments