Files
shadcn-ui/apps/www/scripts/build-components.ts
2023-04-17 12:59:57 +04:00

37 lines
711 B
TypeScript

import fs from "fs"
import path, { basename, dirname } from "path"
import { components } from "../config/components"
const payload = components
.map((component) => {
const files = component.files?.map((file) => {
const content = fs.readFileSync(path.join(process.cwd(), file), "utf8")
return {
name: basename(file),
dir: dirname(file),
content,
}
})
return {
...component,
files,
}
})
.sort((a, b) => {
if (a.name < b.name) {
return -1
}
if (a.name > b.name) {
return 1
}
return 0
})
fs.writeFileSync(
path.join(process.cwd(), "pages/api/components.json"),
JSON.stringify(payload, null, 2)
)