diff --git a/documentation/Functions.md b/documentation/Functions.md index 034ddc69..d2c00d1e 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -186,7 +186,7 @@ createDevon4jProject("com.mycustomer.myapplication") ### buildJava #### parameter -1. The project directory +1. The project directory, relative to workspace. 2. (Optional) Indicator whether tests should be run. Default is false. #### example buildJava("cobigenexample", true) @@ -323,7 +323,7 @@ downloadFile("https://bit.ly/2BCkFa9", "file", "downloads") ### buildNg #### parameter -1. Path to the angular project relative to workspace +1. Path to the angular project, relative to workspace 2. (Optional) Custom output directory. #### example buildNg("exampleAngularProject") @@ -364,6 +364,7 @@ Available attributes in the json objects: 2. content: Plain text to be displayed in the Katacoda step. This Text should be following the formating of asciidoc files. 3. image: Path to an image to be displayed in the Katacoda step. + #### Formatting rules for content and .asciidoc or .txt files. * 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. * A list always needs an empty newline between the last row and the list. diff --git a/engine/parser.ts b/engine/parser.ts index 5d605004..28104278 100644 --- a/engine/parser.ts +++ b/engine/parser.ts @@ -20,8 +20,8 @@ export class Parser { let result = new Playbook(); result.title = parseResult[0][2]; result.subtitle = parseResult[1]? parseResult[1][3]: ""; - result.description = parseResult[2][2].descriptionlines; - result.conclusion = parseResult[4]? parseResult[4][2].conclusionlines: ""; + result.description = this.insertNewlineIntoDescription(parseResult[2][2].descriptionlines); + result.conclusion = this.insertNewlineIntoDescription(parseResult[4]? parseResult[4][2].conclusionlines: ""); for(let index in parseResult[3]){ let step = new Step(); step.text = this.getText(parseResult, index); @@ -81,4 +81,23 @@ export class Parser { return ""; } } + + insertNewlineIntoDescription(description: string): string{ + let result = description; + let offset = 0; + for(let i = 0; i < description.length-1; i++){ + if(description[i] == '#' && description[i+1] == '#'){ + let temp = result.slice(0,i+offset); + result = temp +"\n"+result.slice(i+offset); + offset++; + } + if(description[i] == '*'){ + let temp = result.slice(0,i+offset); + result = temp +"\n"+result.slice(i+offset); + offset++; + } + + } + return result; + } } diff --git a/runners/katacoda/templates/intro.md b/runners/katacoda/templates/intro.md index d569c689..e38545e7 100644 --- a/runners/katacoda/templates/intro.md +++ b/runners/katacoda/templates/intro.md @@ -1,4 +1,4 @@ -<%= description; %> + <% if(tutorialPath){ %> The definition of each step of this tutorial can be found at https://github.com/devonfw-tutorials/tutorials/tree/main/<%= tutorialPath; %>. <% } %> @@ -6,3 +6,4 @@ The definition of each step of this tutorial can be found at https://github.com/ 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]. 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. +<%= description; %> \ No newline at end of file diff --git a/runners/wikiConsole/index.ts b/runners/wikiConsole/index.ts index 5852771b..9bd322ac 100644 --- a/runners/wikiConsole/index.ts +++ b/runners/wikiConsole/index.ts @@ -3,7 +3,7 @@ import { RunCommand } from "../../engine/run_command"; import { RunResult } from "../../engine/run_result"; import { WikiRunner } from "../../engine/wikiRunner"; import * as path from "path"; -import * as fs from "fs"; +import * as fs from "fs-extra"; export class WikiConsole extends WikiRunner { @@ -181,10 +181,10 @@ export class WikiConsole extends WikiRunner { runDisplayContent(runCommand: RunCommand): RunResult { let text = this.checkForText(runCommand); let textAfter = this.checkForTextAfter(runCommand); - this.checkForText(runCommand); - this.checkForTextAfter(runCommand); + let stepTitle = this.checkForTitle(runCommand); let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md"); fs.writeFileSync(tempFile, ""); + let counter = 2; for(let i = 0; i < runCommand.command.parameters[1].length; i++) { let param = runCommand.command.parameters[1][i]; if(param.content) { @@ -192,16 +192,23 @@ export class WikiConsole extends WikiRunner { } else if(param.file) { fs.appendFileSync(tempFile, fs.readFileSync(path.join(this.playbookPath, param.file), "utf-8")); } else if (param.image) { - let image = path.join(this.playbookPath, param.image); - fs.appendFileSync(tempFile, "![" + path.basename(image) + "](./assets/" + path.basename(image) + ")"); + this.createFolder(path.join(this.outputPathTutorial, "images"), false); + let imageName = path.join(this.outputPathTutorial, "images",path.basename(param.image)); + while(fs.existsSync(imageName)){ + imageName = path.join(this.outputPathTutorial, "images",path.parse(param.image).name+"_"+counter+path.parse(param.image).ext); + counter++; + } + fs.copyFileSync(path.join(this.playbookPath, param.image),imageName); + fs.appendFileSync(tempFile, "image::images/"+path.basename(imageName)+"[]"); } fs.appendFileSync(tempFile, "\n\n"); } let content = fs.readFileSync(tempFile, "utf-8"); - this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"), - { title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2], text: text, textAfter: textAfter}); + this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"), + { steptitle: stepTitle, text: text, textAfter: textAfter, title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]}); + return null; } diff --git a/runners/wikiConsole/templates/displayContent.asciidoc b/runners/wikiConsole/templates/displayContent.asciidoc index 97676c12..f077aefb 100644 --- a/runners/wikiConsole/templates/displayContent.asciidoc +++ b/runners/wikiConsole/templates/displayContent.asciidoc @@ -1,5 +1,10 @@ -== <%= title; %> -<%if(text){%><%- text; %><%}%> +<% if(steptitle){ %>== <%= steptitle;%> +=== <%= title; %> +<%if(text){%><%- text; %> <%}%> +<%}else if(steptitle === undefined){%>=== <%= title; %> +<%if(text){%><%- text; %> <%}%> +<%}else if(steptitle === null){ %>== <%= title; %> +<%if(text){%><%- text; %><%}%> <%}%> <%= content; %> @@ -8,3 +13,4 @@ After that, move to the target directory by executing `cd <%= path; %>` in the <% } %> <%if(textAfter){%><%- textAfter; %><%}%> + diff --git a/runners/wikiConsole/templates/npmInstall.asciidoc b/runners/wikiConsole/templates/npmInstall.asciidoc index df4e9e2c..19a3b958 100644 --- a/runners/wikiConsole/templates/npmInstall.asciidoc +++ b/runners/wikiConsole/templates/npmInstall.asciidoc @@ -20,7 +20,7 @@ You can install the package <%= npmCommand.name; %><% if(!npmCommand.global){ %> You need to be located in the project directory where the package.json file lies. 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; %>`.<% } %> -Now execute `npm install<% if(npmCommand.global){ %> -g<% } %> <%= npmCommand.args; %> <%= npmCommand.name; %>` in the terminal. +Now execute `npm install<% if(npmCommand.global){ %> -g<% } %><% if(npmCommand.args){%> <%= npmCommand.args; %><% } %><%if(npmCommand.name){ %> <%= npmCommand.name; %><%}%>` in the terminal. <% if(npmCommand.global){ %>Due to the argument '-g' the package will be installed globally.<% } %> This may take some time.