Skip to content

Commit a8f5ab0

Browse files
committed
added titles, text and textAfter from steps to templates
1 parent fc57bd7 commit a8f5ab0

30 files changed

Lines changed: 383 additions & 144 deletions

engine/wikiRunner.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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";
@@ -11,6 +12,7 @@ export abstract class WikiRunner extends Runner {
1112
[".js", "javascript"], [".html", "html"],
1213
[".scss", "css"], [".asciidoc", "asciidoc"], ]);
1314
protected readonly INSTALLED_TOOLS: string = "installedTools";
15+
public CommandCntMap = new Map();
1416

1517

1618
init(playbook: Playbook): void {
@@ -31,4 +33,22 @@ export abstract class WikiRunner extends Runner {
3133
fs.writeFileSync(tempFile, result, { flag: "a" });
3234
}
3335

36+
protected checkForText(runCommand: RunCommand): string{
37+
return runCommand.lineIndex == 0
38+
? runCommand.text
39+
: undefined;
40+
}
41+
42+
protected checkForTitle(runCommand: RunCommand): string{
43+
return runCommand.lineIndex == 0
44+
? runCommand.stepTitle
45+
: undefined;
46+
}
47+
48+
protected checkForTextAfter(runCommand: RunCommand): string{
49+
return this.CommandCntMap.get(runCommand.stepIndex) == runCommand.lineIndex
50+
? runCommand.textAfter
51+
: undefined;
52+
}
53+
3454
}

runners/wikiConsole/index.ts

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import * as fs from "fs";
88

99
export class WikiConsole extends WikiRunner {
1010

11-
1211

1312
init(playbook: Playbook): void {
1413
super.init(playbook);
1514
this.setVariable(this.WORKSPACE_DIRECTORY, path.join(this.getWorkingDirectory()));
16-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "intro.asciidoc"), {name: playbook.name, title: playbook.title, subtitle: playbook.subtitle, description: playbook.description});
15+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "intro.asciidoc"),
16+
{name: playbook.name, title: playbook.title, subtitle: playbook.subtitle, description: playbook.description});
17+
18+
for(let i = 0; i< playbook.steps.length; i++){
19+
this.CommandCntMap.set(i, playbook.steps[i].lines.length-1);
20+
}
1721
}
1822

1923
async destroy(playbook: Playbook): Promise<void> {
@@ -24,12 +28,16 @@ export class WikiConsole extends WikiRunner {
2428
}
2529

2630
runInstallDevonfwIde(runCommand: RunCommand): RunResult {
31+
let text = this.checkForText(runCommand);
32+
let title = this.checkForTitle(runCommand);
33+
let textAfter = this.checkForTextAfter(runCommand);
2734
let tools = runCommand.command.parameters[0].join(" ");
2835
let version = "";
2936
if(runCommand.command.parameters.length == 2) {
3037
version = runCommand.command.parameters[1];
3138
}
32-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installDevonfwIde.asciidoc"), { tools: tools, version:version })
39+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installDevonfwIde.asciidoc"),
40+
{ tools: tools, version:version, title: title, text: text, textAfter: textAfter })
3341
this.setVariable(this.WORKSPACE_DIRECTORY, path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"));
3442
this.setVariable(this.INSTALLED_TOOLS, tools);
3543
return null;
@@ -39,123 +47,146 @@ export class WikiConsole extends WikiRunner {
3947
return this.runInstallDevonfwIde(runCommand);
4048
}
4149

42-
43-
runChangeFile(runCommand: RunCommand): RunResult{
44-
let workspacePath = this.getVariable(this.WORKSPACE_DIRECTORY).replace(/\\/g, "/");
45-
let filePath = path.join(workspacePath,runCommand.command.parameters[0]);
46-
let fileName = path.basename(runCommand.command.parameters[0]);
47-
let contentPath, contentString;
48-
if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].contentConsole){
49-
contentPath = runCommand.command.parameters[1].fileConsole;
50-
contentString = runCommand.command.parameters[1].contentConsole;
51-
}else{
52-
contentPath = runCommand.command.parameters[1].file;
53-
contentString = runCommand.command.parameters[1].content;
54-
}
55-
contentPath = contentPath
56-
? path.join(this.getPlaybookPath(), contentPath)
57-
: undefined;
58-
let contentFile = contentPath
59-
? path.basename(contentPath)
60-
: undefined;
61-
let placeholder = runCommand.command.parameters[1].placeholder;
62-
let lineNumber = runCommand.command.parameters[1].lineNumber;
63-
64-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath,
65-
contentPath: contentPath, contentString: contentString, placeholder: placeholder, lineNumber: lineNumber, fileName: fileName, contentFile: contentFile});
66-
return null;
67-
}
68-
6950
runRunServerJava(runCommand: RunCommand): RunResult {
51+
let text = this.checkForText(runCommand);
52+
let title = this.checkForTitle(runCommand);
53+
let textAfter = this.checkForTextAfter(runCommand);
7054
let server_path = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
71-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "runServerJava.asciidoc"), { server_path: server_path, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path })
55+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "runServerJava.asciidoc"),
56+
{ server_path: server_path, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path, text: text, textAfter: textAfter, title: title })
7257
return null;
7358
}
7459

7560
runNpmInstall(runCommand: RunCommand): RunResult {
61+
let text = this.checkForText(runCommand);
62+
let title = this.checkForTitle(runCommand);
63+
let textAfter = this.checkForTextAfter(runCommand);
7664
let projectPath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
7765
let npmCommand = {
7866
"name": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].name) ? runCommand.command.parameters[1].name : undefined,
7967
"global": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].global) ? runCommand.command.parameters[1].global : false,
8068
"args": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].args) ? runCommand.command.parameters[1].args.join(" ") : undefined
8169
};
8270

83-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "npmInstall.asciidoc"), { projectPath: projectPath, npmCommand: npmCommand });
71+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "npmInstall.asciidoc"),
72+
{ projectPath: projectPath, npmCommand: npmCommand, text: text, textAfter: textAfter, title: title });
8473
return null;
8574
}
8675

8776
runCloneRepository(runCommand: RunCommand): RunResult {
77+
let text = this.checkForText(runCommand);
78+
let title = this.checkForTitle(runCommand);
79+
let textAfter = this.checkForTextAfter(runCommand);
8880
let directoryPath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
89-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "cloneRepository.asciidoc"), { directoryPath: directoryPath, url: runCommand.command.parameters[1] });
81+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "cloneRepository.asciidoc"),
82+
{ directoryPath: directoryPath, url: runCommand.command.parameters[1], text: text, title: title, textAfter: textAfter });
9083
return null;
9184
}
9285

9386

9487
runDownloadFile(runCommand: RunCommand): RunResult{
88+
let text = this.checkForText(runCommand);
89+
let title = this.checkForTitle(runCommand);
90+
let textAfter = this.checkForTextAfter(runCommand);
9591
let url = runCommand.command.parameters[0];
9692
let fileName = runCommand.command.parameters[1];
9793
let dir = runCommand.command.parameters[2];
98-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "downloadFile.asciidoc"), {url: url, dir: dir, fileName: fileName});
94+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "downloadFile.asciidoc"),
95+
{url: url, dir: dir, fileName: fileName, title: title, textAfter: textAfter, text: text});
9996

10097
return null;
10198
}
10299

103100
runBuildNg(runCommand: RunCommand): RunResult {
101+
let text = this.checkForText(runCommand);
102+
let title = this.checkForTitle(runCommand);
103+
let textAfter = this.checkForTextAfter(runCommand);
104104
let angularPath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
105105
let outputPath = runCommand.command.parameters.length < 1 ? runCommand.command.parameters[1] : "";
106-
this.renderWiki(path.join(this.getRunnerDirectory(), "template", "buildNg.asciidoc"), {angularPath: angularPath, outputPath: outputPath});
106+
this.renderWiki(path.join(this.getRunnerDirectory(), "template", "buildNg.asciidoc"),
107+
{angularPath: angularPath, outputPath: outputPath, title: title, text: text, textAfter: textAfter});
107108

108109
return null;
109110
}
110111

111112

112113
runDockerCompose(runCommand: RunCommand): RunResult {
114+
let text = this.checkForText(runCommand);
115+
let title = this.checkForTitle(runCommand);
116+
let textAfter = this.checkForTextAfter(runCommand);
113117
let dir = runCommand.command.parameters[0];
114-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "dockerCompose.asciidoc"), { dir: dir, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path })
118+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "dockerCompose.asciidoc"),
119+
{ dir: dir, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path, text: text, textAfter: textAfter, title: title })
115120
return null;
116121
}
117122

118123
runCreateFolder(runCommand: RunCommand): RunResult {
124+
let text = this.checkForText(runCommand);
125+
let title = this.checkForTitle(runCommand);
126+
let textAfter = this.checkForTextAfter(runCommand);
119127
let folderPath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
120-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFolder.asciidoc"), { folderPath: folderPath });
128+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFolder.asciidoc"),
129+
{ folderPath: folderPath, text: text, textAfter: textAfter, title: title });
121130
return null;
122131
}
123132

124133
runBuildJava(runCommand: RunCommand): RunResult {
134+
let text = this.checkForText(runCommand);
135+
let title = this.checkForTitle(runCommand);
136+
let textAfter = this.checkForTextAfter(runCommand);
125137
let directoryPath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
126138
let skipTest = (runCommand.command.parameters.length == 2 && runCommand.command.parameters[1] == true) ? false : true;
127-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "buildJava.asciidoc"), { directoryPath: directoryPath, skipTest: skipTest });
139+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "buildJava.asciidoc"),
140+
{ directoryPath: directoryPath, skipTest: skipTest, text: text, textAfter: textAfter, title: title });
128141
return null;
129142
}
130143

131144
runInstallCobiGen(runCommand: RunCommand): RunResult{
145+
let text = this.checkForText(runCommand);
146+
let title = this.checkForTitle(runCommand);
147+
let textAfter = this.checkForTextAfter(runCommand);
132148
let devonPath = path.relative(this.getWorkingDirectory(), this.getVariable(this.WORKSPACE_DIRECTORY)).replace(/\\/g, "/");;
133-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installCobiGen.asciidoc"), {devonPath: devonPath});
149+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installCobiGen.asciidoc"),
150+
{devonPath: devonPath, text: text, textAfter: textAfter, title: title});
134151
return null;
135152
}
136153

137154
runCreateDevon4jProject(runCommand: RunCommand): RunResult {
138-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createDevon4jProject.asciidoc"), { name: runCommand.command.parameters[0] });
155+
let text = this.checkForText(runCommand);
156+
let title = this.checkForTitle(runCommand);
157+
let textAfter = this.checkForTextAfter(runCommand);
158+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createDevon4jProject.asciidoc"),
159+
{ name: runCommand.command.parameters[0], text: text, textAfter: textAfter, title: title });
139160
return null;
140161
}
141162

142163
runAddSetupScript(runCommand: RunCommand): RunResult{
164+
let text = this.checkForText(runCommand);
165+
let title = this.checkForTitle(runCommand);
166+
let textAfter = this.checkForTextAfter(runCommand);
143167
let scriptNameLinux = path.basename(runCommand.command.parameters[0]);
144168
let scriptNameWindows = path.basename(runCommand.command.parameters[1]);
145169
let windowsContent = fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1]), { encoding: "utf-8" });
146170
let linuxContent = fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[0]), { encoding: "utf-8" });
147171
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "addSetupScript.asciidoc"), {scriptNameWindows: scriptNameWindows, windowsContent: windowsContent,
148-
scriptNameLinux: scriptNameLinux, linuxContent: linuxContent});
172+
scriptNameLinux: scriptNameLinux, linuxContent: linuxContent, text: text, textAfter: textAfter, title: title});
149173
return null;
150174
}
151175

152-
runAdaptTemplatesCobiGen(runComannd: RunCommand): RunResult{
176+
runAdaptTemplatesCobiGen(runCommand: RunCommand): RunResult{
177+
let title = this.checkForTitle(runCommand);
178+
let text = this.checkForText(runCommand);
179+
let textAfter = this.checkForTextAfter(runCommand);
153180
let devonPath = path.relative(this.getWorkingDirectory(), this.getVariable(this.WORKSPACE_DIRECTORY)).replace(/\\/g, "/");
154-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "adaptTemplates.asciidoc"), {devonPath: devonPath});
181+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "adaptTemplates.asciidoc"), {devonPath: devonPath, text: text, textAfter: textAfter, title: title});
155182
return null;
156183
}
157184

158185
runDisplayContent(runCommand: RunCommand): RunResult {
186+
let text = this.checkForText(runCommand);
187+
let textAfter = this.checkForTextAfter(runCommand);
188+
this.checkForText(runCommand);
189+
this.checkForTextAfter(runCommand);
159190
let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md");
160191
fs.writeFileSync(tempFile, "");
161192
for(let i = 0; i < runCommand.command.parameters[1].length; i++) {
@@ -172,9 +203,11 @@ export class WikiConsole extends WikiRunner {
172203
}
173204

174205
let content = fs.readFileSync(tempFile, "utf-8");
175-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"), { title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]});
206+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"),
207+
{ title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2], text: text, textAfter: textAfter});
176208

177209
return null;
178210
}
211+
179212
}
180213

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
== Generate CobiGen Templates
1+
<%if(title){%>== <%- title; %>
2+
<%if(text){%><%- text; %><%}%><%}else{%>
3+
4+
=== Generate CobiGen Templates
5+
<%if(text){%><%- text; %><%}%>
6+
27
How to use CobiGen, to generate templates for the following code generation.
38
More information about CobiGen on https://devonfw.com/website/pages/docs/master-cobigen.asciidoc.html.
49

5-
=== Prerequisites
10+
11+
==== Prerequisites
612

713
* An installed devonfw distribution is needed. To execute the CobiGen CLI, you have to install the devonfw IDE first. Follow the https://devonfw.com/website/pages/docs/devonfw-ide-introduction.asciidoc.html[devonfw IDE] documentation to install the same.
814

9-
=== Generate CobiGen Templates with CobiGen CLI
15+
==== Generate CobiGen Templates with CobiGen CLI
1016

1117
First open a command prompt in your current workspace. You should be inside your devonfw directory, if not change your directory to *<%= devonPath;%>*.
1218
Run the CobiGen command `devon cobigen adapt-templates`
1319
to generate a new templates folder next to the CobiGen CLI and save its location in a configuration file.
1420

1521
You can also spezify the location of the templates folder with the parameter `--custom-location` or `-cl` and pass the absolute path to your custom location.
1622

17-
18-
23+
<%if(textAfter){%><%- textAfter; %><%}%>
1924

runners/wikiConsole/templates/addSetupScript.asciidoc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
== Run a Setupscript
2-
Run a Script to setup the enviroment for the Tutorial.
1+
<%if(title){%>== <%- title; %>
2+
<%if(text){%><%- text; %><%}%><%}else{%>
3+
4+
=== Run a Setupscript
5+
<%if(text){%><%- text; %><%}%><%}%>
36

7+
Run a Script to setup the enviroment for the Tutorial.
48

5-
=== Prerequisites
9+
==== Prerequisites
610
* Any Editor that can edit files.
711

8-
=== Create the Setupscript
12+
==== Create the Setupscript
913
Open a editor and create a new file by going to the file context menu in the top left corner of the editor and select *New* or *New File* or mostly also the keyboard shortcut ctrl+n will also work.
1014

1115
.Operating system
@@ -29,11 +33,13 @@ The editor opens a new editor window for an untitled file where you can insert t
2933
Save the file by selecting *Save* or *Save as* in the file context menu or by using the keyboard shortcut ctrl+s.
3034
A file explorer window opens where you should set the filename to *<%= scriptNameLinux; %>* and save it to your current directory.
3135

32-
=== Run the Setupscript
36+
==== Run the Setupscript
3337

3438
.Operating system
3539
. Windows +
3640
Open the PowerShell in your current workspace and execute the command `./<%= scriptNameWindows; %>` to run the script.
3741
. Linux and macOS +
3842
Open the Terminal in your current workspace and execute the command `bash <%= scriptNameWindows; %>` to run the script.
3943

44+
<%if(textAfter){%><%- textAfter; %><%}%>
45+
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
== Build the Java Project with Maven
1+
<%if(title){%>== <%- title; %>
2+
<%if(text){%><%- text; %><%}%><%}else{%>
23

3-
=== Prerequisites
4+
=== Build the Java Project with Maven
5+
<%if(text){%><%- text; %><%}%><%}%>
6+
7+
==== Prerequisites
48

59
* You need to have Maven installed. If not already installed, you can download it https://maven.apache.org/download.cgi[here]. Alternativly, you can make use of the devonfw-ide, where you can install Maven directly to your workspace. For more details on how to do that, see the https://devonfw.com/website/pages/docs/devonfw-ide-introduction.asciidoc.html#setup.asciidoc[devonfw-ide setup].
610

7-
=== Execution
11+
==== Execution
812

913
Now move to your project directory manually or by executing `cd <%= directoryPath; %>` in the terminal.
1014
Next, use the following command to build the java project.
@@ -15,4 +19,7 @@ The maven command 'clean' will clear the target directory beforehand. So your bu
1519
Install will then compile, test and package your Java project and copy your built .jar/.war file into your local Maven repository.
1620
<% if(skipTest){ %>
1721
We do not need to execute the test cases, so we can skip them by using the option '-Dmaven.test.skip=true'.
18-
<% } %>
22+
<% } %>
23+
24+
<%if(textAfter){%><%- textAfter; %><%}%>
25+

0 commit comments

Comments
 (0)