@antora/playbook-builder 3.0.0-alpha.9 → 3.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 +1 -1
- package/lib/build-playbook.js +35 -41
- package/lib/config/schema.js +21 -4
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The Playbook Builder is the configuration component for Antora.
|
|
|
4
4
|
It's responsible for building a playbook object from user input that's then used for configuring components in an Antora generator pipeline.
|
|
5
5
|
|
|
6
6
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
7
|
-
Its site generator
|
|
7
|
+
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
8
8
|
|
|
9
9
|
## Copyright and License
|
|
10
10
|
|
package/lib/build-playbook.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const camelCaseKeys = require('camelcase-keys')
|
|
4
|
-
const { configureLogger } = require('@antora/logger')
|
|
5
4
|
const convict = require('./solitary-convict')
|
|
5
|
+
const defaultSchema = require('./config/schema')
|
|
6
6
|
const fs = require('fs')
|
|
7
7
|
const ospath = require('path')
|
|
8
8
|
|
|
@@ -21,12 +21,14 @@ const ospath = require('path')
|
|
|
21
21
|
* option flags and switches. Should begin with the first flag or switch.
|
|
22
22
|
* @param {Object} [env={}] - A map of environment variables.
|
|
23
23
|
* @param {Object} [schema=undefined] - A convict configuration schema.
|
|
24
|
+
* @param {Function} [beforeValidate=undefined] - A function to invoke on the
|
|
25
|
+
* config before validating it.
|
|
24
26
|
*
|
|
25
27
|
* @returns {Object} A playbook object containing a hierarchical structure that
|
|
26
28
|
* mirrors the configuration schema. With the exception of the top-level asciidoc
|
|
27
29
|
* key and its descendants, all keys in the playbook are camelCased.
|
|
28
30
|
*/
|
|
29
|
-
function buildPlaybook (args = [], env = {}, schema = undefined) {
|
|
31
|
+
function buildPlaybook (args = [], env = {}, schema = undefined, beforeValidate = undefined) {
|
|
30
32
|
const config = loadConvictConfig(args, env, schema)
|
|
31
33
|
const relSpecFilePath = config.get('playbook')
|
|
32
34
|
if (relSpecFilePath) {
|
|
@@ -55,58 +57,50 @@ function buildPlaybook (args = [], env = {}, schema = undefined) {
|
|
|
55
57
|
config.loadFile(absSpecFilePath)
|
|
56
58
|
if (relSpecFilePath !== absSpecFilePath) config.set('playbook', absSpecFilePath)
|
|
57
59
|
}
|
|
58
|
-
config.
|
|
59
|
-
|
|
60
|
+
const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')]
|
|
61
|
+
if (beforeValidateFromSchema) beforeValidateFromSchema(config)
|
|
62
|
+
if (beforeValidate) beforeValidate(config)
|
|
63
|
+
return config.getModel()
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
function loadConvictConfig (args, env, customSchema) {
|
|
63
|
-
return convict(customSchema ||
|
|
67
|
+
return Object.assign(convict(customSchema || defaultSchema, { args, env }), { getModel })
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const data = config.getProperties()
|
|
74
|
-
if (
|
|
75
|
-
'site' in schemaProperties &&
|
|
76
|
-
'keys' in schemaProperties.site._cvtProperties &&
|
|
77
|
-
'__private__google_analytics_key' in schemaProperties.site._cvtProperties
|
|
78
|
-
) {
|
|
79
|
-
const site = data.site
|
|
80
|
-
if (site.__private__google_analytics_key != null) site.keys.google_analytics = site.__private__google_analytics_key
|
|
81
|
-
delete site.__private__google_analytics_key
|
|
70
|
+
function getModel (name = '') {
|
|
71
|
+
let config = this
|
|
72
|
+
const data = config.get(name)
|
|
73
|
+
let schema = config._schema
|
|
74
|
+
if (name) {
|
|
75
|
+
schema = name.split('.').reduce((accum, key) => accum._cvtProperties[key], schema)
|
|
76
|
+
config = Object.assign(convict(name.split('.').reduce((def, key) => def[key], config._def)), { _instance: data })
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (runtime.silent) {
|
|
90
|
-
if (runtime.quiet === false) runtime.quiet = true
|
|
91
|
-
if (log && 'level' in log) log.level = 'silent'
|
|
92
|
-
}
|
|
93
|
-
if (log) configureLogger(log, playbook.dir)
|
|
78
|
+
config.validate({ allowed: 'strict' })
|
|
79
|
+
const model = camelCaseKeys(data, { deep: true, stopPaths: getStopPaths(schema._cvtProperties) })
|
|
80
|
+
if (!name) {
|
|
81
|
+
Object.defineProperty(model, 'env', { value: config.getEnv() })
|
|
82
|
+
model.dir = model.playbook ? ospath.dirname((model.file = model.playbook)) : process.cwd()
|
|
83
|
+
delete model.playbook
|
|
94
84
|
}
|
|
95
|
-
|
|
96
|
-
return deepFreeze(playbook)
|
|
85
|
+
return deepFreeze(model)
|
|
97
86
|
}
|
|
98
87
|
|
|
99
|
-
function getStopPaths (schemaProperties, schemaPath = []) {
|
|
100
|
-
const stopPaths = []
|
|
88
|
+
function getStopPaths (schemaProperties, schemaPath = [], stopPaths = []) {
|
|
101
89
|
for (const [key, { preserve, _cvtProperties }] of Object.entries(schemaProperties)) {
|
|
102
90
|
if (preserve) {
|
|
103
|
-
|
|
104
|
-
? preserve.
|
|
105
|
-
: stopPaths.
|
|
91
|
+
Array.isArray(preserve)
|
|
92
|
+
? preserve.forEach((it) => stopPaths.push(schemaPath.concat(key, it).join('.')))
|
|
93
|
+
: stopPaths.push(schemaPath.concat(key).join('.'))
|
|
94
|
+
} else if (_cvtProperties) {
|
|
95
|
+
stopPaths.push(...getStopPaths(_cvtProperties, schemaPath.concat(key)))
|
|
106
96
|
}
|
|
107
|
-
if (_cvtProperties) stopPaths.push(...getStopPaths(_cvtProperties, schemaPath.concat(key)))
|
|
108
97
|
}
|
|
109
98
|
return stopPaths
|
|
110
99
|
}
|
|
111
100
|
|
|
112
|
-
|
|
101
|
+
function deepFreeze (o) {
|
|
102
|
+
for (const v of Object.values(o)) Object.isFrozen(v) || deepFreeze(v)
|
|
103
|
+
return Object.freeze(o)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = Object.assign(buildPlaybook, { defaultSchema })
|
package/lib/config/schema.js
CHANGED
|
@@ -7,10 +7,16 @@ module.exports = {
|
|
|
7
7
|
default: undefined,
|
|
8
8
|
arg: 'playbook',
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
antora: {
|
|
11
|
+
generator: {
|
|
12
|
+
doc: 'A require request for the generator package name or script to use.',
|
|
13
|
+
format: String,
|
|
14
|
+
default: '@antora/site-generator-default',
|
|
15
|
+
arg: 'generator',
|
|
16
|
+
},
|
|
11
17
|
extensions: {
|
|
12
18
|
doc:
|
|
13
|
-
'A list of extensions that listen for
|
|
19
|
+
'A list of extensions that listen for lifecycle events. ' +
|
|
14
20
|
'Each extension is specified as a require request string or an object with a require key.',
|
|
15
21
|
format: 'require-array',
|
|
16
22
|
default: [],
|
|
@@ -65,7 +71,7 @@ module.exports = {
|
|
|
65
71
|
branches: {
|
|
66
72
|
doc: 'The default branch pattern to use when no specific pattern is provided.',
|
|
67
73
|
format: Array,
|
|
68
|
-
default: ['HEAD', 'v*'],
|
|
74
|
+
default: ['HEAD', 'v{0..9}*'],
|
|
69
75
|
},
|
|
70
76
|
edit_url: {
|
|
71
77
|
doc: 'The default edit URL setting when no specific setting is provided.',
|
|
@@ -316,7 +322,7 @@ module.exports = {
|
|
|
316
322
|
},
|
|
317
323
|
redirect_facility: {
|
|
318
324
|
doc: 'The facility for handling page alias and start page redirections.',
|
|
319
|
-
format: ['disabled', 'httpd', 'netlify', 'nginx', 'static'],
|
|
325
|
+
format: ['disabled', 'gitlab', 'httpd', 'netlify', 'nginx', 'static'],
|
|
320
326
|
default: 'static',
|
|
321
327
|
arg: 'redirect-facility',
|
|
322
328
|
},
|
|
@@ -340,4 +346,15 @@ module.exports = {
|
|
|
340
346
|
default: undefined,
|
|
341
347
|
},
|
|
342
348
|
},
|
|
349
|
+
[Symbol.for('convict.beforeValidate')]: ({ _schema: schema, _instance: data }) => {
|
|
350
|
+
const runtime = data.runtime
|
|
351
|
+
if (runtime.silent) {
|
|
352
|
+
if (runtime.quiet === false) runtime.quiet = true
|
|
353
|
+
if (runtime.log.level !== 'silent') runtime.log.level = 'silent'
|
|
354
|
+
}
|
|
355
|
+
const site = data.site
|
|
356
|
+
if (site.__private__google_analytics_key != null) site.keys.google_analytics = site.__private__google_analytics_key
|
|
357
|
+
delete site.__private__google_analytics_key
|
|
358
|
+
delete schema._cvtProperties.site._cvtProperties.__private__google_analytics_key
|
|
359
|
+
},
|
|
343
360
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/playbook-builder",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.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)",
|
|
@@ -16,15 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@antora/logger": "3.0.0-alpha.9",
|
|
20
19
|
"@iarna/toml": "~2.2",
|
|
21
|
-
"camelcase-keys": "~
|
|
22
|
-
"convict": "~6.
|
|
20
|
+
"camelcase-keys": "~7.0",
|
|
21
|
+
"convict": "~6.2",
|
|
23
22
|
"js-yaml": "~4.1",
|
|
24
23
|
"json5": "~2.2"
|
|
25
24
|
},
|
|
26
25
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
26
|
+
"node": ">=12.21.0"
|
|
28
27
|
},
|
|
29
28
|
"files": [
|
|
30
29
|
"lib/"
|
|
@@ -37,5 +36,5 @@
|
|
|
37
36
|
"static site",
|
|
38
37
|
"web publishing"
|
|
39
38
|
],
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "7c5ef1ea93dd489af533c80a936c736013c41769"
|
|
41
40
|
}
|