Skip to content

Commit 8d5c92e

Browse files
authored
Merge pull request #121 from denise-khuu/feature/adaptCobiGenTemplates
feature/adaptTemplatesCobiGen
2 parents 09968a0 + b9d26fa commit 8d5c92e

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

documentation/Functions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The following functions are already implemented:
1616
* dockerCompose
1717
* downloadFile
1818
* nextKatacodaStep
19+
* adaptTemplatesCobiGen
1920

2021
***
2122

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

232233
***
233234

235+
236+
### adaptTemplatesCobiGen
237+
#### parameter
238+
* No parameters
239+
#### example
240+
adaptTemplatesCobiGen()
241+
242+
***

runners/console/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ export class Console extends Runner {
332332
return null;
333333
}
334334

335+
runAdaptTemplatesCobiGen(step: Step, command: Command): RunResult {
336+
let result = new RunResult();
337+
result.returnCode = 0;
338+
339+
if(!this.getVariable(this.useDevonCommand)){
340+
console.warn("Devonfw IDE is not installed");
341+
}
342+
this.executeDevonCommandSync("cobigen adapt-templates",path.join(this.getWorkingDirectory(), "devonfw"), result);
343+
return result;
344+
}
345+
335346
async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) {
336347
try {
337348
let installedTools = command.parameters[0];
@@ -624,6 +635,21 @@ export class Console extends Runner {
624635
}
625636
}
626637

638+
async assertAdaptTemplatesCobiGen(step: Step, command: Command, result: RunResult) {
639+
try {
640+
let templatesDir = path.join(os.homedir(), ".cobigen", "templates");
641+
new Assertions()
642+
.noErrorCode(result)
643+
.noException(result)
644+
.directoryExits(templatesDir)
645+
.directoryNotEmpty(templatesDir);
646+
647+
} catch(error) {
648+
this.cleanUp();
649+
throw error;
650+
}
651+
}
652+
627653
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
628654
if(result.returnCode != 0) return;
629655

runners/katacoda/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@ export class Katacoda extends Runner {
343343
return null;
344344
}
345345

346+
347+
runAdaptTemplatesCobiGen(step: Step, command: Command): RunResult {
348+
this.steps.push({
349+
"title": "Adapt cobiGen templates",
350+
"text": "step" + this.stepsCount + ".md"
351+
});
352+
this.renderTemplate("adaptTemplatesCobiGen.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter});
353+
return null;
354+
}
355+
346356
runDockerCompose(step: Step, command: Command) : RunResult {
347357
let terminal = this.getTerminal('runDockerCompose');
348358
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 {
354364

355365
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});
356366
return null;
367+
357368
}
358369

359370
private renderTemplate(name: string, targetPath: string, variables) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= text; %>
2+
3+
Run the cobiGen command 'adapt-templates' to generate a new templates folder and save its location in a configuration file.
4+
5+
`devon cobigen adapt-templates`{{execute T1}}
6+
7+
8+
<%= textAfter; %>

0 commit comments

Comments
 (0)