@@ -12,8 +12,16 @@ var getObject = function(path, cb){
12
12
cb ( ) ;
13
13
}
14
14
15
+ var getImagePath = function ( mapName ) {
16
+ return `${ mapName } /dbm.json` ;
17
+ }
18
+
15
19
var getImageConfig = function ( mapName , cb ) {
16
- return getObject ( `${ mapName } /dbm.json` , cb ) ; ;
20
+ return getObject ( getImagePath ( mapName ) , cb ) ; ;
21
+ }
22
+
23
+ var setImageConfig = function ( mapName , config ) {
24
+ fs . writeFileSync ( getImagePath ( mapName ) , JSON . stringify ( config , null , 4 ) ) ;
17
25
}
18
26
19
27
var config = getObject ( './dbm-global.json' , ( ) => {
@@ -34,10 +42,13 @@ var dbmCommandInfo = {
34
42
}
35
43
}
36
44
37
- var spawnCommand = function ( program , attrs ) {
45
+ var spawnCommand = function ( program , attrs , exitCb ) {
38
46
spawn ( program , attrs , { stdio : 'inherit' } )
39
47
. on ( 'exit' , function ( exitCode ) {
40
- process . exit ( exitCode )
48
+ if ( ! exitCb )
49
+ process . exit ( exitCode )
50
+ else
51
+ exitCb ( ) ;
41
52
} )
42
53
}
43
54
@@ -55,16 +66,45 @@ var invalidDirectory = (directory) => {
55
66
}
56
67
var quit = ( code ) => { process . exit ( code ) ; }
57
68
69
+ var getIncreasedVersion = function ( version ) {
70
+ // TODO also work for other versionformats
71
+ var splitted = version . split ( '.' ) ;
72
+ var last = parseInt ( splitted [ splitted . length - 1 ] ) + 1 ;
73
+ var newVersion = "" ;
74
+ for ( var i = 0 ; i < splitted . length - 1 ; i ++ ) {
75
+ newVersion += `${ splitted [ i ] } .` ;
76
+ }
77
+ newVersion += last ;
78
+ return newVersion ;
79
+ }
80
+
58
81
var dbmCommands = {
59
- "build" : ( ) => {
82
+ "build" : ( exitCb ) => {
60
83
var info = dbmCommandInfo . cmdImage ( ) ;
61
84
var attrs = [ 'build' , info . mapName , `-t` , `${ config . registry_name } /${ info . imageName } :${ info . imageConfig . version } ` ] ;
62
- spawnCommand ( 'docker' , attrs ) ;
85
+ spawnCommand ( 'docker' , attrs , exitCb ) ;
63
86
} ,
64
- "push" : ( ) => {
87
+ "push" : ( exitCb ) => {
65
88
var info = dbmCommandInfo . cmdImage ( ) ;
66
89
var attrs = [ 'push' , `${ config . registry_name } /${ info . imageName } :${ info . imageConfig . version } ` ] ;
67
- spawnCommand ( 'docker' , attrs ) ;
90
+ spawnCommand ( 'docker' , attrs , exitCb ) ;
91
+ } ,
92
+ "update" : ( ) => {
93
+ var info = dbmCommandInfo . cmdImage ( ) ;
94
+ info . imageConfig . version = getIncreasedVersion ( info . imageConfig . version ) ;
95
+ setImageConfig ( info . mapName , info . imageConfig ) ;
96
+ console . log ( 'Updated version in config' ) ;
97
+ } ,
98
+ "ub" : ( ) => {
99
+ dbmCommands . update ( ) ;
100
+ dbmCommands . build ( ) ;
101
+ } ,
102
+ "ubp" : ( ) => {
103
+ dbmCommands . update ( ) ;
104
+ dbmCommands . bp ( ) ;
105
+ } ,
106
+ "bp" : ( ) => {
107
+ dbmCommands . build ( ( ) => dbmCommands . push ( ) ) ;
68
108
}
69
109
}
70
110
0 commit comments