@antora/playbook-builder 3.2.0-alpha.9 → 3.2.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/lib/build-playbook.js +25 -2
- package/lib/config/schema.js +6 -1
- package/lib/solitary-convict.js +35 -13
- package/package.json +5 -6
package/lib/build-playbook.js
CHANGED
|
@@ -4,7 +4,6 @@ const convict = require('./solitary-convict')
|
|
|
4
4
|
const defaultSchema = require('./config/schema')
|
|
5
5
|
const fs = require('node:fs')
|
|
6
6
|
const ospath = require('node:path')
|
|
7
|
-
const parseArgs = require('yargs-parser')
|
|
8
7
|
const yaml = require('js-yaml')
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -30,7 +29,7 @@ const yaml = require('js-yaml')
|
|
|
30
29
|
* marked in the schema as preserve, all keys in the playbook are camelCased.
|
|
31
30
|
*/
|
|
32
31
|
function buildPlaybook (args = [], env = process.env, schema = defaultSchema, beforeValidate = undefined) {
|
|
33
|
-
const parsedArgs = parseArgs(args
|
|
32
|
+
const parsedArgs = args.length ? parseArgs(args) : {}
|
|
34
33
|
const opts = { args: [], env: {} }
|
|
35
34
|
const config = Object.assign(convict(schema, opts), { getModel, getSchema })
|
|
36
35
|
Object.assign(opts, { args, env })
|
|
@@ -151,4 +150,28 @@ function getDetails (playbook, absPlaybookPath) {
|
|
|
151
150
|
return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})`
|
|
152
151
|
}
|
|
153
152
|
|
|
153
|
+
function parseArgs (args) {
|
|
154
|
+
let currentOptionName
|
|
155
|
+
return Object.assign(
|
|
156
|
+
args.reduce((accum, it) => {
|
|
157
|
+
if (it.startsWith('--') && it !== '--') {
|
|
158
|
+
if (currentOptionName) accum[currentOptionName] = true
|
|
159
|
+
currentOptionName = it.substring(2)
|
|
160
|
+
} else if (currentOptionName) {
|
|
161
|
+
const currentOptionValue = accum[currentOptionName]
|
|
162
|
+
if (currentOptionValue == null || currentOptionValue === true) {
|
|
163
|
+
accum[currentOptionName] = it
|
|
164
|
+
} else if (currentOptionValue.constructor === Array) {
|
|
165
|
+
currentOptionValue.push(it)
|
|
166
|
+
} else {
|
|
167
|
+
accum[currentOptionName] = [currentOptionValue, it]
|
|
168
|
+
}
|
|
169
|
+
currentOptionName = undefined
|
|
170
|
+
}
|
|
171
|
+
return accum
|
|
172
|
+
}, {}),
|
|
173
|
+
currentOptionName ? { [currentOptionName]: true } : undefined
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
154
177
|
module.exports = Object.assign(buildPlaybook, { defaultSchema })
|
package/lib/config/schema.js
CHANGED
|
@@ -86,6 +86,11 @@ module.exports = {
|
|
|
86
86
|
format: 'array-or-string',
|
|
87
87
|
default: undefined,
|
|
88
88
|
},
|
|
89
|
+
worktrees: {
|
|
90
|
+
doc: 'The default worktrees pattern to use when no specific pattern is provided.',
|
|
91
|
+
format: 'boolean-or-array-or-string',
|
|
92
|
+
default: '.',
|
|
93
|
+
},
|
|
89
94
|
},
|
|
90
95
|
ui: {
|
|
91
96
|
bundle: {
|
|
@@ -245,7 +250,7 @@ module.exports = {
|
|
|
245
250
|
log: {
|
|
246
251
|
level: {
|
|
247
252
|
doc: 'Set the minimum log level of messages that get logged.',
|
|
248
|
-
format: ['all', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'],
|
|
253
|
+
format: ['all', 'trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'],
|
|
249
254
|
default: 'warn',
|
|
250
255
|
arg: 'log-level',
|
|
251
256
|
env: 'ANTORA_LOG_LEVEL',
|
package/lib/solitary-convict.js
CHANGED
|
@@ -44,6 +44,14 @@ function registerFormats (convict) {
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
})
|
|
47
|
+
convict.addFormat({
|
|
48
|
+
name: 'boolean-or-array-or-string',
|
|
49
|
+
validate: (val) => {
|
|
50
|
+
if (!(val == null || typeof val === 'boolean' || val.constructor === String || Array.isArray(val))) {
|
|
51
|
+
throw new Error('must be a boolean, array, string, or null')
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
})
|
|
47
55
|
convict.addFormat({
|
|
48
56
|
name: 'map',
|
|
49
57
|
validate: (val) => {
|
|
@@ -58,15 +66,15 @@ function registerFormats (convict) {
|
|
|
58
66
|
let v = ''
|
|
59
67
|
const equalsIdx = entry.indexOf('=')
|
|
60
68
|
if (~equalsIdx) {
|
|
61
|
-
if (!(k = entry.
|
|
62
|
-
v = entry.
|
|
69
|
+
if (!(k = entry.substring(0, equalsIdx))) continue
|
|
70
|
+
v = entry.substring(equalsIdx + 1)
|
|
63
71
|
}
|
|
64
72
|
let parsed = v
|
|
65
73
|
if (v) {
|
|
66
74
|
const match = v.match(YAML_PREFIX_RX)
|
|
67
75
|
if (match) {
|
|
68
76
|
try {
|
|
69
|
-
parsed = yaml.load(match[1] === 'auto' ? v.
|
|
77
|
+
parsed = yaml.load(match[1] === 'auto' ? v.substring(7) : v, { schema: yaml.CORE_SCHEMA })
|
|
70
78
|
} catch {}
|
|
71
79
|
}
|
|
72
80
|
}
|
|
@@ -97,15 +105,15 @@ function registerFormats (convict) {
|
|
|
97
105
|
let v = ''
|
|
98
106
|
const equalsIdx = entry.indexOf('=')
|
|
99
107
|
if (~equalsIdx) {
|
|
100
|
-
if (!(k = entry.
|
|
101
|
-
v = entry.
|
|
108
|
+
if (!(k = entry.substring(0, equalsIdx))) continue
|
|
109
|
+
v = entry.substring(equalsIdx + 1)
|
|
102
110
|
}
|
|
103
111
|
let parsed = v
|
|
104
112
|
if (v) {
|
|
105
113
|
const match = v.match(YAML_PREFIX_RX)
|
|
106
114
|
if (match) {
|
|
107
115
|
try {
|
|
108
|
-
parsed = yaml.load(match[1] === 'auto' ? v.
|
|
116
|
+
parsed = yaml.load(match[1] === 'auto' ? v.substring(7) : v, { schema: yaml.CORE_SCHEMA })
|
|
109
117
|
if (parsed && !~PRIMITIVE_TYPES.indexOf(parsed.constructor)) parsed = v
|
|
110
118
|
} catch {}
|
|
111
119
|
}
|
|
@@ -122,16 +130,30 @@ function registerFormats (convict) {
|
|
|
122
130
|
},
|
|
123
131
|
coerce: (val, config, name) => {
|
|
124
132
|
const accum = config?.has(name) ? config.get(name) : []
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
const byId = {}
|
|
134
|
+
const byRequire = {}
|
|
135
|
+
let orderIdx = 0
|
|
136
|
+
const order = new Map()
|
|
137
|
+
for (const [idx, it] of accum.entries()) {
|
|
138
|
+
const ext = it.constructor === Object ? it : (accum[idx] = { require: it })
|
|
139
|
+
byRequire[ext.require] ??= ext
|
|
140
|
+
if ('id' in ext) byId[ext.id] ??= ext
|
|
141
|
+
order.set(it, orderIdx++)
|
|
142
|
+
}
|
|
143
|
+
for (let request of val.split(',')) {
|
|
144
|
+
const enable = request.charAt() === '!' ? (request = request.substring(1)) == null : true
|
|
145
|
+
let match
|
|
146
|
+
if ((match = byId[request] ?? byRequire[request])) {
|
|
147
|
+
if ((match.enabled ?? true) !== enable) match.enabled = enable
|
|
130
148
|
} else {
|
|
131
|
-
accum.push(
|
|
149
|
+
accum.push((match = byRequire[request] = { require: request }))
|
|
150
|
+
if (!enable) match.enabled = false
|
|
132
151
|
}
|
|
152
|
+
if ((match.order ?? 'auto') === 'auto') order.set(match, orderIdx++)
|
|
133
153
|
}
|
|
134
154
|
return accum
|
|
155
|
+
.sort((a, b) => order.get(a) - order.get(b))
|
|
156
|
+
.map((it) => (Object.keys(it).length === 1 && 'require' in it ? it.require : it))
|
|
135
157
|
},
|
|
136
158
|
})
|
|
137
159
|
convict.addFormat({
|
|
@@ -182,7 +204,7 @@ function registerFormats (convict) {
|
|
|
182
204
|
},
|
|
183
205
|
coerce: (val) => {
|
|
184
206
|
if (!val || val === '~') return null
|
|
185
|
-
return val.length > 1 && val.charAt(val.length - 1) === '/' ? val.
|
|
207
|
+
return val.length > 1 && val.charAt(val.length - 1) === '/' ? val.substring(0, val.length - 1) : val
|
|
186
208
|
},
|
|
187
209
|
})
|
|
188
210
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/playbook-builder",
|
|
3
|
-
"version": "3.2.0-
|
|
3
|
+
"version": "3.2.0-rc.1",
|
|
4
4
|
"description": "Builds a playbook object from user input for configuring successive documentation components in an Antora pipeline.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -29,12 +29,11 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@iarna/toml": "~2.2",
|
|
31
31
|
"convict": "~6.2",
|
|
32
|
-
"js-yaml": "~4.
|
|
33
|
-
"json5": "~2.2"
|
|
34
|
-
"yargs-parser": "~20.2"
|
|
32
|
+
"js-yaml": "~4.2",
|
|
33
|
+
"json5": "~2.2"
|
|
35
34
|
},
|
|
36
35
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
36
|
+
"node": ">=20.0.0"
|
|
38
37
|
},
|
|
39
38
|
"files": [
|
|
40
39
|
"lib/"
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
"web publishing"
|
|
49
48
|
],
|
|
50
49
|
"scripts": {
|
|
51
|
-
"test": "
|
|
50
|
+
"test": "node --test",
|
|
52
51
|
"prepublishOnly": "npx -y downdoc@latest --prepublish",
|
|
53
52
|
"postpublish": "npx -y downdoc@latest --postpublish"
|
|
54
53
|
}
|