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
4 changes: 3 additions & 1 deletion engine/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RunResult } from "./run_result";
import { Playbook } from "./playbook";
import { Step } from "./step";
import * as fs from 'fs';
import * as rimraf from 'rimraf';

const nameof = <T>(name: Extract<keyof T, string>): string => name;

Expand Down Expand Up @@ -101,10 +102,11 @@ export abstract class Runner {
protected createFolder(path: string, deleteFolerIfExist: boolean) {
if(fs.existsSync(path)) {
if(deleteFolerIfExist) {
fs.rmdirSync(path, { recursive: true });
rimraf.sync(path);
fs.mkdirSync(path, { recursive: true });
} else return
}
fs.mkdirSync(path, { recursive: true });
return path;
}
}
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@types/node": "^14.14.2",
"ejs": "^3.1.5",
"pegjs": "^0.10.0",
"rimraf": "^3.0.2",
"ts-pegjs": "^0.2.7",
"yargs": "^16.1.0"
},
Expand Down
45 changes: 41 additions & 4 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@ import { RunResult } from "../../engine/run_result";
import { Step } from "../../engine/step";
import { Command } from "../../engine/command";
import { Assertions } from "../../assertions";
import * as path from 'path';
import * as child_process from "child_process";
import * as fs from "fs";

export class Console extends Runner {

runInstallDevonfwIde(step: Step, command: Command): RunResult {
//TODO
let result = new RunResult();
result.returnCode = 0;

let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true);
this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir, result);

let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim();
let tools = "DEVON_IDE_TOOLS=(" + params + ")";
fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools);
fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git"));
this.executeCommandSync("git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\"", path.join(settingsDir, "settings.git"), result);

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");

return result;
}

Expand All @@ -18,13 +37,31 @@ export class Console extends Runner {
}

async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) {
console.log("assertInstallDevonfwIde");
new Assertions()
let installedTools = command.parameters.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(",");

let assert = new Assertions()
.noErrorCode(result)
.noException(result);
.noException(result)
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software"))
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"));

for(let i = 0; i < installedTools.length; i++) {
assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", installedTools[i]));
}
}

async assertInstallCobiGen(step: Step, command: Command, result: RunResult) {
console.log("assertInstallCobiGen");
}

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 });
if(process.status != 0) {
console.log("Error executing command: " + command + " (exit code: " + process.status + ")");
console.log(process.stderr.toString(), process.stdout.toString());
result.returnCode = process.status;
}
}
}