@antora/playbook-builder
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
@@ -28,38 +28,43 @@ 'use strict' | ||
* @returns {Object} A playbook object containing a hierarchical structure that | ||
* mirrors the configuration schema. With the exception of the top-level asciidoc | ||
* key and its descendants, all keys in the playbook are camelCased. | ||
* mirrors the configuration schema. With the exception of keys and descendants | ||
* marked in the schema as preserve, all keys in the playbook are camelCased. | ||
*/ | ||
function buildPlaybook (args = [], env = {}, schema = undefined, beforeValidate = undefined) { | ||
const config = loadConvictConfig(args, env, schema) | ||
const relSpecFilePath = config.get('playbook') | ||
if (relSpecFilePath) { | ||
let absSpecFilePath = ospath.resolve(relSpecFilePath) | ||
if (ospath.extname(absSpecFilePath)) { | ||
if (!fs.existsSync(absSpecFilePath)) { | ||
let details = '' | ||
if (relSpecFilePath !== absSpecFilePath) { | ||
details = ` (path: ${relSpecFilePath}${ospath.isAbsolute(relSpecFilePath) ? '' : ', cwd: ' + process.cwd()})` | ||
} | ||
throw new Error(`playbook file not found at ${absSpecFilePath}${details}`) | ||
const playbook = config.get('playbook') | ||
let absPlaybookPath | ||
if (playbook) { | ||
if (ospath.extname((absPlaybookPath = ospath.resolve(playbook)))) { | ||
if (!fs.existsSync(absPlaybookPath)) { | ||
throw new Error(`playbook file not found at ${absPlaybookPath}${getDetails(playbook, absPlaybookPath)}`) | ||
} | ||
} else if (fs.existsSync(absSpecFilePath + '.yml')) { | ||
absSpecFilePath += '.yml' | ||
} else if (fs.existsSync(absSpecFilePath + '.json')) { | ||
absSpecFilePath += '.json' | ||
} else if (fs.existsSync(absSpecFilePath + '.toml')) { | ||
absSpecFilePath += '.toml' | ||
} else if (fs.existsSync(absPlaybookPath + '.yml')) { | ||
absPlaybookPath += '.yml' | ||
} else if (fs.existsSync(absPlaybookPath + '.json')) { | ||
absPlaybookPath += '.json' | ||
} else if (fs.existsSync(absPlaybookPath + '.toml')) { | ||
absPlaybookPath += '.toml' | ||
} else { | ||
const details = `(path: ${relSpecFilePath}${ospath.isAbsolute(relSpecFilePath) ? '' : ', cwd: ' + process.cwd()})` | ||
throw new Error( | ||
`playbook file not found at ${absSpecFilePath}.yml, ${absSpecFilePath}.json, or ${absSpecFilePath}.toml ` + | ||
details | ||
`playbook file not found at ${absPlaybookPath}.yml, ${absPlaybookPath}.json, or ${absPlaybookPath}.toml` + | ||
getDetails(playbook, absPlaybookPath) | ||
) | ||
} | ||
config.loadFile(absSpecFilePath) | ||
if (relSpecFilePath !== absSpecFilePath) config.set('playbook', absSpecFilePath) | ||
} | ||
const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')] | ||
if (beforeValidateFromSchema) beforeValidateFromSchema(config) | ||
if (beforeValidate) beforeValidate(config) | ||
return config.getModel() | ||
try { | ||
if (playbook) { | ||
config.loadFile(absPlaybookPath) | ||
if (playbook !== absPlaybookPath) config.set('playbook', absPlaybookPath) | ||
} | ||
const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')] | ||
if (beforeValidateFromSchema) beforeValidateFromSchema(config) | ||
if (beforeValidate) beforeValidate(config) | ||
return config.getModel() | ||
} catch (err) { | ||
if (!playbook) throw err | ||
const message = err.message.replace(/( in the schema)?$/m, (_, inTheSchema) => { | ||
return `${inTheSchema ? inTheSchema + ' for' : ' in'} ${absPlaybookPath}${getDetails(playbook, absPlaybookPath)}` | ||
}) | ||
throw Object.assign(err, { message }) | ||
} | ||
} | ||
@@ -107,2 +112,7 @@ | ||
function getDetails (playbook, absPlaybookPath) { | ||
if (playbook === absPlaybookPath) return '' | ||
return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})` | ||
} | ||
module.exports = Object.assign(buildPlaybook, { defaultSchema }) |
@@ -30,3 +30,3 @@ 'use strict' | ||
parse: () => { | ||
throw new Error('Unexpected playbook file type (must be yml, json, or toml') | ||
throw new Error('Unknown playbook file extension: must be .yml (or .yaml), .json, or .toml') | ||
}, | ||
@@ -33,0 +33,0 @@ }, |
{ | ||
"name": "@antora/playbook-builder", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"description": "Builds a playbook object from user input for configuring successive documentation components in an Antora pipeline.", | ||
@@ -39,3 +39,3 @@ "license": "MPL-2.0", | ||
], | ||
"gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54" | ||
"gitHead": "45da95a2e2dea538379d2d9f42013d2208fb86c3" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39816
627