Skip to content

Commit 682dbfe

Browse files
committed
chore: added comments
1 parent 5071dcb commit 682dbfe

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/scripts/npm/nodeVersion.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
var git = ''
1414

1515
for (var i = 0; i < files.length; i++) {
16+
// update
1617
var file = files[i]
1718
var content = readContent(file)
1819
var updated = updateVersion(file, content, version)
@@ -22,25 +23,25 @@
2223

2324
// save
2425
git += 'git add ' + file + ' && '
25-
content = updateVersion(file, content, version)
26-
saveContent(file, content)
26+
saveContent(file, updated)
2727
}
2828
commitChanges(git, version)
2929
}
3030

31-
function commitChanges (git, version) {
32-
git += 'git commit -m "chore: updated npm version to ' + version + '" && git push'
33-
exec(git, function (err, stdout, stderr) {
34-
if (err) {
35-
throw new Error('BRANCH SDK: Failed commit git changes to npm version. Docs https://goo.gl/GijGKP')
36-
}
37-
})
38-
}
39-
31+
// handle content
4032
function readContent (file) {
4133
return isFileXml(file) ? fileHelper.readFile(file) : JSON.parse(fileHelper.readFile(file))
4234
}
4335

36+
function saveContent (file, content) {
37+
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
38+
}
39+
40+
function isFileXml (file) {
41+
return file.indexOf('xml') > 0
42+
}
43+
44+
// update content based on xml or json
4445
function updateVersion (file, content, version) {
4546
var prev = /id="branch-cordova-sdk"[\s]*version="\d+\.\d+\.\d+"/mgi
4647
var next = 'id="branch-cordova-sdk"\n version="' + version + '"'
@@ -57,14 +58,7 @@
5758
return content
5859
}
5960

60-
function saveContent (file, content) {
61-
return isFileXml(file) ? fileHelper.writeFile(file, content) : fileHelper.writeFile(file, JSON.stringify(content, null, 2))
62-
}
63-
64-
function isFileXml (file) {
65-
return file.indexOf('xml') > 0
66-
}
67-
61+
// get the absolute path of the files within the root directory
6862
function readFilePaths (files) {
6963
var locations = []
7064
for (var i = 0; i < files.length; i++) {
@@ -74,4 +68,14 @@
7468
}
7569
return locations
7670
}
71+
72+
// push file code changes to github
73+
function commitChanges (git, version) {
74+
git += 'git commit -m "chore: updated npm version to ' + version + '" && git push'
75+
exec(git, function (err, stdout, stderr) {
76+
if (err) {
77+
throw new Error('BRANCH SDK: Failed commit git changes to npm version. Docs https://goo.gl/GijGKP')
78+
}
79+
})
80+
}
7781
})()

0 commit comments

Comments
 (0)