@antora/assembler 1.0.0-alpha.9 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/lib/assemble-content.js +213 -26
- package/lib/configure.js +96 -0
- package/lib/index.js +2 -2
- package/lib/load-config.js +41 -24
- package/lib/{produce-aggregate-document.js → produce-assembly-file.js} +309 -153
- package/lib/produce-assembly-files.js +146 -0
- package/lib/util/compute-out.js +57 -0
- package/lib/util/create-asciidoc-file.js +18 -0
- package/package.json +15 -13
- package/lib/asciidoctor/reducer-extension.js +0 -235
- package/lib/produce-aggregate-documents.js +0 -145
- package/lib/util/run-command.js +0 -60
package/lib/util/run-command.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs')
|
|
4
|
-
const LazyReadable = require('./lazy-readable')
|
|
5
|
-
const { spawn } = require('node:child_process')
|
|
6
|
-
|
|
7
|
-
const IS_WIN = process.platform === 'win32'
|
|
8
|
-
const DBL_QUOTE_RX = /"/g
|
|
9
|
-
|
|
10
|
-
const shellEscape = IS_WIN
|
|
11
|
-
? (val) => {
|
|
12
|
-
if (val.charAt() === '-') {
|
|
13
|
-
return val
|
|
14
|
-
} else if (~val.indexOf('"')) {
|
|
15
|
-
return ~val.indexOf(' ') ? `"${val.replace(DBL_QUOTE_RX, '"""')}"` : val.replace(DBL_QUOTE_RX, '""')
|
|
16
|
-
} else if (~val.indexOf(' ')) {
|
|
17
|
-
return `"${val}"`
|
|
18
|
-
}
|
|
19
|
-
return val
|
|
20
|
-
}
|
|
21
|
-
: (val) => val
|
|
22
|
-
|
|
23
|
-
async function runCommand (cmd, argv = [], opts = {}) {
|
|
24
|
-
if (!cmd) throw new TypeError('Command not specified')
|
|
25
|
-
const cmdv = cmd.split(' ').map(shellEscape)
|
|
26
|
-
const { input, output, implicitStdin, ...spawnOpts } = opts
|
|
27
|
-
if (input) input instanceof Buffer ? implicitStdin || argv.push('-') : argv.push(input)
|
|
28
|
-
if (IS_WIN) Object.assign(spawnOpts, { shell: true, windowsHide: true })
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const stdout = []
|
|
31
|
-
const stderr = []
|
|
32
|
-
const ps = spawn(cmdv[0], [...cmdv.slice(1), ...argv.map(shellEscape)], spawnOpts)
|
|
33
|
-
ps.on('close', (code) => {
|
|
34
|
-
if (code === 0) {
|
|
35
|
-
if (stderr.length) process.stderr.write(stderr.join(''))
|
|
36
|
-
resolve(output ? new LazyReadable(() => fs.createReadStream(output)) : Buffer.from(stdout.join('')))
|
|
37
|
-
} else {
|
|
38
|
-
let msg = `Command failed: ${ps.spawnargs.join(' ')}`
|
|
39
|
-
if (stderr.length) msg += '\n' + stderr.join('')
|
|
40
|
-
reject(new Error(msg))
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
ps.on('error', (err) => reject(err.code === 'ENOENT' ? new Error(`Command not found: ${cmdv.join(' ')}`) : err))
|
|
44
|
-
ps.stdout.on('data', (data) => (output ? process.stdout.write(data) : stdout.push(data)))
|
|
45
|
-
ps.stderr.on('data', (data) => stderr.push(data))
|
|
46
|
-
if (input instanceof Buffer) {
|
|
47
|
-
try {
|
|
48
|
-
ps.stdin.on('error', () => undefined)
|
|
49
|
-
ps.stdin.end(input)
|
|
50
|
-
} catch (err) {
|
|
51
|
-
if (!ps.stdin.writableEnded) ps.stdin.end()
|
|
52
|
-
reject(err)
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
ps.stdin.end()
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = runCommand
|