@antora/assembler 1.0.0-alpha.1 → 1.0.0-alpha.10

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.
@@ -3,8 +3,9 @@
3
3
  const loadConfig = require('./load-config')
4
4
  const produceAggregateDocuments = require('./produce-aggregate-documents')
5
5
  const PromiseQueue = require('./util/promise-queue')
6
+ const runCommand = require('@antora/run-command-helper')
6
7
 
7
- async function assembleContent (playbook, contentCatalog, converter, { siteCatalog, configSource }) {
8
+ async function assembleContent (playbook, contentCatalog, convertDocument, { siteCatalog, configSource }) {
8
9
  // Q: could we get ContentCatalog#getComponentVersionStartPage() in Antora core?
9
10
  if (typeof contentCatalog.getComponentVersionStartPage !== 'function') {
10
11
  contentCatalog.getComponentVersionStartPage = function (component, version) {
@@ -16,14 +17,14 @@ async function assembleContent (playbook, contentCatalog, converter, { siteCatal
16
17
  const generatorFunctions = this ? this.getFunctions() : {}
17
18
  const { loadAsciiDoc = require('@antora/asciidoc-loader') } = generatorFunctions
18
19
  const aggregateDocuments = produceAggregateDocuments(loadAsciiDoc, contentCatalog, assemblerConfig)
19
- if (!converter) return aggregateDocuments
20
+ if (!convertDocument) return aggregateDocuments
20
21
  const { publishSite: publishFiles = require('@antora/site-publisher') } = generatorFunctions
21
22
  const buildConfig = assemblerConfig.build
22
23
  await prepareWorkspace(publishFiles, aggregateDocuments, contentCatalog, buildConfig)
23
- // TODO: pass more information to converter so it doesn't have to compute internal stuff
24
+ // TODO: pass more information to convertDocument so it doesn't have to compute internal stuff
24
25
  // Q: don't we need to pass in the combined/resolved AsciiDoc attributes per file or component version?
25
26
  return new PromiseQueue({ concurrency: buildConfig.processLimit })
26
- .add(aggregateDocuments.map((doc) => () => converter.call(this, doc, buildConfig)))
27
+ .add(aggregateDocuments.map((doc) => () => convertDocument.call(this, doc, buildConfig, runCommand)))
27
28
  .toPromise()
28
29
  .then((files) => {
29
30
  if (buildConfig.publish && siteCatalog) siteCatalog.addFiles(files)
@@ -31,7 +32,7 @@ async function assembleContent (playbook, contentCatalog, converter, { siteCatal
31
32
  })
32
33
  }
33
34
 
34
- // TODO: if no workspace dir is defined; we shouldn't continue
35
+ // TODO: if no workspace dir is defined, we shouldn't continue
35
36
  function prepareWorkspace (publishFiles, aggregateDocuments, contentCatalog, buildConfig) {
36
37
  const { dir, clean, keepAggregateSource } = buildConfig
37
38
  const files = contentCatalog.findBy({ family: 'image' }).filter(({ out }) => out?.assembled)
@@ -21,11 +21,11 @@ function compilePatterns (patterns) {
21
21
  if (patterns[0].charAt() === '!') patterns = ['**', ...patterns]
22
22
  return patterns.map((pattern) => {
23
23
  const negated = pattern.charAt() === '!'
24
- if (negated) pattern = pattern.substr(1)
24
+ if (negated) pattern = pattern.slice(1)
25
25
  let version
26
26
  const separatorIdx = pattern.search(VERSION_SEPARATOR_RX)
27
27
  if (~separatorIdx) {
28
- pattern = (version = true) && `${pattern.substr(0, separatorIdx)}%${pattern.substr(separatorIdx + 1) || '*'}`
28
+ pattern = (version = true) && `${pattern.slice(0, separatorIdx)}%${pattern.slice(separatorIdx + 1) || '*'}`
29
29
  }
30
30
  return Object.assign(makePicomatchRx(pattern, PICOMATCH_OPTS), {
31
31
  globstar: pattern === '**',
package/lib/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
3
  const assembleContent = require('./assemble-content')
4
- const runCommand = require('./util/run-command')
5
4
 
6
- module.exports = { assembleContent, runCommand }
5
+ module.exports = { assembleContent }
@@ -1,39 +1,37 @@
1
1
  'use strict'
2
2
 
3
- const camelCaseKeys = require('camelcase-keys')
4
3
  const expandPath = require('@antora/expand-path-helper')
5
- const { promises: fsp } = require('fs')
6
- const os = require('os')
4
+ const fsp = require('node:fs/promises')
5
+ const os = require('node:os')
7
6
  const yaml = require('js-yaml')
8
7
 
9
- const CAMEL_CASE_KEYS_OPTS = { deep: true, stopPaths: ['asciidoc'] }
10
-
11
8
  function loadConfig (playbook, configSource = './antora-assembler.yml') {
12
9
  return (
13
10
  configSource.constructor === Object
14
11
  ? Promise.resolve(configSource)
15
12
  : fsp
16
- .access((configSource = expandPath(configSource, { dot: playbook.dir })))
17
- .then(
18
- () => true,
19
- () => false
20
- )
21
- .then((exists) =>
22
- exists
23
- ? fsp.readFile(configSource).then((data) => camelCaseKeys(yaml.load(data), CAMEL_CASE_KEYS_OPTS))
24
- : {}
25
- )
13
+ .access((configSource = expandPath(configSource, { dot: playbook.dir })))
14
+ .then(
15
+ () => true,
16
+ () => false
17
+ )
18
+ .then((exists) =>
19
+ exists ? fsp.readFile(configSource).then((data) => camelCaseKeys(yaml.load(data), ['asciidoc'])) : {}
20
+ )
26
21
  ).then((config) => {
27
22
  if (config.enabled === false) return undefined
28
23
  let asciidocAttrs
29
24
  if (!config.asciidoc) {
30
- config.asciidoc = { attributes: (asciidocAttrs = { doctype: 'book' }) }
25
+ config.asciidoc = { attributes: (asciidocAttrs = {}) }
31
26
  } else if (!(asciidocAttrs = config.asciidoc.attributes)) {
32
- config.asciidoc.attributes = asciidocAttrs = { doctype: 'book' }
27
+ config.asciidoc.attributes = asciidocAttrs = {}
33
28
  }
34
- Object.assign(asciidocAttrs, { revdate: new Date().toISOString().split('T')[0], 'page-partial': null })
29
+ if (!('doctype' in asciidocAttrs)) asciidocAttrs.doctype = 'book'
30
+ if (!('revdate' in asciidocAttrs)) asciidocAttrs.revdate = getLocalDate()
31
+ asciidocAttrs['page-partial'] = null
32
+ asciidocAttrs['loader-assembler'] = ''
35
33
  if (config.componentVersions == null) {
36
- config.componentVersions = ['**']
34
+ config.componentVersions = ['*']
37
35
  } else if (typeof config.componentVersions === 'string') {
38
36
  config.componentVersions = config.componentVersions.split(', ')
39
37
  }
@@ -44,12 +42,10 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') {
44
42
  }
45
43
  const build = config.build || (config.build = {})
46
44
  if (build.dir === '$' + '{playbook.output.dir}') {
47
- //build.dir = playbook.output.dir
48
45
  throw new Error('Not implemented')
49
- } else {
50
- build.dir = expandPath(build.dir || './build/assembler', { dot: playbook.dir })
51
46
  }
52
- build.cwd = playbook.dir // use playbook.dir the purpose of finding and loading require scripts
47
+ build.dir = expandPath(build.dir || './build/assembler', { dot: playbook.dir })
48
+ build.cwd = playbook.dir // use playbook.dir for the purpose of finding and loading require scripts
53
49
  if (!('clean' in build) && 'output' in playbook) build.clean = playbook.output.clean
54
50
  if (!('publish' in build)) build.publish = true
55
51
  if (!build.processLimit) {
@@ -59,4 +55,20 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') {
59
55
  })
60
56
  }
61
57
 
58
+ function camelCaseKeys (o, stopPaths = [], p = undefined) {
59
+ if (Array.isArray(o)) return o.map((it) => camelCaseKeys(it, stopPaths, p))
60
+ if (o == null || o.constructor !== Object) return o
61
+ const pathPrefix = p ? p + '.' : ''
62
+ const accum = {}
63
+ for (const [k, v] of Object.entries(o)) {
64
+ const camelKey = k.charAt() + k.slice(1).replace(/_([a-z])/g, (_, l) => l.toUpperCase())
65
+ accum[camelKey] = ~stopPaths.indexOf(pathPrefix + camelKey) ? v : camelCaseKeys(v, stopPaths, pathPrefix + camelKey)
66
+ }
67
+ return accum
68
+ }
69
+
70
+ function getLocalDate (now = new Date()) {
71
+ return new Date(now - now.getTimezoneOffset() * 60000).toISOString().split('T')[0]
72
+ }
73
+
62
74
  module.exports = loadConfig