From a1f9c5eb438066f306526d241c0a698ec8e7177e Mon Sep 17 00:00:00 2001 From: prklm10 Date: Thu, 12 Oct 2023 10:04:52 +0530 Subject: [PATCH] intial POC --- a.js | 5 +++++ packages/cli-exec/src/exec.js | 38 +++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 a.js diff --git a/a.js b/a.js new file mode 100644 index 000000000..c7e3606e1 --- /dev/null +++ b/a.js @@ -0,0 +1,5 @@ +console.log("HEl01") +console.log("HElo2") +console.log("HElo3") +console.log("HElo4") +console.logsd("HElo5") \ No newline at end of file diff --git a/packages/cli-exec/src/exec.js b/packages/cli-exec/src/exec.js index 76aa61a46..d1f9d4620 100644 --- a/packages/cli-exec/src/exec.js +++ b/packages/cli-exec/src/exec.js @@ -57,6 +57,7 @@ export const exec = command('exec', { // attempt to start percy if enabled if (!percy) { log.warn('Percy is disabled'); + // we can send this data as well. } else { try { // Skip this for app because they are triggered as app:exec @@ -97,14 +98,47 @@ export const exec = command('exec', { async function* spawn(cmd, args) { let { default: crossSpawn } = await import('cross-spawn'); let proc, closed, error; + let stderrData = ''; + let stdoutData = ''; try { - proc = crossSpawn(cmd, args, { stdio: 'inherit' }); - proc.on('close', code => (closed = code)); + proc = crossSpawn(cmd, args, { stdio: 'pipe' }); + // Writing stdout of proc to process + if (proc.stdout) { + proc.stdout.on('data', (data) => { + stdoutData += data; + process.stdout.write(`${data}`); + }); + } + + if (proc.stderr) { + proc.stderr.on('data', (data) => { + stderrData += data; + process.stderr.write(`${data}`); + }); + } + proc.on('error', err => (error = err)); + proc.on('close', (code, signal) => { + closed = code; + if (code === 0) { + console.log('Process successfully completed'); + } else { + console.error(`Process exited with code ${code}`); + } + + //console.error('Stderr:', stderrData); + console.error('stdoutData:', stdoutData.length); + console.error('Stderr:', stderrData.length); + }); + + // run until an event is triggered /* eslint-disable-next-line no-unmodified-loop-condition */ + // console.error('Stderr:', stderrData); + // console.error('Stderr:', stderrData.length); + while (closed == null && error == null) { yield new Promise(r => setImmediate(r)); }