-
Notifications
You must be signed in to change notification settings - Fork 1
/
up-version.js
39 lines (34 loc) · 983 Bytes
/
up-version.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
import fs from 'fs'
const minorUp = process.argv.length === 3
const filePath = "index.js";
const regexPattern = /const version = '(\d+)\.(\d+)\.(\d+)'/g
// Read the content of the file
fs.readFile(filePath, "utf-8", (err, data) => {
if (err) {
console.error("Error reading the file:", err)
return
}
// Modify the content
const modifiedContent = data.replace(
regexPattern,
(match, major, minor, patch) => {
let newPatch = parseInt(patch)
let newMinor = parseInt(minor)
if (minorUp) {
newMinor = parseInt(minor) + 1
newPatch = 0
} else {
newPatch = parseInt(patch) + 1
}
return `const version = '${major}.${newMinor}.${newPatch}'`
}
)
// Write the modified content back to the file
fs.writeFile(filePath, modifiedContent, "utf-8", (err) => {
if (err) {
console.error("Error writing to the file:", err)
return
}
console.log("Line replacement complete.")
})
})