Skip to content

Commit

Permalink
fix(docz-core): forward cli status code properly (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb authored and rakannimer committed Dec 14, 2019
1 parent 29e0165 commit 99ebf82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/docz-core/src/bundler/build.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions core/docz-core/src/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 13 additions & 0 deletions core/docz-core/src/utils/spawn.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 99ebf82

Please sign in to comment.