@antora/assembler 1.0.0-beta.8 → 1.0.0-rc.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/adapters/asciidoctor/jsonl-logger.rb +25 -0
- package/lib/assemble-content.js +93 -70
- package/lib/configure.js +36 -15
- package/lib/constants.js +22 -0
- package/lib/filter-component-versions.js +25 -62
- package/lib/load-config.js +74 -39
- package/lib/log-command.js +20 -0
- package/lib/produce-assembly-file.js +375 -407
- package/lib/produce-assembly-files.js +51 -60
- package/lib/select-mutable-attributes.js +1 -0
- package/lib/util/create-resource-key.js +7 -0
- package/lib/util/generate-scoped-id.js +25 -0
- package/lib/util/matcher.js +150 -0
- package/lib/util/parse-resource-ref.js +36 -0
- package/lib/util/resolver.js +36 -0
- package/lib/util/rewriter.js +206 -0
- package/lib/util/rx.js +5 -0
- package/lib/util/unconvert-inline-asciidoc.js +22 -14
- package/package.json +14 -12
- package/lib/util/compute-out.js +0 -57
- package/lib/util/create-asciidoc-file.js +0 -17
package/lib/load-config.js
CHANGED
|
@@ -3,43 +3,47 @@
|
|
|
3
3
|
const expandPath = require('@antora/expand-path-helper')
|
|
4
4
|
const fsp = require('node:fs/promises')
|
|
5
5
|
const os = require('node:os')
|
|
6
|
+
const ospath = require('node:path')
|
|
6
7
|
const yaml = require('js-yaml')
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'sectionMergeStrategy',
|
|
12
|
-
'linkReferenceStyle',
|
|
13
|
-
'dropExplicitXrefText',
|
|
14
|
-
]
|
|
9
|
+
const { LEGACY_ASSEMBLY_KEYS } = require('./constants')
|
|
10
|
+
const CAMEL_CASE_STOP_PATHS = ['asciidoc.attributes', 'assembly.attributes']
|
|
11
|
+
const PACKAGE_NAME = require('../package.json').name
|
|
15
12
|
|
|
16
|
-
function loadConfig (playbook, configSource = '
|
|
13
|
+
function loadConfig (playbook, configSource, preferredQualifier = '') {
|
|
14
|
+
let resolvedConfigSource
|
|
17
15
|
return (
|
|
18
|
-
configSource
|
|
16
|
+
configSource?.constructor === Object
|
|
19
17
|
? Promise.resolve(configSource)
|
|
20
|
-
:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
18
|
+
: fileExists(
|
|
19
|
+
(resolvedConfigSource = expandPath(configSource ?? `./antora-assembler${preferredQualifier}.yml`, {
|
|
20
|
+
dot: playbook.dir,
|
|
21
|
+
}))
|
|
22
|
+
)
|
|
23
|
+
.then((exists) => {
|
|
24
|
+
if (exists || configSource || !preferredQualifier) return exists
|
|
25
|
+
return fileExists(
|
|
26
|
+
(resolvedConfigSource =
|
|
27
|
+
resolvedConfigSource.substring(0, resolvedConfigSource.length - 4 - preferredQualifier.length) + '.yml')
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
.then((exists) => {
|
|
31
|
+
if (!exists) {
|
|
32
|
+
let logger
|
|
33
|
+
if (configSource && (logger = this?.getLogger?.(PACKAGE_NAME))) {
|
|
34
|
+
const ctx = { file: { path: configSource } }
|
|
35
|
+
logger.warn(ctx, 'Could not resolve config file; reverting to default settings')
|
|
36
|
+
}
|
|
37
|
+
return {}
|
|
38
|
+
}
|
|
39
|
+
return fsp
|
|
40
|
+
.readFile(resolvedConfigSource)
|
|
41
|
+
.then((data) =>
|
|
42
|
+
Object.assign(camelCaseKeys(yaml.load(data), CAMEL_CASE_STOP_PATHS), { file: resolvedConfigSource })
|
|
43
|
+
)
|
|
44
|
+
})
|
|
33
45
|
).then((config) => {
|
|
34
|
-
if (config.enabled === false) return
|
|
35
|
-
let asciidocAttrs
|
|
36
|
-
if (!config.asciidoc) {
|
|
37
|
-
config.asciidoc = { attributes: (asciidocAttrs = {}) }
|
|
38
|
-
} else if (!(asciidocAttrs = config.asciidoc.attributes)) {
|
|
39
|
-
config.asciidoc.attributes = asciidocAttrs = {}
|
|
40
|
-
}
|
|
41
|
-
if (!('revdate' in asciidocAttrs)) asciidocAttrs.revdate = getLocalDate()
|
|
42
|
-
asciidocAttrs['page-partial'] = null
|
|
46
|
+
if (config.enabled === false) return config
|
|
43
47
|
const remapComponentVersionsKey = !('componentVersionFilter' in config)
|
|
44
48
|
const componentVersionFilter = (config.componentVersionFilter ??= {})
|
|
45
49
|
if (remapComponentVersionsKey && 'componentVersions' in config) {
|
|
@@ -54,14 +58,30 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') {
|
|
|
54
58
|
const remapAssemblyKeys = !('assembly' in config)
|
|
55
59
|
const assembly = (config.assembly ??= {})
|
|
56
60
|
if (remapAssemblyKeys) {
|
|
57
|
-
for (const key of
|
|
61
|
+
for (const key of LEGACY_ASSEMBLY_KEYS) {
|
|
58
62
|
if (!(key in config)) continue
|
|
59
63
|
assembly[key] = config[key]
|
|
60
64
|
delete config[key]
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let assemblyAttrs
|
|
68
|
+
if ('attributes' in assembly) {
|
|
69
|
+
assemblyAttrs = assembly.attributes ??= {}
|
|
70
|
+
if ('asciidoc' in config) delete config.asciidoc
|
|
71
|
+
} else if ('asciidoc' in config) {
|
|
72
|
+
assemblyAttrs = assembly.attributes = config.asciidoc?.attributes ?? {}
|
|
73
|
+
delete config.asciidoc
|
|
74
|
+
} else {
|
|
75
|
+
assemblyAttrs = assembly.attributes = {}
|
|
76
|
+
}
|
|
77
|
+
assemblyAttrs['page-partial'] = null
|
|
78
|
+
config.asciidoc = Object.defineProperty({}, 'attributes', {
|
|
79
|
+
get: function () {
|
|
80
|
+
return this.assembly.attributes
|
|
81
|
+
}.bind(config),
|
|
82
|
+
})
|
|
83
|
+
if (!('doctype' in assembly)) assembly.doctype = 'doctype' in assemblyAttrs ? assemblyAttrs.doctype : 'book'
|
|
84
|
+
delete assemblyAttrs.doctype
|
|
65
85
|
if (!('rootLevel' in assembly)) assembly.rootLevel = 0
|
|
66
86
|
if (!('insertStartPage' in assembly)) assembly.insertStartPage = true
|
|
67
87
|
if (['discrete', 'fuse', 'enclose'].indexOf(assembly.sectionMergeStrategy) < 0) {
|
|
@@ -73,12 +93,20 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') {
|
|
|
73
93
|
if (['always', 'if-redundant', 'never'].indexOf(assembly.dropExplicitXrefText) < 0) {
|
|
74
94
|
assembly.dropExplicitXrefText = 'never'
|
|
75
95
|
}
|
|
96
|
+
assembly.revdate = getLocalDate()
|
|
76
97
|
const build = (config.build ??= {})
|
|
77
|
-
if (build.dir === '$' + '{playbook.output.dir}') {
|
|
78
|
-
throw new Error('Not implemented')
|
|
79
|
-
}
|
|
80
98
|
build.dir &&= expandPath(build.dir, { dot: playbook.dir })
|
|
81
|
-
|
|
99
|
+
// used as cwd of command (and any scripts it requires)
|
|
100
|
+
build.cwd = build.cwd == null ? playbook.dir : expandPath(build.cwd, { dot: playbook.dir })
|
|
101
|
+
if (build.command?.includes('$')) {
|
|
102
|
+
const vars = {
|
|
103
|
+
$NODE: process.execPath,
|
|
104
|
+
$NPM: ospath.join(process.execPath, '../npm'),
|
|
105
|
+
$NPX: ospath.join(process.execPath, '../npx'),
|
|
106
|
+
$PWD: build.cwd,
|
|
107
|
+
}
|
|
108
|
+
build.command = build.command.replace(/^\$(?:NODE|NP[MX])(?= )|\$PWD\b/g, (ref) => vars[ref])
|
|
109
|
+
}
|
|
82
110
|
if (!('clean' in build) && 'output' in playbook) build.clean = playbook.output.clean
|
|
83
111
|
if (!('publish' in build)) build.publish = true
|
|
84
112
|
if ('keepAggregateSource' in build) {
|
|
@@ -106,12 +134,19 @@ function camelCaseKeys (o, stopPaths = [], p = undefined) {
|
|
|
106
134
|
const pathPrefix = p ? p + '.' : ''
|
|
107
135
|
const accum = {}
|
|
108
136
|
for (const [k, v] of Object.entries(o)) {
|
|
109
|
-
const camelKey = k.charAt() + k.
|
|
137
|
+
const camelKey = k.charAt() + k.substring(1).replace(/_([a-z])/g, (_, l) => l.toUpperCase())
|
|
110
138
|
accum[camelKey] = ~stopPaths.indexOf(pathPrefix + camelKey) ? v : camelCaseKeys(v, stopPaths, pathPrefix + camelKey)
|
|
111
139
|
}
|
|
112
140
|
return accum
|
|
113
141
|
}
|
|
114
142
|
|
|
143
|
+
function fileExists (path) {
|
|
144
|
+
return fsp.access(path).then(
|
|
145
|
+
() => true,
|
|
146
|
+
() => false
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
115
150
|
function getLocalDate (now = new Date()) {
|
|
116
151
|
return new Date(now - now.getTimezoneOffset() * 60000).toISOString().split('T')[0]
|
|
117
152
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function logCommand (loggerName, command, extraArgsOrAttributeOptionFlag, file, convertAttributes) {
|
|
4
|
+
const logger = this?.getLogger(loggerName)
|
|
5
|
+
if (!logger?.isLevelEnabled('debug')) return
|
|
6
|
+
const { docfile, 'assembler-filetype': filetype } = convertAttributes
|
|
7
|
+
const args = (
|
|
8
|
+
Array.isArray(extraArgsOrAttributeOptionFlag)
|
|
9
|
+
? extraArgsOrAttributeOptionFlag
|
|
10
|
+
: extraArgsOrAttributeOptionFlag
|
|
11
|
+
? convertAttributes.toArgs(extraArgsOrAttributeOptionFlag)
|
|
12
|
+
: []
|
|
13
|
+
).map((it) => (~it.indexOf(' ') ? `'${it}'` : it))
|
|
14
|
+
const ctx = { command: [command].concat(args).join(' '), file: { path: docfile } }
|
|
15
|
+
const msg = `Running external command to export assembly in %s to %s: %s`
|
|
16
|
+
const componentVersionStr = file.src.version ? `${file.src.version}@${file.src.component}` : file.src.component
|
|
17
|
+
logger.debug(ctx, msg, componentVersionStr, filetype, file.src.relative)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = logCommand
|