diff --git a/documentation/Functions.md b/documentation/Functions.md index a70cc0af..1d224b66 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -17,6 +17,7 @@ The following functions are already implemented: * downloadFile * nextKatacodaStep * adaptTemplatesCobiGen +* createDevon4ngProject *** @@ -240,7 +241,6 @@ image: Path to an image to be displayed in the katacoda step. *** - ### adaptTemplatesCobiGen #### parameter * No parameters @@ -248,3 +248,20 @@ image: Path to an image to be displayed in the katacoda step. adaptTemplatesCobiGen() *** + +### createDevon4ngProject +#### parameter +1. Name of the Project. +2. Path to where the Project should be created (relative to workspace). Folder should exist. +3. (Optional) String array of parameters, according to https://angular.io/cli/new. +#### example +createDevon4ngProject("exampleAngularProject", "") +Will create the angular project to the current workspace with the name exampleAngularProject. + +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. + +*** \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index 30b9656b..750a4424 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -347,6 +347,19 @@ export class Console extends Runner { return result; } + runCreateDevon4ngProject(runCommand: RunCommand): RunResult { + let result = new RunResult(); + result.returnCode = 0; + + let projectDir = 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.getVariable(this.useDevonCommand) + ? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0] + params, projectDir, result) + : this.executeCommandSync("ng new " + runCommand.command.parameters[0] + params, projectDir, result); + + return result; + } + async assertInstallDevonfwIde(runCommand: RunCommand, result: RunResult) { try { let installedTools = runCommand.command.parameters[0]; @@ -659,6 +672,20 @@ export class Console extends Runner { } } + async assertCreateDevon4ngProject(runCommand: RunCommand, result: RunResult) { + try { + let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1], 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..9fb99b22 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -331,6 +331,16 @@ 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], params: params, 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/createDevon4ngProject.md b/runners/katacoda/templates/createDevon4ngProject.md new file mode 100644 index 00000000..d75124eb --- /dev/null +++ b/runners/katacoda/templates/createDevon4ngProject.md @@ -0,0 +1,13 @@ +<%= text; %> + +<%= cdCommand; %> + +<% if(useDevonCommand){ %> +Use the ng create command to create a new Angular Project with the name <%= projectName; %>. +`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(params){ %> <%= params; %><% } %>`{{execute T1}} +<% } %> + +<%= textAfter; %> \ No newline at end of file