@antora/playbook-builder
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,8 +5,5 @@ 'use strict' | ||
const convict = require('./solitary-convict') | ||
const cson = require('cson-parser') | ||
const freezeDeep = require('deep-freeze') | ||
const deepFreeze = require('deep-freeze') | ||
const fs = require('fs') | ||
const json = require('json5') | ||
const ospath = require('path') | ||
const yaml = require('js-yaml') | ||
@@ -49,3 +46,3 @@ /** | ||
} | ||
config.load(parseSpecFile(absSpecFilePath)) | ||
config.loadFile(absSpecFilePath) | ||
if (relSpecFilePath !== absSpecFilePath) config.set('playbook', absSpecFilePath) | ||
@@ -60,21 +57,5 @@ } | ||
function loadConvictConfig (args, env, customSchema) { | ||
return convict(customSchema || require('./config/schema'), { args: args, env: env }) | ||
return convict(customSchema || require('./config/schema'), { args, env }) | ||
} | ||
function parseSpecFile (specFilePath) { | ||
const data = fs.readFileSync(specFilePath, 'utf8') | ||
switch (ospath.extname(specFilePath)) { | ||
case '.yml': | ||
case '.yaml': | ||
return yaml.safeLoad(data) | ||
case '.json': | ||
return json.parse(data) | ||
case '.cson': | ||
return cson.parse(data) | ||
default: | ||
throw new Error('Unsupported file type') | ||
} | ||
} | ||
function exportModel (config) { | ||
@@ -89,5 +70,5 @@ const properties = config.getProperties() | ||
delete playbook.playbook | ||
return freezeDeep(playbook) | ||
return deepFreeze(playbook) | ||
} | ||
module.exports = buildPlaybook |
@@ -112,4 +112,3 @@ 'use strict' | ||
doc: 'A document attribute to set on each page. May be specified multiple times.', | ||
// NOTE format must be 'object' rather than Object to be validated | ||
format: 'object', | ||
format: 'map', | ||
default: {}, | ||
@@ -116,0 +115,0 @@ arg: 'attribute', |
'use strict' | ||
const convict = require('convict') | ||
const cson = require('cson-parser') | ||
const json = require('json5') | ||
const yaml = require('js-yaml') | ||
@@ -9,46 +11,35 @@ | ||
/** | ||
* A convict function wrapper that decouples it from the process environment. | ||
* This wrapper allows the args array and env map to be specified as options. | ||
* A convict function wrapper that registers custom formats and parsers and | ||
* isolates the configuration from the process environment by default. | ||
*/ | ||
function solitaryConvict (schema, opts = {}) { | ||
registerCustomFormats(convict) | ||
function solitaryConvict (schema, opts) { | ||
registerFormats(convict) | ||
registerParsers(convict) | ||
return convict(schema, opts || { args: [], env: {} }) | ||
} | ||
let processArgv | ||
let args = opts.args || [] | ||
processArgv = process.argv | ||
// NOTE convict expects first two arguments to be node command and script filename | ||
let argv = processArgv.slice(0, 2).concat(args) | ||
process.argv = argv | ||
let processEnv | ||
let env = opts.env || {} | ||
processEnv = process.env | ||
process.env = env | ||
const config = convict(schema) | ||
process.argv = processArgv | ||
process.env = processEnv | ||
const originalLoad = config.load | ||
config.load = function (configOverlay) { | ||
process.argv = argv | ||
process.env = env | ||
const combinedConfig = originalLoad.apply(this, [configOverlay]) | ||
process.argv = processArgv | ||
process.env = processEnv | ||
return combinedConfig | ||
} | ||
return config | ||
function registerParsers (convict) { | ||
convict.addParser([ | ||
{ extension: 'cson', parse: cson.parse }, | ||
{ extension: 'json', parse: json.parse }, | ||
{ extension: 'yaml', parse: yaml.safeLoad }, | ||
{ extension: 'yml', parse: yaml.safeLoad }, | ||
{ | ||
extension: '*', | ||
parse: () => { | ||
throw new Error('Unexpected playbook file type (must be yml, json, or cson') | ||
}, | ||
}, | ||
]) | ||
} | ||
function registerCustomFormats (convict) { | ||
function registerFormats (convict) { | ||
convict.addFormat({ | ||
name: 'object', | ||
name: 'map', | ||
validate: (val) => { | ||
if (typeof val !== 'object') throw new Error('must be an object (key/value pairs)') | ||
if (typeof val !== 'object') throw new Error('must be a map of key/value pairs') | ||
}, | ||
coerce: (val) => { | ||
const accum = {} | ||
coerce: (val, config) => { | ||
// TODO we can remove this hardcoded value once coerce passes the path to which this function is bound | ||
const accum = config.has('asciidoc.attributes') ? config.get('asciidoc.attributes') : {} | ||
let match | ||
@@ -58,3 +49,3 @@ ARGS_SCANNER_RX.lastIndex = 0 | ||
const [, k, v] = match | ||
if (k) accum[k] = v ? yaml.safeLoad(v) : '' | ||
if (k) accum[k] = v ? (v === '-' ? '-' : yaml.safeLoad(v)) : '' | ||
} | ||
@@ -61,0 +52,0 @@ return accum |
{ | ||
"name": "@antora/playbook-builder", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Builds a playbook object from user input for configuring successive documentation components in an Antora pipeline.", | ||
@@ -20,6 +20,6 @@ "license": "MPL-2.0", | ||
"camelcase-keys": "^4.2.0", | ||
"convict": "^4.2.0", | ||
"convict": "^4.3.2", | ||
"cson-parser": "^3.0.0", | ||
"deep-freeze": "^0.0.1", | ||
"js-yaml": "^3.11.0", | ||
"js-yaml": "^3.12.0", | ||
"json5": "^1.0.1" | ||
@@ -26,0 +26,0 @@ }, |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
2
11704
311
Updatedconvict@^4.3.2
Updatedjs-yaml@^3.12.0