-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proper logging to output shown when verbose flag is active
- Loading branch information
1 parent
79a9ecb
commit 3672a68
Showing
6 changed files
with
33 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
import childProcess from "child_process"; | ||
import { promisify } from "util"; | ||
import signal from "signale" | ||
|
||
const {Signale} = signal; | ||
|
||
const exec = promisify(childProcess.exec); | ||
|
||
export async function executeCommand( | ||
command: string, | ||
verbose = false | ||
): Promise<string> { | ||
const signale = new Signale({scope: "exec", interactive: !verbose}) | ||
|
||
if (verbose) { | ||
console.log(command); | ||
signale.info(`Running command: ${command}`); | ||
} | ||
|
||
try { | ||
const { stdout, stderr } = await exec(command); | ||
|
||
if (stderr && verbose) { | ||
console.error(stderr); | ||
signale.error(stderr); | ||
} | ||
|
||
if (verbose) { | ||
console.log(stdout); | ||
signale.info(`Command output: ${stdout}`); | ||
} | ||
|
||
return stdout.trim(); | ||
} catch (error) { | ||
console.log(error); | ||
signale.error(error); | ||
process.exit(1); | ||
} | ||
} |