Skip to content

Commit 0f95870

Browse files
Merge pull request #141 from MarcelDiessner/feature/createNgProject
feature/createNgProject
2 parents 0ca3a88 + cf4f17d commit 0f95870

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

documentation/Functions.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The following functions are already implemented:
1717
* downloadFile
1818
* nextKatacodaStep
1919
* adaptTemplatesCobiGen
20+
* createDevon4ngProject
2021

2122
***
2223

@@ -240,11 +241,27 @@ image: Path to an image to be displayed in the katacoda step.
240241

241242
***
242243

243-
244244
### adaptTemplatesCobiGen
245245
#### parameter
246246
* No parameters
247247
#### example
248248
adaptTemplatesCobiGen()
249249

250250
***
251+
252+
### createDevon4ngProject
253+
#### parameter
254+
1. Name of the Project.
255+
2. Path to where the Project should be created (relative to workspace). Folder should exist.
256+
3. (Optional) String array of parameters, according to https://angular.io/cli/new.
257+
#### example
258+
createDevon4ngProject("exampleAngularProject", "")
259+
Will create the angular project to the current workspace with the name exampleAngularProject.
260+
261+
createDevon4ngProject("exampleAngularProject", "projects", ["--verbose"])
262+
Will create the angular project to the directory projects within the current workspace and adds more details to output logging.
263+
264+
#### Details
265+
This command also works if the devonfw IDE is not installed, but then you have to make sure that the Angular cli is installed.
266+
267+
***

runners/console/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,19 @@ export class Console extends Runner {
347347
return result;
348348
}
349349

350+
runCreateDevon4ngProject(runCommand: RunCommand): RunResult {
351+
let result = new RunResult();
352+
result.returnCode = 0;
353+
354+
let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1]);
355+
let params = runCommand.command.parameters.length > 2 && (runCommand.command.parameters[2] instanceof Array) ? (" " + runCommand.command.parameters[2].join(" ")) : "";
356+
this.getVariable(this.useDevonCommand)
357+
? this.executeDevonCommandSync("ng create " + runCommand.command.parameters[0] + params, projectDir, result)
358+
: this.executeCommandSync("ng new " + runCommand.command.parameters[0] + params, projectDir, result);
359+
360+
return result;
361+
}
362+
350363
async assertInstallDevonfwIde(runCommand: RunCommand, result: RunResult) {
351364
try {
352365
let installedTools = runCommand.command.parameters[0];
@@ -659,6 +672,20 @@ export class Console extends Runner {
659672
}
660673
}
661674

675+
async assertCreateDevon4ngProject(runCommand: RunCommand, result: RunResult) {
676+
try {
677+
let projectDir = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1], runCommand.command.parameters[0]);
678+
new Assertions()
679+
.noErrorCode(result)
680+
.noException(result)
681+
.directoryExits(projectDir)
682+
.directoryNotEmpty(projectDir);
683+
} catch(error) {
684+
this.cleanUp();
685+
throw error;
686+
}
687+
}
688+
662689
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
663690
if(result.returnCode != 0) return;
664691

runners/katacoda/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ export class Katacoda extends Runner {
329329

330330
}
331331

332+
runCreateDevon4ngProject(runCommand: RunCommand): RunResult {
333+
let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[1]));
334+
let params = runCommand.command.parameters.length > 2 && (runCommand.command.parameters[2] instanceof Array) ? runCommand.command.parameters[2].join(" ") : "";
335+
336+
this.pushStep(runCommand, "Create Angular Project", "step" + this.getStepsCount(runCommand) + ".md");
337+
338+
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) });
339+
return null;
340+
}
341+
332342
private renderTemplate(name: string, targetPath: string, variables) {
333343
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8');
334344
let result = ejs.render(template, variables);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%= text; %>
2+
3+
<%= cdCommand; %>
4+
5+
<% if(useDevonCommand){ %>
6+
Use the ng create command to create a new Angular Project with the name <%= projectName; %>.
7+
`devon ng create <%= projectName; %><% if(params){ %> <%= params; %><% } %>`{{execute T1}}
8+
<% } else { %>
9+
Use the ng new command to create a new Angular Project with the name <%= projectName; %>.
10+
`ng new <%= projectName; %><% if(params){ %> <%= params; %><% } %>`{{execute T1}}
11+
<% } %>
12+
13+
<%= textAfter; %>

0 commit comments

Comments
 (0)