This repository was archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
71 lines (58 loc) · 1.73 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Npm module entrypoint, built into `dist`.
*
* Uses the Webpack `require.context` API to bundle all reference file JSON.
* @see https://webpack.js.org/guides/dependency-management/#context-module-api
*/
import { versions, features } from './scripts/config'
const context = require.context('./files', true, /\.json$/)
const paths = context.keys()
export type ReferenceFileGroup = {
files: ReferenceFile[]
document: number
sketchVersions: string[]
}
export type ReferenceFile = {
id: string
name: string
description: string
data: {
document: any
meta: any
user: any
pages: any[]
}
}
const data: ReferenceFileGroup[] = []
for (const { document, sketchVersions } of versions) {
const group: ReferenceFileGroup = {
files: [],
document,
sketchVersions: sketchVersions.map(versionTuple => versionTuple[0]),
}
data.push(group)
for (const feature of features) {
const documentPath = `./${document}/${feature.id}/document.json`
const metaPath = `./${document}/${feature.id}/meta.json`
const pagesPath = `./${document}/${feature.id}/pages`
const userPath = `./${document}/${feature.id}/user.json`
const featureExists = !!paths.find(path => path === documentPath)
if (!featureExists) continue
const documentJson = context(documentPath)
const metaJson = context(metaPath)
const userJson = context(userPath)
const pagesJson = paths.filter(path => path.startsWith(pagesPath)).map(path => context(path))
group.files.push({
id: feature.id,
name: feature.name,
description: feature.description,
data: {
document: documentJson,
meta: metaJson,
user: userJson,
pages: pagesJson,
},
})
}
}
export default data