Skip to content

Commit

Permalink
validate semver
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbalfour committed Sep 21, 2023
1 parent 77b2b8a commit c6edf1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/version-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"type": "module",
"bin": {
"reapit-version-package": "./src/index.js"
},
"dependencies": {
"semver": "^7.5.4"
}
}
12 changes: 9 additions & 3 deletions packages/version-package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import fs from 'fs'
import path from 'path'
import { valid } from 'semver'
const { RELEASE_VERSION } = process.env

if (!RELEASE_VERSION) {
throw new Error('RELEASE_VERSION env var not set')
}

const versionStr = RELEASE_VERSION.replace('v', '')

if (!valid(versionStr)) {
throw new Error('RELEASE_VERSION env var not valid semver')
}

const loc = path.resolve('./package.json')

const pkgJson = JSON.parse(fs.readFileSync(loc, 'utf-8'))
const { name, version } = pkgJson
if (version !== '0.0.0') {
throw new Error(`${name} version was ${version}, failing out of an abundance of caution`)
}
console.log(`Updating ${name} version from ${version} to ${versionStr}`)

console.log(`Updating ${name} version from ${version} to ${RELEASE_VERSION}`)

pkgJson.version = RELEASE_VERSION
pkgJson.version = versionStr

fs.writeFileSync(loc, JSON.stringify(pkgJson, null, 2))

Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,8 @@ __metadata:
"@reapit-cdk/version-package@workspace:^, @reapit-cdk/version-package@workspace:packages/version-package":
version: 0.0.0-use.local
resolution: "@reapit-cdk/version-package@workspace:packages/version-package"
dependencies:
semver: ^7.5.4
bin:
reapit-version-package: ./src/index.js
languageName: unknown
Expand Down

0 comments on commit c6edf1e

Please sign in to comment.