-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck-parcel-collisions.js
More file actions
41 lines (34 loc) · 1.15 KB
/
check-parcel-collisions.js
File metadata and controls
41 lines (34 loc) · 1.15 KB
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
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const projects = glob.sync('scenes/*/scene.json', { absolute: true })
const parcels = new Map()
for (const projectFolder of projects.map(path.dirname)) {
const sceneJsonPath = path.resolve(projectFolder, 'scene.json')
const sceneJson = JSON.parse(fs.readFileSync(sceneJsonPath))
for (const tile of sceneJson.scene.parcels) {
const arr = parcels.get(tile) || []
arr.push(projectFolder)
parcels.set(tile, arr)
}
}
// update dcl-workspace.json
{
const workspaceJsonPath = path.resolve('dcl-workspace.json')
const workspaceJson = JSON.parse(fs.readFileSync(workspaceJsonPath))
workspaceJson.folders = projects.map(path.dirname).map(_ => ({ path: path.relative(process.cwd(), _).replace(/\\/g, '/') })).sort()
fs.writeFileSync(workspaceJsonPath, JSON.stringify(workspaceJson, null, 2))
}
let fail = false
for (const [tile, arr] of parcels) {
if (arr.length > 1) {
fail = true
console.error(`❌🔴 Tile ${tile} has two or more scenes assigned: \n${arr.join('\n')}`)
}
}
if (fail) {
process.exit(1)
}
else{
console.log('✅ No collisions found')
}