From 99ebf824e3f50a092574bdfc25780aeeb813bee1 Mon Sep 17 00:00:00 2001 From: Ayoub Adib Date: Sat, 14 Dec 2019 10:15:49 +0100 Subject: [PATCH] fix(docz-core): forward cli status code properly (#1319) --- core/docz-core/src/bundler/build.ts | 4 ++-- core/docz-core/src/commands/serve.ts | 4 ++-- core/docz-core/src/utils/spawn.ts | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 core/docz-core/src/utils/spawn.ts diff --git a/core/docz-core/src/bundler/build.ts b/core/docz-core/src/bundler/build.ts index e4beaf4c2..211269b85 100644 --- a/core/docz-core/src/bundler/build.ts +++ b/core/docz-core/src/bundler/build.ts @@ -1,11 +1,11 @@ import * as fs from 'fs-extra' import * as path from 'path' -import spawn from 'cross-spawn' import sh from 'shelljs' import * as paths from '../config/paths' import { BuildFn } from '../lib/Bundler' import { ensureFiles } from './machine/actions' +import { spawnSync } from '../utils/spawn' export const build: BuildFn = async (config, dist) => { const publicDir = path.join(paths.docz, 'public') @@ -19,6 +19,6 @@ export const build: BuildFn = async (config, dist) => { } ensureFiles({ args: config }) sh.cd(paths.docz) - spawn.sync('npm', cliArgs, { stdio: 'inherit' }) + spawnSync('npm', cliArgs) await fs.copy(publicDir, dist) } diff --git a/core/docz-core/src/commands/serve.ts b/core/docz-core/src/commands/serve.ts index 72527c118..f09d10e63 100644 --- a/core/docz-core/src/commands/serve.ts +++ b/core/docz-core/src/commands/serve.ts @@ -1,10 +1,10 @@ -import spawn from 'cross-spawn' import sh from 'shelljs' import * as paths from '../config/paths' +import { spawnSync } from '../utils/spawn' export const serve = async () => { const cliArgs = ['run', 'serve'] sh.cd(paths.docz) - spawn.sync('npm', cliArgs, { stdio: 'inherit' }) + spawnSync('npm', cliArgs) } diff --git a/core/docz-core/src/utils/spawn.ts b/core/docz-core/src/utils/spawn.ts new file mode 100644 index 000000000..cec5348a6 --- /dev/null +++ b/core/docz-core/src/utils/spawn.ts @@ -0,0 +1,13 @@ +import crossSpawn from 'cross-spawn' + +export const spawnSync = (command: string, args?: readonly string[]) => { + const output = crossSpawn.sync(command, args, { + stdio: ['inherit', 'inherit', 'pipe'], + }) + + if (!output.stderr) { + return + } + + process.exitCode = output.status || 1 +}