|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | 3 | const path = require('path'); |
4 | | -const {spawn} = require('child_process'); |
| 4 | +const {spawnSync} = require('child_process'); |
5 | 5 | const program = require('commander'); |
6 | 6 | const chalk = require('chalk'); |
7 | 7 | const deepAssign = require('deep-assign'); |
@@ -152,29 +152,44 @@ const exitHandler = code => { |
152 | 152 | } |
153 | 153 | }; |
154 | 154 |
|
155 | | -// Parse command |
156 | | -const cliCommand = cliAction.command |
157 | | - .replace('%action%', action || '') |
158 | | - .replace('%args%', args.join(' ')) |
159 | | - .split(' '); |
160 | | - |
161 | | -// Args |
162 | | -const user = cliAction.user ? ['--user', cliAction.user] : []; |
163 | | - |
164 | | -const cliArgs = dockerComposeFiles |
165 | | - .concat(cliAction.exec ? ['exec', ...user, cliAction.service] : []) |
166 | | - .concat(cliAction.detached ? ['-d'] : []) |
167 | | - .concat(cliAction.privileged ? ['--privileged'] : []) |
168 | | - .concat(cliAction.index ? ['--index', cliAction.index] : []) |
169 | | - .concat(cliCommand); |
170 | | - |
171 | | -if (program.verbose) { |
172 | | - console.log(chalk.gray('ENV: ' + env)); |
173 | | - console.log(chalk.gray('CWD: ' + basePath)); |
174 | | - console.log(chalk.gray('CMD: docker-compose ' + cliArgs.join(' '))); |
175 | | -} |
| 155 | +cliAction.command.forEach(command => { |
| 156 | + if (program.verbose) { |
| 157 | + console.log(chalk.gray('ENV: ' + env)); |
| 158 | + console.log(chalk.gray('CWD: ' + basePath)); |
| 159 | + } |
| 160 | + |
| 161 | + // Is it a reference to another action? |
| 162 | + if (command[0] === '@') { |
| 163 | + const refArgs = dockerProjectArgs.slice(2).concat(command.substr(1)); |
| 164 | + |
| 165 | + if (program.verbose) { |
| 166 | + console.log(chalk.gray('CMD: dopr ' + refArgs.join(' '))); |
| 167 | + } |
| 168 | + |
| 169 | + // Fire! |
| 170 | + return exitHandler(spawnSync('dopr ', refArgs, cliOptions).status); |
| 171 | + } |
176 | 172 |
|
177 | | -// Fire! |
178 | | -const childProcess = spawn('docker-compose', cliArgs, cliOptions); |
| 173 | + // Parse command |
| 174 | + const cliCommand = command |
| 175 | + .replace('%action%', action || '') |
| 176 | + .replace('%args%', args.join(' ')) |
| 177 | + .split(' '); |
179 | 178 |
|
180 | | -childProcess.on('close', exitHandler); |
| 179 | + // Args |
| 180 | + const user = cliAction.user ? ['--user', cliAction.user] : []; |
| 181 | + |
| 182 | + const cliArgs = dockerComposeFiles |
| 183 | + .concat(cliAction.exec ? ['exec', ...user, cliAction.service] : []) |
| 184 | + .concat(cliAction.detached ? ['-d'] : []) |
| 185 | + .concat(cliAction.privileged ? ['--privileged'] : []) |
| 186 | + .concat(cliAction.index ? ['--index', cliAction.index] : []) |
| 187 | + .concat(cliCommand); |
| 188 | + |
| 189 | + if (program.verbose) { |
| 190 | + console.log(chalk.gray('CMD: docker-compose ' + cliArgs.join(' '))); |
| 191 | + } |
| 192 | + |
| 193 | + // Fire! |
| 194 | + exitHandler(spawnSync('docker-compose', cliArgs, cliOptions).status); |
| 195 | +}); |
0 commit comments