From 0344a3f141d9455e3635cd225c2954d3bfa4331f Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 12 Feb 2021 16:14:13 +0100 Subject: [PATCH 1/8] feature/katacodaAdaptCobigenTemplates --- documentation/Functions.md | 11 +++++++++++ runners/katacoda/index.ts | 10 ++++++++++ runners/katacoda/templates/adaptCobiGenTemplates.md | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 runners/katacoda/templates/adaptCobiGenTemplates.md diff --git a/documentation/Functions.md b/documentation/Functions.md index 87a18bd3..4fee20d7 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -15,6 +15,7 @@ The following functions are already implemented: * npmInstall * downloadFile * nextKatacodaStep +* adaptCobiGenTemplates *** @@ -214,3 +215,13 @@ content: Plain text to be displayed in the katacoda step. image: Path to an image to be displayed in the katacoda step. *** + +### adaptCobiGenTemplates +#### parameter +* No parameters +#### example +adaptCobiGenTemplates() + +*** + + diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 050273fe..73d10ca4 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -338,6 +338,16 @@ export class Katacoda extends Runner { return null; } + runAdaptCobiGenTemplates(step: Step, command: Command): RunResult { + this.steps.push({ + "title": "Adapt cobiGen templates", + "text": "step" + this.stepsCount + ".md" + }); + this.renderTemplate("adaptCobiGenTemplates.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter}); + 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/adaptCobiGenTemplates.md b/runners/katacoda/templates/adaptCobiGenTemplates.md new file mode 100644 index 00000000..009582cb --- /dev/null +++ b/runners/katacoda/templates/adaptCobiGenTemplates.md @@ -0,0 +1,8 @@ +<%= text; %> + +`devon cobigen adapt-templates`{{execute T1}} + +Run the cobiGen command 'adapt-templates' to generate a new templates folder and save its location in a configuration file. +The cobiGen CLI will use the specified templates folder later to generate the needed codes. + +<%= textAfter; %> \ No newline at end of file From 7b897131752a7a6447bb7bea40b3e7d5b9030762 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 12 Feb 2021 16:48:27 +0100 Subject: [PATCH 2/8] feature/consoleAdaptCobigenTemplates --- runners/console/index.ts | 25 +++++++++++++++++++ runners/katacoda/index.ts | 4 +-- ...nTemplates.md => adaptTemplatesCobiGen.md} | 0 3 files changed, 27 insertions(+), 2 deletions(-) rename runners/katacoda/templates/{adaptCobiGenTemplates.md => adaptTemplatesCobiGen.md} (100%) diff --git a/runners/console/index.ts b/runners/console/index.ts index 2a9d2e87..1b50062f 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -309,6 +309,17 @@ export class Console extends Runner { return null; } + runAdaptTemplatesCobiGen(step: Step, command: Command): RunResult { + let result = new RunResult(); + result.returnCode = 0; + + if(!this.getVariable(this.useDevonCommand)){ + console.warn("Devonfw IDE is not installed"); + } + this.executeDevonCommandSync("cobigen adapt-templates",path.join(this.getWorkingDirectory(), "devonfw"), result); + return result; + } + async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { try { let installedTools = command.parameters[0]; @@ -571,6 +582,20 @@ export class Console extends Runner { } } + async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) { + try { + new Assertions() + .noErrorCode(result) + .noException(result) + .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cg")) + .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "class-loader-agent.jar")); + + } 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 73d10ca4..173c937e 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -338,12 +338,12 @@ export class Katacoda extends Runner { return null; } - runAdaptCobiGenTemplates(step: Step, command: Command): RunResult { + runAdaptTemplatesCobiGen(step: Step, command: Command): RunResult { this.steps.push({ "title": "Adapt cobiGen templates", "text": "step" + this.stepsCount + ".md" }); - this.renderTemplate("adaptCobiGenTemplates.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter}); + this.renderTemplate("adaptTemplatesCobiGen.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter}); return null; } diff --git a/runners/katacoda/templates/adaptCobiGenTemplates.md b/runners/katacoda/templates/adaptTemplatesCobiGen.md similarity index 100% rename from runners/katacoda/templates/adaptCobiGenTemplates.md rename to runners/katacoda/templates/adaptTemplatesCobiGen.md From e7898e4d0d8d2f1f4fabc0727f41c3765b7c4ba5 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 15 Feb 2021 09:21:43 +0100 Subject: [PATCH 3/8] changed Name --- documentation/Functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 4fee20d7..4020ef03 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -216,11 +216,11 @@ image: Path to an image to be displayed in the katacoda step. *** -### adaptCobiGenTemplates +### adaptTemplatesCobiGen #### parameter * No parameters #### example -adaptCobiGenTemplates() +adaptTemplatesCobiGen() *** From 66003e2246d4aecea02f1075e6f18dccd1f64ad2 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 15 Feb 2021 15:00:19 +0100 Subject: [PATCH 4/8] new description --- runners/katacoda/templates/adaptTemplatesCobiGen.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/katacoda/templates/adaptTemplatesCobiGen.md b/runners/katacoda/templates/adaptTemplatesCobiGen.md index 009582cb..8065a038 100644 --- a/runners/katacoda/templates/adaptTemplatesCobiGen.md +++ b/runners/katacoda/templates/adaptTemplatesCobiGen.md @@ -1,8 +1,8 @@ <%= text; %> +Run the cobiGen command 'adapt-templates' to generate a new templates folder and save its location in a configuration file. + `devon cobigen adapt-templates`{{execute T1}} -Run the cobiGen command 'adapt-templates' to generate a new templates folder and save its location in a configuration file. -The cobiGen CLI will use the specified templates folder later to generate the needed codes. <%= textAfter; %> \ No newline at end of file From 7cd719c35f50d4bf0393e175db3b22b6a29f9635 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 15 Feb 2021 15:10:26 +0100 Subject: [PATCH 5/8] typo --- documentation/Functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 5529ec3f..79a7a30c 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -16,7 +16,7 @@ The following functions are already implemented: * dockerCompose * downloadFile * nextKatacodaStep -* adaptCobiGenTemplates +* adaptTemplatesCobiGen *** From bb9cdcf17e9fb02e49993f93e70d667f70c5f547 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 15 Feb 2021 16:18:31 +0100 Subject: [PATCH 6/8] changed assertions --- runners/console/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 7bd7a2bc..ff223eb3 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -637,11 +637,11 @@ export class Console extends Runner { async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) { try { + let homedir = os.homedir(); new Assertions() .noErrorCode(result) .noException(result) - .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cg")) - .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "class-loader-agent.jar")); + .directoryExits(path.join(homedir, ".cobigen", "templates")); } catch(error) { this.cleanUp(); From 870a61d1c4722d45b0ebc85c2d47c06d2f6fedbb Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Tue, 16 Feb 2021 08:25:30 +0100 Subject: [PATCH 7/8] added directoryNotEmpty assertion --- runners/console/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index ff223eb3..477d26f8 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -637,11 +637,12 @@ export class Console extends Runner { async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) { try { - let homedir = os.homedir(); + let templateDir = path.join(os.homedir(), ".cobigen", "templates"); new Assertions() .noErrorCode(result) .noException(result) - .directoryExits(path.join(homedir, ".cobigen", "templates")); + .directoryExits(templateDir) + .directoryNotEmpty(templateDir); } catch(error) { this.cleanUp(); From b9d26fac321350e447c4294d3fcaeaf5be1603eb Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Tue, 16 Feb 2021 08:26:28 +0100 Subject: [PATCH 8/8] rename variable --- runners/console/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 477d26f8..29a9c88b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -637,12 +637,12 @@ export class Console extends Runner { async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) { try { - let templateDir = path.join(os.homedir(), ".cobigen", "templates"); + let templatesDir = path.join(os.homedir(), ".cobigen", "templates"); new Assertions() .noErrorCode(result) .noException(result) - .directoryExits(templateDir) - .directoryNotEmpty(templateDir); + .directoryExits(templatesDir) + .directoryNotEmpty(templatesDir); } catch(error) { this.cleanUp();