@@ -3,13 +3,32 @@ import { RunResult } from "../../engine/run_result";
33import { Step } from "../../engine/step" ;
44import { Command } from "../../engine/command" ;
55import { Assertions } from "../../assertions" ;
6+ import * as path from 'path' ;
7+ import * as child_process from "child_process" ;
8+ import * as fs from "fs" ;
69
710export 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 ( / m v n / , "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