Skip to content

Commit e4f4aa7

Browse files
Merge pull request #286 from EduardKrieger/enhancement/reworkNextKatacodaStep
rework nextKatacodaStep
2 parents 74d5470 + 57640fb commit e4f4aa7

6 files changed

Lines changed: 49 additions & 15 deletions

File tree

documentation/Functions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ createDevon4jProject("com.mycustomer.myapplication")
186186

187187
### buildJava <a name="buildJava"></a>
188188
#### parameter
189-
1. The project directory
189+
1. The project directory, relative to workspace.
190190
2. (Optional) Indicator whether tests should be run. Default is false.
191191
#### example
192192
buildJava("cobigenexample", true)
@@ -323,7 +323,7 @@ downloadFile("https://bit.ly/2BCkFa9", "file", "downloads")
323323

324324
### buildNg <a name="buildNg"></a>
325325
#### parameter
326-
1. Path to the angular project relative to workspace
326+
1. Path to the angular project, relative to workspace
327327
2. (Optional) Custom output directory.
328328
#### example
329329
buildNg("exampleAngularProject")
@@ -364,6 +364,7 @@ Available attributes in the json objects:
364364
2. content: Plain text to be displayed in the Katacoda step. This Text should be following the formating of asciidoc files.
365365
3. image: Path to an image to be displayed in the Katacoda step.
366366

367+
367368
#### Formatting rules for content and .asciidoc or .txt files.
368369
* 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.
369370
* A list always needs an empty newline between the last row and the list.

engine/parser.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class Parser {
2020
let result = new Playbook();
2121
result.title = parseResult[0][2];
2222
result.subtitle = parseResult[1]? parseResult[1][3]: "";
23-
result.description = parseResult[2][2].descriptionlines;
24-
result.conclusion = parseResult[4]? parseResult[4][2].conclusionlines: "";
23+
result.description = this.insertNewlineIntoDescription(parseResult[2][2].descriptionlines);
24+
result.conclusion = this.insertNewlineIntoDescription(parseResult[4]? parseResult[4][2].conclusionlines: "");
2525
for(let index in parseResult[3]){
2626
let step = new Step();
2727
step.text = this.getText(parseResult, index);
@@ -81,4 +81,23 @@ export class Parser {
8181
return "";
8282
}
8383
}
84+
85+
insertNewlineIntoDescription(description: string): string{
86+
let result = description;
87+
let offset = 0;
88+
for(let i = 0; i < description.length-1; i++){
89+
if(description[i] == '#' && description[i+1] == '#'){
90+
let temp = result.slice(0,i+offset);
91+
result = temp +"\n"+result.slice(i+offset);
92+
offset++;
93+
}
94+
if(description[i] == '*'){
95+
let temp = result.slice(0,i+offset);
96+
result = temp +"\n"+result.slice(i+offset);
97+
offset++;
98+
}
99+
100+
}
101+
return result;
102+
}
84103
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<%= description; %>
1+
22

33
<% if(tutorialPath){ %>
44
The definition of each step of this tutorial can be found at https://github.com/devonfw-tutorials/tutorials/tree/main/<%= tutorialPath; %>. <% } %>
55

66
Feel free to report any errors to us or fix them yourself. Errors can be reported by creating an issue in the https://github.com/devonfw-tutorials/tutorials/issues[tutorials repository]. To fix the error fork the repository and create a pull request. Errors in the wiki can be reported and fixed in the https://github.com/devonfw-tutorials/tutorial-compiler[Tutorial-compiler repository].
77
You can find a description of what to look for when creating a pull request at the devonfw contribution guide: https://devonfw.com/website/pages/community/community.html#community.asciidoc_contributing-to-devonfw. If you want to create a tutorial you can start with the https://katacoda.com/devonfw/scenarios/create-your-own-tutorial[katacoda tutorial] and read the description for creating your own tutorials: https://github.com/devonfw-tutorials/tutorials/wiki/Development.
88

9+
<%= description; %>

runners/wikiConsole/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RunCommand } from "../../engine/run_command";
33
import { RunResult } from "../../engine/run_result";
44
import { WikiRunner } from "../../engine/wikiRunner";
55
import * as path from "path";
6-
import * as fs from "fs";
6+
import * as fs from "fs-extra";
77

88

99
export class WikiConsole extends WikiRunner {
@@ -181,27 +181,34 @@ export class WikiConsole extends WikiRunner {
181181
runDisplayContent(runCommand: RunCommand): RunResult {
182182
let text = this.checkForText(runCommand);
183183
let textAfter = this.checkForTextAfter(runCommand);
184-
this.checkForText(runCommand);
185-
this.checkForTextAfter(runCommand);
184+
let stepTitle = this.checkForTitle(runCommand);
186185
let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md");
187186
fs.writeFileSync(tempFile, "");
187+
let counter = 2;
188188
for(let i = 0; i < runCommand.command.parameters[1].length; i++) {
189189
let param = runCommand.command.parameters[1][i];
190190
if(param.content) {
191191
fs.appendFileSync(tempFile, param.content);
192192
} else if(param.file) {
193193
fs.appendFileSync(tempFile, fs.readFileSync(path.join(this.playbookPath, param.file), "utf-8"));
194194
} else if (param.image) {
195-
let image = path.join(this.playbookPath, param.image);
196-
fs.appendFileSync(tempFile, "![" + path.basename(image) + "](./assets/" + path.basename(image) + ")");
195+
this.createFolder(path.join(this.outputPathTutorial, "images"), false);
196+
let imageName = path.join(this.outputPathTutorial, "images",path.basename(param.image));
197+
while(fs.existsSync(imageName)){
198+
imageName = path.join(this.outputPathTutorial, "images",path.parse(param.image).name+"_"+counter+path.parse(param.image).ext);
199+
counter++;
200+
}
201+
fs.copyFileSync(path.join(this.playbookPath, param.image),imageName);
202+
fs.appendFileSync(tempFile, "image::images/"+path.basename(imageName)+"[]");
197203
}
198204
fs.appendFileSync(tempFile, "\n\n");
199205
}
200206

201207
let content = fs.readFileSync(tempFile, "utf-8");
202-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"),
203-
{ title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2], text: text, textAfter: textAfter});
204208

209+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"),
210+
{ steptitle: stepTitle, text: text, textAfter: textAfter, title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]});
211+
205212
return null;
206213
}
207214

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
== <%= title; %>
2-
<%if(text){%><%- text; %><%}%>
1+
<% if(steptitle){ %>== <%= steptitle;%>
2+
=== <%= title; %>
3+
<%if(text){%><%- text; %> <%}%>
4+
<%}else if(steptitle === undefined){%>=== <%= title; %>
5+
<%if(text){%><%- text; %> <%}%>
6+
<%}else if(steptitle === null){ %>== <%= title; %>
7+
<%if(text){%><%- text; %><%}%> <%}%>
38

49
<%= content; %>
510

@@ -8,3 +13,4 @@ After that, move to the target directory by executing `cd <%= path; %>` in the
813
<% } %>
914

1015
<%if(textAfter){%><%- textAfter; %><%}%>
16+

runners/wikiConsole/templates/npmInstall.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can install the package <%= npmCommand.name; %><% if(!npmCommand.global){ %>
2020
You need to be located in the project directory where the package.json file lies.
2121
For this tutorial it is `<%= projectPath; %>`. You can either move there manually and open the terminal there or open the terminal and move there by executing `cd <%= projectPath; %>`.<% } %>
2222

23-
Now execute `npm install<% if(npmCommand.global){ %> -g<% } %> <%= npmCommand.args; %> <%= npmCommand.name; %>` in the terminal.
23+
Now execute `npm install<% if(npmCommand.global){ %> -g<% } %><% if(npmCommand.args){%> <%= npmCommand.args; %><% } %><%if(npmCommand.name){ %> <%= npmCommand.name; %><%}%>` in the terminal.
2424

2525
<% if(npmCommand.global){ %>Due to the argument '-g' the package will be installed globally.<% } %>
2626
This may take some time.

0 commit comments

Comments
 (0)