bigint-mod-arith/build/build.docs.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict'
const fs = require('fs')
const jsdoc2md = require('jsdoc-to-markdown')
const path = require('path')
const pkgJson = require('../package.json')
const rootDir = path.join(__dirname, '..')
2020-04-08 09:53:15 +00:00
function camelise (str) {
return str.replace(/-([a-z])/g,
function (m, w) {
return w.toUpperCase()
})
}
const templateFile = path.join(rootDir, pkgJson.directories.src, 'doc', 'readme-template.md')
const template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
.replace(/\{\{PKG_NAME\}\}/g, pkgJson.name)
.replace(/\{\{PKG_CAMELCASE\}\}/g, camelise(pkgJson.name))
.replace(/\{\{IIFE_BUNDLE\}\}/g, 'IIFE bundle')
.replace(/\{\{ESM_BUNDLE\}\}/g, 'ES6 bundle module')
const input = path.join(rootDir, pkgJson.browser)
// Let us replace bigint literals by standard numbers to avoid issues with bigint
const source = fs.readFileSync(input, { encoding: 'UTF-8' }).replace(/([0-9]+)n([,\s\n)])/g, '$1$2')
const options = {
2020-04-08 09:53:15 +00:00
source,
template,
'heading-depth': 3, // The initial heading depth. For example, with a value of 2 the top-level markdown headings look like "## The heading"
'global-index-format': 'none' // none, grouped, table, dl.
}
2020-04-08 09:53:15 +00:00
jsdoc2md.clear().then(() => {
const readmeContents = jsdoc2md.renderSync(options)
2020-04-08 09:53:15 +00:00
const readmeFile = path.join(rootDir, 'README.md')
fs.writeFileSync(readmeFile, readmeContents)
})