From 57de549ed27def413355e27a1c9e5dd1aa2fd0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Mon, 8 Mar 2021 13:27:46 +0100 Subject: [PATCH 1/6] Initial Commit --- runners/console/index.ts | 31 +++++++++++++++++++ runners/katacoda/index.ts | 10 ++++++ runners/katacoda/templates/createNgProject.md | 8 +++++ 3 files changed, 49 insertions(+) create mode 100644 runners/katacoda/templates/createNgProject.md diff --git a/runners/console/index.ts b/runners/console/index.ts index 30b9656b..7c0e5ad3 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -347,6 +347,22 @@ export class Console extends Runner { return result; } + runCreateNgProject(runCommand: RunCommand): RunResult { + let result = new RunResult(); + result.returnCode = 0; + + let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; + let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath); + console.log(projectDir); + let command1 = "ng new " + runCommand.command.parameters[0]; + + this.getVariable(this.useDevonCommand) + ? this.executeDevonCommandSync(command1, projectDir, result) + : this.executeCommandSync(command1, projectDir, result); + + return result; + } + async assertInstallDevonfwIde(runCommand: RunCommand, result: RunResult) { try { let installedTools = runCommand.command.parameters[0]; @@ -659,6 +675,21 @@ export class Console extends Runner { } } + async assertCreateNgProject(runCommand: RunCommand, result: RunResult) { + try { + let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; + let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath, runCommand.command.parameters[0]); + new Assertions() + .noErrorCode(result) + .noException(result) + .directoryExits(projectDir) + .directoryNotEmpty(projectDir); + } catch(error) { + this.cleanUp(); + throw error; + } + } + private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { if(result.returnCode != 0) return; diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 6ecc5c5a..17a348c3 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -331,6 +331,16 @@ export class Katacoda extends Runner { } + runCreateNgProject(runCommand: RunCommand): RunResult { + let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; + let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), projectPath)); + + this.pushStep(runCommand, "Create Angular Project", "step" + this.getStepsCount(runCommand) + ".md"); + + this.renderTemplate("createNgProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], useDevonCommand: this.getVariable(this.useDevonCommand) }); + 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/createNgProject.md b/runners/katacoda/templates/createNgProject.md new file mode 100644 index 00000000..f0d56137 --- /dev/null +++ b/runners/katacoda/templates/createNgProject.md @@ -0,0 +1,8 @@ +<%= text; %> + +<%= cdCommand; %> + +Use the ng new command to create a new Angular Project. +`<% if(useDevonCommand){ %>devon<% } %> ng new <%= projectName; %>`{{execute T1}} + +<%= textAfter; %> \ No newline at end of file From 03480368b75e170953f232de28fdb232de007f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 10 Mar 2021 09:14:31 +0100 Subject: [PATCH 2/6] Function now to work devon exclusive --- documentation/Functions.md | 14 ++++++++++++++ runners/console/index.ts | 15 ++++++++------- runners/katacoda/index.ts | 4 ++-- .../katacoda/templates/createDevon4ngProject.md | 8 ++++++++ runners/katacoda/templates/createNgProject.md | 8 -------- 5 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 runners/katacoda/templates/createDevon4ngProject.md delete mode 100644 runners/katacoda/templates/createNgProject.md diff --git a/documentation/Functions.md b/documentation/Functions.md index a70cc0af..2e2a00e3 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -17,6 +17,7 @@ The following functions are already implemented: * downloadFile * nextKatacodaStep * adaptTemplatesCobiGen +* createDevon4ngProject *** @@ -248,3 +249,16 @@ image: Path to an image to be displayed in the katacoda step. adaptTemplatesCobiGen() *** + +### createDevon4ngProject +#### parameter +1. Name of the Project. +2. (Optional) Path to where the Project should be created (relative to workspace). Folder should exist. +#### example +createDevon4ngProject("exampleAngularProject") +Will create the angular project to the current workspace with the name exampleAngularProject. + +createDevon4ngProject("exampleAngularProject", "projects") +Will create the angular project to the directory projects within the current workspace. + +*** \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index 7c0e5ad3..7e09b2d3 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -347,18 +347,19 @@ export class Console extends Runner { return result; } - runCreateNgProject(runCommand: RunCommand): RunResult { + runCreateDevon4ngProject(runCommand: RunCommand): RunResult { let result = new RunResult(); result.returnCode = 0; let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath); - console.log(projectDir); - let command1 = "ng new " + runCommand.command.parameters[0]; + let command1 = "ng create " + runCommand.command.parameters[0]; - this.getVariable(this.useDevonCommand) - ? this.executeDevonCommandSync(command1, projectDir, result) - : this.executeCommandSync(command1, projectDir, result); + if(!this.getVariable(this.useDevonCommand)){ + console.warn("Devonfw IDE is not installed"); + } + + this.executeDevonCommandSync(command1, projectDir, result); return result; } @@ -675,7 +676,7 @@ export class Console extends Runner { } } - async assertCreateNgProject(runCommand: RunCommand, result: RunResult) { + async assertCreateDevon4ngProject(runCommand: RunCommand, result: RunResult) { try { let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath, runCommand.command.parameters[0]); diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 17a348c3..662da308 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -331,13 +331,13 @@ export class Katacoda extends Runner { } - runCreateNgProject(runCommand: RunCommand): RunResult { + runCreateDevon4ngProject(runCommand: RunCommand): RunResult { let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), projectPath)); this.pushStep(runCommand, "Create Angular Project", "step" + this.getStepsCount(runCommand) + ".md"); - this.renderTemplate("createNgProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], useDevonCommand: this.getVariable(this.useDevonCommand) }); + this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], useDevonCommand: this.getVariable(this.useDevonCommand) }); return null; } diff --git a/runners/katacoda/templates/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md new file mode 100644 index 00000000..d0844fe8 --- /dev/null +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -0,0 +1,8 @@ +<%= text; %> + +<%= cdCommand; %> + +Use the ng create command to create a new Angular Project with the name <%= projectName; %>. +`<% if(useDevonCommand){ %>devon<% } %> ng create <%= projectName; %>`{{execute T1}} + +<%= textAfter; %> \ No newline at end of file diff --git a/runners/katacoda/templates/createNgProject.md b/runners/katacoda/templates/createNgProject.md deleted file mode 100644 index f0d56137..00000000 --- a/runners/katacoda/templates/createNgProject.md +++ /dev/null @@ -1,8 +0,0 @@ -<%= text; %> - -<%= cdCommand; %> - -Use the ng new command to create a new Angular Project. -`<% if(useDevonCommand){ %>devon<% } %> ng new <%= projectName; %>`{{execute T1}} - -<%= textAfter; %> \ No newline at end of file From 8809f220f850917a4cf98735d470eaf36656c86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Thu, 11 Mar 2021 11:46:03 +0100 Subject: [PATCH 3/6] Work without installed IDE --- documentation/Functions.md | 4 +++- runners/console/index.ts | 9 +++------ runners/katacoda/templates/createDevon4ngProject.md | 7 ++++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 2e2a00e3..31bc5d00 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -241,7 +241,6 @@ image: Path to an image to be displayed in the katacoda step. *** - ### adaptTemplatesCobiGen #### parameter * No parameters @@ -261,4 +260,7 @@ Will create the angular project to the current workspace with the name exampleAn createDevon4ngProject("exampleAngularProject", "projects") Will create the angular project to the directory projects within the current workspace. +#### Details +This command also works if the devonfw IDE is not installed, but then you have to make sure that the Angular cli is installed. + *** \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index 7e09b2d3..4cf9501b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -353,13 +353,10 @@ export class Console extends Runner { let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath); - let command1 = "ng create " + runCommand.command.parameters[0]; - if(!this.getVariable(this.useDevonCommand)){ - console.warn("Devonfw IDE is not installed"); - } - - this.executeDevonCommandSync(command1, projectDir, result); + this.getVariable(this.useDevonCommand) + ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0], projectDir, result) + : this.executeCommandSync("ng new " + runCommand.command.parameters[0], projectDir, result); return result; } diff --git a/runners/katacoda/templates/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md index d0844fe8..dafde70b 100644 --- a/runners/katacoda/templates/createDevon4ngProject.md +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -2,7 +2,12 @@ <%= cdCommand; %> +<% if(useDevonCommand){ %> Use the ng create command to create a new Angular Project with the name <%= projectName; %>. -`<% if(useDevonCommand){ %>devon<% } %> ng create <%= projectName; %>`{{execute T1}} +`devon ng create <%= projectName; %> `{{execute T1}} +<% } else { %> +Use the ng new command to create a new Angular Project with the name <%= projectName; %>. +`ng new <%= projectName; %>`{{execute T1}} +<% } %> <%= textAfter; %> \ No newline at end of file From 4934995c605a01c30c2bb4bbcbcb11be84b3bda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Thu, 11 Mar 2021 12:44:50 +0100 Subject: [PATCH 4/6] Added options --- documentation/Functions.md | 3 ++- runners/console/index.ts | 12 +++++------- runners/katacoda/index.ts | 5 ++--- runners/katacoda/templates/createDevon4ngProject.md | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 31bc5d00..64601d39 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -252,7 +252,8 @@ adaptTemplatesCobiGen() ### createDevon4ngProject #### parameter 1. Name of the Project. -2. (Optional) Path to where the Project should be created (relative to workspace). Folder should exist. +2. Path to where the Project should be created (relative to workspace). Folder should exist. +3. (Optional) Optional parameters, according to https://angular.io/cli/new . #### example createDevon4ngProject("exampleAngularProject") Will create the angular project to the current workspace with the name exampleAngularProject. diff --git a/runners/console/index.ts b/runners/console/index.ts index 4cf9501b..81cd273b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -351,12 +351,11 @@ export class Console extends Runner { let result = new RunResult(); result.returnCode = 0; - let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; - let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath); - + let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1]); + let optional = runCommand.command.parameters.length > 2 ? (" " + runCommand.command.parameters[2]) : ""; this.getVariable(this.useDevonCommand) - ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0], projectDir, result) - : this.executeCommandSync("ng new " + runCommand.command.parameters[0], projectDir, result); + ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0] + optional, projectDir, result) + : this.executeCommandSync("ng new " + runCommand.command.parameters[0] + optional, projectDir, result); return result; } @@ -675,8 +674,7 @@ export class Console extends Runner { async assertCreateDevon4ngProject(runCommand: RunCommand, result: RunResult) { try { - let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; - let projectDir = path.join(this.getVariable(this.workspaceDirectory), projectPath, runCommand.command.parameters[0]); + let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1], runCommand.command.parameters[0]); new Assertions() .noErrorCode(result) .noException(result) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 662da308..d1aadb54 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -332,12 +332,11 @@ export class Katacoda extends Runner { } runCreateDevon4ngProject(runCommand: RunCommand): RunResult { - let projectPath = (runCommand.command.parameters.length > 1) ? runCommand.command.parameters[1] : ""; - let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), projectPath)); + let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1])); this.pushStep(runCommand, "Create Angular Project", "step" + this.getStepsCount(runCommand) + ".md"); - this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], useDevonCommand: this.getVariable(this.useDevonCommand) }); + this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], optional: runCommand.command.parameters[2], useDevonCommand: this.getVariable(this.useDevonCommand) }); return null; } diff --git a/runners/katacoda/templates/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md index dafde70b..0829e050 100644 --- a/runners/katacoda/templates/createDevon4ngProject.md +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -4,10 +4,10 @@ <% if(useDevonCommand){ %> Use the ng create command to create a new Angular Project with the name <%= projectName; %>. -`devon ng create <%= projectName; %> `{{execute T1}} +`devon ng create <%= projectName; %><% if(optional){ %> <%= optional; %> <% } %>`{{execute T1}} <% } else { %> Use the ng new command to create a new Angular Project with the name <%= projectName; %>. -`ng new <%= projectName; %>`{{execute T1}} +`ng new <%= projectName; %><% if(optional){ %> <%= optional; %> <% } %>`{{execute T1}} <% } %> <%= textAfter; %> \ No newline at end of file From cfa8eca83953dec15d7bf1113e7d31e589cef0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Thu, 11 Mar 2021 13:22:51 +0100 Subject: [PATCH 5/6] small fix --- runners/katacoda/templates/createDevon4ngProject.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/katacoda/templates/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md index 0829e050..17d64152 100644 --- a/runners/katacoda/templates/createDevon4ngProject.md +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -4,10 +4,10 @@ <% if(useDevonCommand){ %> Use the ng create command to create a new Angular Project with the name <%= projectName; %>. -`devon ng create <%= projectName; %><% if(optional){ %> <%= optional; %> <% } %>`{{execute T1}} +`devon ng create <%= projectName; %><% if(optional){ %> <%= optional; %><% } %>`{{execute T1}} <% } else { %> Use the ng new command to create a new Angular Project with the name <%= projectName; %>. -`ng new <%= projectName; %><% if(optional){ %> <%= optional; %> <% } %>`{{execute T1}} +`ng new <%= projectName; %><% if(optional){ %> <%= optional; %><% } %>`{{execute T1}} <% } %> <%= textAfter; %> \ No newline at end of file From cf4f17dfbe16ee892855c08f95970842d82c3bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Fri, 12 Mar 2021 13:35:30 +0100 Subject: [PATCH 6/6] Param now a string array --- documentation/Functions.md | 8 ++++---- runners/console/index.ts | 6 +++--- runners/katacoda/index.ts | 5 +++-- runners/katacoda/templates/createDevon4ngProject.md | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 64601d39..1d224b66 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -253,13 +253,13 @@ adaptTemplatesCobiGen() #### parameter 1. Name of the Project. 2. Path to where the Project should be created (relative to workspace). Folder should exist. -3. (Optional) Optional parameters, according to https://angular.io/cli/new . +3. (Optional) String array of parameters, according to https://angular.io/cli/new. #### example -createDevon4ngProject("exampleAngularProject") +createDevon4ngProject("exampleAngularProject", "") Will create the angular project to the current workspace with the name exampleAngularProject. -createDevon4ngProject("exampleAngularProject", "projects") -Will create the angular project to the directory projects within the current workspace. +createDevon4ngProject("exampleAngularProject", "projects", ["--verbose"]) +Will create the angular project to the directory projects within the current workspace and adds more details to output logging. #### Details This command also works if the devonfw IDE is not installed, but then you have to make sure that the Angular cli is installed. diff --git a/runners/console/index.ts b/runners/console/index.ts index 81cd273b..750a4424 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -352,10 +352,10 @@ export class Console extends Runner { result.returnCode = 0; let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1]); - let optional = runCommand.command.parameters.length > 2 ? (" " + runCommand.command.parameters[2]) : ""; + let params = runCommand.command.parameters.length > 2 && (runCommand.command.parameters[2] instanceof Array) ? (" " + runCommand.command.parameters[2].join(" ")) : ""; this.getVariable(this.useDevonCommand) - ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0] + optional, projectDir, result) - : this.executeCommandSync("ng new " + runCommand.command.parameters[0] + optional, projectDir, result); + ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0] + params, projectDir, result) + : this.executeCommandSync("ng new " + runCommand.command.parameters[0] + params, projectDir, result); return result; } diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index d1aadb54..9fb99b22 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -333,10 +333,11 @@ export class Katacoda extends Runner { runCreateDevon4ngProject(runCommand: RunCommand): RunResult { let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1])); - + let params = runCommand.command.parameters.length > 2 && (runCommand.command.parameters[2] instanceof Array) ? runCommand.command.parameters[2].join(" ") : ""; + this.pushStep(runCommand, "Create Angular Project", "step" + this.getStepsCount(runCommand) + ".md"); - this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], optional: runCommand.command.parameters[2], useDevonCommand: this.getVariable(this.useDevonCommand) }); + this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], params: params, useDevonCommand: this.getVariable(this.useDevonCommand) }); return null; } diff --git a/runners/katacoda/templates/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md index 17d64152..d75124eb 100644 --- a/runners/katacoda/templates/createDevon4ngProject.md +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -4,10 +4,10 @@ <% if(useDevonCommand){ %> Use the ng create command to create a new Angular Project with the name <%= projectName; %>. -`devon ng create <%= projectName; %><% if(optional){ %> <%= optional; %><% } %>`{{execute T1}} +`devon ng create <%= projectName; %><% if(params){ %> <%= params; %><% } %>`{{execute T1}} <% } else { %> Use the ng new command to create a new Angular Project with the name <%= projectName; %>. -`ng new <%= projectName; %><% if(optional){ %> <%= optional; %><% } %>`{{execute T1}} +`ng new <%= projectName; %><% if(params){ %> <%= params; %><% } %>`{{execute T1}} <% } %> <%= textAfter; %> \ No newline at end of file