Skip to content

Commit

Permalink
fix #101 - fix --output=path/to/filename
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Dec 28, 2018
1 parent b71adb0 commit ab72450
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ function main (args) {
process.exit(0)
}

if (!fs.existsSync(opts.outputDir)) {
fs.mkdirSync(opts.outputDir)
const fullOutputDir = opts.output
? path.join(opts.outputDir, path.dirname(opts.output))
: opts.outputDir

if (!fs.existsSync(fullOutputDir)) {
fs.mkdirSync(fullOutputDir)
}

getStdin().then((txt) => {
Expand All @@ -114,7 +118,7 @@ function main (args) {

const write = (info, _, done) => {
const itemName = getItemName(info)
const outPath = path.resolve(opts.outputDir, `${itemName}.${info.format}`)
const outPath = path.resolve(fullOutputDir, `${itemName}.${info.format}`)

if (pipeToStdOut) {
str(info.body)
Expand Down
24 changes: 24 additions & 0 deletions test/integration/orca_graph_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ tap.test('should respect --output when set (just filename case)', t => {
})
})

tap.test('should respect --output when set (path/to/filename case)', t => {
const subprocess = _spawn(t, [DUMMY_DATA, '--output=build/tmp/graph.png'])
const p = path.join(process.cwd(), 'build', 'tmp', 'graph.png')

subprocess.on('close', code => {
t.same(code, 0)
t.ok(fs.existsSync(p))
fs.unlinkSync(p)
t.end()
})
})

tap.test('should respect --output-dir when set', t => {
const subprocess = _spawn(t, [DUMMY_DATA, '--output-dir=build'])
const p = path.join(process.cwd(), 'build', 'fig.png')
Expand All @@ -93,3 +105,15 @@ tap.test('should respect --output (filename) and --output-dir when set', t => {
t.end()
})
})

tap.test('should respect --output (path/to/filename) and --output-dir when set', t => {
const subprocess = _spawn(t, [DUMMY_DATA, '--output-dir=build', '--output=tmp/graph.png'])
const p = path.join(process.cwd(), 'build', 'tmp', 'graph.png')

subprocess.on('close', code => {
t.same(code, 0)
t.ok(fs.existsSync(p))
fs.unlinkSync(p)
t.end()
})
})

0 comments on commit ab72450

Please sign in to comment.