-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlebartest.ts
More file actions
204 lines (185 loc) · 5.32 KB
/
handlebartest.ts
File metadata and controls
204 lines (185 loc) · 5.32 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import { writeFile } from "fs";
import * as Handlebars from "handlebars";
class Author {
public displayName: string = "";
public constructor(init?: Partial<Author>) {
Object.assign(this, init);
}
}
class ChangeItem {
public path: string = "";
public constructor(init?: Partial<ChangeItem>) {
Object.assign(this, init);
}
}
class Change {
public item: ChangeItem = new ChangeItem();
public constructor(init?: Partial<Change>) {
Object.assign(this, init);
}
}
class Commit {
public id: string = "";
public message: string = "";
public author: Author = new Author();
public changes: Array<Change> = [];
public constructor(init?: Partial<Commit>) {
Object.assign(this, init);
}
}
class Root {
public commits: Array<Commit> = [];
public dbChanges: boolean = false;
public assemblies: Array<object> = [];
}
const output = "HelloWorld.md";
let hbs = Handlebars.create();
let helpers = require("handlebars-helpers")({
handlebars: hbs,
});
const source = `
{{#if (hasDbScripts commits)}}
{{#forEach (getMigrations commits)}}
{{#if isFirst}}### Die DB-Scripts befinden sich unter DbScripts:{{/if}}
- {{this.migration}}
{{/forEach}}
{{else}}
### Es sind keine Datenbank Anpassungen erforderlich.
{{/if}}
# Global list of CS ({{commits.length}})
{{#forEach commits}}
{{#if isFirst}}### Associated commits{{/if}}
* **ID{{this.id}}**
- **Message:** {{this.message}}
- **Commited by:** {{this.author.displayName}}
- **Changed files count:** {{this.changes.length}}
{{/forEach}}
{{#forEach (assemblies commits)}}
{{#if isFirst}}### Changed Assemblies:{{/if}}
- **{{this.assembly}}**
{{/forEach}}
{{#forEach (distinctFiles commits)}}
{{#if isFirst}}### Associated changed files{{/if}}
- **File path:** {{this.path}}
{{/forEach}}`;
let data = new Root();
data.commits = [
new Commit({
id: "34",
author: new Author({ displayName: "Marco" }),
message: "[DevOps] whatever",
changes: [
new Change({
item: new ChangeItem({
path:
"$/ffm.Playground/Nexus.Shared/1.21.x/Modules.Cpoe/Trunk/src/Laboratory.Core/FlalavLabvalues.cs",
}),
}),
],
}),
new Commit({
id: "32",
author: new Author({ displayName: "Marco" }),
message: "[DevOps] whichever",
changes: [
new Change({
item: new ChangeItem({
path:
"$/ffm.Playground/Nexus.Shared/1.21.x/Modules.Cpoe/Trunk/src/Laboratory.Core/FlalavLabvalues.cs",
}),
}),
],
}),
new Commit({
id: "35",
author: new Author({ displayName: "Marco" }),
message: "changed unieuq constraints",
changes: [
new Change({
item: new ChangeItem({
path:
"$/ffm.Playground/Nexus.Shared/1.21.x/Modules.Cpoe/Trunk/DbScripts/SqlServerNG/nexus_ng/CreateDB/Structure/fpoctp_t_cpoe_templates.tab",
}),
}),
],
}),
new Commit({
id: "37",
author: new Author({ displayName: "Marco" }),
message: "added new migration",
changes: [
new Change({
item: new ChangeItem({
path:
"$/ffm.Playground/Nexus.Shared/1.21.x/Modules.Cpoe/Trunk/DbScripts/OracleNG/nexus_ng/Migrati/Structure/20200212_162150_fpocty.tab.mod",
}),
}),
],
}),
new Commit({
id: "38",
author: new Author({ displayName: "Marco" }),
message: "small chane on migration",
changes: [
new Change({
item: new ChangeItem({
path:
"$/ffm.Playground/Nexus.Shared/1.21.x/Modules.Cpoe/Trunk/DbScripts/OracleNG/nexus_ng/Migrati/Structure/20200212_162150_fpocty.tab.mod",
}),
}),
],
}),
];
hbs.registerHelper("assemblies", function (
commits: Array<Commit>
): Array<object> {
const allChanges = commits.reduce(
(cs: Array<Change>, c) => [...cs, ...c.changes],
[]
);
const srcChanges = allChanges
.filter((cs) => cs.item.path.includes("/Trunk/src/"))
.map((c) => c.item.path.split("/Trunk/src/")[1].split("/")[0])
.filter((s) => s.includes("."))
.map((a) => "Nexus.Shared.Modules." + a + ".dll");
const distinct = [...new Set(srcChanges)];
return distinct.map((s) => ({ assembly: s }));
});
hbs.registerHelper("distinctFiles", function (
commits: Array<Commit>
): Array<object> {
const allChanges = commits.reduce(
(cs: Array<Change>, c) => [...cs, ...c.changes],
[]
);
const srcChanges = allChanges.map(
(c) => c.item.path.split("/Modules.Cpoe/")[1]
);
const distinct = [...new Set(srcChanges)];
return distinct.map((s) => ({ path: s }));
});
hbs.registerHelper("hasDbScripts", function (commits: Array<Commit>): boolean {
const allChanges = commits.reduce(
(cs: Array<Change>, c) => [...cs, ...c.changes],
[]
);
return allChanges.some((cs) => cs.item.path.includes("nexus_ng/Migration"));
});
hbs.registerHelper("getMigrations", function (
commits: Array<Commit>
): Array<object> {
const allChanges = commits.reduce(
(cs: Array<Change>, c) => [...cs, ...c.changes],
[]
);
const migrations = allChanges
.filter((cs) => cs.item.path.includes("nexus_ng/Migration"))
.map((c) => c.item.path.split("/Trunk/")[1]);
const distinct = [...new Set(migrations)];
return distinct.map((s) => ({ migration: s }));
});
let template = hbs.compile(source);
const result = template(data);
writeFile(output, result, function (err) {
if (err) return console.log(err);
});