MCPcopy
hub / github.com/vitejs/awesome-vite / run

Function run

scripts/cleanup.mjs:41–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41async function run() {
42 const content = await fs.readFile('README.md', 'utf-8')
43 const lines = content.split('\n')
44 const outdatedIndex = []
45
46 const ages = []
47
48 await Promise.all(
49 lines.map(async (line, index) => {
50 return limit(async () => {
51 const match = line.match(REG_ITEM)
52 if (!match) return
53 const link = match[1]
54 const match2 = link.match(REG_REPO)
55 if (!match2) return
56 const [, owner, repo] = match2
57 const name = owner + '/' + repo
58 if (['rollup', 'vitejs'].includes(owner)) return
59
60 try {
61 const { data } = await octokit.request('GET /repos/{owner}/{repo}/commits', {
62 owner,
63 repo,
64 })
65 const date = data?.[0]?.commit?.author?.date
66 if (!date) return
67 const ms = +new Date(date)
68 const delta = Date.now() - ms
69 const time = toHumanreadableString(delta).padStart(5)
70
71 ages.push(delta)
72
73 if (delta > OUT_DATE) {
74 console.log(name.padEnd(50, ' '), time, '⛔️')
75 outdatedIndex.push(index)
76 } else {
77 console.log(name.padEnd(50, ' '), time)
78 }
79 } catch (e) {
80 console.error(name, e.toString())
81 }
82 })
83 })
84 )
85
86 console.log('\n------\n')
87 console.log(`${ages.length} repos at average of ${toHumanreadableString(average(ages))} old`)
88 console.log(`${outdatedIndex.length} repos out-of-dated`)
89
90 if (outdatedIndex.length) {
91 const newContent = lines.filter((_, idx) => !outdatedIndex.includes(idx)).join('\n')
92
93 await fs.writeFile('README.md', newContent, 'utf-8')
94 console.log('write to README.md')
95 }
96}
97
98run()

Callers 1

cleanup.mjsFile · 0.85

Calls 2

toHumanreadableStringFunction · 0.85
averageFunction · 0.85

Tested by

no test coverage detected