Skip to content

Commit d12939c

Browse files
camcam-lemonaloisklink
authored andcommitted
fix: change to update version.js from scripts
Changed it because it is easier and more testable than doing it from github actions
1 parent 9a42e3c commit d12939c

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/release-publish.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ jobs:
4343
- name: Prepare release
4444
run: npm version --no-git-tag-version --allow-same-version ${{env.RELEASE_VERSION}}
4545

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"prepare": "tsc && vite build",
2626
"prepack": "tsc && vite build",
2727
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
28+
"version": "node scripts/version.js",
2829
"lint": "standard",
2930
"lint-fix": "standard --fix"
3031
},

scripts/version.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* This script reads the version from package.json and writes it to src/version.js.
5+
* It also stages the changes to src/version.js in git.
6+
*
7+
* Should be used as an [`npm version` script](https://docs.npmjs.com/cli/v8/using-npm/scripts#npm-version)!
8+
*/
9+
import { execFile } from 'node:child_process'
10+
import { readFile, writeFile } from 'node:fs/promises'
11+
import { promisify } from 'node:util'
12+
13+
async function main () {
14+
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
15+
const version = packageJson.version
16+
17+
await writeFile('src/version.js', `export const version = '${version}'\n`)
18+
await promisify(execFile)('git', ['add', 'src/version.js'])
19+
}
20+
21+
main().catch((error) => {
22+
console.error(error)
23+
process.exit(1)
24+
})

0 commit comments

Comments
 (0)