Skip to content

Instantly share code, notes, and snippets.

@joutvhu
Last active May 6, 2022 10:00
Show Gist options
  • Save joutvhu/e8392ea1452b5a4fffb82e6b84736fb2 to your computer and use it in GitHub Desktop.
Save joutvhu/e8392ea1452b5a4fffb82e6b84736fb2 to your computer and use it in GitHub Desktop.
Update APP_VERSION by package version
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