Commit b2d3d183 authored by Dan Allen's avatar Dan Allen

rename component descriptor filename to antora.yml

- rename component descriptor from docs-component.yml to antora.yml
- promote component descriptor filename to a constant
- move constants in content-aggregator to a dedicated file
- replace the term "corpus" with the term "aggregate"
- sort const declarations alphabetically
- fix missing files in fixture for documentation component
- update test descriptions
parent 9cf4dece
module.exports = Object.freeze({
COMPONENT_DESC_FILENAME: 'antora.yml',
})
'use strict'
const path = require('path')
const fs = require('fs')
const _ = require('lodash')
const del = require('del')
const File = require('vinyl')
const fs = require('fs')
const git = require('nodegit')
const isMatch = require('matcher').isMatch
const mimeTypes = require('./mime-types-with-asciidoc')
const path = require('path')
const streamToArray = require('stream-to-array')
const vfs = require('vinyl-fs')
const yaml = require('js-yaml')
const { COMPONENT_DESC_FILENAME } = require('./constants')
const localCachePath = path.resolve('.git-cache')
module.exports = async (playbook) => {
......@@ -53,7 +53,7 @@ module.exports = async (playbook) => {
return allRepoComponentVersions
})
return buildCorpus(await Promise.all(componentVersions))
return buildAggregate(await Promise.all(componentVersions))
}
async function openOrCloneRepository (repoUrl) {
......@@ -144,17 +144,17 @@ function branchMatches (branchName, branchPattern) {
}
function readComponentDesc (files) {
const componentDescFile = files.find((file) => file.relative === 'docs-component.yml')
const componentDescFile = files.find((file) => file.relative === COMPONENT_DESC_FILENAME)
if (componentDescFile == null) {
throw new Error('docs-component.yml not found')
throw new Error(COMPONENT_DESC_FILENAME + ' not found')
}
const componentDesc = yaml.safeLoad(componentDescFile.contents.toString())
if (componentDesc.name == null) {
throw new Error('docs-component.yml is missing a name')
throw new Error(COMPONENT_DESC_FILENAME + ' is missing a name')
}
if (componentDesc.version == null) {
throw new Error('docs-component.yml is missing a version')
throw new Error(COMPONENT_DESC_FILENAME + ' is missing a version')
}
return componentDesc
......@@ -222,7 +222,7 @@ function assignFileProperties (file, url, branch, startPath = '/') {
return file
}
function buildCorpus (componentVersions) {
function buildAggregate (componentVersions) {
return _(componentVersions)
.flatten()
.groupBy(({ name, version }) => `${version}@${name}`)
......
:moduledir: ..
include::{moduledir}/_attributes.adoc[]
:attachmentsdir: {moduledir}/assets/attachments
:examplesdir: {moduledir}/examples
:imagesdir: {moduledir}/assets/images
:partialsdir: {moduledir}/documents/_partials
'use strict'
const path = require('path')
const git = require('nodegit')
const fs = require('fs-extra')
const git = require('nodegit')
const path = require('path')
const { COMPONENT_DESC_FILENAME } = require('../lib/constants')
const fixturesPath = path.resolve(__dirname, 'fixtures')
const reposBasePath = path.resolve(__dirname, 'repos')
......@@ -64,27 +65,27 @@ class FixtureRepo {
}
async setDocsComponent ({ name, title, version, nav, startPath = '.' }) {
const filepath = path.join(this.repoPath, startPath, 'docs-component.yml')
const docsComponentYml = []
const filepath = path.join(this.repoPath, startPath, COMPONENT_DESC_FILENAME)
const componentDescYaml = []
if (name) {
docsComponentYml.push(`name: ${name}`)
componentDescYaml.push(`name: ${name}`)
}
if (title) {
docsComponentYml.push(`title: ${title}`)
componentDescYaml.push(`title: ${title}`)
}
if (version) {
docsComponentYml.push(`version: '${version}'`)
componentDescYaml.push(`version: '${version}'`)
}
if (nav) {
docsComponentYml.push('nav:')
componentDescYaml.push('nav:')
nav.forEach((navItem) => {
docsComponentYml.push(` - ${navItem}`)
componentDescYaml.push(` - ${navItem}`)
})
}
if (name != null || version != null) {
await fs.ensureFile(filepath)
await fs.writeFile(filepath, docsComponentYml.join('\n'))
await this.commitAll(`Set docs-component for ${version}`)
await fs.writeFile(filepath, componentDescYaml.join('\n'))
await this.commitAll(`Populate component desc for ${version}`)
}
}
......
......@@ -5,6 +5,7 @@ const { expect } = require('../../../test/test-utils')
const classifyContent = require('../lib/index')
const path = require('path')
const mimeTypes = require('../../content-aggregator/lib/mime-types-with-asciidoc')
const { COMPONENT_DESC_FILENAME } = require('../../content-aggregator/lib/constants')
const createFile = (filepath) => {
const basename = path.basename(filepath)
......@@ -118,13 +119,13 @@ describe('classifyContent()', () => {
})
})
it('should not classify a navigation if not referenced in docs-component.yml', () => {
it('should not classify a navigation if not referenced in component desc', () => {
aggregate[0].files.push(createFile('/modules/ROOT/nav.adoc'))
const files = classifyContent(playbook, aggregate).getFiles()
expect(files).to.have.lengthOf(0)
})
it('should classify a navigation if referenced in docs-component.yml', () => {
it('should classify a navigation if referenced in component desc', () => {
aggregate[0].nav = ['modules/ROOT/nav.adoc']
aggregate[0].files.push(createFile('/modules/ROOT/nav.adoc'))
const files = classifyContent(playbook, aggregate).getFiles()
......@@ -139,7 +140,7 @@ describe('classifyContent()', () => {
})
})
it('should assign a nav.index on navigation based on order in docs-component.yml', () => {
it('should assign a nav.index on navigation based on order in component desc', () => {
aggregate[0].nav = ['modules/ROOT/nav.adoc', 'modules/module-a/nav.adoc', 'modules/module-b/nav.adoc']
aggregate[0].files.push(
...[
......@@ -160,7 +161,7 @@ describe('classifyContent()', () => {
it('should not classify files that do not follow the Antora standard', () => {
aggregate[0].files.push(
...[
createFile('/docs-component.yml'),
createFile('/' + COMPONENT_DESC_FILENAME),
createFile('/README.adoc'),
createFile('/modules/ROOT/_attributes.adoc'),
createFile('/modules/ROOT/assets/bad-file.png'),
......
......@@ -3,7 +3,6 @@
const { expect } = require('../../../test/test-utils')
const buildPlaybook = require('../lib/index')
const path = require('path')
describe('buildPlaybook()', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment