Repository navigation
Expand file tree
/
Copy pathversionManager.js
More file actions
112 lines (92 loc) · 2.63 KB
/
Copy pathversionManager.js
File metadata and controls
112 lines (92 loc) · 2.63 KB
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
111
112
const fs = require('fs')
const path = require('path')
const https = require('https')
const currentConsoleVersion = require('./package.json').version
// --- Simple recursive file walker ---
function walk(dir, callback) {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
if (stat.isDirectory()) {
walk(fullPath, callback)
} else {
callback(fullPath)
}
})
}
// --- Replace inline in files ---
function replaceStringInline(regex, replacement, paths) {
paths.forEach(targetPath => {
const resolvedPath = path.resolve(targetPath)
if (!fs.existsSync(resolvedPath)) return
const stat = fs.statSync(resolvedPath)
if (stat.isDirectory()) {
walk(resolvedPath, file => {
replaceInFile(file, regex, replacement)
})
} else {
replaceInFile(resolvedPath, regex, replacement)
}
})
}
function replaceInFile(file, regex, replacement) {
const content = fs.readFileSync(file, 'utf8')
const updated = content.replace(regex, replacement)
if (content !== updated) {
fs.writeFileSync(file, updated, 'utf8')
}
}
// --- Fetch latest OpenHIM Core version ---
const options = {
hostname: 'github.com',
path: '/jembi/openhim-core-js/releases/latest',
method: 'GET'
}
const req = https.request(options, res => {
let data = ''
res.setEncoding('utf8')
res.on('data', chunk => {
data += chunk
})
res.on('end', () => {
try {
const match = data.match(/releases\/tag\/v(\d+\.\d+\.\d+)/)
if (!match) return
const minimumCoreVersion = match[1]
// Update config
replaceStringInline(
/"minimumCoreVersion":\s*"\d+\.\d+\.\d+"/,
`"minimumCoreVersion": "${minimumCoreVersion}"`,
['./app/config/default.json']
)
// Update README badge
replaceStringInline(
/badge\/openhim--core-\d+\.\d+/,
`badge/openhim--core-${minimumCoreVersion.split('.').slice(0, 2).join('.')}`,
['README.md']
)
// Update docs link
replaceStringInline(
/openhim\.readthedocs\.org\/en\/v\d+\.\d+\.\d+/,
`openhim.readthedocs.org/en/v${minimumCoreVersion}`,
['README.md']
)
} catch (err) {
console.error('Failed to process GitHub response:', err)
}
})
})
req.on('error', e => {
console.log(`Problem fetching core version from GitHub: ${e.message}`)
})
req.end()
// --- Keep console version consistent ---
replaceStringInline(
/"version":\s*"\d+\.\d+\.\d+"/,
`"version": "${currentConsoleVersion}"`,
[
'./app/config/default.json',
'./.travis/test.json',
'./.travis/staging.json'
]
)