@antora/playbook-builder 3.1.10 → 3.1.11
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 +48 -10
- package/lib/config/schema.js +5 -0
- package/lib/solitary-convict.js +28 -24
- package/package.json +8 -6
package/lib/build-playbook.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const convict = require('./solitary-convict')
|
|
4
4
|
const defaultSchema = require('./config/schema')
|
|
5
|
-
const fs = require('fs')
|
|
6
|
-
const ospath = require('path')
|
|
5
|
+
const fs = require('node:fs')
|
|
6
|
+
const ospath = require('node:path')
|
|
7
|
+
const parseArgs = require('yargs-parser')
|
|
8
|
+
const yaml = require('js-yaml')
|
|
9
|
+
|
|
10
|
+
const COERCE_SCHEMA = yaml.FAILSAFE_SCHEMA
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Builds a playbook object according to the provided schema from the specified
|
|
@@ -28,8 +32,22 @@ const ospath = require('path')
|
|
|
28
32
|
* marked in the schema as preserve, all keys in the playbook are camelCased.
|
|
29
33
|
*/
|
|
30
34
|
function buildPlaybook (args = [], env = process.env, schema = defaultSchema, beforeValidate = undefined) {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
35
|
+
const parsedArgs = parseArgs(args, { configuration: { 'dot-notation': false } })
|
|
36
|
+
const opts = { args: [], env: {} }
|
|
37
|
+
const config = Object.assign(convict(schema, opts), { getModel, getSchema })
|
|
38
|
+
Object.assign(opts, { args, env })
|
|
39
|
+
let playbook
|
|
40
|
+
if ('playbook' in schema) {
|
|
41
|
+
const playbookEnv = schema.playbook.env
|
|
42
|
+
if (playbookEnv != null) playbook = env[playbookEnv]
|
|
43
|
+
const playbookArg = schema.playbook.arg
|
|
44
|
+
if (playbookArg != null) playbook = parsedArgs[playbookArg] ?? playbook
|
|
45
|
+
if (playbook === undefined) {
|
|
46
|
+
if (config.has('playbook')) playbook = config.get('playbook')
|
|
47
|
+
} else {
|
|
48
|
+
config.set('playbook', playbook)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
33
51
|
let absPlaybookPath
|
|
34
52
|
if (playbook) {
|
|
35
53
|
if (ospath.extname((absPlaybookPath = ospath.resolve(playbook)))) {
|
|
@@ -50,10 +68,11 @@ function buildPlaybook (args = [], env = process.env, schema = defaultSchema, be
|
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
70
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
71
|
+
Object.assign(opts, { args: [] })
|
|
72
|
+
playbook ? config.loadFile(absPlaybookPath) : config.load({})
|
|
73
|
+
importArguments(config, parsedArgs)
|
|
74
|
+
Object.assign(opts, { args })
|
|
75
|
+
if (playbook && playbook !== absPlaybookPath) config.set('playbook', absPlaybookPath)
|
|
57
76
|
const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')]
|
|
58
77
|
if (beforeValidateFromSchema) beforeValidateFromSchema(config)
|
|
59
78
|
if (beforeValidate) beforeValidate(config)
|
|
@@ -82,9 +101,8 @@ function camelCaseKeys (o, stopPaths = [], p = '') {
|
|
|
82
101
|
function getModel (name) {
|
|
83
102
|
let config = this
|
|
84
103
|
const data = config.get(name)
|
|
85
|
-
|
|
104
|
+
const schema = config.getSchema(name)
|
|
86
105
|
if (name) {
|
|
87
|
-
schema = name.split('.').reduce((accum, key) => accum._cvtProperties[key], schema)
|
|
88
106
|
config = Object.assign(convict(name.split('.').reduce((def, key) => def[key], config._def)), { _instance: data })
|
|
89
107
|
}
|
|
90
108
|
config.validate({ allowed: 'strict' })
|
|
@@ -97,6 +115,10 @@ function getModel (name) {
|
|
|
97
115
|
return model
|
|
98
116
|
}
|
|
99
117
|
|
|
118
|
+
function getSchema (name) {
|
|
119
|
+
return name ? name.split('.').reduce((accum, key) => accum._cvtProperties[key], this._schema) : this._schema
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
function getStopPaths (schemaProperties, schemaPath = [], stopPaths = []) {
|
|
101
123
|
for (const [key, { preserve, _cvtProperties }] of Object.entries(schemaProperties)) {
|
|
102
124
|
if (preserve) {
|
|
@@ -110,6 +132,22 @@ function getStopPaths (schemaProperties, schemaPath = [], stopPaths = []) {
|
|
|
110
132
|
return stopPaths
|
|
111
133
|
}
|
|
112
134
|
|
|
135
|
+
function importArguments (config, args) {
|
|
136
|
+
for (const [argName, configKey] of Object.entries(config._argv)) {
|
|
137
|
+
const argVal = args[argName]
|
|
138
|
+
if (argVal === undefined) continue
|
|
139
|
+
const argFormat = config.getSchema(configKey).format
|
|
140
|
+
let argValStr = argVal
|
|
141
|
+
if (argFormat === 'map' || argFormat === 'primitive-map') {
|
|
142
|
+
const dumpOpts = { condenseFlow: true, flowLevel: 0, quotingType: '"' }
|
|
143
|
+
argValStr = yaml.dump(Array.isArray(argVal) ? argVal : [argVal], dumpOpts)
|
|
144
|
+
} else if (Array.isArray(argVal)) {
|
|
145
|
+
argValStr = argVal.join(',')
|
|
146
|
+
}
|
|
147
|
+
config.set(configKey, argValStr)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
function getDetails (playbook, absPlaybookPath) {
|
|
114
152
|
if (playbook === absPlaybookPath) return ''
|
|
115
153
|
return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})`
|
package/lib/config/schema.js
CHANGED
|
@@ -170,6 +170,11 @@ module.exports = {
|
|
|
170
170
|
format: 'int',
|
|
171
171
|
default: 1,
|
|
172
172
|
},
|
|
173
|
+
fetch_depth: {
|
|
174
|
+
doc: 'Preferred number of commits to fetch from remote repository. 0 indicates full history.',
|
|
175
|
+
format: 'int',
|
|
176
|
+
default: 1,
|
|
177
|
+
},
|
|
173
178
|
plugins: {
|
|
174
179
|
credential_manager: {
|
|
175
180
|
doc: 'A require request for a plugin to replace the built-in credential manager used by the git client.',
|
package/lib/solitary-convict.js
CHANGED
|
@@ -5,8 +5,9 @@ const json = require('json5')
|
|
|
5
5
|
const toml = require('@iarna/toml')
|
|
6
6
|
const yaml = require('js-yaml')
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const ARG_RX = /(?:([^=]+)|(?==))(?:$|=(|("|').*?\3|.*)(?:$))/
|
|
9
9
|
const PRIMITIVE_TYPES = [Boolean, Number, String]
|
|
10
|
+
const COERCE_SCHEMA = yaml.FAILSAFE_SCHEMA
|
|
10
11
|
const YAML_SCHEMA = yaml.CORE_SCHEMA.extend({ implicit: [yaml.types.merge] })
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -51,13 +52,14 @@ function registerFormats (convict) {
|
|
|
51
52
|
coerce: (val, config, name) => {
|
|
52
53
|
if (config == null) return val
|
|
53
54
|
const accum = config.has(name) ? config.get(name) : {}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const entries = yaml.load(val, { schema: COERCE_SCHEMA })
|
|
56
|
+
for (const entry of Array.isArray(entries) ? entries : [entries]) {
|
|
57
|
+
let k, v, match
|
|
58
|
+
if (!(match = entry.match(ARG_RX))) continue
|
|
59
|
+
;[, k, v = ''] = match
|
|
58
60
|
if (!k) continue
|
|
59
61
|
let parsed = v
|
|
60
|
-
if (
|
|
62
|
+
if (v && v !== '-') {
|
|
61
63
|
try {
|
|
62
64
|
parsed = yaml.load(v, { schema: yaml.CORE_SCHEMA })
|
|
63
65
|
} catch {}
|
|
@@ -83,20 +85,18 @@ function registerFormats (convict) {
|
|
|
83
85
|
coerce: (val, config, name) => {
|
|
84
86
|
if (config == null) return val
|
|
85
87
|
const accum = config.has(name) ? config.get(name) : {}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
parsed = v || ''
|
|
97
|
-
}
|
|
98
|
-
accum[~k.indexOf('-') ? k.replace(/-/g, '_') : k] = parsed
|
|
88
|
+
const entries = yaml.load(val, { schema: COERCE_SCHEMA })
|
|
89
|
+
for (const entry of Array.isArray(entries) ? entries : [entries]) {
|
|
90
|
+
let k, v, match
|
|
91
|
+
if (!(match = entry.match(ARG_RX))) continue
|
|
92
|
+
;[, k, v = ''] = match
|
|
93
|
+
if (!k) continue
|
|
94
|
+
let parsed = v
|
|
95
|
+
if (v && v !== '-') {
|
|
96
|
+
parsed = yaml.load(v, { schema: yaml.CORE_SCHEMA })
|
|
97
|
+
if (parsed && PRIMITIVE_TYPES.indexOf(parsed.constructor) < 0) parsed = v
|
|
99
98
|
}
|
|
99
|
+
accum[~k.indexOf('-') ? k.replace(/-/g, '_') : k] = parsed
|
|
100
100
|
}
|
|
101
101
|
return accum
|
|
102
102
|
},
|
|
@@ -104,19 +104,19 @@ function registerFormats (convict) {
|
|
|
104
104
|
convict.addFormat({
|
|
105
105
|
name: 'require-array',
|
|
106
106
|
validate: (val) => {
|
|
107
|
-
if (!Array.isArray(val)) throw new Error('must be
|
|
107
|
+
if (!Array.isArray(val)) throw new Error('must be an array')
|
|
108
108
|
},
|
|
109
109
|
coerce: (val, config, name) => {
|
|
110
110
|
const accum = config?.has(name) ? config.get(name) : []
|
|
111
|
-
val.split(',')
|
|
112
|
-
if (~accum.indexOf(v))
|
|
111
|
+
for (const v of val.split(',')) {
|
|
112
|
+
if (~accum.indexOf(v)) continue
|
|
113
113
|
const match = accum.find((it) => it.constructor === Object && it.id === v)
|
|
114
114
|
if (match) {
|
|
115
115
|
if (match.enabled === false) match.enabled = true
|
|
116
116
|
} else {
|
|
117
117
|
accum.push(v)
|
|
118
118
|
}
|
|
119
|
-
}
|
|
119
|
+
}
|
|
120
120
|
return accum
|
|
121
121
|
},
|
|
122
122
|
})
|
|
@@ -124,7 +124,7 @@ function registerFormats (convict) {
|
|
|
124
124
|
name: 'boolean-or-string',
|
|
125
125
|
validate: (val) => {
|
|
126
126
|
if (!(val == null || val.constructor === String || val.constructor === Boolean)) {
|
|
127
|
-
throw new Error('must be a boolean or
|
|
127
|
+
throw new Error('must be a boolean, string, or null')
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
})
|
|
@@ -166,6 +166,10 @@ function registerFormats (convict) {
|
|
|
166
166
|
}
|
|
167
167
|
if (~parsedUrl.pathname.indexOf('%20')) throw new Error('pathname segment must not contain spaces')
|
|
168
168
|
},
|
|
169
|
+
coerce: (val) => {
|
|
170
|
+
if (!val || val === '~') return null
|
|
171
|
+
return val.length > 1 && val.charAt(val.length - 1) === '/' ? val.slice(0, -1) : val
|
|
172
|
+
},
|
|
169
173
|
})
|
|
170
174
|
}
|
|
171
175
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/playbook-builder",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.11",
|
|
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)",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"homepage": "https://antora.org",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git+https://gitlab.com/antora/antora.git"
|
|
15
|
+
"url": "git+https://gitlab.com/antora/antora.git",
|
|
16
|
+
"directory": "packages/playbook-builder"
|
|
16
17
|
},
|
|
17
18
|
"bugs": {
|
|
18
19
|
"url": "https://gitlab.com/antora/antora/issues"
|
|
@@ -29,10 +30,11 @@
|
|
|
29
30
|
"@iarna/toml": "~2.2",
|
|
30
31
|
"convict": "~6.2",
|
|
31
32
|
"js-yaml": "~4.1",
|
|
32
|
-
"json5": "~2.2"
|
|
33
|
+
"json5": "~2.2",
|
|
34
|
+
"yargs-parser": "~20.2"
|
|
33
35
|
},
|
|
34
36
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
37
|
+
"node": ">=18.0.0"
|
|
36
38
|
},
|
|
37
39
|
"files": [
|
|
38
40
|
"lib/"
|
|
@@ -47,7 +49,7 @@
|
|
|
47
49
|
],
|
|
48
50
|
"scripts": {
|
|
49
51
|
"test": "_mocha",
|
|
50
|
-
"prepublishOnly": "npx -y downdoc --prepublish",
|
|
51
|
-
"postpublish": "npx -y downdoc --postpublish"
|
|
52
|
+
"prepublishOnly": "npx -y downdoc@latest --prepublish",
|
|
53
|
+
"postpublish": "npx -y downdoc@latest --postpublish"
|
|
52
54
|
}
|
|
53
55
|
}
|