forked from bandinopla/weightxreps-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincrease-build-number.js
110 lines (87 loc) · 3.03 KB
/
increase-build-number.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
*
* This script is used when i make a change and want to update the
* changelog with a version number...
*
*/
var fs = require('fs');
const yargs = require('yargs');
const validModes = [
// cambio totalmente el sitio. Otra estructura, otra mecanica.
'mayor',
// Se agregó una pagina nueva o un widget nuevo.
'minor',
// se corrigio un bug o se agrego/quito texto/imagenes.
'fix',
// when you want to set it manually
'set'
];
//console.log('Incrementing build number' );
async function run(argv) {
const { type, value } = argv;
console.log( argv )
if (validModes.indexOf(type) === -1) {
throw new TypeError(
`Unrecognized mode '${type}'. Did you mean one of "${validModes.join('", "')}"?`,
);
}
fs.readFile('src/version.json',function(err,content) {
if (err) throw err;
var metadata = JSON.parse(content);
var oldValue = `${metadata.buildMajor}.${metadata.buildMinor}.${metadata.buildRevision}`;
switch( type )
{
case "mayor":
metadata.buildMajor++;
metadata.buildMinor=0;
metadata.buildRevision=0;
break;
case "minor":
metadata.buildMinor++;
metadata.buildRevision=0;
break;
case "set":
let v = value.split(".");
metadata.buildMajor = v[0];
metadata.buildMinor = v[1];
metadata.buildRevision = v[2];
break;
case "fix":
default:
metadata.buildRevision++;
}
metadata.when = new Date().toUTCString();
fs.writeFile('src/version.json',JSON.stringify(metadata),function(err){
if (err) throw err;
console.log(`Current build number changed from ${oldValue} -> ${metadata.buildMajor}.${metadata.buildMinor}.${metadata.buildRevision}`); // ${metadata.buildTag}
})
});
}
yargs
.command({
command: '$0 <type> [value]',
description: `Modifica el archivo [src/version.json] en base a lo que tipees en <type>
mayor = cambio grande. Incompatible con version anterior.
minor = se agrega algo nuevo, sea un widget o una pagina o funcionalidad nueva.
fix = bug fix, corrección, retoque, optimización...
set = cuando queres setearla manualmente usando el flag "-value MAYOR.MINOR.FIX"
`,
builder: (command) => {
return command
.positional('type', {
description: `Valid types: "${validModes.join('" | "')}"`,
type: 'string',
})
.option('value', {
type: 'string',
describe: 'Seteala manualmente. Formato: mayor.minor.fix',
})
// .option('out-dir', { default: './build', type: 'string' })
// .option('verbose', { type: 'boolean' });
},
handler: run,
})
.help()
.strict(true)
.version(false)
.parse();