kopia lustrzana https://github.com/badgen/badgen.net
Refactor gen-examples script
rodzic
c820b37c1f
commit
1f222c7f4f
|
@ -0,0 +1,26 @@
|
|||
import path from 'path'
|
||||
import { examples as staticBadgeExamples } from '../endpoints/badge'
|
||||
|
||||
const rel = (...args) => path.resolve(__dirname, ...args)
|
||||
|
||||
// sort live badge examples manually
|
||||
const liveBadgeExampleList = [
|
||||
'github',
|
||||
'amo',
|
||||
'homebrew'
|
||||
]
|
||||
|
||||
export async function loadExamples () {
|
||||
const liveBadgeExamples = await Promise.all(liveBadgeExampleList.map(async name => {
|
||||
const { title, examples } = await import(rel('../endpoints', name))
|
||||
return {
|
||||
title: title || name,
|
||||
examples
|
||||
}
|
||||
}))
|
||||
|
||||
return {
|
||||
live: liveBadgeExamples,
|
||||
static: staticBadgeExamples
|
||||
}
|
||||
}
|
|
@ -1,43 +1,14 @@
|
|||
import path from 'path'
|
||||
import fse from 'fs-extra'
|
||||
import { loadExamples } from '../libs/examples'
|
||||
|
||||
const rel = (...args) => path.resolve(__dirname, ...args)
|
||||
|
||||
async function main () {
|
||||
const staticExamples = (await import(rel('../endpoints/badge'))).examples
|
||||
|
||||
// sort badges manually
|
||||
const liveBadgeList = {
|
||||
github: 'github',
|
||||
// npm: 'npm',
|
||||
// david: 'david-dm',
|
||||
// packagephobia: 'packagephobia',
|
||||
// bundlephobia: 'bundlephobia',
|
||||
// xo: 'xo',
|
||||
// crates: 'crates',
|
||||
// docker: 'docker',
|
||||
homebrew: 'homebrew'
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const liveExamples = await Promise.all(Object.entries(liveBadgeList).map(async ([name, title]) => {
|
||||
const { examples, handlers } = await import(rel('../endpoints', name))
|
||||
return {
|
||||
title,
|
||||
examples,
|
||||
schemes: Object.keys(handlers)
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
const examples = {
|
||||
live: liveExamples,
|
||||
static: staticExamples
|
||||
}
|
||||
const examples = await loadExamples()
|
||||
console.log(examples)
|
||||
|
||||
await fse.outputJson(rel('../static/.gen/examples.json'), examples)
|
||||
|
||||
console.log(examples.live)
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Ładowanie…
Reference in New Issue