From dbd20bf21db76c17ed37bbededab12af058cdd7f Mon Sep 17 00:00:00 2001 From: EduardKrieger Date: Sat, 10 Jul 2021 12:37:04 +0200 Subject: [PATCH 1/2] added picture display for wiki asciidocs --- documentation/Functions.md | 4 ++-- engine/parser.ts | 23 +++++++++++++++++-- runners/katacoda/templates/intro.md | 3 ++- runners/wikiConsole/index.ts | 18 +++++++++++---- .../templates/displayContent.asciidoc | 5 ++++ .../wikiConsole/templates/npmInstall.asciidoc | 2 +- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index f2aa1bd7..e8cd33a6 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") 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 b4d00d39..53b91523 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 { @@ -158,6 +158,7 @@ export class WikiConsole extends WikiRunner { runDisplayContent(runCommand: RunCommand): RunResult { 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) { @@ -165,15 +166,22 @@ 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",counter+"_"+path.basename(param.image)); + counter++; + } + fs.createFileSync(imageName); + fs.copyFileSync(path.join(this.playbookPath, param.image),imageName); + fs.appendFileSync(tempFile, "image::images/"+path.basename(imageName)+"[]"); + counter = 2; } 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]}); - + this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "nextKatacodaStep.asciidoc"), { steptitle: runCommand.stepTitle, text: runCommand.text, textAfter: runCommand.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 63f7f203..c915447a 100644 --- a/runners/wikiConsole/templates/displayContent.asciidoc +++ b/runners/wikiConsole/templates/displayContent.asciidoc @@ -1,7 +1,12 @@ == <%= title; %> +=== <%= steptitle; %> + +<%- text; %> <%= content; %> +<%- textAfter; %> + <% if(path) {%> After that, move to the target directory by executing `cd <%= path; %>` in the terminal. <% } %> \ No newline at end of file diff --git a/runners/wikiConsole/templates/npmInstall.asciidoc b/runners/wikiConsole/templates/npmInstall.asciidoc index 94ff21e7..e82f5b60 100644 --- a/runners/wikiConsole/templates/npmInstall.asciidoc +++ b/runners/wikiConsole/templates/npmInstall.asciidoc @@ -16,7 +16,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. \ No newline at end of file From 57640fba570e4c37e454302aaa278c2fc37e9e1d Mon Sep 17 00:00:00 2001 From: EduardKrieger Date: Mon, 12 Jul 2021 11:37:03 +0200 Subject: [PATCH 2/2] removed unnecessary code --- runners/wikiConsole/index.ts | 10 ++++------ runners/wikiConsole/templates/displayContent.asciidoc | 11 +++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/runners/wikiConsole/index.ts b/runners/wikiConsole/index.ts index 4045eb6f..9bd322ac 100644 --- a/runners/wikiConsole/index.ts +++ b/runners/wikiConsole/index.ts @@ -181,7 +181,7 @@ export class WikiConsole extends WikiRunner { runDisplayContent(runCommand: RunCommand): RunResult { let text = this.checkForText(runCommand); let textAfter = this.checkForTextAfter(runCommand); - let title = this.checkForTitle(runCommand); + let stepTitle = this.checkForTitle(runCommand); let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md"); fs.writeFileSync(tempFile, ""); let counter = 2; @@ -195,21 +195,19 @@ export class WikiConsole extends WikiRunner { 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",counter+"_"+path.basename(param.image)); + imageName = path.join(this.outputPathTutorial, "images",path.parse(param.image).name+"_"+counter+path.parse(param.image).ext); counter++; } - fs.createFileSync(imageName); fs.copyFileSync(path.join(this.playbookPath, param.image),imageName); fs.appendFileSync(tempFile, "image::images/"+path.basename(imageName)+"[]"); - counter = 2; } fs.appendFileSync(tempFile, "\n\n"); } let content = fs.readFileSync(tempFile, "utf-8"); - this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "nextKatacodaStep.asciidoc"), - { steptitle: runCommand.stepTitle, text: runCommand.text, textAfter: runCommand.textAfter, title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]}); + 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 de536113..f077aefb 100644 --- a/runners/wikiConsole/templates/displayContent.asciidoc +++ b/runners/wikiConsole/templates/displayContent.asciidoc @@ -1,7 +1,9 @@ -<% if(steptitle){ %> == <%= steptitle;%> +<% if(steptitle){ %>== <%= steptitle;%> === <%= title; %> -<%if(text){%><%- text; %><%}%> -<%}else{%> == <%= title; %> +<%if(text){%><%- text; %> <%}%> +<%}else if(steptitle === undefined){%>=== <%= title; %> +<%if(text){%><%- text; %> <%}%> +<%}else if(steptitle === null){ %>== <%= title; %> <%if(text){%><%- text; %><%}%> <%}%> <%= content; %> @@ -10,4 +12,5 @@ After that, move to the target directory by executing `cd <%= path; %>` in the terminal. <% } %> -<%if(textAfter){%><%- textAfter; %><%}%> \ No newline at end of file +<%if(textAfter){%><%- textAfter; %><%}%> +