Skip to content

Commit be861ce

Browse files
authored
resolves #196 wait for all output to be written to stdout (#197)
1 parent 09588b8 commit be861ce

File tree

5 files changed

+1419
-68
lines changed

5 files changed

+1419
-68
lines changed

Diff for: lib/invoker.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* global Opal */
12
const fs = require('fs')
23
const ospath = require('path')
4+
const { once } = require('events')
35
const asciidoctor = require('@asciidoctor/core')()
46
const pkg = require('../package.json')
57
const stdin = require('./stdin')
@@ -24,10 +26,10 @@ class Invoker {
2426
const failureLevel = options.failure_level
2527
if (this.options.stdin) {
2628
await Invoker.convertFromStdin(options, args)
27-
Invoker.exit(failureLevel)
29+
await Invoker.exit(failureLevel, options)
2830
} else if (files && files.length > 0) {
2931
Invoker.processFiles(files, verbose, args.timings, options)
30-
Invoker.exit(failureLevel)
32+
await Invoker.exit(failureLevel, options)
3133
} else {
3234
this.showHelp()
3335
process.exit(0)
@@ -99,7 +101,7 @@ CLI version ${pkg.version}`
99101
}
100102

101103
static processFiles (files, verbose, timings, options) {
102-
files.forEach((file) => {
104+
for (const file of files) {
103105
if (verbose) {
104106
console.log(`converting file ${file}`)
105107
}
@@ -111,7 +113,7 @@ CLI version ${pkg.version}`
111113
} else {
112114
Invoker.convertFile(file, options)
113115
}
114-
})
116+
}
115117
}
116118

117119
static requireLibrary (requirePath, cwd = process.cwd()) {
@@ -142,12 +144,15 @@ CLI version ${pkg.version}`
142144
}
143145
}
144146

145-
static exit (failureLevel) {
147+
static async exit (failureLevel, options = {}) {
146148
let code = 0
147149
const logger = asciidoctor.LoggerManager.getLogger()
148150
if (logger && typeof logger.getMaxSeverity === 'function' && logger.getMaxSeverity() && logger.getMaxSeverity() >= failureLevel) {
149151
code = 1
150152
}
153+
if (options.to_file === Opal.gvars.stdout) {
154+
await once(process.stdout.end(), 'close')
155+
}
151156
process.exit(code)
152157
}
153158
}

Diff for: package-lock.json

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"chai": "^4.2.0",
5555
"dirty-chai": "^2.0.1",
5656
"mocha": "9.2.2",
57-
"sinon": "^13.0.0",
57+
"sinon": "^14.0.0",
5858
"standard": "16.0.4"
5959
},
6060
"peerDependencies": {

0 commit comments

Comments
 (0)