From cbce24d7afcc6b994e55d185aaaefbc8a303e16a Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Wed, 9 Dec 2020 16:26:24 +0100 Subject: [PATCH 1/6] Delete build - Shortcut.lnk --- build - Shortcut.lnk | Bin 1289 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 build - Shortcut.lnk diff --git a/build - Shortcut.lnk b/build - Shortcut.lnk deleted file mode 100644 index 5cad820559373fdbafe35678ccfb95fb2ffc01ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1289 zcmbVMTS!!45dOBbG{cU$nT4eV)kdhRMzWS5?51mld+i2CbKOgw-1QuHSIvUxrEqC| z=s^g=knlpJLXh+jg;Dg-Lu?o9LJ##8nwa!b^wP}PbzMX-8u;cv|3CA8GiPSbIR-$Z zT}2w0R5fa^BLf0G-;KO|mi}r=qc7M0NL^JU*)?(hq@LAiQE2^Qi4{#(Ny42E8Q7=S z_isU|u}VxjEk2w;nYvMIp)&$J-cGsA*M%BnA`Np-6x&8STT001+CUmeUkU@HBtz(ZG(L!;U(L;7E;Vhwmz+=E`1%bs!*i2YWxY?b% zn@7pwFiD|S&>$rGEOyDk){x?IdqX0ZQ4Dv4<)Gy97rW(vBKf^RF`gsVq6A_}@a8!6 zz$sc;+}`s2hDv>WL;77oV!9pY%S| zxPe~cDsxyJv--!MjEK~Y{EFochI~8Q>6}Y|LP9BF<@y&v2P4gixMW_%W#>#x&d6R4 zqe_%CC!?R=^>D6kt1vXbsyTXlW^@~!uVW8RW(^^=NtOq~Xf$6_FGQup%$rm8 G7vwJ?aS2HP From c12013dcae1e2fb349807e2b36c3a9a57c10db4c Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 14 Dec 2020 14:51:36 +0100 Subject: [PATCH 2/6] createFile for Katacoda --- runners/katacoda/index.ts | 23 +++++++++++++++++++++++ runners/katacoda/templates/createFile.md | 14 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 runners/katacoda/templates/createFile.md diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 0ef680ca..eecddd1b 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -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 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, content: content}); + return null; + } + runBuildJava(step: Step, command: Command): RunResult{ let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main", command.parameters[0]));; @@ -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); diff --git a/runners/katacoda/templates/createFile.md b/runners/katacoda/templates/createFile.md new file mode 100644 index 00000000..2a2c95e9 --- /dev/null +++ b/runners/katacoda/templates/createFile.md @@ -0,0 +1,14 @@ +<%= text; %> + +<%= cdCommand; %> + + +`mkdir -p <%= filePath; %>`{{execute}} + +Switch to the IDE and click 'Copy to Editor' in the following java class. The java file will be created automatically inside the newly created package. + +
+<%= content; %>
+
+ +<%= textAfter; %> \ No newline at end of file From b380c341be893ffaae6f6dd6f1ddf62634e36a0b Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 14 Dec 2020 15:46:11 +0100 Subject: [PATCH 3/6] feature/dirUtil --- runners/katacoda/dirUtils.ts | 6 +++--- spec/runners/katacoda/dirUtilsSpec.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runners/katacoda/dirUtils.ts b/runners/katacoda/dirUtils.ts index 2c5780a2..78d36078 100644 --- a/runners/katacoda/dirUtils.ts +++ b/runners/katacoda/dirUtils.ts @@ -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 @@ -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, "/"); } diff --git a/spec/runners/katacoda/dirUtilsSpec.ts b/spec/runners/katacoda/dirUtilsSpec.ts index 9e7186b4..dbc864dd 100644 --- a/spec/runners/katacoda/dirUtilsSpec.ts +++ b/spec/runners/katacoda/dirUtilsSpec.ts @@ -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'); }); }); From 8bc5b18bc4a9755e099a42c61eb8e330c0091973 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 14 Dec 2020 16:06:25 +0100 Subject: [PATCH 4/6] Revert "dirUtil for Katacoda" This reverts commit e3717a6f4e6b70cb12cb0a239d883bf46fa48541. --- runners/katacoda/dirUtils.ts | 6 +++--- spec/runners/katacoda/dirUtilsSpec.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runners/katacoda/dirUtils.ts b/runners/katacoda/dirUtils.ts index 2c5780a2..78d36078 100644 --- a/runners/katacoda/dirUtils.ts +++ b/runners/katacoda/dirUtils.ts @@ -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 @@ -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, "/"); } diff --git a/spec/runners/katacoda/dirUtilsSpec.ts b/spec/runners/katacoda/dirUtilsSpec.ts index 9e7186b4..dbc864dd 100644 --- a/spec/runners/katacoda/dirUtilsSpec.ts +++ b/spec/runners/katacoda/dirUtilsSpec.ts @@ -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'); }); }); From 4f31ea1d57131ac012550c26626d46f252e46729 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 14 Dec 2020 17:44:29 +0100 Subject: [PATCH 5/6] createFile Katacoda --- runners/katacoda/index.ts | 4 ++-- runners/katacoda/templates/createFile.md | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index eecddd1b..8cb21069 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -144,7 +144,7 @@ export class Katacoda extends Runner { 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" }); @@ -155,7 +155,7 @@ export class Katacoda extends Runner { "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, content: content}); + 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; } diff --git a/runners/katacoda/templates/createFile.md b/runners/katacoda/templates/createFile.md index 2a2c95e9..80139828 100644 --- a/runners/katacoda/templates/createFile.md +++ b/runners/katacoda/templates/createFile.md @@ -2,10 +2,12 @@ <%= 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' in the following java class. The java file will be created automatically inside the newly created package. +Switch to the IDE and click 'Copy to Editor'. +'<%= fileName; %>' will be created automatically inside the newly created folder.
 <%= content; %>

From c526eab34130de6e84ccaa0678361496864daeb7 Mon Sep 17 00:00:00 2001
From: denise-khuu <74537227+denise-khuu@users.noreply.github.com>
Date: Mon, 14 Dec 2020 17:54:35 +0100
Subject: [PATCH 6/6] createFile Katacoda

---
 runners/katacoda/index.ts                | 2 +-
 runners/katacoda/templates/createFile.md | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts
index 8cb21069..ea1c7569 100644
--- a/runners/katacoda/index.ts
+++ b/runners/katacoda/index.ts
@@ -144,7 +144,7 @@ export class Katacoda extends Runner {
         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 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" });
diff --git a/runners/katacoda/templates/createFile.md b/runners/katacoda/templates/createFile.md
index 80139828..03b83af4 100644
--- a/runners/katacoda/templates/createFile.md
+++ b/runners/katacoda/templates/createFile.md
@@ -7,6 +7,7 @@ If the parent directories aren't already in the project, 'mkdir -p' will create
 `mkdir -p <%= filePath; %>`{{execute}}
 
 Switch to the IDE and click 'Copy to Editor'. 
+
 '<%= fileName; %>' will be created automatically inside the newly created folder.