-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.ts
53 lines (41 loc) · 1.45 KB
/
update.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
import { promises as fs } from 'fs'
import { execSync } from 'child_process'
import axios from 'axios'
const categoriesNames = ['Utilities']
function getPackages(categories: any) {
return Object.entries(categories)
.filter(([key]) => categoriesNames.includes(key))
.flatMap(([k, v]) => v)
.filter((i: any) => !i.depreacted)
}
function getExports(categories: any) {
return getPackages(categories)
.map((i: any) => i.name)
.join(', ')
}
async function updateREADME(data: any) {
const functions = [
...getPackages(data.core.categories),
...getPackages(data.shared.categories),
]
.map(({ name, docs, description }: any) => ` - [\`${name}\`](${docs}) - ${description}`)
.join('\n')
let readme = await fs.readFile('README.md', 'utf-8')
readme = readme.replace(/<!--FUNCTIONS_LIST_STARTS-->[\s\S]+?<!--FUNCTIONS_LIST_ENDS-->/m, `<!--FUNCTIONS_LIST_STARTS-->\n\n${functions}\n\n<!--FUNCTIONS_LIST_ENDS-->`)
await fs.writeFile('README.md', readme, 'utf-8')
}
async function run() {
execSync('npx taze -w', { stdio: 'inherit' })
execSync('npm i', { stdio: 'inherit' })
const { data } = await axios.get(
'https://raw.githubusercontent.com/antfu/vueuse/master/indexes.json',
)
await fs.writeFile(
'src/index.ts',
`export { ${getExports(data.core.categories)} } from '@vueuse/core'\n`
+ `export { ${getExports(data.shared.categories)} } from '@vueuse/shared'\n`,
'utf-8',
)
updateREADME(data)
}
run()