-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve.js
More file actions
21 lines (20 loc) · 819 Bytes
/
resolve.js
File metadata and controls
21 lines (20 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const dtmiToPath = (dtmi) => `/${dtmi.toLowerCase().replace(/:/g, '/').replace(';', '-')}.json`
export const resolveDtmi = async (dtmi, x, baseRepo) => {
const modelpath = `${baseRepo}${dtmiToPath(dtmi)}`
if (x) {
return await (await window.fetch(modelpath.replace('.json', '.expanded.json'))).json()
} else {
const root = []
const model = await (await window.fetch(modelpath)).json()
root.push(model)
const children = model.contents.filter(c => c['@type'] === 'Component')
for await (const compo of children) {
if (root.filter(r => r['@id'] === compo.schema).length === 0) {
const compoPath = `${baseRepo}${dtmiToPath(compo.schema)}`
const compDoc = await (await window.fetch(compoPath)).json()
root.push(compDoc)
}
}
return root
}
}