technote-space/github-action-helper

use spawn instead of exec

Closed this issue · 1 comments

コマンドが完了するまでログが表示されないため

function execCommand(cmd: string): Promise<string> {
  return new Promise((resolve, reject) => {
    const process = spawn(cmd, [], { shell: true })
    let stdout = ""
    process.stdout.on('data', (data) => {
      console.log(data.toString());
      stdout += data.toString();
    });

    process.stderr.on('data', (data) => {
      console.error(data.toString());
    });

    process.on('exit', (code) => {
      if (code !== 0) {
        reject(new Error(code ? code.toString() : undefined))
      }
      resolve(stdout)
    });
  });
}