aboutsummaryrefslogtreecommitdiff
path: root/scripts/updateVersion.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/updateVersion.js')
-rw-r--r--scripts/updateVersion.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/updateVersion.js b/scripts/updateVersion.js
new file mode 100644
index 00000000..218ffa9a
--- /dev/null
+++ b/scripts/updateVersion.js
@@ -0,0 +1,47 @@
+import p from '../package.json'
+import cp from 'child_process'
+import fs from 'fs'
+import { basename } from 'path'
+
+const setVersionToIcons = (version, files) => {
+ for (const i in files) {
+ const file = files[i]
+
+ if (fs.existsSync(`src/_icons/${file}.svg`)) {
+ let svgFile = fs.readFileSync(`src/_icons/${file}.svg`).toString()
+
+ if (!svgFile.match(/version: ([0-9.]+)/i)) {
+ svgFile = svgFile.replace(/---\n<svg>/i, function(m) {
+ return `version: "${version}"\n${m}`
+ })
+
+ console.log(`Set version to ${version} in "${basename(file)}"`);
+ fs.writeFileSync(`src/_icons/${file}.svg`, svgFile)
+ } else {
+ console.log(`File ${file} already has version`)
+ }
+ } else {
+ console.log(`File ${file} doesn't exists`)
+ }
+ }
+}
+
+const updateIconsVersion = (version) => {
+
+ if (version) {
+ cp.exec(`grep -RiL "version: " ./src/_icons/*.svg`, function(err, ret) {
+
+ let newIcons = []
+
+ ret.replace(/src\/_icons\/([a-z0-9-]+)\.svg/g, function(m, fileName) {
+ newIcons.push(fileName)
+ })
+
+ if (newIcons.length) {
+ setVersionToIcons(version.replace(/\.0$/, ''), newIcons)
+ }
+ })
+ }
+}
+
+updateIconsVersion(p.version)