Skip to content

Commit b567257

Browse files
authored
Merge pull request devonfw-tutorials#250 from denise-khuu/feature/openFile
feature/openFile
2 parents e5aaa1b + 1b81893 commit b567257

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

documentation/Functions.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,13 @@ This command also works if the devonfw IDE is not installed, but then you have t
361361
2. Path of the script (Windows). Relative to the playbook directory
362362

363363
#### example
364-
addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1")
364+
addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1")
365+
366+
***
367+
368+
### openFile
369+
#### parameter
370+
1. Path of the file to be opened (relative path to the workspace directory)
371+
372+
#### example
373+
openFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java")

runners/console/index.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class Console extends Runner {
406406
}
407407

408408
runNextKatacodaStep(runCommand: RunCommand): RunResult {
409-
//Only needed for katacoda runner
409+
//Only needed for katacoda and wiki runner
410410
return null;
411411
}
412412

@@ -459,6 +459,13 @@ export class Console extends Runner {
459459
return result;
460460
}
461461

462+
runOpenFile(runCommand: RunCommand): RunResult {
463+
let result = new RunResult();
464+
result.returnCode = 0;
465+
//Only needed for katacoda, wiki runner and the assertions
466+
return result;
467+
}
468+
462469
async assertInstallDevonfwIde(runCommand: RunCommand, result: RunResult) {
463470
try {
464471
let installedTools = runCommand.command.parameters[0];
@@ -804,6 +811,20 @@ export class Console extends Runner {
804811
}
805812
}
806813

814+
async assertOpenFile(runCommand: RunCommand, result: RunResult){
815+
try{
816+
new Assertions()
817+
.noErrorCode(result)
818+
.noException(result)
819+
.fileExits(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]));
820+
}
821+
catch(error) {
822+
await this.cleanUp();
823+
throw error;
824+
}
825+
}
826+
827+
807828
private lookup(obj, lookupkey) {
808829
for(var key in obj) {
809830

runners/katacoda/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ export class Katacoda extends Runner {
212212
}
213213

214214
runChangeFile(runCommand: RunCommand): RunResult{
215-
let workspaceDir = path.join(this.getVariable(this.workspaceDirectory).concat(path.sep).replace(path.sep + "root" + path.sep, ""));
216215
let fileName = path.basename(path.join(runCommand.command.parameters[0]));
217-
let fileDir = path.join(workspaceDir, runCommand.command.parameters[0]).replace(/\\/g, "/");
216+
let fileDir = path.relative('/root', path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0])).replace(/\\/g, "/");
218217
let placeholder = runCommand.command.parameters[1].placeholder ? runCommand.command.parameters[1].placeholder : "";
219218
let dataTarget = runCommand.command.parameters[1].placeholder ? "insert" : "replace";
220219
let content = "";
@@ -422,6 +421,16 @@ export class Katacoda extends Runner {
422421
return null;
423422
}
424423

424+
runOpenFile(runCommand: RunCommand): RunResult {
425+
let fileName = path.basename(runCommand.command.parameters[0]);
426+
let filePath = path.relative('/root', path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0])).replace(/\\/g, "/");
427+
428+
this.pushStep(runCommand, "Open " + fileName, "step" + runCommand.stepIndex + ".md");
429+
430+
this.renderTemplate("openFile.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, fileName: fileName, filePath: filePath});
431+
return null;
432+
}
433+
425434
private renderTemplate(name: string, targetPath: string, variables) {
426435
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8');
427436
let result = ejs.render(template, variables);

runners/katacoda/templates/cd.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% if(terminalId) { %>
2-
Now you have to open another terminal. Click on the cd command twice and you will change to '<%= dir; %>' in terminal <%= terminalId; %> automatically. The first click will open a new terminal and the second one will change the directory. Alternatively you can click on the + next to 'IDE', choose the option 'Open New Terminal' and run the cd command afterwards.
2+
Now you have to open another terminal. Click on the cd command twice and you will change to '<%= dir; %>' in terminal <%= terminalId; %> automatically. The first click will open a new terminal and the second one will change the directory. Alternatively you can click on the '+', choose the option 'Open New Terminal' and run the cd command afterwards.
33
<% } else { %>Please change the folder to '<%= dir; %>'.<% } %>
44

55
`cd <%= dir; %>`{{execute <%= terminal; %>}}

runners/katacoda/templates/changeFile.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= text; %>
22

3-
Switch to the IDE and open the file '<%= fileDir; %>'.
3+
Switch to the editor and open the file '<%= fileDir; %>'.
44

55
`<%= fileDir; %>`{{open}}
66

runners/katacoda/templates/createFile.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If the parent directories aren't already in the project, 'mkdir -p' will create
44

55
`mkdir -p <%= filePath; %>`{{execute T1}}
66

7-
Switch to the IDE and click 'Copy to Editor'.
7+
Switch to the editor and click 'Copy to Editor'.
88

99
'<%= fileName; %>' will be created automatically inside the newly created folder.
1010

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Now we want to open the file <%= fileName; %>.
2+
3+
You can either click on this link, here:
4+
5+
`<%= filePath; %>`{{open}}
6+
7+
and it will open the file automatically or switch to the editor and open it yourself.

0 commit comments

Comments
 (0)