forked from vitest-dev/vitest
/
recently-updated.ts
57 lines (49 loc) · 1.39 KB
/
recently-updated.ts
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
import { resolve } from 'path'
import Git from 'simple-git'
import fs from 'fs-extra'
import { functionNames, functions } from '../meta/function-indexes'
import { stringifyFunctions } from './utils'
const git = Git()
function uniq<T>(arr: T[]) {
return Array.from(new Set(arr))
}
export async function generateRecentUpdated() {
const logs = await git.log({ maxCount: 100 })
const hashMaps: Record<string, string> = {}
const names = uniq(
logs.all
.map((i) => {
const name = i.message.match(/^\w+!?\((\w+)\)!?:/)?.[1]
if (name && functionNames.includes(name)) {
if (!hashMaps[name])
hashMaps[name] = i.hash
return name
}
return null
})
.filter(i => i),
)
const news = names.slice(0, 7)
let md = stringifyFunctions(
news
.map((name) => {
const fn = functions.find(i => i.name === name)
if (fn) {
const hash = hashMaps[name]
return {
...fn,
description: `${fn.description} ([\`${hash.slice(0, 5)}\`](https://github.com/vueuse/vueuse/commit/${hash}))`,
}
}
return null
})
.filter(i => i),
false,
).replace(/\n+/g, '\n')
md = `# Recently updated
${md}
Go back to the [full-list](/functions)
`
await fs.writeFile(resolve(__dirname, '../packages/recently-updated.md'), md, 'utf-8')
}
generateRecentUpdated()