Skip to content

Commit 74d5470

Browse files
Merge pull request #290 from EduardKrieger/bugfix/wikiRunnerStepDescription
Bugfix/wiki runner step description
2 parents 87ef43f + e261dfa commit 74d5470

34 files changed

Lines changed: 432 additions & 169 deletions

documentation/Functions.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The following functions are already implemented:
1818
* [npmInstall](#npmInstall)
1919
* [dockerCompose](#dockerCompose)
2020
* [downloadFile](#downloadFile)
21-
* [nextKatacodaStep](#nextKatacodaStep)
21+
* [displayContent](#displayContent)
2222
* [adaptTemplatesCobiGen](#adaptTemplatesCobiGen)
2323
* [createDevon4ngProject](#createDevon4ngProject)
2424
* [addSetupScript](#addSetupScript)
@@ -349,20 +349,46 @@ path: The URL path on which is checked if the server is running
349349
If the tutorial should be tested on the console environment, you have to specify a port.
350350
***
351351

352-
### nextKatacodaStep <a name="nextKatacodaStep"></a>
352+
### displayContent <a name="displayContent"></a>
353353
#### parameter
354-
1. The title of the step.
355-
2. An array of json objects with files, content, or images to be rendered within the katacoda step.
354+
1. The title of the step.
355+
2. An array of json objects with files, content, or images to be rendered within the Katacoda step. The use for this function is to display an image and some descriptive text. No Katacoda syntax is allowed in the files or the content!
356356
3. (Optional) Path to the current directory where the user is located (relative to the workspace directory). Only needed if the directory is changed within this step.
357357
#### example
358-
nextKatacodaStep("Step title", [{ "file": "files/description.md" }, { "content": "This is just plain content." }, { "image": "files/image.png" }])
358+
display("Step title", [{ "file": "files/description.asciidoc" }, { "content": "This is just plain content." }, { "image": "files/image.png" }])
359359

360360
#### Details
361361
Available attributes in the json objects:
362362

363-
file: Path to a file whose content is to be displayed in the katacoda step (e.g. .md or .txt file).
364-
content: Plain text to be displayed in the katacoda step.
365-
image: Path to an image to be displayed in the katacoda step.
363+
1. file: Path to a file whose content is to be displayed in the Katacoda step (e.g. .asciidoc or .txt file). The file should be following the formating of asciidoc files.
364+
2. content: Plain text to be displayed in the Katacoda step. This Text should be following the formating of asciidoc files.
365+
3. image: Path to an image to be displayed in the Katacoda step.
366+
367+
#### Formatting rules for content and .asciidoc or .txt files.
368+
* You can add headers to structure your text. The generated headers are shown in the examples below. The headers should fit into the overall structure of the generated wiki so level 1 header are not allowed, but the other header can be used at your judgement.
369+
* A list always needs an empty newline between the last row and the list.
370+
* Use asciidoc style of links
371+
372+
#### examples
373+
```
374+
Existing header structure
375+
= Level 1: tutorial title
376+
== Level 2: subtitle
377+
=== Level 3: prerequisites and learning goals
378+
== Level 2: steptitle
379+
=== Level 3: titles from functions
380+
==== Level 4: subtitles from functions
381+
== Level 2: conclusion
382+
383+
List:
384+
This an unordered List (The empty line is necessary)
385+
386+
* First Item
387+
* Second Item
388+
389+
Link:
390+
The tutorials repository can be found https://github.com/devonfw-tutorials/tutorials/issues[here].
391+
```
366392

367393
***
368394

engine/wikiRunner.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import { Runner } from "./runner";
22
import { Playbook } from "./playbook";
3+
import { RunCommand } from "./run_command";
34
import * as fs from "fs";
45
import * as path from "path";
56
import * as ejs from "ejs";
67

78
export abstract class WikiRunner extends Runner {
89

910
public outputPathTutorial: string;
11+
public commandCntMap = new Map();
12+
13+
protected readonly INSTALLED_TOOLS: string = "installedTools";
1014
protected fileTypeMap = new Map([ [".java", "java"],[".ts", "typescript"],
1115
[".js", "javascript"], [".html", "html"],
1216
[".scss", "css"], [".asciidoc", "asciidoc"], ]);
13-
protected readonly INSTALLED_TOOLS: string = "installedTools";
17+
1418

1519

1620
init(playbook: Playbook): void {
1721
let outputDirectory = this.createFolder(path.join(this.getOutputDirectory(), "wiki", this.environmentName), false)
1822
this.outputPathTutorial = this.createFolder(path.join(outputDirectory, playbook.name), true);
1923
this.setVariable(this.WORKSPACE_DIRECTORY, path.join(this.getWorkingDirectory()));
2024
this.setVariable(this.INSTALLED_TOOLS, "");
25+
for(let i = 0; i< playbook.steps.length; i++){
26+
this.commandCntMap.set(i, playbook.steps[i].lines.length-1);
27+
}
2128
}
2229

2330
async destroy(playbook: Playbook): Promise<void> {
@@ -31,4 +38,22 @@ export abstract class WikiRunner extends Runner {
3138
fs.writeFileSync(tempFile, result, { flag: "a" });
3239
}
3340

41+
protected checkForText(runCommand: RunCommand): string{
42+
return runCommand.lineIndex == 0
43+
? runCommand.text
44+
: undefined;
45+
}
46+
47+
protected checkForTitle(runCommand: RunCommand): string{
48+
return runCommand.lineIndex == 0
49+
? runCommand.stepTitle
50+
: undefined;
51+
}
52+
53+
protected checkForTextAfter(runCommand: RunCommand): string{
54+
return this.commandCntMap.get(runCommand.stepIndex) == runCommand.lineIndex
55+
? runCommand.textAfter
56+
: undefined;
57+
}
58+
3459
}

runners/console/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class Console extends Runner {
413413
return result;
414414
}
415415

416-
runNextKatacodaStep(runCommand: RunCommand): RunResult {
416+
runDisplayContent(runCommand: RunCommand): RunResult {
417417
//Only needed for katacoda and wiki runner
418418
return null;
419419
}
@@ -941,16 +941,6 @@ export class Console extends Runner {
941941
for(let asyncProcess of this.asyncProcesses) {
942942
killProcessesRecursively(systemProcesses, asyncProcess.pid);
943943
}
944-
}
945-
for(let proc of systemProcesses){
946-
if(path.normalize(proc.path).includes(path.normalize(this.getWorkingDirectory()))){
947-
try {
948-
process.kill(proc.pid);
949-
} catch(e) {
950-
console.error("Error killing process "+proc.name+" with id: " + proc.pid , e);
951-
}
952-
}
953-
}
954944
//Check if there are still running processes on the given ports
955945
// Maybe not needed anymore can be deleted and the function documentation should be updated
956946
for(let asyncProcess of this.asyncProcesses.reverse()) {
@@ -965,9 +955,17 @@ export class Console extends Runner {
965955
}
966956
}
967957
}
968-
969-
958+
for(let proc of systemProcesses){
959+
if(path.normalize(proc.path).includes(path.normalize(this.getWorkingDirectory()))){
960+
try {
961+
process.kill(proc.pid);
962+
} catch(e) {
963+
console.error("Error killing process "+proc.name+" with id: " + proc.pid , e);
964+
}
965+
}
966+
}
970967
}
968+
}
971969

972970
private async cleanUp(): Promise<void> {
973971
await this.killAsyncProcesses();

runners/katacoda/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class Katacoda extends Runner {
344344
return null;
345345
}
346346

347-
runNextKatacodaStep(runCommand: RunCommand): RunResult {
347+
runDisplayContent(runCommand: RunCommand): RunResult {
348348
let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md");
349349
fs.writeFileSync(tempFile, "");
350350
for(let i = 0; i < runCommand.command.parameters[1].length; i++) {
@@ -364,7 +364,7 @@ export class Katacoda extends Runner {
364364
let content = fs.readFileSync(tempFile, "utf-8");
365365
this.pushStep(runCommand, runCommand.command.parameters[0], "step" + runCommand.stepIndex + ".md");
366366

367-
this.renderTemplate("nextKatacodaStep.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, content: content });
367+
this.renderTemplate("displayContent.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, content: content });
368368

369369
if(runCommand.command.parameters[2]) {
370370
this.currentDir = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2]);
File renamed without changes.

0 commit comments

Comments
 (0)