Ein Kommando fahren und alles einsammeln, was es sagt.
(command, args, options = {})
| 264 | |
| 265 | /** Ein Kommando fahren und alles einsammeln, was es sagt. */ |
| 266 | function run(command, args, options = {}) { |
| 267 | const started = Date.now(); |
| 268 | return new Promise((done) => { |
| 269 | const child = spawn(command, args, { |
| 270 | cwd: options.cwd ?? ROOT, |
| 271 | env: { |
| 272 | ...process.env, |
| 273 | NO_UPDATE_NOTIFIER: '1', |
| 274 | npm_config_update_notifier: 'false', |
| 275 | npm_config_audit: 'false', |
| 276 | npm_config_fund: 'false', |
| 277 | CI: '1', |
| 278 | }, |
| 279 | stdio: ['ignore', 'pipe', 'pipe'], |
| 280 | }); |
| 281 | let out = ''; |
| 282 | child.stdout.on('data', (chunk) => { |
| 283 | out += chunk.toString(); |
| 284 | }); |
| 285 | child.stderr.on('data', (chunk) => { |
| 286 | out += chunk.toString(); |
| 287 | }); |
| 288 | child.on('error', (error) => done({ code: 127, out: out + error.message, ms: Date.now() - started })); |
| 289 | child.on('close', (code) => done({ code: code ?? 1, out, ms: Date.now() - started })); |
| 290 | }); |
| 291 | } |
| 292 | |
| 293 | const tail = (text, lines = 12) => |
| 294 | text.trim().split('\n').slice(-lines).map((line) => line.trimEnd()); |