diff --git a/documentation/Functions.md b/documentation/Functions.md index 8c45855a..79a7a30c 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -16,6 +16,7 @@ The following functions are already implemented: * dockerCompose * downloadFile * nextKatacodaStep +* adaptTemplatesCobiGen *** @@ -231,3 +232,11 @@ image: Path to an image to be displayed in the katacoda step. *** + +### adaptTemplatesCobiGen +#### parameter +* No parameters +#### example +adaptTemplatesCobiGen() + +*** diff --git a/runners/console/index.ts b/runners/console/index.ts index e2ea2275..29a9c88b 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -332,6 +332,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]; @@ -624,6 +635,21 @@ export class Console extends Runner { } } + async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) { + try { + let templatesDir = path.join(os.homedir(), ".cobigen", "templates"); + new Assertions() + .noErrorCode(result) + .noException(result) + .directoryExits(templatesDir) + .directoryNotEmpty(templatesDir); + + } 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 44a14247..426387cc 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -343,6 +343,16 @@ export class Katacoda extends Runner { return null; } + + runAdaptTemplatesCobiGen(step: Step, command: Command): RunResult { + this.steps.push({ + "title": "Adapt cobiGen templates", + "text": "step" + this.stepsCount + ".md" + }); + this.renderTemplate("adaptTemplatesCobiGen.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter}); + return null; + } + runDockerCompose(step: Step, command: Command) : RunResult { let terminal = this.getTerminal('runDockerCompose'); let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), command.parameters[0]), terminal.terminalId, terminal.isRunning); @@ -354,6 +364,7 @@ export class Katacoda extends Runner { this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: command.parameters[1].port}); return null; + } private renderTemplate(name: string, targetPath: string, variables) { diff --git a/runners/katacoda/templates/adaptTemplatesCobiGen.md b/runners/katacoda/templates/adaptTemplatesCobiGen.md new file mode 100644 index 00000000..8065a038 --- /dev/null +++ b/runners/katacoda/templates/adaptTemplatesCobiGen.md @@ -0,0 +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}} + + +<%= textAfter; %> \ No newline at end of file