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

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 })
@@ -27,7 +27,7 @@ function registerParsers (convict) {
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
  ])
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.3",
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)",
@@ -36,5 +36,5 @@
36
36
  "static site",
37
37
  "web publishing"
38
38
  ],
39
- "gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54"
39
+ "gitHead": "45da95a2e2dea538379d2d9f42013d2208fb86c3"
40
40
  }