Last active
May 6, 2022 10:00
-
-
Save joutvhu/e8392ea1452b5a4fffb82e6b84736fb2 to your computer and use it in GitHub Desktop.
Update APP_VERSION by package version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
function updateVersion(file, packagePath = 'package.json') { | |
fs.readFile(file, 'utf8', (err, data) => { | |
if (err) console.error(err); | |
else if (data) { | |
const packageFile = fs.readFileSync(packagePath, 'utf8'); | |
const packageData = JSON.parse(packageFile); | |
const formatted = data.replace( | |
/export const APP_VERSION = '([^'"]+)';/g, | |
`export const APP_VERSION = '${packageData.version}';` | |
); | |
fs.writeFile(file, formatted, 'utf8', (err) => { | |
if (err) console.error(err); | |
}); | |
} | |
}); | |
} | |
updateVersion('src/app/config/web.config.ts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment