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 +}