Open History to see the last commit
1// @ts-check
2β
3import fs from 'node:fs'
4import { glob } from 'tinyglobby'
5β
6const outputPath = './gpt/db.json'
7const packages = []
8const docs = []
9const examples = []
10β
11Promise.resolve()
12 .then(() => {
13 return glob('./packages/*').then((dirs) => {
14 return Promise.all(
15 dirs.map((dir) => {
16 const pkg = {
17 name: dir.replace('./packages/', ''),
18 files: [],
19 }
20β
21 packages.push(pkg)
22β
23 return glob(`./${dir}/src/**/*`, {
24 onlyFiles: true,
25 }).then((files) => {
26 files.forEach((file) => {
27 const content = fs.readFileSync(file, 'utf8')
28β
29 pkg.files.push({ file, content })
30 })
31 })
32 }),
33 )
34 })
35 })
36 .then(() => {
37 return glob('./docs/**/*.md').then((files) => {
38 files.forEach((file) => {
39 const content = fs.readFileSync(file, 'utf8')
40 const title = file.replace('./', '').replace('.md', '')
41β
42 docs.push({ page: title, content })
43 })
44 })
45 })
46 .then(() => {
47 return glob('./examples/react/*').then((dirs) => {
48 return Promise.all(
49 dirs.map((dir) => {
50 if (dir.includes('wip')) {
51 return
52 }
53 const example = {
54 name: dir.replace('./examples/react/', ''),
55 files: [],
56 }
57β
58 examples.push(example)
59β
60 return glob(`./${dir}/src/**/*`, {
61 onlyFiles: true,
62 }).then((files) => {
63 files.forEach((file) => {
64 const content = fs.readFileSync(file, 'utf8')
65β
66 example.files.push({ file, content })
67 })
68 })
69 }),
70 )
71 })
72 })
73 .then(() => {
74 fs.writeFileSync(
75 outputPath,
76 JSON.stringify({ packages, docs, examples }, null, 2),
77 )
78 })
79 .catch((err) => {
80 console.error('Error reading files:', err)
81 return
82 })