@antora/playbook-builder 3.2.0-alpha.10 → 3.2.0-alpha.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.
@@ -4,7 +4,6 @@ const convict = require('./solitary-convict')
4
4
  const defaultSchema = require('./config/schema')
5
5
  const fs = require('node:fs')
6
6
  const ospath = require('node:path')
7
- const parseArgs = require('yargs-parser')
8
7
  const yaml = require('js-yaml')
9
8
 
10
9
  /**
@@ -30,7 +29,7 @@ const yaml = require('js-yaml')
30
29
  * marked in the schema as preserve, all keys in the playbook are camelCased.
31
30
  */
32
31
  function buildPlaybook (args = [], env = process.env, schema = defaultSchema, beforeValidate = undefined) {
33
- const parsedArgs = parseArgs(args, { configuration: { 'dot-notation': false } })
32
+ const parsedArgs = args.length ? parseArgs(args) : {}
34
33
  const opts = { args: [], env: {} }
35
34
  const config = Object.assign(convict(schema, opts), { getModel, getSchema })
36
35
  Object.assign(opts, { args, env })
@@ -151,4 +150,28 @@ function getDetails (playbook, absPlaybookPath) {
151
150
  return ` (${ospath.isAbsolute(playbook) ? '' : 'cwd: ' + process.cwd() + ', '}playbook: ${playbook})`
152
151
  }
153
152
 
153
+ function parseArgs (args) {
154
+ let currentOptionName
155
+ return Object.assign(
156
+ args.reduce((accum, it) => {
157
+ if (it.startsWith('--') && it !== '--') {
158
+ if (currentOptionName) accum[currentOptionName] = true
159
+ currentOptionName = it.slice(2)
160
+ } else if (currentOptionName) {
161
+ const currentOptionValue = accum[currentOptionName]
162
+ if (currentOptionValue == null || currentOptionValue === true) {
163
+ accum[currentOptionName] = it
164
+ } else if (currentOptionValue.constructor === Array) {
165
+ currentOptionValue.push(it)
166
+ } else {
167
+ accum[currentOptionName] = [currentOptionValue, it]
168
+ }
169
+ currentOptionName = undefined
170
+ }
171
+ return accum
172
+ }, {}),
173
+ currentOptionName ? { [currentOptionName]: true } : undefined
174
+ )
175
+ }
176
+
154
177
  module.exports = Object.assign(buildPlaybook, { defaultSchema })
@@ -250,7 +250,7 @@ module.exports = {
250
250
  log: {
251
251
  level: {
252
252
  doc: 'Set the minimum log level of messages that get logged.',
253
- format: ['all', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'],
253
+ format: ['all', 'trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'],
254
254
  default: 'warn',
255
255
  arg: 'log-level',
256
256
  env: 'ANTORA_LOG_LEVEL',
@@ -130,16 +130,30 @@ function registerFormats (convict) {
130
130
  },
131
131
  coerce: (val, config, name) => {
132
132
  const accum = config?.has(name) ? config.get(name) : []
133
- for (const v of val.split(',')) {
134
- if (~accum.indexOf(v)) continue
135
- const match = accum.find((it) => it.constructor === Object && it.id === v)
136
- if (match) {
137
- if (match.enabled === false) match.enabled = true
133
+ const byId = {}
134
+ const byRequire = {}
135
+ let orderIdx = 0
136
+ const order = new Map()
137
+ for (const [idx, it] of accum.entries()) {
138
+ const ext = it.constructor === Object ? it : (accum[idx] = { require: it })
139
+ byRequire[ext.require] ??= ext
140
+ if ('id' in ext) byId[ext.id] ??= ext
141
+ order.set(it, orderIdx++)
142
+ }
143
+ for (let request of val.split(',')) {
144
+ const enable = request.charAt() === '!' ? (request = request.slice(1)) == null : true
145
+ let match
146
+ if ((match = byId[request] ?? byRequire[request])) {
147
+ if ((match.enabled ?? true) !== enable) match.enabled = enable
138
148
  } else {
139
- accum.push(v)
149
+ accum.push((match = byRequire[request] = { require: request }))
150
+ if (!enable) match.enabled = false
140
151
  }
152
+ if ((match.order ?? 'auto') === 'auto') order.set(match, orderIdx++)
141
153
  }
142
154
  return accum
155
+ .sort((a, b) => order.get(a) - order.get(b))
156
+ .map((it) => (Object.keys(it).length === 1 && 'require' in it ? it.require : it))
143
157
  },
144
158
  })
145
159
  convict.addFormat({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/playbook-builder",
3
- "version": "3.2.0-alpha.10",
3
+ "version": "3.2.0-alpha.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)",
@@ -30,8 +30,7 @@
30
30
  "@iarna/toml": "~2.2",
31
31
  "convict": "~6.2",
32
32
  "js-yaml": "~4.1",
33
- "json5": "~2.2",
34
- "yargs-parser": "~20.2"
33
+ "json5": "~2.2"
35
34
  },
36
35
  "engines": {
37
36
  "node": ">=18.0.0"
@@ -48,7 +47,7 @@
48
47
  "web publishing"
49
48
  ],
50
49
  "scripts": {
51
- "test": "_mocha",
50
+ "test": "node --test",
52
51
  "prepublishOnly": "npx -y downdoc@latest --prepublish",
53
52
  "postpublish": "npx -y downdoc@latest --postpublish"
54
53
  }