Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/openFile #250

Merged
merged 6 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion documentation/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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")
23 changes: 22 additions & 1 deletion runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {

Expand Down
13 changes: 11 additions & 2 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions runners/katacoda/templates/openFile.md
Original file line number Diff line number Diff line change
@@ -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 IDE and open it yourself.
denise-khuu marked this conversation as resolved.
Show resolved Hide resolved