@antora/playbook-builder 3.1.11 → 3.1.12

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.
@@ -2,12 +2,8 @@
2
2
 
3
3
  const convict = require('./solitary-convict')
4
4
  const defaultSchema = require('./config/schema')
5
- const fs = require('node:fs')
6
- const ospath = require('node:path')
7
- const parseArgs = require('yargs-parser')
8
- const yaml = require('js-yaml')
9
-
10
- const COERCE_SCHEMA = yaml.FAILSAFE_SCHEMA
5
+ const fs = require('fs')
6
+ const ospath = require('path')
11
7
 
12
8
  /**
13
9
  * Builds a playbook object according to the provided schema from the specified
@@ -32,22 +28,8 @@ const COERCE_SCHEMA = yaml.FAILSAFE_SCHEMA
32
28
  * marked in the schema as preserve, all keys in the playbook are camelCased.
33
29
  */
34
30
  function buildPlaybook (args = [], env = process.env, schema = defaultSchema, beforeValidate = undefined) {
35
- const parsedArgs = parseArgs(args, { configuration: { 'dot-notation': false } })
36
- const opts = { args: [], env: {} }
37
- const config = Object.assign(convict(schema, opts), { getModel, getSchema })
38
- Object.assign(opts, { args, env })
39
- let playbook
40
- if ('playbook' in schema) {
41
- const playbookEnv = schema.playbook.env
42
- if (playbookEnv != null) playbook = env[playbookEnv]
43
- const playbookArg = schema.playbook.arg
44
- if (playbookArg != null) playbook = parsedArgs[playbookArg] ?? playbook
45
- if (playbook === undefined) {
46
- if (config.has('playbook')) playbook = config.get('playbook')
47
- } else {
48
- config.set('playbook', playbook)
49
- }
50
- }
31
+ const config = Object.assign(convict(schema, { args, env }), { getModel })
32
+ const playbook = config.has('playbook') && config.get('playbook')
51
33
  let absPlaybookPath
52
34
  if (playbook) {
53
35
  if (ospath.extname((absPlaybookPath = ospath.resolve(playbook)))) {
@@ -68,11 +50,10 @@ function buildPlaybook (args = [], env = process.env, schema = defaultSchema, be
68
50
  }
69
51
  }
70
52
  try {
71
- Object.assign(opts, { args: [] })
72
- playbook ? config.loadFile(absPlaybookPath) : config.load({})
73
- importArguments(config, parsedArgs)
74
- Object.assign(opts, { args })
75
- if (playbook && playbook !== absPlaybookPath) config.set('playbook', absPlaybookPath)
53
+ if (playbook) {
54
+ config.loadFile(absPlaybookPath)
55
+ if (playbook !== absPlaybookPath) config.set('playbook', absPlaybookPath)
56
+ }
76
57
  const beforeValidateFromSchema = config._def[Symbol.for('convict.beforeValidate')]
77
58
  if (beforeValidateFromSchema) beforeValidateFromSchema(config)
78
59
  if (beforeValidate) beforeValidate(config)
@@ -101,8 +82,9 @@ function camelCaseKeys (o, stopPaths = [], p = '') {
101
82
  function getModel (name) {
102
83
  let config = this
103
84
  const data = config.get(name)
104
- const schema = config.getSchema(name)
85
+ let schema = config._schema
105
86
  if (name) {
87
+ schema = name.split('.').reduce((accum, key) => accum._cvtProperties[key], schema)
106
88
  config = Object.assign(convict(name.split('.').reduce((def, key) => def[key], config._def)), { _instance: data })
107
89
  }
108
90
  config.validate({ allowed: 'strict' })
@@ -115,10 +97,6 @@ function getModel (name) {
115
97
  return model
116
98
  }
117
99
 
118
- function getSchema (name) {
119
- return name ? name.split('.').reduce((accum, key) => accum._cvtProperties[key], this._schema) : this._schema
120
- }
121
-
122
100
  function getStopPaths (schemaProperties, schemaPath = [], stopPaths = []) {
123
101
  for (const [key, { preserve, _cvtProperties }] of Object.entries(schemaProperties)) {
124
102
  if (preserve) {
@@ -132,22 +110,6 @@ function getStopPaths (schemaProperties, schemaPath = [], stopPaths = []) {
132
110
  return stopPaths
133
111
  }
134
112
 
135
- function importArguments (config, args) {
136
- for (const [argName, configKey] of Object.entries(config._argv)) {
137
- const argVal = args[argName]
138
- if (argVal === undefined) continue
139
- const argFormat = config.getSchema(configKey).format
140
- let argValStr = argVal
141
- if (argFormat === 'map' || argFormat === 'primitive-map') {
142
- const dumpOpts = { condenseFlow: true, flowLevel: 0, quotingType: '"' }
143
- argValStr = yaml.dump(Array.isArray(argVal) ? argVal : [argVal], dumpOpts)
144
- } else if (Array.isArray(argVal)) {
145
- argValStr = argVal.join(',')
146
- }
147
- config.set(configKey, argValStr)
148
- }
149
- }
150
-
151
113
  function getDetails (playbook, absPlaybookPath) {
152
114
  if (playbook === absPlaybookPath) return ''
153
115
  return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})`
@@ -170,11 +170,6 @@ module.exports = {
170
170
  format: 'int',
171
171
  default: 1,
172
172
  },
173
- fetch_depth: {
174
- doc: 'Preferred number of commits to fetch from remote repository. 0 indicates full history.',
175
- format: 'int',
176
- default: 1,
177
- },
178
173
  plugins: {
179
174
  credential_manager: {
180
175
  doc: 'A require request for a plugin to replace the built-in credential manager used by the git client.',
@@ -5,9 +5,8 @@ const json = require('json5')
5
5
  const toml = require('@iarna/toml')
6
6
  const yaml = require('js-yaml')
7
7
 
8
- const ARG_RX = /(?:([^=]+)|(?==))(?:$|=(|("|').*?\3|.*)(?:$))/
8
+ const ARGS_SCANNER_RX = /(?:([^=,]+)|(?==))(?:,|$|=(|("|').*?\3|[^,]+)(?:,|$))/g
9
9
  const PRIMITIVE_TYPES = [Boolean, Number, String]
10
- const COERCE_SCHEMA = yaml.FAILSAFE_SCHEMA
11
10
  const YAML_SCHEMA = yaml.CORE_SCHEMA.extend({ implicit: [yaml.types.merge] })
12
11
 
13
12
  /**
@@ -52,14 +51,13 @@ function registerFormats (convict) {
52
51
  coerce: (val, config, name) => {
53
52
  if (config == null) return val
54
53
  const accum = config.has(name) ? config.get(name) : {}
55
- const entries = yaml.load(val, { schema: COERCE_SCHEMA })
56
- for (const entry of Array.isArray(entries) ? entries : [entries]) {
57
- let k, v, match
58
- if (!(match = entry.match(ARG_RX))) continue
59
- ;[, k, v = ''] = match
54
+ let match
55
+ ARGS_SCANNER_RX.lastIndex = 0
56
+ while ((match = ARGS_SCANNER_RX.exec(val))) {
57
+ const [, k, v = ''] = match
60
58
  if (!k) continue
61
59
  let parsed = v
62
- if (v && v !== '-') {
60
+ if (parsed && parsed !== '-') {
63
61
  try {
64
62
  parsed = yaml.load(v, { schema: yaml.CORE_SCHEMA })
65
63
  } catch {}
@@ -85,18 +83,20 @@ function registerFormats (convict) {
85
83
  coerce: (val, config, name) => {
86
84
  if (config == null) return val
87
85
  const accum = config.has(name) ? config.get(name) : {}
88
- const entries = yaml.load(val, { schema: COERCE_SCHEMA })
89
- for (const entry of Array.isArray(entries) ? entries : [entries]) {
90
- let k, v, match
91
- if (!(match = entry.match(ARG_RX))) continue
92
- ;[, k, v = ''] = match
93
- if (!k) continue
94
- let parsed = v
95
- if (v && v !== '-') {
96
- parsed = yaml.load(v, { schema: yaml.CORE_SCHEMA })
97
- if (parsed && PRIMITIVE_TYPES.indexOf(parsed.constructor) < 0) parsed = v
86
+ let match
87
+ ARGS_SCANNER_RX.lastIndex = 0
88
+ while ((match = ARGS_SCANNER_RX.exec(val))) {
89
+ const [, k, v] = match
90
+ if (k) {
91
+ let parsed
92
+ if (v && v !== '-') {
93
+ parsed = yaml.load(v, { schema: yaml.CORE_SCHEMA })
94
+ if (parsed && PRIMITIVE_TYPES.indexOf(parsed.constructor) < 0) parsed = v
95
+ } else {
96
+ parsed = v || ''
97
+ }
98
+ accum[~k.indexOf('-') ? k.replace(/-/g, '_') : k] = parsed
98
99
  }
99
- accum[~k.indexOf('-') ? k.replace(/-/g, '_') : k] = parsed
100
100
  }
101
101
  return accum
102
102
  },
@@ -104,7 +104,7 @@ function registerFormats (convict) {
104
104
  convict.addFormat({
105
105
  name: 'require-array',
106
106
  validate: (val) => {
107
- if (!Array.isArray(val)) throw new Error('must be an array')
107
+ if (!Array.isArray(val)) throw new Error('must be of type Array')
108
108
  },
109
109
  coerce: (val, config, name) => {
110
110
  const accum = config?.has(name) ? config.get(name) : []
@@ -124,7 +124,7 @@ function registerFormats (convict) {
124
124
  name: 'boolean-or-string',
125
125
  validate: (val) => {
126
126
  if (!(val == null || val.constructor === String || val.constructor === Boolean)) {
127
- throw new Error('must be a boolean, string, or null')
127
+ throw new Error('must be a boolean or string')
128
128
  }
129
129
  },
130
130
  })
@@ -166,10 +166,6 @@ function registerFormats (convict) {
166
166
  }
167
167
  if (~parsedUrl.pathname.indexOf('%20')) throw new Error('pathname segment must not contain spaces')
168
168
  },
169
- coerce: (val) => {
170
- if (!val || val === '~') return null
171
- return val.length > 1 && val.charAt(val.length - 1) === '/' ? val.slice(0, -1) : val
172
- },
173
169
  })
174
170
  }
175
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/playbook-builder",
3
- "version": "3.1.11",
3
+ "version": "3.1.12",
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)",
@@ -12,8 +12,7 @@
12
12
  "homepage": "https://antora.org",
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+https://gitlab.com/antora/antora.git",
16
- "directory": "packages/playbook-builder"
15
+ "url": "git+https://gitlab.com/antora/antora.git"
17
16
  },
18
17
  "bugs": {
19
18
  "url": "https://gitlab.com/antora/antora/issues"
@@ -30,11 +29,10 @@
30
29
  "@iarna/toml": "~2.2",
31
30
  "convict": "~6.2",
32
31
  "js-yaml": "~4.1",
33
- "json5": "~2.2",
34
- "yargs-parser": "~20.2"
32
+ "json5": "~2.2"
35
33
  },
36
34
  "engines": {
37
- "node": ">=18.0.0"
35
+ "node": ">=16.0.0"
38
36
  },
39
37
  "files": [
40
38
  "lib/"
@@ -49,7 +47,7 @@
49
47
  ],
50
48
  "scripts": {
51
49
  "test": "_mocha",
52
- "prepublishOnly": "npx -y downdoc@latest --prepublish",
53
- "postpublish": "npx -y downdoc@latest --postpublish"
50
+ "prepublishOnly": "npx -y downdoc --prepublish",
51
+ "postpublish": "npx -y downdoc --postpublish"
54
52
  }
55
53
  }