forked from faasjs/faasjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-docs.js
92 lines (75 loc) · 2.31 KB
/
build-docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const globSync = require('glob').sync
const promisify = require('node:util').promisify
const exec = promisify(require('node:child_process').exec)
const { readFileSync, writeFileSync } = require('node:fs')
async function run(cmd) {
console.log(cmd)
await exec(cmd, { stdio: 'inherit' })
}
async function build(path) {
const pkg = require(`${__dirname}/${path}`)
if (!pkg.types) return
await run(
`npm run build:doc ${path.replace(
'/package.json',
'/src'
)} -- --tsconfig ${path.replace(
'/package.json',
'/tsconfig.json'
)} --out ${path.replace('/package.json', '/')}`
)
const files = globSync(path.replace('/package.json', '/**/*.md'))
for (const file of files) {
const content = readFileSync(file, 'utf8').toString()
if (content.includes('***'))
writeFileSync(file, content.replaceAll('\n***\n', ''))
}
// const modules = readFileSync(
// path.replace('/package.json', '/modules.md'),
// 'utf8'
// )
// .toString()
// .replace(`# ${pkg.name}\n\n## Table of contents\n`, '')
// .replaceAll('(modules.md#', '(#')
// let readme = readFileSync(
// path.replace('/package.json', '/README.md'),
// 'utf8'
// ).toString()
// if (readme.includes('## Modules')) {
// readme = readme.replace(/## Modules[\s\S]+/g, `## Modules\n${modules}`)
// } else readme += `\n## Modules\n\n${modules}`
// writeFileSync(path.replace('/package.json', '/README.md'), readme)
// await run(`rm ${path.replace('/package.json', '/modules.md')}`)
// const classes = globSync(path.replace('/package.json', '/classes/*.md'))
// if (classes.length)
// for (const file of classes)
// writeFileSync(
// file,
// readFileSync(file, 'utf8').replaceAll('(../modules.md#', '(../#')
// )
}
async function buildAll() {
const list = globSync('packages/*/package.json').filter(
path => !['/cli', '/create-faas-app'].includes(path)
)
for (const name of [
'browser',
'logger',
'deep_merge',
'ts-transform',
'func',
'load',
'http',
'cloud_function',
'deployer',
'request',
]) {
await build(`packages/${name}/package.json`)
list.splice(list.indexOf(`packages/${name}/package.json`), 1)
}
for (const file of list) {
await build(file)
}
}
buildAll()
module.exports = { build }