Skip to content

Commit 5479938

Browse files
Merge remote-tracking branch 'UPSTREAM/main' into feature/katacodaDockerCompose
# Conflicts: # documentation/Functions.md
2 parents ec9b8a6 + bf68d8a commit 5479938

29 files changed

+1322
-164
lines changed

assertions/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { DirectoryExist } from "./directoryExist";
77
import { FileExist } from "./fileExist";
88
import { DirectoryNotEmpty } from "./directoryNotEmpty";
99
import { FileContains } from "./fileContains";
10+
import { ServerIsReachable } from "./serverIsReachable";
11+
import { RepositoryIsClean } from "./repositoryIsClean";
1012

1113

1214
export class Assertions {
@@ -40,4 +42,13 @@ export class Assertions {
4042
FileContains.run(filepath, content);
4143
return this;
4244
}
45+
46+
public serverIsReachable(port: number, path: string): Promise<boolean> {
47+
return ServerIsReachable.run(port, path);
48+
}
49+
50+
public repositoryIsClean(directory: string): Assertions {
51+
RepositoryIsClean.run(directory);
52+
return this;
53+
}
4354
}

assertions/repositoryIsClean.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as child_process from "child_process";
2+
3+
export class RepositoryIsClean {
4+
public static run(directory: string): void {
5+
let process = child_process.spawnSync("git status -s", { shell: true, cwd: directory });
6+
if(process.status != 0) {
7+
throw new Error("'git status -s' execution in directory " + directory + " returned error.")
8+
} else if(process.stdout.toString()) {
9+
throw new Error("Repository in directory " + directory + " is not clean. Current Status: " + process.stdout.toString());
10+
}
11+
}
12+
}

assertions/serverIsReachable.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as isReachable from "is-reachable";
2+
3+
export class ServerIsReachable {
4+
public static run(port: number, path: string): Promise<boolean> {
5+
return isReachable("http://localhost:" + port + "/" + path);
6+
}
7+
}

documentation/Functions.md

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
## Functions
22
The following functions are already implemented:
3-
* installDevonIde
3+
* installDevonfwIde
4+
* restoreDevonfwIde
45
* installCobiGen
56
* cobiGenJava
67
* createDevon4jProject
78
* buildJava
89
* createFile
9-
* dockerCompose
10+
* changeFile
11+
* createFolder
12+
* cloneRepository
13+
* runServerJava
14+
* buildNg
15+
* npmInstall
16+
* downloadFile
17+
* nextKatacodaStep
1018

1119
***
1220

@@ -84,7 +92,7 @@ createFile("cobigenexample/core/src/main/java/com/example/application/cobigenexa
8492
#### parameter
8593
1. Path of the file to be changed (relative path to the workspace directory)
8694
2.
87-
* path of the file to get the content from or a string, that should be inserted.
95+
* Path of the file to get the content from or a string, that should be inserted.
8896
* (Optional) Name of a placeholder
8997
#### example
9098
changeFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java", { "file": "files/Placeholder.java", "placeholder": "private static final long serialVersionUID = 1L;" })
@@ -94,6 +102,8 @@ If you want to add content from a file:
94102
{"file": "[path]"}
95103
If you want to add a string to a file:
96104
{"content": "[string]"}
105+
If you want to add different contents for the katacoda and console runner, then use the properties "fileConsole" and "fileKatacoda" or "contentConsole" and "contentKatacoda":
106+
{"fileConsole": "[pathToConsoleFile]", "fileKatacoda": "[pathToKatacodaFile]"}
97107
##### Name of the placeholder
98108
If you want to insert content into your code between two existing lines, take the previous line as your placeholder. Add your placeholder into the new file or string, otherwise it will be replaced entirely.
99109

@@ -108,11 +118,100 @@ Please try not to use custom placeholders. Keep in mind that you might want to b
108118

109119
***
110120

111-
### dockerCompose
121+
### createFolder
112122
#### parameter
113-
1. Path to the Dockerfile
123+
1. Path of the folder to be created, relative to the workspace directory. Subdirectories are also created.
114124
#### example
115-
dockerCompose("exampleproject")
125+
createFolder("directoryPath/subDirectory")
126+
127+
***
128+
129+
### cloneRepository
130+
#### parameter
131+
1. Path into which the repository is to be cloned, relative to workspace.
132+
2. Git repository URL
133+
#### example
134+
cloneRepository("", "https://github.com/devonfw-forge/tutorial-compiler.git")
135+
Repository will be cloned directly into the workspace directory.
136+
137+
cloneRepository("devonfw-forge", "https://github.com/devonfw-forge/tutorial-compiler.git")
138+
Repository will be cloned into a newly created subdirectory devonfw-forge.
139+
140+
***
141+
142+
143+
### runServerJava
144+
#### parameter
145+
1. Path to the server directory within the java project.
146+
2. Assertion information. Only needed for the console runner to check if the server was started properly.
147+
#### example
148+
runServerJava("devonfw/workspaces/main/jump-the-queue/java/jtqj/server", { "startupTime": 40, "port": 8081, "path": "jumpthequeue" })
149+
150+
##### Assertion information
151+
startupTime = Time in seconds to wait before checking if the server is running
152+
port: Port on which the server is running
153+
path: The URL path on which is checked if the server is running
154+
155+
***
156+
157+
### npmInstall
158+
#### parameter
159+
1. Path to the project where the dependencies from the package.json file are to be installed.
160+
#### example
161+
npmInstall("my-thai-star/angular")
162+
163+
***
164+
165+
### downloadFile
166+
#### parameter
167+
1. URL of the file to be downloaded.
168+
2. Name of file.
169+
3. (Optional) Downloads file to a given directory relative to workspace. Directory is created, if its not existing.
170+
#### example
171+
downloadFile("https://bit.ly/2BCkFa9", "file", "downloads")
172+
173+
***
174+
175+
### buildNg
176+
#### parameter
177+
1. Path to the angular project relative to workspace
178+
2. (Optional) Custom output directory.
179+
#### example
180+
buildNg("exampleAngularProject")
181+
Will build the angular project to default output directory defined in angular.json outputPath key, normally set to dist/.
182+
183+
buildNg("exampleAngularProject", "testOutput")
184+
Will build the angular project to output directory testOutput.
185+
186+
***
187+
188+
### runClientNg
189+
#### parameter
190+
1. Path to the angular project from which the frontend server is to be started.
191+
2. Assertion information. Only needed for the console runner to check if the server was started properly.
192+
#### example
193+
runClientNg("jump-the-queue/angular", { "startupTime": 200, "port": 4200, "path": "" })
194+
195+
##### Assertion information
196+
startupTime = Time in seconds to wait before checking if the server is running
197+
port: Port on which the server is running
198+
path: The URL path on which is checked if the server is running
199+
200+
***
201+
202+
### nextKatacodaStep
203+
#### parameter
204+
1. The title of the step.
205+
2. An array of json objects with files, content, or images to be rendered within the katacoda step.
206+
#### example
207+
nextKatacodaStep("Step title", [{ "file": "files/description.md" }, { "content": "This is just plain content." }, { "image": "files/image.png" }])
208+
209+
#### Details
210+
Available attributes in the json objects:
211+
212+
file: Path to a file whose content is to be displayed in the katacoda step (e.g. .md or .txt file).
213+
content: Plain text to be displayed in the katacoda step.
214+
image: Path to an image to be displayed in the katacoda step.
116215

117216
***
118217

engine/runner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { Step } from "./step";
55
import * as fs from 'fs';
66
import * as rimraf from 'rimraf';
77

8-
const nameof = <T>(name: Extract<keyof T, string>): string => name;
9-
108
export abstract class Runner {
119
public path: string;
1210
public name: string;
1311
public playbookName: string;
1412
public playbookPath: string;
1513
public playbookTitle: string;
14+
protected readonly useDevonCommand: string = "useDevonCommand";
15+
protected readonly workspaceDirectory: string = "workspaceDirectory";
1616

1717
private setVariableCallback: (name: string, value: any) => any;
1818
registerSetVariableCallback(callback: (name: string, value: any) => any) {
@@ -83,6 +83,7 @@ export abstract class Runner {
8383
}
8484

8585
init(playbook: Playbook): void {
86+
this.setVariable(this.useDevonCommand, false);
8687
}
8788

8889
run(step: Step, command: Command): RunResult {

0 commit comments

Comments
 (0)