Skip to content

Commit

Permalink
devonfw-tutorials#183 wikiRunner/createDevon4ngProject
Browse files Browse the repository at this point in the history
  • Loading branch information
derochs committed May 13, 2021
1 parent 48340c3 commit 973ece8
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 2 deletions.
108 changes: 106 additions & 2 deletions runners/wikiConsole/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,119 @@ export class WikiConsole extends WikiRunner {

init(playbook: Playbook): void {
super.init(playbook);
this.setVariable(this.workspaceDirectory, path.join(this.getWorkingDirectory()));
}

async destroy(playbook: Playbook): Promise<void> {
if(playbook.conclusion) {
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "conclusion.asciidoc"), { conclusion: playbook.conclusion});
}
super.destroy(playbook);
}

runInstallDevonfwIde(runCommand: RunCommand): RunResult {
let tools = runCommand.command.parameters[0].join(" ");
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installDevonfwIde.asciidoc"), { tools: tools })
let version = "";
if(runCommand.command.parameters.length == 2) {
version = runCommand.command.parameters[1];
}
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "installDevonfwIde.asciidoc"), { tools: tools, version:version })
this.setVariable(this.workspaceDirectory, path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"));
return null;
}
}


runChangeFile(runCommand: RunCommand): RunResult{
let workspacePath = this.getVariable(this.workspaceDirectory).replace(/\\/g, "/");
let filePath = path.join(workspacePath,runCommand.command.parameters[0]);
let fileName = path.basename(runCommand.command.parameters[0]);
let contentPath, contentString;
if(runCommand.command.parameters[1].fileConsole || runCommand.command.parameters[1].contentConsole){
contentPath = runCommand.command.parameters[1].fileConsole;
contentString = runCommand.command.parameters[1].contentConsole;
}else{
contentPath = runCommand.command.parameters[1].file;
contentString = runCommand.command.parameters[1].content;
}
contentPath = contentPath
? path.join(this.getPlaybookPath(), contentPath)
: undefined;
let contentFile = contentPath
? path.basename(contentPath)
: undefined;
let placeholder = runCommand.command.parameters[1].placeholder;
let lineNumber = runCommand.command.parameters[1].lineNumber;

this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "changeFile.asciidoc"), {filePath : filePath,
contentPath: contentPath, contentString: contentString, placeholder: placeholder, lineNumber: lineNumber, fileName: fileName, contentFile: contentFile});
return null;
}


runRunServerJava(runCommand: RunCommand): RunResult {
let server_path = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "runServerJava.asciidoc"), { server_path: server_path, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path })
return null;
}

runNpmInstall(runCommand: RunCommand): RunResult {
let projectPath = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
let npmCommand = {
"name": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].name) ? runCommand.command.parameters[1].name : undefined,
"global": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].global) ? runCommand.command.parameters[1].global : false,
"args": (runCommand.command.parameters.length > 1 && runCommand.command.parameters[1].args) ? runCommand.command.parameters[1].args.join(" ") : undefined
};

this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "npmInstall.asciidoc"), { projectPath: projectPath, npmCommand: npmCommand });
return null;
}

runCloneRepository(runCommand: RunCommand): RunResult {
let directoryPath = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "cloneRepository.asciidoc"), { directoryPath: directoryPath, url: runCommand.command.parameters[1] });
return null;
}

runDownloadFile(runCommand: RunCommand): RunResult{
let url = runCommand.command.parameters[0];
let fileName = runCommand.command.parameters[1];
let dir = runCommand.command.parameters[2];
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "downloadFile.asciidoc"), {url: url, dir: dir, fileName: fileName});

return null;
}

runBuildNg(runCommand: RunCommand): RunResult {
let angularPath = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
let outputPath = runCommand.command.parameters.length < 1 ? runCommand.command.parameters[1] : "";
this.renderWiki(path.join(this.getRunnerDirectory(), "template", "buildNg.asciidoc"), {angularPath: angularPath, outputPath: outputPath});

return null;
}

runDockerCompose(runCommand: RunCommand): RunResult {
let dir = runCommand.command.parameters[0];
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "dockerCompose.asciidoc"), { dir: dir, port: runCommand.command.parameters[1].port, app_path: runCommand.command.parameters[1].path })
return null;
}

runCreateFolder(runCommand: RunCommand): RunResult {
let folderPath = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createFolder.asciidoc"), { folderPath: folderPath });
return null;
}

runBuildJava(runCommand: RunCommand): RunResult {
let directoryPath = path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]);
let skipTest = (runCommand.command.parameters.length == 2 && runCommand.command.parameters[1] == true) ? false : true;
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "buildJava.asciidoc"), { directoryPath: directoryPath, skipTest: skipTest });
return null;
}

runCreateDevon4ngProject(runCommand: RunCommand): RunResult {
let cdCommand = runCommand.command.parameters[1];
let ngParams = runCommand.command.parameters.length > 2 && (runCommand.command.parameters[2] instanceof Array) ? runCommand.command.parameters[2].join(" ") : "";
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "createDevon4ngProject.asciidoc"), {cdCommand: cdCommand, projectName: runCommand.command.parameters[0], ngParams: ngParams})
return null;
}
}
15 changes: 15 additions & 0 deletions runners/wikiConsole/templates/createDevon4ngProject.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
== Create devon4ng project

<% if (cdCommand) { %>

=== Prerequisites

As the project should be created at `<%= cdCommand; %>`, make sure that this directory exists before proceeding with the next step.

<% } %>

=== Creating the Angular project

Use the `ng` command provided by the `devonfw-ide` to create the project <%= projectName; %>:

`devon ng create <%= projectName; %><% if(ngParams){ %><%= ngParams; %><% } %>`

0 comments on commit 973ece8

Please sign in to comment.