Heet Vakharia
Heet Vakharia

Reputation: 445

How can I run command which has it own options in node child process exec

I am creating make node CLI automate my npm package publishing, I am struck by this problem. After all Confirmation, I want to run the command semantic-release but problem it has its own prompts I currently use exec command but It does not show any prompts created by semantic-release

Code

const timer = showLoading(`running ${chalk.blue(command)} `);
exec(command, (error, stdout, stderr) => {
                process.stdout.write(chalk.dim(`\r running ${chalk.blue(command)}   `));
                clearInterval(timer);
                defaults.onFinish();
                if (error) {
                    defaults.onError(error);
                    console.log(error);
                }
                defaults.onSuccess(stdout);
                console.log(stdout);
            });

Upvotes: 2

Views: 406

Answers (2)

Besworks
Besworks

Reputation: 4483

You can show the prompts by spawning a synchronous child process that inherits it's stdio pipes from the parent process.

JS :

import { spawnSync } from 'child_process';
let { status } = spawnSync('./test.sh', [], { stdio: 'inherit' });
if (status > 0) { throw new Error('spawned process exited abnormally'); }

test.sh

#!/bin/bash
read -p 'enter something: ' value
[ -z "$value" ] && exit 1
echo "$value"

Upvotes: 2

Elias Salom
Elias Salom

Reputation: 326

I have used this way to create my own CLI, it's an easy way to create all the commands that I want and to do what I want, check the link maybe that helps you, in the website there also good explanation with images

Click here

Upvotes: -1

Related Questions