-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-view-files.js
43 lines (38 loc) · 1.17 KB
/
process-view-files.js
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
import { promises as fs } from 'fs'
import addToMapSet from './add-to-map-set.js'
import getViewIdFromFile from './get-view-id-from-file.js'
import path from 'path'
import slash from 'slash'
export default async function processViewFiles({
filesView,
filesViewLogic,
filesViewGraphql,
viewsById,
viewsToFiles,
}) {
await Promise.all(
[...filesView].map(async (file) => {
let id = getViewIdFromFile(file)
addToMapSet(viewsById, id, file)
let view = viewsToFiles.has(file) ? viewsToFiles.get(file) : {}
let logic = slash(path.join(path.dirname(file), 'logic.js'))
logic = filesViewLogic.has(logic) && logic
let query = slash(path.join(path.dirname(file), 'data.graphql'))
query = filesViewGraphql.has(query) && query
let data = slash(path.join(path.dirname(file), 'data.js'))
viewsToFiles.set(file, {
...view,
custom: false,
flow: false,
data,
query,
file,
importFile: file.replace(/view\.blocks$/, 'index.js'),
id,
logic,
source: await fs.readFile(file, 'utf8'),
version: view.version ? view.version + 1 : 0,
})
})
)
}