-
Notifications
You must be signed in to change notification settings - Fork 0
/
mendilangelo.ts
50 lines (44 loc) · 2.14 KB
/
mendilangelo.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
/*
Create microflows for Validation, FindOrCreate, DeleteAll, Save (Validate & Close)
*/
import { MendixPlatformClient } from "mendixplatformsdk";
import { generateSaveMFEntity } from "./generateSaveMFEntity";
import { generateDeleteAllForEntity } from "./generateDeleteAllForEntity";
import { generateFindOrCreateForEntity } from "./generateFindOrCreateForEntity";
import { generateValidationMicroflowForEntity } from "./generateValidationMicroflowForEntity";
import { askApp, askBranch, keysAndTokensOk, askModule} from './getAppsAndBranches'
async function main() {
console.info("Mendilangelo - Mendix code generator - v 0.2 (c) Chris de Gelder / Low code connect 2022")
// check the environment variables and token
if (!keysAndTokensOk())
return;
const client = new MendixPlatformClient();
// ask for which app
let projectId = await askApp();
// for which branch (if more than one)
let branch = await askBranch(projectId);
// open the app
const app = client.getApp(projectId);
// create a working copy online
const workingCopy = await app.createTemporaryWorkingCopy(branch);
// open the model
const model = await workingCopy.openModel();
// name the target module
const targetModule = 'Mendilangelo';
// ask for which module
const moduleresponse = await askModule(model, targetModule);
// get the selected domeinmodel
const domainModelInterface = model.allDomainModels().filter(dm => dm.containerAsModule.name === moduleresponse.name)[0];
// load the data from the domainmodel interface
const domainModel = await domainModelInterface.load();
// generate for all entities
domainModel.entities.forEach(entity => {
generateValidationMicroflowForEntity(model, domainModel, entity.name, targetModule);
generateFindOrCreateForEntity(model, domainModel, entity.name, targetModule);
generateDeleteAllForEntity(model, domainModel, entity.name, targetModule);
generateSaveMFEntity(model, domainModel, entity.name, targetModule);
});
await model.flushChanges();
await workingCopy.commitToRepository(branch);
}
main().catch(console.error);