Skip to content

Commit eba3fa3

Browse files
Merge pull request #2 from devonfw-forge/main
Merge with base repo
2 parents f3e9ce4 + 56c138d commit eba3fa3

File tree

4 files changed

+103
-5
lines changed

4 files changed

+103
-5
lines changed

engine/runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RunResult } from "./run_result";
33
import { Playbook } from "./playbook";
44
import { Step } from "./step";
55
import * as fs from 'fs';
6+
import * as rimraf from 'rimraf';
67

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

@@ -101,10 +102,11 @@ export abstract class Runner {
101102
protected createFolder(path: string, deleteFolerIfExist: boolean) {
102103
if(fs.existsSync(path)) {
103104
if(deleteFolerIfExist) {
104-
fs.rmdirSync(path, { recursive: true });
105+
rimraf.sync(path);
105106
fs.mkdirSync(path, { recursive: true });
106107
} else return
107108
}
108109
fs.mkdirSync(path, { recursive: true });
110+
return path;
109111
}
110112
}

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@types/node": "^14.14.2",
88
"ejs": "^3.1.5",
99
"pegjs": "^0.10.0",
10+
"rimraf": "^3.0.2",
1011
"ts-pegjs": "^0.2.7",
1112
"yargs": "^16.1.0"
1213
},

runners/console/index.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,32 @@ 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 * as path from 'path';
7+
import * as child_process from "child_process";
8+
import * as fs from "fs";
69

710
export class Console extends Runner {
811

912
runInstallDevonfwIde(step: Step, command: Command): RunResult {
10-
//TODO
1113
let result = new RunResult();
1214
result.returnCode = 0;
15+
16+
let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true);
17+
this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir, result);
18+
19+
let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim();
20+
let tools = "DEVON_IDE_TOOLS=(" + params + ")";
21+
fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools);
22+
fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git"));
23+
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);
24+
25+
let installDir = path.join(this.getWorkingDirectory(), "devonfw");
26+
this.createFolder(installDir, true);
27+
this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result);
28+
this.executeCommandSync("tar -xf devonfw.tar.gz", installDir, result);
29+
30+
this.executeCommandSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), "", result, "yes");
31+
1332
return result;
1433
}
1534

@@ -18,13 +37,31 @@ export class Console extends Runner {
1837
}
1938

2039
async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) {
21-
console.log("assertInstallDevonfwIde");
22-
new Assertions()
40+
let installedTools = command.parameters.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(",");
41+
42+
let assert = new Assertions()
2343
.noErrorCode(result)
24-
.noException(result);
44+
.noException(result)
45+
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software"))
46+
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"));
47+
48+
for(let i = 0; i < installedTools.length; i++) {
49+
assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", installedTools[i]));
50+
}
2551
}
2652

2753
async assertInstallCobiGen(step: Step, command: Command, result: RunResult) {
2854
console.log("assertInstallCobiGen");
2955
}
56+
57+
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
58+
if(result.returnCode != 0) return;
59+
60+
let process = child_process.spawnSync("cd " + path.join(directory) + " && " + command, { shell: true, input: input });
61+
if(process.status != 0) {
62+
console.log("Error executing command: " + command + " (exit code: " + process.status + ")");
63+
console.log(process.stderr.toString(), process.stdout.toString());
64+
result.returnCode = process.status;
65+
}
66+
}
3067
}

0 commit comments

Comments
 (0)