Skip to content

Commit b728ff9

Browse files
authored
Merge pull request #42 from GuentherJulian/feature/consoleCreateFile
feature/consoleCreateFile
2 parents cc99151 + cf7b456 commit b728ff9

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

documentation/Functions.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
The following functions are already implemented:
33
* installDevonIde
44
* installCobiGen
5-
* createProject
65
* cobiGenJava
6+
* createDevon4jProject
7+
* buildJava
8+
* createFile
79

810
***
911

@@ -31,7 +33,6 @@ installCobiGen()
3133
#### example
3234
cobiGenJava("path/to/java/file/MyEntity.java",[1,3,5,6,8])
3335

34-
3536
***
3637

3738
### createDevon4jProject
@@ -50,3 +51,12 @@ createDevon4jProject("cobigenexample")
5051
buildJava("cobigenexample", true)
5152

5253
***
54+
55+
### createFile
56+
#### parameter
57+
1. Path of the file to be created (relative path to the workspace directory)
58+
2. (Optional) Path of the file to get the content from. Relative to the playbook directory
59+
#### example
60+
createFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java", "files/CustomerEntity.java")
61+
62+
***

runners/console/index.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Console extends Runner {
6868
let result = new RunResult();
6969
result.returnCode = 0;
7070

71-
let workspaceDir = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main")
71+
let workspaceDir = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main");
7272
let projectName = command.parameters[0];
7373
if(this.platform == ConsolePlatform.WINDOWS) {
7474
this.executeCommandSync("devon java create com.example.application." + projectName, workspaceDir, result);
@@ -79,6 +79,26 @@ export class Console extends Runner {
7979
return result;
8080
}
8181

82+
runCreateFile(step: Step, command: Command): RunResult {
83+
let result = new RunResult();
84+
result.returnCode = 0;
85+
86+
let workspaceDir = path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main");
87+
let filepath = path.join(workspaceDir, command.parameters[0]);
88+
if(!fs.existsSync(filepath.substr(0, filepath.lastIndexOf(path.sep)))) {
89+
fs.mkdirSync(filepath.substr(0, filepath.lastIndexOf(path.sep)), { recursive: true });
90+
}
91+
92+
let content = "";
93+
if(command.parameters.length == 2) {
94+
content = fs.readFileSync(path.join(this.playbookPath, command.parameters[1]), { encoding: "utf-8" });
95+
}
96+
fs.writeFileSync(filepath, content);
97+
98+
return result;
99+
}
100+
101+
82102
runBuildJava(step: Step, command: Command): RunResult {
83103
let result = new RunResult();
84104
result.returnCode = 0;
@@ -149,7 +169,12 @@ export class Console extends Runner {
149169
.fileExits(path.join(workspaceDir, command.parameters[0], "core", "src", "main", "java", "com", "example", "application", command.parameters[0], "SpringBootApp.java"));
150170
}
151171

152-
172+
async assertCreateFile(step: Step, command: Command, result: RunResult) {
173+
new Assertions()
174+
.noErrorCode(result)
175+
.noException(result)
176+
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", command.parameters[0]));
177+
}
153178

154179
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
155180
if(result.returnCode != 0) return;

runners/katacoda/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ export class Katacoda extends Runner {
138138
return null;
139139
}
140140

141-
runCreateDevon4jProject(step: Step, command: Command): RunResult{
142-
return null;
143-
}
144-
145141
runBuildJava(step: Step, command: Command): RunResult{
146142

147143
//cdCommand needs to be added

0 commit comments

Comments
 (0)