UNPKG

824 BJavaScriptView Raw
1import { promises as fs } from 'fs'
2import addToMapSet from './add-to-map-set.js'
3import getViewIdFromFile from './get-view-id-from-file.js'
4import path from 'path'
5
6export default async function processViewFiles({
7 filesView,
8 filesViewLogic,
9 viewsById,
10 viewsToFiles,
11}) {
12 await Promise.all(
13 [...filesView].map(async file => {
14 let id = getViewIdFromFile(file)
15
16 addToMapSet(viewsById, id, file)
17
18 let view = viewsToFiles.has(file) ? viewsToFiles.get(file) : {}
19 let logic = path.join(path.dirname(file), 'logic.js')
20
21 viewsToFiles.set(file, {
22 ...view,
23 custom: false,
24 file,
25 id,
26 logic: filesViewLogic.has(logic) && logic,
27 source: await fs.readFile(file, 'utf8'),
28 version: view.version ? view.version + 1 : 0,
29 })
30 })
31 )
32}