Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion documentation/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The following functions are already implemented:
* downloadFile
* nextKatacodaStep
* adaptTemplatesCobiGen
* createDevon4ngProject

***

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

***


### adaptTemplatesCobiGen
#### parameter
* No parameters
#### example
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.

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

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