-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion.js
42 lines (39 loc) · 1.4 KB
/
version.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
// Author Charles GRIMONT
/**
* Allow us to set package.json version number into c8osdk
*/
const jq = require('node-jq');
const fs = require('fs')
const path = require('path');
const filter = '.version'
const pathVersion = './projects/c8osdkangular/package.json';
const regex0 = /(["]([0-9]*).[.].([0-9]*)[.]([0-9]*)((-?)(\w*))["])/g
const regex1 = /(["][v][e][r][s][i][o][n]["][:][ ]["]([0-9]*).[.].([0-9]*)[.]([0-9]*)((-?)(\w*))["])/g
const c8ofile = "./projects/c8osdkangular/src/c8osdk-angular-core/lib/c8o.service.ts"
const filePathAng = [path.join(__dirname, 'projects', 'c8osdkangular', 'src', 'c8osdk-angular-core' ,'lib', 'c8o.service.ts')];
// Get version and trans
const getAndTrans = (regex,versiAppend, path, path2)=>{
jq.run(filter, path, {})
.then((v) => {
let version = versiAppend + v;
fs.readFile(path2, 'utf8', (err,data) => {
if (err) {
return console.log(err);
}
var result = data.replace(regex, version);
if(result.indexOf(version) != -1){
console.log("[version.js] version "+ version + " has been written in " + path2);
}
fs.writeFile(path2, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
})
.catch((err) => {
console.error(err)
})
};
getAndTrans(regex0, "", pathVersion, c8ofile);
for(let path of filePathAng){
getAndTrans(regex1, '"version": ', pathVersion, path)
}