cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
scripts/check-version.cjs
20lines · modeblame
2d51afdcstainless-app[bot]2 years ago | 1 | const fs = require('fs'); |
| 2 | const path = require('path'); | |
| 3 | | |
| 4 | const main = () => { | |
| 5 | const pkg = require('../package.json'); | |
| 6 | const version = pkg['version']; | |
| 7 | if (!version) throw 'The version property is not set in the package.json file'; | |
| 8 | if (typeof version !== 'string') { | |
| 9 | throw `Unexpected type for the package.json version field; got ${typeof version}, expected string`; | |
| 10 | } | |
| 11 | | |
| 12 | const versionFile = path.resolve(__dirname, '..', 'src', 'version.ts'); | |
| 13 | const contents = fs.readFileSync(versionFile, 'utf8'); | |
| 14 | const output = contents.replace(/(export const VERSION = ')(.*)(')/g, `$1${version}$3`); | |
| 15 | fs.writeFileSync(versionFile, output); | |
| 16 | }; | |
| 17 | | |
| 18 | if (require.main === module) { | |
| 19 | main(); | |
| 20 | } |