-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ts
56 lines (48 loc) · 1.81 KB
/
script.ts
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
55
56
import { MendixSdkClient, Project } from 'mendixplatformsdk';
import { createObjectCsvWriter } from 'csv-writer';
import { ObjectMap } from 'csv-writer/src/lib/lang/object';
import { domainmodels } from 'mendixmodelsdk';
// Project & auth config
const username = '';
const apikey = '';
const projectId = "";
const projectName = ""
const client = new MendixSdkClient(username, apikey);
const createCsvWriter = createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: 'domainmodels.csv',
header: [
{id: 'entity', title: 'Entity'},
{id: 'generalization', title: 'Generalization'},
{id: 'attribute', title: 'Attribute'},
{id: 'type', title: 'Type'},
]
});
const records: ObjectMap<any>[] = [];
async function main() {
const project = new Project(client, projectId, projectName);
const workingCopy = await client.platform().createOnlineWorkingCopy(project);
const model = workingCopy.model();
model.allDomainModels().forEach(domainModel => {
domainModel.entities.forEach(entity => {
let generalizationName: string;
if (entity.generalization instanceof domainmodels.Generalization){
const generalization = <domainmodels.Generalization> entity.generalization;
generalizationName = generalization.generalizationQualifiedName;
}
entity.attributes.forEach(attribute => {
records.push({
entity: entity.qualifiedName,
generalization: generalizationName,
attribute: attribute.name,
type: attribute.type.structureTypeName
})
})
});
});
csvWriter.writeRecords(records) // returns a promise
.then(() => {
console.log('...Done');
});
}
main();