mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-17 07:50:12 +01:00
feat: demo version additions
This commit is contained in:
parent
0eec54695f
commit
eee950248e
322 changed files with 23456 additions and 188 deletions
37
scripts/docs/run-command.ts
Normal file
37
scripts/docs/run-command.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue