ngx-admin/scripts/docs/run-command.ts
Alex Kurbako 63ac65eada Gh pages deploy fix (#5669)
* fix(app):redirect after 404

* fix(app):docs building script

* fix(app):add gulpfile for docs

* fix(app): directory splitting

* fix(app): build docs script

* fix(app): build docs script

* fix(app): build docs script

* fix(app): relative path for scss

* fix(app): relative path for scss

* fix(app): relative path for scss

* fix(app):fix footer icons

* fix(app):fix footer icons

* fix(app):fix footer icons

* fix(app):config

* fix(app):remove small-social

* fix(docs): footer icons style

* fix(docs): material page index file

* fix(docs): descriptions and keyword

* fix(docs): og description

* fix(docs): og description and title

* fix(docs): dem,o branch url

* fix(docs): dynamic title for docs page

* fix(docs): remove unused script

* fix(docs): static title

Co-authored-by: Evgeny Lupanov <e.lupanov@akveo.com>
2020-08-28 19:29:15 +03:00

37 lines
1,022 B
TypeScript

import { exec } from 'child_process';
import { promisify } from 'util';
export interface RunCommandOptions {
cwd?: string;
showLog?: boolean;
}
const DEFAULT_OPTIONS: RunCommandOptions = { cwd: process.cwd(), showLog: false };
export async function runCommand(command: string, options?: RunCommandOptions) {
let { cwd, showLog } = Object.assign({}, DEFAULT_OPTIONS, options);
try {
console.log(`Running "${command}" in "${cwd}"`);
const { stdout, stderr } = await promisify(exec)(command, { cwd });
if (showLog && stdout) {
console.log(stdout);
}
if (stderr) {
console.log(`stderr from "${command}" in "${cwd}"`);
console.warn(stderr);
}
} catch ({ message, stdout, stderr }) {
let errorMessage = `Error running "${command}" in "${cwd}": ${message}.`;
if (stdout) {
errorMessage += `\nstdout: ${stdout}`;
console.error(stdout);
}
if (stderr) {
errorMessage += `\nstderr: ${stderr}`;
}
throw new Error(errorMessage);
}
}