2020-09-27 15:10:11 +03:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2020-10-09 18:52:59 +03:00
|
|
|
const slash = require('slash')
|
2020-09-27 15:10:11 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const { difference } = require('lodash')
|
|
|
|
const yaml = require('js-yaml')
|
|
|
|
const contentDir = path.join(process.cwd(), 'content')
|
|
|
|
const frontmatter = require('@github-docs/frontmatter')
|
2020-09-29 20:36:07 +03:00
|
|
|
const getApplicableVersions = require('./get-applicable-versions')
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
// the product order is determined by data/products.yml
|
2020-09-27 15:10:11 +03:00
|
|
|
const productsFile = path.join(process.cwd(), 'data/products.yml')
|
|
|
|
const productsYml = yaml.load(fs.readFileSync(productsFile, 'utf8'))
|
|
|
|
const sortedProductIds = productsYml.productsInOrder
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
const contentProductIds = fs.readdirSync(contentDir, { withFileTypes: true })
|
2020-09-27 15:10:11 +03:00
|
|
|
.filter(entry => entry.isDirectory())
|
|
|
|
.map(entry => entry.name)
|
|
|
|
|
|
|
|
assert(difference(sortedProductIds, contentProductIds).length === 0)
|
|
|
|
assert(difference(contentProductIds, sortedProductIds).length === 0)
|
|
|
|
|
|
|
|
const internalProducts = {}
|
|
|
|
|
|
|
|
sortedProductIds.forEach(productId => {
|
2020-09-29 20:36:07 +03:00
|
|
|
const relPath = productId
|
2020-10-09 18:52:59 +03:00
|
|
|
const dir = slash(path.join('content', relPath))
|
|
|
|
const toc = slash(path.join(dir, 'index.md'))
|
2020-09-27 15:10:11 +03:00
|
|
|
const { data } = frontmatter(fs.readFileSync(toc, 'utf8'))
|
2020-09-29 20:36:07 +03:00
|
|
|
const applicableVersions = getApplicableVersions(data.versions, toc)
|
2020-10-09 18:52:59 +03:00
|
|
|
const href = slash(path.join('/', applicableVersions[0], productId))
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
internalProducts[productId] = {
|
|
|
|
id: productId,
|
|
|
|
name: data.shortTitle || data.title,
|
|
|
|
href,
|
|
|
|
dir,
|
|
|
|
toc,
|
|
|
|
wip: data.wip || false
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
internalProducts[productId].versions = applicableVersions
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
const externalProducts = {
|
|
|
|
atom: {
|
|
|
|
id: 'atom',
|
|
|
|
name: 'Atom',
|
|
|
|
href: 'https://atom.io/docs',
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
electron: {
|
|
|
|
id: 'electron',
|
|
|
|
name: 'Electron',
|
|
|
|
href: 'https://electronjs.org/docs',
|
|
|
|
external: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const allProducts = Object.assign({}, internalProducts, externalProducts)
|
|
|
|
|
|
|
|
module.exports = allProducts
|