-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
88 lines (80 loc) · 3.63 KB
/
script.ts
File metadata and controls
88 lines (80 loc) · 3.63 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { MendixPlatformClient} from "mendixplatformsdk";
import { ModelSdkClient, IModel, projects, domainmodels, microflows, pages, navigation, texts, security, IStructure, menus } from "mendixmodelsdk";
const appID = "{{appID}}";
const projectName = "{{projectName}}";
const branchName = null // null for mainline
const client = new MendixPlatformClient();
var officegen = require('officegen');
var docx = officegen('docx');
var fs = require('fs');
var pObj = docx.createP();
var totalNumberPages = 0;
var totalNumberMicroflows=0;
var totalNumberEntities = 0;
/*
* PROJECT TO ANALYZE
*/
async function main() {
const app = client.getApp(appID);
var useBranch:string ="";
if(branchName === null){
var repositoryInfo = await app.getRepository().getInfo();
if (repositoryInfo.type === `svn`)
useBranch = `trunk`;
else
useBranch = `main`;
}else{
useBranch = branchName;
}
const workingCopy = await app.createTemporaryWorkingCopy(useBranch);
pObj.addText(projectName, { bold: true, underline: true, font_size: 20 });
pObj.addLineBreak();
pObj.addLineBreak();
const model = await workingCopy.openModel();
model.allDomainModels().forEach(domainModel => {
pObj.addText(getModuleName(domainModel), { bold: true, underline: true, font_size: 18 });
pObj.addLineBreak();
totalNumberEntities+= domainModel.entities.length;
pObj.addText(`Total Entities: ${domainModel.entities.length}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
var totalPages = model.allPages().filter(page => {
return getModuleName(page) === getModuleName(domainModel);
});
totalNumberPages+= totalPages.length;
pObj.addText(`Total Pages: ${totalPages.length}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
var microflows = model.allMicroflows().filter(microflow => {
return getModuleName(microflow) === getModuleName(domainModel);
});
totalNumberMicroflows+= microflows.length;
pObj.addText(`Total Microflows: ${microflows.length}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
pObj.addLineBreak();
return;
});
pObj.addText(`Total Stats`, { bold: true, underline: true, font_size: 18 });
pObj.addLineBreak();
pObj.addText(`Total Application Objects: ${totalNumberPages+totalNumberEntities+totalNumberMicroflows}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
pObj.addText(`Total Pages: ${totalNumberPages}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
pObj.addText(`Total Microflows: ${totalNumberMicroflows}`, { bold: false, underline: false, font_size: 15 });
pObj.addLineBreak();
pObj.addText(`Total Entities: ${totalNumberEntities}`, { bold: false, underline: false, font_size: 15 });
var out = fs.createWriteStream(`${projectName} Application Counts.docx`);
docx.generate(out);
out.on('close', function () {
console.log('Finished to creating Document');
});
}
export function getModuleName(element: IStructure): string {
let current = element.unit;
while (current) {
if (current instanceof projects.Module) {
return current.name;
}
current = current.container;
}
return "";
}
main().catch(console.error);