Skip to content

Commit d53171e

Browse files
committed
feat: pipe stdio!
Signed-off-by: Kipras Melnikovas <[email protected]>
1 parent f4b83ef commit d53171e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

run.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ const parseArgv = () => (
4444
}
4545
);
4646

47+
/**
48+
* will pipe stdio as if we were running the command ourselves!
49+
*
50+
* see https://stackoverflow.com/a/47338488/9285308
51+
*
52+
* usage:
53+
*
54+
* ```js
55+
* const command = "ls -la";
56+
* require("child_process").execSync(command, { ...pipeStdioOpts() });
57+
* ```
58+
*
59+
*/
60+
const pipeStdioOpts = (cwd = process.cwd()) => ({ cwd, stdio: 'inherit' });
61+
4762
run();
4863

4964
function run() {
@@ -65,7 +80,7 @@ function run() {
6580
const dir = path.dirname(t);
6681
const cmd = `yarn --cwd ${dir} build`;
6782
console.log('transform to run, build cmd', { cmd });
68-
cp.execSync(cmd);
83+
cp.execSync(cmd, { ...pipeStdioOpts() });
6984
return t;
7085
}
7186
})
@@ -77,17 +92,7 @@ function run() {
7792
const cmdToExec = `${cliPath} --parser ${parser} -e ${extensions} -t ${transformsToRun} ${fileOrDirectoryToModify}`;
7893
console.log({ cmdToExec });
7994

80-
cp.exec(cmdToExec, (err, stdout, stderr) => {
81-
if (err) {
82-
console.error(stderr);
83-
return process.exit(1);
84-
}
85-
86-
console.log(stdout);
87-
88-
console.log('succ');
89-
process.exit(0);
90-
});
95+
cp.execSync(cmdToExec, { ...pipeStdioOpts() });
9196
}
9297

9398
function parseArrayFromCsv(csv = '') {
@@ -99,7 +104,7 @@ function parseArrayFromCsv(csv = '') {
99104
}
100105

101106
function resolveTransformsFromShorthand([pathToCodemodPkg, transformVersion]) {
102-
cp.execSync(`yarn --cwd ${pathToCodemodPkg} build`);
107+
cp.execSync(`yarn --cwd ${pathToCodemodPkg} build`, { ...pipeStdioOpts() });
103108
console.log('built');
104109

105110
const pathToCodemodConfig = path.join(

0 commit comments

Comments
 (0)