Skip to content

Commit 0945379

Browse files
authored
Merge pull request #215 from EduardKrieger/feature/wikiRunnerCreateFile
Feature/wikiRunnerCreateFile
2 parents eef9d28 + 97739de commit 0945379

11 files changed

Lines changed: 153 additions & 7 deletions

File tree

documentation/Functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ buildJava("cobigenexample", true)
195195

196196
### createFile <a name="createFile"></a>
197197
#### parameter
198-
1. Path of the file to be created (relative path to the workspace directory)
198+
1. Path of the file to be created (relative path to the workspace directory).
199199
2. (Optional) Path of the file to get the content from. Relative to the playbook directory
200200
#### example
201201
createFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java", "files/CustomerEntity.java")

engine/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export abstract class Runner {
105105
try {
106106
fs.removeSync(path);
107107
} catch(e) {
108-
console.log("Error deleting foler " + path, e);
108+
console.log("Error deleting folder " + path, e);
109109
}
110110
} else return path;
111111
}

engine/wikiRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export abstract class WikiRunner extends Runner {
1212
[".scss", "css"], [".asciidoc", "asciidoc"], ]);
1313
protected readonly INSTALLED_TOOLS: string = "installedTools";
1414

15+
1516
init(playbook: Playbook): void {
1617
let outputDirectory = this.createFolder(path.join(this.getOutputDirectory(), "wiki", this.environmentName), false)
1718
this.outputPathTutorial = this.createFolder(path.join(outputDirectory, playbook.name), true);

runners/katacoda/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class Katacoda extends Runner {
208208
}
209209
this.pushStep(runCommand, "Create a new file", "step" + runCommand.stepIndex + ".md");
210210

211-
this.renderTemplate("createFile.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, filePath: filePath, fileDir: fileDir , fileName:fileName , content: content});
211+
this.renderTemplate("createFile.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, filePath: filePath, fileDir: fileDir , fileName:fileName , content: content});
212212
return null;
213213
}
214214

runners/wikiConsole/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as fs from "fs";
88

99
export class WikiConsole extends WikiRunner {
1010

11+
12+
1113
init(playbook: Playbook): void {
1214
super.init(playbook);
1315
this.setVariable(this.WORKSPACE_DIRECTORY, path.join(this.getWorkingDirectory()));
@@ -37,6 +39,33 @@ export class WikiConsole extends WikiRunner {
3739
return this.runInstallDevonfwIde(runCommand);
3840
}
3941

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+
4069
runRunServerJava(runCommand: RunCommand): RunResult {
4170
let server_path = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0]);
4271
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 })
@@ -61,6 +90,7 @@ export class WikiConsole extends WikiRunner {
6190
return null;
6291
}
6392

93+
6494
runDownloadFile(runCommand: RunCommand): RunResult{
6595
let url = runCommand.command.parameters[0];
6696
let fileName = runCommand.command.parameters[1];

runners/wikiEclipse/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ export class WikiEclipse extends WikiRunner {
1515
super.destroy(playbook);
1616
}
1717

18+
runCreateFile(runCommand: RunCommand): RunResult{
19+
let fileName = path.basename(runCommand.command.parameters[0]);
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 parentFolder = path.basename(filePath);
24+
let content = runCommand.command.parameters[1]
25+
? fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1]), { encoding: "utf-8" })
26+
: undefined;
27+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFile.asciidoc"), {filePath : filePath ,fileName: fileName, content : content, fileType: fileType, parentFolder: parentFolder });
28+
return null;
29+
}
30+
1831
runChangeFile(runCommand: RunCommand): RunResult{
1932
let fileName = path.basename(runCommand.command.parameters[0]);
2033
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
== Create the file <%= fileName; %>
2+
3+
=== Prerequisites
4+
* Existing folder you want to create the file. (If the folder doesn't exist you can create it from with the editor).
5+
* Eclipse IDE (can be installed in your devonfw environment).
6+
7+
=== Creating <%= fileName; %> in the Eclipse IDE
8+
9+
Create <%= fileName; %> in the Eclipse IDE<% if(content) { %> and insert the following data into it<% } %>.
10+
11+
First, you have to load the project directory into Eclipse by going into the *File* context menu in the top left corner and select *Open Projects from File System...*. Eclipse opens a *Import Projects from File System or Archive* window, where you should specify your directory by selecting the *Directory...* button and choosing `<%= filePath;%>` in the Windows file explorer window and confirm the choice with the *Finish* button.
12+
Opening a new file can be done by going to the *File* context menu again and select *New* or use the keyboard shortcut alt+shift+n and a dropdown menu will be opened where you have to select *File*.
13+
Eclipse opens a *Create New File* window. Select the parent folder you want to save the file into. Insert `<%= parentFolder; %>` at the top text field named *enter or select the parent folder*. If the directory does not exist, create the missing folders or run through the previous steps from the wiki again.
14+
Also, a name for the file is needed, so you can insert `<%= fileName; %>` in the text field *File name* or type it yourself.
15+
Confirm your inputs with the *Finish* button in the bottom right corner and an empty <%= fileName; %> has been created and can be edited.<% if(content) { %>
16+
Copy the following text.
17+
[source, <%= fileType; %>]
18+
----
19+
<%- content; %>
20+
----
21+
Now insert the copied text into the new file. <% } %>
22+
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 created <% if(content){%>with the data from above<% }%>.

runners/wikiEditor/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +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";
6+
import * as fs from "fs-extra"
77

88
export class WikiEditor extends WikiRunner {
99

@@ -15,6 +15,20 @@ export class WikiEditor extends WikiRunner {
1515
super.destroy(playbook);
1616
}
1717

18+
19+
20+
runCreateFile(runCommand: RunCommand): RunResult{
21+
let fileName = path.basename(runCommand.command.parameters[0]);
22+
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
23+
filePath = path.relative(this.getWorkingDirectory(), filePath).replace(/\\/g, "/");
24+
let fileType = this.fileTypeMap.get(fileName.substr(fileName.indexOf(".")));
25+
let content = runCommand.command.parameters[1]
26+
? fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1]), { encoding: "utf-8" })
27+
: undefined;
28+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFile.asciidoc"), {filePath : filePath ,fileName: fileName, content : content, fileType: fileType });
29+
return null;
30+
}
31+
1832
runChangeFile(runCommand: RunCommand): RunResult{
1933
let fileName = path.basename(runCommand.command.parameters[0]);
2034
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
== Create the file <%= fileName; %>
2+
3+
=== Prerequisites
4+
* Existing folder you want to create the file. (If the folder doesn't exist you can create it from with the editor).
5+
* Any Editor that can edit files
6+
7+
=== Creating <%= fileName; %> in any Editor
8+
9+
Create <%= fileName; %> in any Editor<% if(content) { %> and insert the following data into it. <% } %>.
10+
11+
Opening a new file can be done 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.
12+
The editor opens a new editor window for an untitled file that can be edited now.
13+
<% if(content) { %>
14+
Copy the following text.
15+
[source, <%= fileType; %>]
16+
----
17+
<%- content; %>
18+
----
19+
Now insert the copied text into the new file.
20+
<% } %>
21+
The next step is to save the file by selecting *Save* or *Save as* in the file context menu or by using the keyboard shortcut ctrl+s.
22+
A file explorer window opens.
23+
You should check if you are currently in the right directory where you want to save *<%= filePath; %>/<%= fileName;%>*.
24+
Select the directory `<%= filePath; %>`. If the directory does not exist, create the missing folders or run through the previous steps from the wiki again.
25+
To save the file specify the name of the file. Paste `<%= fileName; %>` in the text field *File name:*.
26+
The last step is to save the file with the *Save* button in the bottom right corner and <%= fileName; %> has been created<% if(content) { %> and filled with some data<%} %>.
27+
28+

runners/wikiVsCode/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Playbook } from "../../engine/playbook";
2-
import { WikiRunner } from "../../engine/wikiRunner";
32
import { RunCommand } from "../../engine/run_command";
43
import { RunResult } from "../../engine/run_result";
4+
import { WikiRunner } from "../../engine/wikiRunner";
55
import * as path from "path";
66
import * as fs from "fs-extra";
77

@@ -16,6 +16,19 @@ export class WikiVsCode extends WikiRunner {
1616
super.destroy(playbook);
1717
}
1818

19+
20+
runCreateFile(runCommand: RunCommand): RunResult{
21+
let fileName = path.basename(runCommand.command.parameters[0]);
22+
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
23+
filePath = path.relative(this.getWorkingDirectory(), filePath).replace(/\\/g, "/");
24+
let fileType = this.fileTypeMap.get(fileName.substr(fileName.indexOf(".")));
25+
let content = runCommand.command.parameters[1]
26+
? fs.readFileSync(path.join(this.playbookPath, runCommand.command.parameters[1]), { encoding: "utf-8" })
27+
: undefined;
28+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFile.asciidoc"), {filePath : filePath , fileName: fileName, content : content, fileType: fileType});
29+
return null
30+
}
31+
1932
runChangeFile(runCommand: RunCommand): RunResult{
2033
let fileName = path.basename(runCommand.command.parameters[0]);
2134
let filePath = path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[0].replace(fileName, ""));
@@ -38,7 +51,7 @@ export class WikiVsCode extends WikiRunner {
3851
}
3952

4053
runInstallCobiGen(runCommand: RunCommand): RunResult{
41-
let dir = path.relative(this.getVariable(this.WORKSPACE_DIRECTORY), this.getWorkingDirectory()).replace(/\\/g, "/");;
54+
let dir = path.relative(this.getVariable(this.WORKSPACE_DIRECTORY), this.getWorkingDirectory()).replace(/\\/g, "/");
4255
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installCobiGen.asciidoc"), {dir: dir});
4356
return null;
4457
}
@@ -49,4 +62,4 @@ export class WikiVsCode extends WikiRunner {
4962
: false;
5063
}
5164

52-
}
65+
}

0 commit comments

Comments
 (0)