diff --git a/documentation/Functions.md b/documentation/Functions.md index fb00dfbb..4ffd6ad0 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -361,4 +361,13 @@ This command also works if the devonfw IDE is not installed, but then you have t 2. Path of the script (Windows). Relative to the playbook directory #### example -addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1") \ No newline at end of file +addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1") + +*** + +### openFile +#### parameter +1. Path of the file to be opened (relative path to the workspace directory) + +#### example +openFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java") \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index f902da7c..ee9aa9c7 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -406,7 +406,7 @@ export class Console extends Runner { } runNextKatacodaStep(runCommand: RunCommand): RunResult { - //Only needed for katacoda runner + //Only needed for katacoda and wiki runner return null; } @@ -459,6 +459,13 @@ export class Console extends Runner { return result; } + runOpenFile(runCommand: RunCommand): RunResult { + let result = new RunResult(); + result.returnCode = 0; + //Only needed for katacoda, wiki runner and the assertions + return result; + } + async assertInstallDevonfwIde(runCommand: RunCommand, result: RunResult) { try { let installedTools = runCommand.command.parameters[0]; @@ -804,6 +811,20 @@ export class Console extends Runner { } } + async assertOpenFile(runCommand: RunCommand, result: RunResult){ + try{ + new Assertions() + .noErrorCode(result) + .noException(result) + .fileExits(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0])); + } + catch(error) { + await this.cleanUp(); + throw error; + } + } + + private lookup(obj, lookupkey) { for(var key in obj) { diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 9cf7ce69..d2642fba 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -212,9 +212,8 @@ export class Katacoda extends Runner { } runChangeFile(runCommand: RunCommand): RunResult{ - let workspaceDir = path.join(this.getVariable(this.workspaceDirectory).concat(path.sep).replace(path.sep + "root" + path.sep, "")); let fileName = path.basename(path.join(runCommand.command.parameters[0])); - let fileDir = path.join(workspaceDir, runCommand.command.parameters[0]).replace(/\\/g, "/"); + let fileDir = path.relative('/root', path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0])).replace(/\\/g, "/"); let placeholder = runCommand.command.parameters[1].placeholder ? runCommand.command.parameters[1].placeholder : ""; let dataTarget = runCommand.command.parameters[1].placeholder ? "insert" : "replace"; let content = ""; @@ -422,6 +421,16 @@ export class Katacoda extends Runner { return null; } + runOpenFile(runCommand: RunCommand): RunResult { + let fileName = path.basename(runCommand.command.parameters[0]); + let filePath = path.relative('/root', path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0])).replace(/\\/g, "/"); + + this.pushStep(runCommand, "Open " + fileName, "step" + runCommand.stepIndex + ".md"); + + this.renderTemplate("openFile.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, fileName: fileName, filePath: filePath}); + return null; + } + private renderTemplate(name: string, targetPath: string, variables) { let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8'); let result = ejs.render(template, variables); diff --git a/runners/katacoda/templates/cd.md b/runners/katacoda/templates/cd.md index 9d1b88e1..db414982 100644 --- a/runners/katacoda/templates/cd.md +++ b/runners/katacoda/templates/cd.md @@ -1,5 +1,5 @@ <% if(terminalId) { %> -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. +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. <% } else { %>Please change the folder to '<%= dir; %>'.<% } %> `cd <%= dir; %>`{{execute <%= terminal; %>}} \ No newline at end of file diff --git a/runners/katacoda/templates/changeFile.md b/runners/katacoda/templates/changeFile.md index d32407a1..a627b8c2 100644 --- a/runners/katacoda/templates/changeFile.md +++ b/runners/katacoda/templates/changeFile.md @@ -1,6 +1,6 @@ <%= text; %> -Switch to the IDE and open the file '<%= fileDir; %>'. +Switch to the editor and open the file '<%= fileDir; %>'. `<%= fileDir; %>`{{open}} diff --git a/runners/katacoda/templates/createFile.md b/runners/katacoda/templates/createFile.md index 24c8aca2..445f5f72 100644 --- a/runners/katacoda/templates/createFile.md +++ b/runners/katacoda/templates/createFile.md @@ -4,7 +4,7 @@ If the parent directories aren't already in the project, 'mkdir -p' will create `mkdir -p <%= filePath; %>`{{execute T1}} -Switch to the IDE and click 'Copy to Editor'. +Switch to the editor and click 'Copy to Editor'. '<%= fileName; %>' will be created automatically inside the newly created folder. diff --git a/runners/katacoda/templates/openFile.md b/runners/katacoda/templates/openFile.md new file mode 100644 index 00000000..d5ac6a34 --- /dev/null +++ b/runners/katacoda/templates/openFile.md @@ -0,0 +1,7 @@ +Now we want to open the file <%= fileName; %>. + +You can either click on this link, here: + +`<%= filePath; %>`{{open}} + +and it will open the file automatically or switch to the editor and open it yourself. \ No newline at end of file