Skip to content
9 changes: 9 additions & 0 deletions documentation/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following functions are already implemented:
* dockerCompose
* downloadFile
* nextKatacodaStep
* adaptTemplatesCobiGen

***

Expand Down Expand Up @@ -231,3 +232,11 @@ image: Path to an image to be displayed in the katacoda step.

***


### adaptTemplatesCobiGen
#### parameter
* No parameters
#### example
adaptTemplatesCobiGen()

***
26 changes: 26 additions & 0 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions runners/katacoda/templates/adaptTemplatesCobiGen.md
Original file line number Diff line number Diff line change
@@ -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; %>