Skip to content

Commit cc2d022

Browse files
authored
Merge pull request #257 from EduardKrieger/bugfix/wikiRunnerChangeFile
bugfix/wikiRunnerChangeFile
2 parents bf1526a + 547dd26 commit cc2d022

11 files changed

Lines changed: 95 additions & 157 deletions

File tree

engine/runner.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { RunResult } from "./run_result";
22
import { Playbook } from "./playbook";
3-
import * as fs from 'fs';
4-
import * as rimraf from 'rimraf';
3+
import * as fs from 'fs-extra';
54
import { RunCommand } from "./run_command";
65

76
export abstract class Runner {
@@ -104,7 +103,7 @@ export abstract class Runner {
104103
if(fs.existsSync(path)) {
105104
if(deleteFolderIfExist) {
106105
try {
107-
rimraf.sync(path);
106+
fs.removeSync(path);
108107
} catch(e) {
109108
console.log("Error deleting foler " + path, e);
110109
}

engine/wikiRunner.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import * as ejs from "ejs";
77
export abstract class WikiRunner extends Runner {
88

99
public outputPathTutorial: string;
10+
protected fileTypeMap = new Map([ [".java", "java"],[".ts", "typescript"],
11+
[".js", "javascript"], [".html", "html"],
12+
[".scss", "css"], [".asciidoc", "asciidoc"], ]);
1013
protected readonly INSTALLED_TOOLS: string = "installedTools";
1114

1215
init(playbook: Playbook): void {

runners/katacoda/templates/intro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ The definition of each step of this tutorial can be found at https://github.com/
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.
8+

runners/wikiConsole/index.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,6 @@ export class WikiConsole extends WikiRunner {
3737
return this.runInstallDevonfwIde(runCommand);
3838
}
3939

40-
runChangeFile(runCommand: RunCommand): RunResult{
41-
let workspacePath = this.getVariable(this.WORKSPACE_DIRECTORY).replace(/\\/g, "/");
42-
let filePath = path.join(workspacePath,runCommand.command.parameters[0]);
43-
let fileName = path.basename(runCommand.command.parameters[0]);
44-
let contentPath, contentString;
45-
if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].contentConsole){
46-
contentPath = runCommand.command.parameters[1].fileConsole;
47-
contentString = runCommand.command.parameters[1].contentConsole;
48-
}else{
49-
contentPath = runCommand.command.parameters[1].file;
50-
contentString = runCommand.command.parameters[1].content;
51-
}
52-
contentPath = contentPath
53-
? path.join(this.getPlaybookPath(), contentPath)
54-
: undefined;
55-
let contentFile = contentPath
56-
? path.basename(contentPath)
57-
: undefined;
58-
let placeholder = runCommand.command.parameters[1].placeholder;
59-
let lineNumber = runCommand.command.parameters[1].lineNumber;
60-
61-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath,
62-
contentPath: contentPath, contentString: contentString, placeholder: placeholder, lineNumber: lineNumber, fileName: fileName, contentFile: contentFile});
63-
return null;
64-
}
65-
66-
6740
runRunServerJava(runCommand: RunCommand): RunResult {
6841
let server_path = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
6942
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 })

runners/wikiConsole/templates/changeFile.asciidoc

Lines changed: 0 additions & 24 deletions
This file was deleted.

runners/wikiEclipse/index.ts

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

78
export class WikiEclipse extends WikiRunner {
89

@@ -15,29 +16,23 @@ export class WikiEclipse extends WikiRunner {
1516
}
1617

1718
runChangeFile(runCommand: RunCommand): RunResult{
18-
let workspacePath = this.getVariable(this.WORKSPACE_DIRECTORY).replace(/\\/g, "/");
1919
let fileName = path.basename(runCommand.command.parameters[0]);
20-
let filePath = path.join(workspacePath,runCommand.command.parameters[0].replace(fileName, ""));
21-
let contentPath, contentFile, contentString;
22-
if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].contentConsole){
23-
contentPath = runCommand.command.parameters[1].fileConsole;
24-
contentString = runCommand.command.parameters[1].contentConsole;
25-
}else{
26-
contentPath = runCommand.command.parameters[1].file;
27-
contentString = runCommand.command.parameters[1].content;
20+
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
21+
filePath = path.relative(this.getWorkingDirectory(), filePath).replace(/\\/g, "/");
22+
let fileType = this.fileTypeMap.get(fileName.substr(fileName.indexOf(".")));
23+
let content = undefined;
24+
if(runCommand.command.parameters[1].content || runCommand.command.parameters[1].contentConsole){
25+
content = runCommand.command.parameters[1].content
26+
? runCommand.command.parameters[1].content
27+
: runCommand.command.parameters[1].contentConsole;
28+
}else if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].file){
29+
content = runCommand.command.parameters[1].file
30+
? fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1].file), { encoding: "utf-8" })
31+
: fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1].fileConsole), { encoding: "utf-8" });
2832
}
29-
contentFile = contentPath
30-
? path.basename(contentPath)
31-
: undefined;
32-
contentPath = contentPath
33-
? path.join(this.getPlaybookPath(), contentPath.replace(contentFile, ""))
34-
: undefined;
3533
let placeholder = runCommand.command.parameters[1].placeholder;
3634
let lineNumber = runCommand.command.parameters[1].lineNumber;
37-
38-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath,
39-
contentPath: contentPath, contentString: contentString, placeholder: placeholder, lineNumber: lineNumber,
40-
contentFile: contentFile, fileName: fileName});
35+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath ,fileName: fileName, content : content, fileType: fileType, lineNumber: lineNumber, placeholder: placeholder });
4136
return null;
4237
}
4338

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
== Changing of the <%= fileName; %> File
22

3+
=== Prerequisites
4+
* Eclipse IDE (can be installed in your devonfw environment).
5+
36
=== Changing of <%= fileName; %> in the Eclipse IDE
47

5-
<% if(contentPath) {%>
6-
First, you want to open the file <%= contentFile; %> where you get the content from, you want to insert into <%= fileName; %>.
7-
Go to the file context menu in the top left corner right and choose *Open File...*.
8-
Based on your operating system a window with the file explorer opens. You have to navigate to <%= contentFile; %> and select it. Select the right folder manually or by inserting the path `<%= contentPath; %>` into the path bar, so you can jump into the right folder and select the file `<%= contentFile; %>`.
9-
You confirm this with the *Open* button in the bottom right corner.
10-
The file will be opened in a new Eclipse editor window where you can select the whole text with the keyboard shortcut ctrl+a or just select the text you want to copy and copy the text with ctrl+c.<% } %>
118

129
To change the <%= fileName; %> file, you have to open it in the Eclipse IDE.
1310
Open Eclipse and choose in the file context menu in the top left corner *Open File...*.
14-
Based on your operating system a window with the file explorer opens. You have to navigate to <%= fileName; %> and select it. Select the right folder manually or by inserting the path `<%= filePath; %>` into the path bar, so you can jump into the right folder and select the file `<%= fileName; %>`.
15-
You confirm this with the *Open* button in the bottom right corner.
16-
The file will be opened in a new Eclipse editor window.
11+
Based on your operating system a window with the file explorer opens. You have to navigate to <%= fileName; %> and select it. Choose the right folder manually by selecting the folders from the path `<%= filePath; %>` and select the file `<%= fileName; %>`.
12+
You confirm this with the *Open* button in the bottom right corner and <%= fileName; %> will be opened in a new Eclipse editor window.
13+
14+
Copy the following text.
15+
[source, <%= fileType; %>]
16+
----
17+
<%- content; %>
18+
----
1719

18-
<% if(contentString) { %>Now we can copy the content *<%= contentString; %>* with ctrl+c we want to insert into <%= fileName; %>. <% } %>
19-
<% if(lineNumber) { %>Inserting the content into a specific line number can be done by a left mouse click into the line *<%= lineNumber%>* and using the keyboard shortcut ctrl+v.
20-
<%}else if(placeholder) {%>To replace the content with a specific Placeholder you have to locate the placeholder in <%= fileName %>. The fastest way is to search through the file with ctrl+f. A *Find/Replace* window will be opened and pasting the placeholder *<%= placeholder; %>* into the text field *find*. Use the button *Find* and the placeholder will be marked in the text and you can replace him with the new content.
21-
<% }else{ %>Now you can select the place you want to insert the content or just append it at the end of the file and paste the content with the shortcut ctrl+v. <% } %>
2220

23-
The final step is to save the file by selecting *Save* in the file context menu or by using the keyboard shortcut ctrl+s and <%= fileName; %> has been changed.
21+
<% if(lineNumber) { %>Insert the content into the line *<%= lineNumber%>* in the opened <%= fileName; %>.
22+
<%}else if(placeholder) {%>To replace the content with a specific placeholder you have to locate the placeholder in the file. The fastest way is to search through the opened file and replace *<%= placeholder; %>* with the new content.
23+
<% }else{ %>Now insert the copied text into the opened <%= fileName; %>. <% } %>
24+
The final step is to save the file by selecting *Save* in the file context menu or by using the keyboard shortcut ctrl+s and <%= fileName; %> has been changed.

runners/wikiEditor/index.ts

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

78
export class WikiEditor extends WikiRunner {
89

@@ -15,29 +16,23 @@ export class WikiEditor extends WikiRunner {
1516
}
1617

1718
runChangeFile(runCommand: RunCommand): RunResult{
18-
let workspacePath = this.getVariable(this.WORKSPACE_DIRECTORY).replace(/\\/g, "/");
1919
let fileName = path.basename(runCommand.command.parameters[0]);
20-
let filePath = path.join(workspacePath,runCommand.command.parameters[0].replace(fileName, ""));
21-
let contentPath, contentFile, contentString;
22-
if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].contentConsole){
23-
contentPath = runCommand.command.parameters[1].fileConsole;
24-
contentString = runCommand.command.parameters[1].contentConsole;
25-
}else{
26-
contentPath = runCommand.command.parameters[1].file;
27-
contentString = runCommand.command.parameters[1].content;
20+
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
21+
filePath = path.relative(this.getWorkingDirectory(), filePath).replace(/\\/g, "/");
22+
let fileType = this.fileTypeMap.get(fileName.substr(fileName.indexOf(".")));
23+
let content = undefined;
24+
if(runCommand.command.parameters[1].content || runCommand.command.parameters[1].contentConsole){
25+
content = runCommand.command.parameters[1].content
26+
? runCommand.command.parameters[1].content
27+
: runCommand.command.parameters[1].contentConsole;
28+
}else if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].file){
29+
content = runCommand.command.parameters[1].file
30+
? fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1].file), { encoding: "utf-8" })
31+
: fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1].fileConsole), { encoding: "utf-8" });
2832
}
29-
contentFile = contentPath
30-
? path.basename(contentPath)
31-
: undefined;
32-
contentPath = contentPath
33-
? path.join(this.getPlaybookPath(), contentPath.replace(contentFile, ""))
34-
: undefined;
3533
let placeholder = runCommand.command.parameters[1].placeholder;
3634
let lineNumber = runCommand.command.parameters[1].lineNumber;
37-
38-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath,
39-
contentPath: contentPath, contentString: contentString, placeholder: placeholder, lineNumber: lineNumber,
40-
contentFile: contentFile, fileName: fileName});
35+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath ,fileName: fileName, content : content, fileType: fileType, lineNumber: lineNumber, placeholder: placeholder });
4136
return null;
4237
}
4338
}

0 commit comments

Comments
 (0)