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')
|
2021-02-11 19:15:59 +03:00
|
|
|
const frontmatter = require('./read-frontmatter')
|
2020-09-29 20:36:07 +03:00
|
|
|
const getApplicableVersions = require('./get-applicable-versions')
|
2021-01-14 21:34:32 +03:00
|
|
|
const removeFPTFromPath = require('./remove-fpt-from-path')
|
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-11-14 00:27:27 +03:00
|
|
|
.map(entry => {
|
|
|
|
// `fs.readdir` provides file entries based on `fs.lstat`, which doesn't
|
|
|
|
// resolve symbolic links to their target file/directory. We need to take
|
|
|
|
// an extra step here to resolve the Early Access symlinked directory.
|
|
|
|
const { name } = entry
|
|
|
|
if (entry.isSymbolicLink()) {
|
|
|
|
entry = fs.statSync(path.join(contentDir, entry.name))
|
|
|
|
entry.name = name
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
.filter(entry => entry.isDirectory())
|
|
|
|
.map(entry => entry.name)
|
|
|
|
|
2020-10-21 16:43:23 +03:00
|
|
|
// require the content/<subdir> list to match the list in data/products.yml,
|
|
|
|
// with the exception of content/early-access, which lives in a separate private repo
|
2020-11-10 04:44:10 +03:00
|
|
|
const publicContentProductIds = contentProductIds.filter(id => id !== 'early-access')
|
2020-10-21 16:43:23 +03:00
|
|
|
assert(difference(sortedProductIds, publicContentProductIds).length === 0)
|
|
|
|
assert(difference(publicContentProductIds, sortedProductIds).length === 0)
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
const internalProducts = {}
|
|
|
|
|
2020-10-21 16:43:23 +03:00
|
|
|
// add optional early access content dir to sorted products list if present
|
2020-11-10 23:37:03 +03:00
|
|
|
const earlyAccessId = contentProductIds.find(id => id === 'early-access')
|
|
|
|
if (earlyAccessId) sortedProductIds.push(earlyAccessId)
|
2020-10-21 16:43:23 +03:00
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
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)
|
2021-01-15 17:50:23 +03:00
|
|
|
const href = removeFPTFromPath(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,
|
2020-10-21 00:22:08 +03:00
|
|
|
wip: data.wip || false,
|
|
|
|
hidden: data.hidden || false
|
2020-09-27 15:10:11 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
internalProducts[productId].versions = applicableVersions
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
const externalProducts = {
|
2020-11-03 10:11:49 +03:00
|
|
|
cli: {
|
|
|
|
id: 'cli',
|
|
|
|
name: 'GitHub CLI',
|
|
|
|
href: 'https://cli.github.com/manual',
|
|
|
|
external: true
|
|
|
|
},
|
2020-09-27 15:10:11 +03:00
|
|
|
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
|