forked from flexn-io/renative
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version-tizen.js
84 lines (61 loc) · 1.88 KB
/
version-tizen.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
const fs = require('fs')
const path = require('path')
const workspacePath = './platforms/tizen'
const configFilePath = workspacePath + path.sep + 'config.xml'
function getConfigXML () {
let data = null
if (fs.existsSync(configFilePath)) {
data = fs.readFileSync(configFilePath, 'utf-8')
return data
}
console.log('Project appears to have no Tizen config.', configFilePath)
return null
}
function getWidgetTag () {
const configXML = getConfigXML()
if (!configXML) {
// No config XML present, so nothing to do here
return null
}
// Since there are multiple matches of a "version" attribute within the config.xml, we need to be more specific
const widgetRegex = /\<widget(.*?)\>/
const match = configXML.match(widgetRegex)
if (!match) {
// No widget tag found
return null
}
return match[0]
}
function getPackageVersion () {
const widgetTag = getWidgetTag()
if (!widgetTag) {
// Something is wrong
return null
}
const match = widgetTag.match(/ version="[0-9].[0-9].[0-9]"/)
if (!match) {
// No (valid) version attribute found
return null
}
// Finally return the middle part of the match, which is the version
return match[0].split('"')[1]
}
function updatePackageVersion () {
const configXML = getConfigXML()
if (!configXML) {
// No config XML present, so nothing to do here
return false
}
const widgetTag = getWidgetTag()
// Now look for the version attribute and replace the value with the correct version
const newWidgetTag = widgetTag.replace(/ version="[0-9].[0-9].[0-9]"/, ' version="' + process.env.npm_package_version + '"')
const updatedConfigXML = configXML.replace(widgetTag, newWidgetTag)
fs.writeFileSync(configFilePath, updatedConfigXML, 'utf-8')
return true
}
module.exports = {
getConfigXML,
getWidgetTag,
getPackageVersion,
updatePackageVersion
}