|
13 | 13 | var git = ''
|
14 | 14 |
|
15 | 15 | for (var i = 0; i < files.length; i++) {
|
| 16 | + // update |
16 | 17 | var file = files[i]
|
17 | 18 | var content = readContent(file)
|
18 | 19 | var updated = updateVersion(file, content, version)
|
|
22 | 23 |
|
23 | 24 | // save
|
24 | 25 | git += 'git add ' + file + ' && '
|
25 |
| - content = updateVersion(file, content, version) |
26 |
| - saveContent(file, content) |
| 26 | + saveContent(file, updated) |
27 | 27 | }
|
28 | 28 | commitChanges(git, version)
|
29 | 29 | }
|
30 | 30 |
|
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 |
40 | 32 | function readContent (file) {
|
41 | 33 | return isFileXml(file) ? fileHelper.readFile(file) : JSON.parse(fileHelper.readFile(file))
|
42 | 34 | }
|
43 | 35 |
|
| 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 |
44 | 45 | function updateVersion (file, content, version) {
|
45 | 46 | var prev = /id="branch-cordova-sdk"[\s]*version="\d+\.\d+\.\d+"/mgi
|
46 | 47 | var next = 'id="branch-cordova-sdk"\n version="' + version + '"'
|
|
57 | 58 | return content
|
58 | 59 | }
|
59 | 60 |
|
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 |
68 | 62 | function readFilePaths (files) {
|
69 | 63 | var locations = []
|
70 | 64 | for (var i = 0; i < files.length; i++) {
|
|
74 | 68 | }
|
75 | 69 | return locations
|
76 | 70 | }
|
| 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 | + } |
77 | 81 | })()
|
0 commit comments