diff --git a/runners/console/consoleInterfaces.ts b/runners/console/consoleInterfaces.ts new file mode 100644 index 00000000..9f2076ba --- /dev/null +++ b/runners/console/consoleInterfaces.ts @@ -0,0 +1,4 @@ +export enum ConsolePlatform { + WINDOWS, + LINUX +} \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index a63478fa..540222b0 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -3,12 +3,24 @@ import { RunResult } from "../../engine/run_result"; import { Step } from "../../engine/step"; import { Command } from "../../engine/command"; import { Assertions } from "../../assertions"; +import { Playbook } from "../../engine/playbook"; +import { ConsolePlatform } from "./consoleInterfaces"; import * as path from 'path'; import * as child_process from "child_process"; import * as fs from "fs"; export class Console extends Runner { + private platform: ConsolePlatform; + + init(playbook: Playbook): void { + if(process.platform=="win32") { + this.platform = ConsolePlatform.WINDOWS; + } else { + this.platform = ConsolePlatform.LINUX; + } + } + runInstallDevonfwIde(step: Step, command: Command): RunResult { let result = new RunResult(); result.returnCode = 0; @@ -23,16 +35,29 @@ export class Console extends Runner { let installDir = path.join(this.getWorkingDirectory(), "devonfw"); this.createFolder(installDir, true); - this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result); - this.executeCommandSync("tar -xf devonfw.tar.gz", installDir, result); - - this.executeCommandSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), "", result, "yes"); - + + if(this.platform == ConsolePlatform.WINDOWS) { + this.executeCommandSync("powershell.exe Invoke-WebRequest -OutFile devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result); + this.executeCommandSync("powershell.exe tar -xvzf devonfw.tar.gz", installDir, result); + this.executeCommandSync("powershell.exe ./setup " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), installDir, result, "yes"); + } else { + this.executeCommandSync("wget -c https://bit.ly/2BCkFa9 -O - | tar -xz", installDir, result); + this.executeCommandSync("bash setup " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), installDir, result, "yes"); + } + return result; } runInstallCobiGen(step: Step, command: Command): RunResult { - return null; + let result = new RunResult(); + result.returnCode = 0; + + if(this.platform == ConsolePlatform.WINDOWS) { + this.executeCommandSync("devon cobigen", path.join(this.getWorkingDirectory(), "devonfw"), result); + } else { + this.executeCommandSync("~/.devon/devon cobigen", path.join(this.getWorkingDirectory(), "devonfw"), result); + } + return result; } runCobiGenJava(step: Step, command: Command): RunResult { @@ -55,7 +80,12 @@ export class Console extends Runner { } async assertInstallCobiGen(step: Step, command: Command, result: RunResult) { - console.log("assertInstallCobiGen"); + let assert = new Assertions() + .noErrorCode(result) + .noException(result) + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli")) + .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen.jar")) + .fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen")); } async assertCobiGenJava(step: Step, command: Command, result: RunResult) { @@ -65,7 +95,7 @@ export class Console extends Runner { private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { if(result.returnCode != 0) return; - let process = child_process.spawnSync("cd " + path.join(directory) + " && " + command, { shell: true, input: input }); + let process = child_process.spawnSync(command, { shell: true, cwd: directory, input: input }); if(process.status != 0) { console.log("Error executing command: " + command + " (exit code: " + process.status + ")"); console.log(process.stderr.toString(), process.stdout.toString());