-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.ts
More file actions
54 lines (49 loc) · 1.7 KB
/
Copy pathparser.ts
File metadata and controls
54 lines (49 loc) · 1.7 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
42
43
44
45
46
47
48
49
50
51
52
53
54
import {Reader} from './reader';
import {DataType, FlowType, RuntimeFunctionDefinition} from "@code0-tech/sagittarius-graphql-types";
import {Feature, Meta, MetaType} from "../index";
export const Definition = (rootPath: string): Feature[] => {
const meta = Reader(rootPath);
if (!meta) return [];
const features: Feature[] = [];
for (const m of meta) {
let feature = features.find((f) => f.name === m.name);
if (feature) {
appendMeta(feature, m);
} else {
feature = {
name: m.name,
dataTypes: [],
flowTypes: [],
runtimeFunctions: [],
};
appendMeta(feature, m);
features.push(feature);
}
}
return features;
}
function appendMeta(feature: Feature, meta: Meta): void {
for (const definition of meta.data) {
try {
switch (meta.type) {
case MetaType.DataType: {
const parsed = JSON.parse(definition) as DataType;
feature.dataTypes.push(parsed);
break;
}
case MetaType.FlowType: {
const parsed = JSON.parse(definition) as FlowType;
feature.flowTypes.push(parsed);
break;
}
case MetaType.RuntimeFunction: {
const parsed = JSON.parse(definition) as RuntimeFunctionDefinition;
feature.runtimeFunctions.push(parsed);
break;
}
}
} catch (err: any) {
console.error(`Error parsing ${meta.type} ${meta.name}:`, err);
}
}
}