-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-content
executable file
·81 lines (69 loc) · 2.51 KB
/
create-content
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
#!/usr/bin/env node
require('rubico/global')
const Transducer = require('rubico/Transducer')
const x = require('rubico/x')
const cronist = require('cronist')
const fs = require('fs')
const FileSystem = require('./internal/FileSystem')
const walkPathForJSFilePaths = require('./internal/walkPathForJSFilePaths')
const { inspect } = require('util')
const readFileUtf8 = path => fs.promises.readFile(path, { encoding: 'utf8' })
const createMdastFile = async function (source, dest, options = {}) {
await pipe(source, [
readFileUtf8,
cronist.parseMarkdown,
data => fs.promises.writeFile(dest, `
export default ${inspect(data, { depth: Infinity, maxArrayLength: null })}
`.trim()),
])
}
const createCronistFile = async function (source, dest, options = {}) {
const { requiredKeys, ignoreDirs } = options
await pipe(source, [
curry.arity(2, walkPathForJSFilePaths, __, { ignoreDirs }),
flatMap(async fileName => pipe(fileName, [
readFileUtf8,
cronist,
map(assign({ fileName: always(fileName) })),
])),
data => fs.promises.writeFile(dest, `
export default ${inspect(data, { depth: Infinity, maxArrayLength: null })}
`.trim()),
])
}
// createMdast() -> Promise<>
const createMdast = async function () {
const publicFs = new FileSystem({ cwd: `${__dirname}/public` })
const articlesFs = new FileSystem({ cwd: `${__dirname}/articles` })
for (const path of await articlesFs.find('.')) {
const filename = path.replace(articlesFs.cwd, '').replace(/^[/.]+/g, '')
const mdastPath = `mdast/${filename.replace('.md', '.js')}`
console.log('Creating', mdastPath)
await createMdastFile(
`${__dirname}/articles/${filename}`,
`${__dirname}/public/${mdastPath}`,
)
}
console.log('Creating mdast/readme.js')
await createMdastFile(
// `${__dirname}/node_modules/rubico/README.md`,
`${__dirname}/../rubico/README.md`, // uncomment for local changes
`${__dirname}/public/mdast/readme.js`,
)
const rubicoVersion = require('rubico/package').version
const rubicoMajorVersion = rubicoVersion.split('.')[0]
console.log(`Creating cronist/rubico-v${rubicoMajorVersion}.js`)
await createCronistFile(
// `${__dirname}/node_modules/rubico`,
`${__dirname}/../rubico`, // uncomment for local changes
`${__dirname}/public/cronist/rubico-v${rubicoMajorVersion}.js`,
{
requiredKeys: ['name', 'synopsis', 'description'],
ignoreDirs: ['node_modules', 'archive'],
},
)
}
if (require.main == module) {
createMdast()
}
module.exports = createMdast