Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions runners/katacoda/dirUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class DirUtils{

//saves the remaining path, if currentdir is the prefix of targetDir
if(targetDir.substring(0,currentDir.length) == currentDir){
return path.join(targetDir.replace(currentDir + path.sep, '')).replace("\\", "/");
return path.join(targetDir.replace(currentDir + path.sep, '')).replace(/\\/g, "/");
}


else{
//returns the absolut directory, if the first parent folder is different
if(currentPaths[1] != targetPaths[1]){
return targetDir.replace("\\", "/");
return targetDir.replace(/\\/g, "/");
}

//iterates throught currentPath array to compare parent directories
Expand All @@ -42,7 +42,7 @@ export class DirUtils{
//slice targetPaths to get the relative path
targetPaths = targetPaths.slice(index + 1, targetPaths.length);

return path.join(dirPath, targetPaths.join(path.sep)).replace("\\", "/");
return path.join(dirPath, targetPaths.join(path.sep)).replace(/\\/g, "/");

}

Expand Down
23 changes: 23 additions & 0 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ export class Katacoda extends Runner {
return null;
}

runCreateFile(step: Step, command: Command): RunResult{

let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main"));
let workspaceDir = path.join("devonfw", "workspaces", "main");
let filePath = path.join(command.parameters[0].substring(0,path.join(command.parameters[0]).lastIndexOf(path.sep))).replace(/\\/g, "/");
let fileDir = path.join(workspaceDir, command.parameters[0]).replace(/\\/g, "/");
let fileName = path.join(command.parameters[0].substring(path.join( command.parameters[0]).lastIndexOf(path.sep) + 1 , command.parameters[0].length )).replace(/\\/g, "/");
let content = "";
if(command.parameters.length == 2) {
content = fs.readFileSync(path.join(this.playbookPath, command.parameters[1]), { encoding: "utf-8" });
}

this.steps.push({
"title": "Create a new file",
"text": "step" + this.stepsCount + ".md"
});

this.renderTemplate("createFile.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, filePath: filePath, fileDir: fileDir , fileName:fileName , content: content});
return null;
}

runBuildJava(step: Step, command: Command): RunResult{

let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main", command.parameters[0]));;
Expand All @@ -159,6 +180,8 @@ export class Katacoda extends Runner {

}



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
17 changes: 17 additions & 0 deletions runners/katacoda/templates/createFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= text; %>

<%= cdCommand; %>

If the parent directories aren't already in the project, 'mkdir -p' will create them for you.

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

Switch to the IDE and click 'Copy to Editor'.

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

<pre class="file" data-filename="<%= fileDir; %>">
<%= content; %>
</pre>

<%= textAfter; %>
8 changes: 4 additions & 4 deletions spec/runners/katacoda/dirUtilsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ describe("DirUtils", () => {
expect(target.getCdParam(path.join('/root'), path.join('/root'))).toBe('');
});
it("changes directly to the child folder, because currentDir is the prefix of dir", () => {
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/devonfw/setup'))).toBe(path.join('setup').replace("\\", "/"));
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/devonfw/setup'))).toBe('setup');
});
it("returns an absolute path, because both dirs don't have matching parent folders", () => {
expect(target.getCdParam(path.join('/setup'), path.join('/root/devonfw/setup'))).toBe(path.join('/root/devonfw/setup').replace("\\", "/"));
expect(target.getCdParam(path.join('/setup'), path.join('/root/devonfw/setup'))).toBe('/root/devonfw/setup');
});
it("changes to parent folder before changing to child folder", () => {
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/setup/folder0/folder1'))).toBe(path.join('../setup/folder0/folder1').replace("\\", "/"));
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/setup/folder0/folder1'))).toBe('../setup/folder0/folder1');
});
it("changes to parent folder before changing to child folder and one child folder has the same position and name", () => {
expect(target.getCdParam(path.join('/root/devonfw/folder/setup'), path.join('/root/devonfw/setup/setup'))).toBe(path.join('../../setup/setup').replace("\\", "/"));
expect(target.getCdParam(path.join('/root/devonfw/folder/setup'), path.join('/root/devonfw/setup/setup'))).toBe('../../setup/setup');
});

});
Expand Down