@antora/playbook-builder 3.0.0-beta.2 → 3.0.0-beta.6

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.
@@ -25,42 +25,47 @@ const ospath = require('path')
25
25
  * config before validating it.
26
26
  *
27
27
  * @returns {Object} A playbook object containing a hierarchical structure that
28
- * mirrors the configuration schema. With the exception of the top-level asciidoc
29
- * key and its descendants, all keys in the playbook are camelCased.
28
+ * mirrors the configuration schema. With the exception of keys and descendants
29
+ * marked in the schema as preserve, all keys in the playbook are camelCased.
30
30
  */
31
31
  function buildPlaybook (args = [], env = {}, schema = undefined, beforeValidate = undefined) {
32
32
  const config = loadConvictConfig(args, env, schema)
33
- const relSpecFilePath = config.get('playbook')
34
- if (relSpecFilePath) {
35
- let absSpecFilePath = ospath.resolve(relSpecFilePath)
36
- if (ospath.extname(absSpecFilePath)) {
37
- if (!fs.existsSync(absSpecFilePath)) {
38
- let details = ''
39
- if (relSpecFilePath !== absSpecFilePath) {
40
- details = ` (path: ${relSpecFilePath}${ospath.isAbsolute(relSpecFilePath) ? '' : ', cwd: ' + process.cwd()})`
41
- }
42
- throw new Error(`playbook file not found at ${absSpecFilePath}${details}`)
33
+ const playbook = config.get('playbook')
34
+ let absPlaybookPath
35
+ if (playbook) {
36
+ if (ospath.extname((absPlaybookPath = ospath.resolve(playbook)))) {
37
+ if (!fs.existsSync(absPlaybookPath)) {
38
+ throw new Error(`playbook file not found at ${absPlaybookPath}${getDetails(playbook, absPlaybookPath)}`)
43
39
  }
44
- } else if (fs.existsSync(absSpecFilePath + '.yml')) {
45
- absSpecFilePath += '.yml'
46
- } else if (fs.existsSync(absSpecFilePath + '.json')) {
47
- absSpecFilePath += '.json'
48
- } else if (fs.existsSync(absSpecFilePath + '.toml')) {
49
- absSpecFilePath += '.toml'
40
+ } else if (fs.existsSync(absPlaybookPath + '.yml')) {
41
+ absPlaybookPath += '.yml'
42
+ } else if (fs.existsSync(absPlaybookPath + '.json')) {
43
+ absPlaybookPath += '.json'
44
+ } else if (fs.existsSync(absPlaybookPath + '.toml')) {
45
+ absPlaybookPath += '.toml'
50
46
  } else {
51
- const details = `(path: ${relSpecFilePath}${ospath.isAbsolute(relSpecFilePath) ? '' : ', cwd: ' + process.cwd()})`
52
47
  throw new Error(
53
- `playbook file not found at ${absSpecFilePath}.yml, ${absSpecFilePath}.json, or ${absSpecFilePath}.toml ` +
54
- details
48
+ `playbook file not found at ${absPlaybookPath}.yml, ${absPlaybookPath}.json, or ${absPlaybookPath}.toml` +
49
+ getDetails(playbook, absPlaybookPath)
55
50
  )
56
51
  }
57
- config.loadFile(absSpecFilePath)
58
- if (relSpecFilePath !== absSpecFilePath) config.set('playbook', absSpecFilePath)
59
52
  }
60
- const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')]
61
- if (beforeValidateFromSchema) beforeValidateFromSchema(config)
62
- if (beforeValidate) beforeValidate(config)
63
- return config.getModel()
53
+ try {
54
+ if (playbook) {
55
+ config.loadFile(absPlaybookPath)
56
+ if (playbook !== absPlaybookPath) config.set('playbook', absPlaybookPath)
57
+ }
58
+ const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')]
59
+ if (beforeValidateFromSchema) beforeValidateFromSchema(config)
60
+ if (beforeValidate) beforeValidate(config)
61
+ return config.getModel()
62
+ } catch (err) {
63
+ if (!playbook) throw err
64
+ const message = err.message.replace(/( in the schema)?$/m, (_, inTheSchema) => {
65
+ return `${inTheSchema ? inTheSchema + ' for' : ' in'} ${absPlaybookPath}${getDetails(playbook, absPlaybookPath)}`
66
+ })
67
+ throw Object.assign(err, { message })
68
+ }
64
69
  }
65
70
 
66
71
  function loadConvictConfig (args, env, customSchema) {
@@ -103,4 +108,9 @@ function deepFreeze (o) {
103
108
  return Object.freeze(o)
104
109
  }
105
110
 
111
+ function getDetails (playbook, absPlaybookPath) {
112
+ if (playbook === absPlaybookPath) return ''
113
+ return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})`
114
+ }
115
+
106
116
  module.exports = Object.assign(buildPlaybook, { defaultSchema })
@@ -11,7 +11,7 @@ module.exports = {
11
11
  generator: {
12
12
  doc: 'A require request for the generator package name or script to use.',
13
13
  format: String,
14
- default: '@antora/site-generator-default',
14
+ default: '@antora/site-generator',
15
15
  arg: 'generator',
16
16
  },
17
17
  extensions: {
@@ -259,7 +259,7 @@ module.exports = {
259
259
  },
260
260
  format: new Proxy(
261
261
  {
262
- doc: 'Set the format of log messages. Defaults to json if CI=true, pretty otherwise.',
262
+ doc: 'Set the format of log messages. Defaults to pretty if CI=true or stdout is a TTY, json otherwise.',
263
263
  format: ['json', 'pretty'],
264
264
  default: undefined,
265
265
  arg: 'log-format',
@@ -268,7 +268,7 @@ module.exports = {
268
268
  {
269
269
  get (target, property) {
270
270
  if (property !== 'default') return target[property]
271
- return process.env.CI === 'true' || process.env.NODE_ENV === 'test' ? 'json' : 'pretty'
271
+ return process.env.CI === 'true' || process.stdout.isTTY ? 'pretty' : 'json'
272
272
  },
273
273
  }
274
274
  ),
@@ -22,12 +22,12 @@ function registerParsers (convict) {
22
22
  convict.addParser([
23
23
  { extension: 'json', parse: json.parse },
24
24
  { extension: 'toml', parse: toml.parse },
25
- { extension: 'yaml', parse: yaml.load },
26
- { extension: 'yml', parse: yaml.load },
25
+ { extension: 'yaml', parse: (source) => yaml.load(source, { schema: yaml.CORE_SCHEMA }) },
26
+ { extension: 'yml', parse: (source) => yaml.load(source, { schema: yaml.CORE_SCHEMA }) },
27
27
  {
28
28
  extension: '*',
29
29
  parse: () => {
30
- throw new Error('Unexpected playbook file type (must be yml, json, or toml')
30
+ throw new Error('Unknown playbook file extension: must be .yml (or .yaml), .json, or .toml')
31
31
  },
32
32
  },
33
33
  ])
@@ -46,7 +46,7 @@ function registerFormats (convict) {
46
46
  ARGS_SCANNER_RX.lastIndex = 0
47
47
  while ((match = ARGS_SCANNER_RX.exec(val))) {
48
48
  const [, k, v] = match
49
- if (k) accum[k] = v ? (v === '-' ? '-' : yaml.load(v)) : ''
49
+ if (k) accum[k] = v ? (v === '-' ? '-' : yaml.load(v, { schema: yaml.CORE_SCHEMA })) : ''
50
50
  }
51
51
  return accum
52
52
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/playbook-builder",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.6",
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)",
@@ -15,6 +15,9 @@
15
15
  "url": "https://gitlab.com/antora/antora/issues"
16
16
  },
17
17
  "main": "lib/index.js",
18
+ "scripts": {
19
+ "test": "_mocha"
20
+ },
18
21
  "dependencies": {
19
22
  "@iarna/toml": "~2.2",
20
23
  "camelcase-keys": "~7.0",
@@ -36,5 +39,5 @@
36
39
  "static site",
37
40
  "web publishing"
38
41
  ],
39
- "gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54"
42
+ "gitHead": "f9f747965f599442562f59206d870b7e38864806"
40
43
  }