Skip to content

Commit 279e05e

Browse files
committed
Add basic version increase
1 parent 8d613af commit 279e05e

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

cli.js

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ var getObject = function(path, cb){
1212
cb();
1313
}
1414

15+
var getImagePath = function(mapName){
16+
return `${mapName}/dbm.json`;
17+
}
18+
1519
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));
1725
}
1826

1927
var config = getObject('./dbm-global.json', () => {
@@ -34,10 +42,13 @@ var dbmCommandInfo = {
3442
}
3543
}
3644

37-
var spawnCommand = function(program, attrs){
45+
var spawnCommand = function(program, attrs, exitCb){
3846
spawn(program, attrs, {stdio: 'inherit'})
3947
.on('exit', function (exitCode) {
40-
process.exit(exitCode)
48+
if(!exitCb)
49+
process.exit(exitCode)
50+
else
51+
exitCb();
4152
})
4253
}
4354

@@ -55,16 +66,45 @@ var invalidDirectory = (directory) => {
5566
}
5667
var quit = (code) => { process.exit(code); }
5768

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+
5881
var dbmCommands = {
59-
"build": () => {
82+
"build": (exitCb) => {
6083
var info = dbmCommandInfo.cmdImage();
6184
var attrs = ['build', info.mapName, `-t`, `${config.registry_name}/${info.imageName}:${info.imageConfig.version}`];
62-
spawnCommand('docker', attrs);
85+
spawnCommand('docker', attrs, exitCb);
6386
},
64-
"push": () => {
87+
"push": (exitCb) => {
6588
var info = dbmCommandInfo.cmdImage();
6689
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());
68108
}
69109
}
70110

0 commit comments

Comments
 (0)