check-version.cjs 701 B

1234567891011121314151617181920
  1. const fs = require('fs');
  2. const path = require('path');
  3. const main = () => {
  4. const pkg = require('../../package.json');
  5. const version = pkg['version'];
  6. if (!version) throw 'The version property is not set in the package.json file';
  7. if (typeof version !== 'string') {
  8. throw `Unexpected type for the package.json version field; got ${typeof version}, expected string`;
  9. }
  10. const versionFile = path.resolve(__dirname, '..', '..', 'src', 'version.ts');
  11. const contents = fs.readFileSync(versionFile, 'utf8');
  12. const output = contents.replace(/(export const VERSION = ')(.*)(')/g, `$1${version}$3`);
  13. fs.writeFileSync(versionFile, output);
  14. };
  15. if (require.main === module) {
  16. main();
  17. }