Skip to content

Commit

Permalink
fix: change to update version.js from scripts
Browse files Browse the repository at this point in the history
Changed it because it is easier and more testable than doing it from github actions
  • Loading branch information
camcam-lemon authored and aloisklink committed Dec 2, 2024
1 parent 9a42e3c commit d12939c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ jobs:
- name: Prepare release
run: npm version --no-git-tag-version --allow-same-version ${{env.RELEASE_VERSION}}

- name: Update version file
run: |
echo "export const version = '${{env.RELEASE_VERSION}}'" > src/version.js
git add src/version.js
- name: Convert repository name to lower case
run: echo "GITHUB_REPOSITORY_LOWER_CASE=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"prepare": "tsc && vite build",
"prepack": "tsc && vite build",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
"version": "node scripts/version.js",
"lint": "standard",
"lint-fix": "standard --fix"
},
Expand Down
24 changes: 24 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

/**
* This script reads the version from package.json and writes it to src/version.js.
* It also stages the changes to src/version.js in git.
*
* Should be used as an [`npm version` script](https://docs.npmjs.com/cli/v8/using-npm/scripts#npm-version)!
*/
import { execFile } from 'node:child_process'
import { readFile, writeFile } from 'node:fs/promises'
import { promisify } from 'node:util'

async function main () {
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
const version = packageJson.version

await writeFile('src/version.js', `export const version = '${version}'\n`)
await promisify(execFile)('git', ['add', 'src/version.js'])
}

main().catch((error) => {
console.error(error)
process.exit(1)
})

0 comments on commit d12939c

Please # to comment.