Skip to content

Commit 643c598

Browse files
Merge pull request #271 from MarcelDiessner/feature/syntaxChecking
Patch feature/syntaxChecking
2 parents 917c907 + ba48846 commit 643c598

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

engine/engine.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,36 @@ export class Engine {
2828
console.log("Environment incomplete: " + this.environmentName + " (ignored)");
2929
}
3030
}
31-
32-
mainloop: for (let stepIndex = 0; stepIndex < this.playbook.steps.length; stepIndex++) {
33-
for (let lineIndex = 0; lineIndex < this.playbook.steps[stepIndex].lines.length; lineIndex++) {
34-
let runCommand = this.initRunCommand(stepIndex, lineIndex);
35-
let foundRunnerToExecuteCommand = false;
36-
for (let runnerIndex in this.environment.runners) {
37-
let runner = await this.getRunner(this.environment.runners[runnerIndex]);
38-
if (runner.supports(this.playbook.steps[stepIndex].lines[lineIndex].name, this.playbook.steps[stepIndex].lines[lineIndex].parameters)) {
39-
var result = new RunResult();
40-
if(runner.commandIsSkippable(runCommand.command.name)) {
41-
console.log("Command " + runCommand.command.name + " will be skipped.");
42-
continue;
43-
}
44-
try {
45-
result = runner.run(runCommand);
31+
if(!this.syntaxErrorLogger.activated) {
32+
mainloop: for (let stepIndex = 0; stepIndex < this.playbook.steps.length; stepIndex++) {
33+
for (let lineIndex = 0; lineIndex < this.playbook.steps[stepIndex].lines.length; lineIndex++) {
34+
let runCommand = this.initRunCommand(stepIndex, lineIndex);
35+
let foundRunnerToExecuteCommand = false;
36+
for (let runnerIndex in this.environment.runners) {
37+
let runner = await this.getRunner(this.environment.runners[runnerIndex]);
38+
if (runner.supports(this.playbook.steps[stepIndex].lines[lineIndex].name, this.playbook.steps[stepIndex].lines[lineIndex].parameters)) {
39+
var result = new RunResult();
40+
if(runner.commandIsSkippable(runCommand.command.name)) {
41+
console.log("Command " + runCommand.command.name + " will be skipped.");
42+
continue;
43+
}
44+
try {
45+
result = runner.run(runCommand);
46+
}
47+
catch (e) {
48+
result.exceptions.push(e);
49+
}
50+
51+
await runner.assert(runCommand, result);
52+
53+
foundRunnerToExecuteCommand = true;
54+
break;
4655
}
47-
catch (e) {
48-
result.exceptions.push(e);
49-
}
50-
51-
await runner.assert(runCommand, result);
52-
53-
foundRunnerToExecuteCommand = true;
54-
break;
5556
}
57+
if(!foundRunnerToExecuteCommand && !this.environment.skipMissingFunctions) {
58+
break mainloop;
59+
}
5660
}
57-
if(!foundRunnerToExecuteCommand && !this.environment.skipMissingFunctions) {
58-
break mainloop;
59-
}
6061
}
6162
}
6263

@@ -86,7 +87,8 @@ export class Engine {
8687
}
8788
}
8889
if(missingFunctions.length > 0) {
89-
this.syntaxErrorLogger.handle("Environment incomplete: " + this.environmentName + " | Missing functions: \n - " + missingFunctions.join("\n - "));
90+
console.log(missingFunctions);
91+
this.syntaxErrorLogger.handleMissingFunction(missingFunctions);
9092
return false;
9193
} else {
9294
return true;

engine/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Run {
4545
}
4646
}
4747
}
48+
this.syntaxErrorLogger.deactivate();
4849
} catch (error) {
4950
console.error(error);
5051
this.errors.push(error);
@@ -72,7 +73,7 @@ class Run {
7273
}
7374
} catch(e) {
7475
console.error("Error while parsing playbook: " + playbookDirs[index], e);
75-
this.syntaxErrorLogger.handle("Error while parsing playbook: " + playbookDirs[index] + "\n"+ "- " + e);
76+
this.syntaxErrorLogger.handleParseError(playbookDirs[index], e);
7677
this.errors.push(e);
7778
}
7879
}

engine/syntax_error_logger.ts

Lines changed: 27 additions & 6 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 header = "## Syntax Errors found";
7+
private errors = new Array;
88

99
activate() {
1010
this.activated = true;
@@ -13,12 +13,33 @@ export class SyntaxErrorLogger {
1313
}
1414
}
1515

16-
handle(message: string) {
16+
deactivate() {
17+
if(this.activated && this.errors.length > 0){
18+
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"),
19+
"## Function(s) not found: \n - "
20+
+ this.errors.join("\n - ")
21+
+ "\n \n You can find all supported functions and how to use them [here](https://github.com/devonfw-tutorials/tutorials/wiki/Functions).\n"
22+
, {flag: "a"});
23+
this.activated = false;
24+
}
25+
}
26+
27+
handleMissingFunction(missingFunctions: any[]) {
1728
if(this.activated){
18-
if(!fs.existsSync(path.join(this.outputDir, "syntaxErrors.md"))) {
19-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), this.header + "\n", {flag: "a"});
20-
}
21-
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"), message + "\n", {flag: "a"});
29+
this.errors = missingFunctions;
30+
}
31+
}
32+
33+
handleParseError(playbook, error) {
34+
if(this.activated) {
35+
fs.writeFileSync(path.join(this.outputDir, "syntaxErrors.md"),
36+
"## Error while parsing playbook: "
37+
+ playbook +
38+
"\n" + "- "
39+
+ error + "\n"
40+
+ "\n You can find informations on the syntax [here](https://github.com/devonfw-tutorials/tutorials/wiki/Tutorials)" + "\n",
41+
{flag: "a"});
42+
this.activated = false;
2243
}
2344
}
2445
}

0 commit comments

Comments
 (0)