Skip to content

Commit d0abbbf

Browse files
restructured logger
1 parent 7f10593 commit d0abbbf

2 files changed

Lines changed: 16 additions & 29 deletions

File tree

engine/engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export class Engine {
8686
}
8787
}
8888
if(missingFunctions.length > 0) {
89-
this.syntaxErrorLogger.handleMissingFunction(this.environmentName, missingFunctions);
89+
console.log(missingFunctions);
90+
this.syntaxErrorLogger.handleMissingFunction(missingFunctions);
9091
return false;
9192
} else {
9293
return true;

engine/syntax_error_logger.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path = require('path');
44
export class SyntaxErrorLogger {
55
public activated = false;
66
private outputDir = __dirname + "/../errors/";
7-
private errorMap = new Map<string, Set<any>>();
7+
private errors = new Array;
88

99
activate() {
1010
this.activated = true;
@@ -14,44 +14,30 @@ export class SyntaxErrorLogger {
1414
}
1515

1616
deactivate() {
17-
if(this.activated && this.errorMap.size > 0){
18-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), "## Syntax Errors found" + "\n", {flag: "a"});
19-
this.errorMap.forEach((value: Set<any>, key: string) => {
20-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), "Environment incomplete: " + key + " | Missing functions: \n", {flag: "a"});
21-
console.log("Environment incomplete: " + key + " | Missing functions: \n");
22-
let missingFunctions = "";
23-
value.forEach(element => {
24-
missingFunctions = missingFunctions + "- " + element + "\n";
25-
});
26-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), missingFunctions + "\n", {flag: "a"});
27-
console.log(missingFunctions);
28-
});
17+
if(this.activated && this.errors.length > 0){
18+
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), "## Function(s) not found: \n - ", {flag: "a"});
19+
let ending = "\n You can find all supported functions and how to use them [here](https://github.com/devonfw-tutorials/tutorials/wiki/Functions)."
20+
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), this.errors.join("\n - ") + "\n" + ending + "\n", {flag: "a"});
2921
this.activated = false;
3022
}
3123
}
3224

33-
handleMissingFunction(environment: string, missingFunctions: any[]) {
25+
handleMissingFunction(missingFunctions: any[]) {
3426
if(this.activated){
35-
let set = new Set;
36-
if(this.errorMap.has(environment)) {
37-
set = this.errorMap.get(environment);
38-
}
39-
this.errorMap.set(environment, this.addToSet(set, missingFunctions));
40-
console.log(this.errorMap);
27+
this.errors = missingFunctions;
4128
}
4229
}
4330

4431
handleParseError(playbook, error) {
4532
if(this.activated) {
46-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), "## Error while parsing playbook: " + playbook + "\n" + "- " + error + "\n", {flag: "a"});
33+
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"),
34+
"## Error while parsing playbook: "
35+
+ playbook +
36+
"\n" + "- "
37+
+ error + "\n"
38+
+ "\n You can find informations on the syntax [here](https://github.com/devonfw-tutorials/tutorials/wiki/Tutorials)" + "\n",
39+
{flag: "a"});
4740
this.activated = false;
4841
}
4942
}
50-
51-
private addToSet(set: Set<any>, array: any[]): Set<any> {
52-
array.forEach(element => {
53-
set.add(element);
54-
});
55-
return set;
56-
}
5743
}

0 commit comments

Comments
 (0)