-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent.mjs
47 lines (40 loc) · 1.49 KB
/
current.mjs
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
import fs from 'fs'
import glob from 'glob'
import path from 'path'
import logSymbols from 'log-symbols'
/**
* Validates that the documentation is up to date by checking the files that it references.
* @param {import('./models.mjs').RawPage[]} files
*/
export async function run (files) {
let count = 0
for (const original of files) {
const source = original.source
if (original.data.files) {
const globs = [].concat(original.data.files)
const updatedAt = fs.statSync(source).mtime
for (const glb of globs) {
const files = glob.sync(glb, {
cwd: path.resolve(source, '../')
})
for (const file of files) {
const filePath = path.resolve(source, '../', file)
const stat = fs.statSync(filePath)
if (stat.mtime > updatedAt) {
console.log(logSymbols.error, `${file} is newer than ${original.relativeSource}, update your documentation.`)
count++
}
}
}
}
}
if (count) process.exit(count)
}
export function help () {
return `
Current: Validates that the documentation is up to date by checking the files that it references.
No command line options.
In the header of your documentation, you may specify a "files" property, which is an array of globs. Ex.
files: ["*.tsx"]
`.replace(/\n[ ]+/g, '\n')
}