Skip to content

Commit 4628865

Browse files
Merge pull request #36 from GuentherJulian/feature/consoleInstallCobiGen
WIP: feature/consoleInstallCobiGen
2 parents 08f6c83 + 8611be0 commit 4628865

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum ConsolePlatform {
2+
WINDOWS,
3+
LINUX
4+
}

runners/console/index.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ import { RunResult } from "../../engine/run_result";
33
import { Step } from "../../engine/step";
44
import { Command } from "../../engine/command";
55
import { Assertions } from "../../assertions";
6+
import { Playbook } from "../../engine/playbook";
7+
import { ConsolePlatform } from "./consoleInterfaces";
68
import * as path from 'path';
79
import * as child_process from "child_process";
810
import * as fs from "fs";
911

1012
export class Console extends Runner {
1113

14+
private platform: ConsolePlatform;
15+
16+
init(playbook: Playbook): void {
17+
if(process.platform=="win32") {
18+
this.platform = ConsolePlatform.WINDOWS;
19+
} else {
20+
this.platform = ConsolePlatform.LINUX;
21+
}
22+
}
23+
1224
runInstallDevonfwIde(step: Step, command: Command): RunResult {
1325
let result = new RunResult();
1426
result.returnCode = 0;
@@ -23,16 +35,29 @@ export class Console extends Runner {
2335

2436
let installDir = path.join(this.getWorkingDirectory(), "devonfw");
2537
this.createFolder(installDir, true);
26-
this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result);
27-
this.executeCommandSync("tar -xf devonfw.tar.gz", installDir, result);
28-
29-
this.executeCommandSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), "", result, "yes");
30-
38+
39+
if(this.platform == ConsolePlatform.WINDOWS) {
40+
this.executeCommandSync("powershell.exe Invoke-WebRequest -OutFile devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result);
41+
this.executeCommandSync("powershell.exe tar -xvzf devonfw.tar.gz", installDir, result);
42+
this.executeCommandSync("powershell.exe ./setup " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), installDir, result, "yes");
43+
} else {
44+
this.executeCommandSync("wget -c https://bit.ly/2BCkFa9 -O - | tar -xz", installDir, result);
45+
this.executeCommandSync("bash setup " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), installDir, result, "yes");
46+
}
47+
3148
return result;
3249
}
3350

3451
runInstallCobiGen(step: Step, command: Command): RunResult {
35-
return null;
52+
let result = new RunResult();
53+
result.returnCode = 0;
54+
55+
if(this.platform == ConsolePlatform.WINDOWS) {
56+
this.executeCommandSync("devon cobigen", path.join(this.getWorkingDirectory(), "devonfw"), result);
57+
} else {
58+
this.executeCommandSync("~/.devon/devon cobigen", path.join(this.getWorkingDirectory(), "devonfw"), result);
59+
}
60+
return result;
3661
}
3762

3863
runCobiGenJava(step: Step, command: Command): RunResult {
@@ -55,7 +80,12 @@ export class Console extends Runner {
5580
}
5681

5782
async assertInstallCobiGen(step: Step, command: Command, result: RunResult) {
58-
console.log("assertInstallCobiGen");
83+
let assert = new Assertions()
84+
.noErrorCode(result)
85+
.noException(result)
86+
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli"))
87+
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen.jar"))
88+
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen"));
5989
}
6090

6191
async assertCobiGenJava(step: Step, command: Command, result: RunResult) {
@@ -65,7 +95,7 @@ export class Console extends Runner {
6595
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
6696
if(result.returnCode != 0) return;
6797

68-
let process = child_process.spawnSync("cd " + path.join(directory) + " && " + command, { shell: true, input: input });
98+
let process = child_process.spawnSync(command, { shell: true, cwd: directory, input: input });
6999
if(process.status != 0) {
70100
console.log("Error executing command: " + command + " (exit code: " + process.status + ")");
71101
console.log(process.stderr.toString(), process.stdout.toString());

0 commit comments

Comments
 (0)