Skip to content

Commit 7af6b16

Browse files
committed
chore: Add multi release build script
1 parent 6b71265 commit 7af6b16

4 files changed

Lines changed: 70 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# production
1212
/dist
1313
/src/locales/*/messages.js
14+
/tmp-dist
1415

1516
# local test files
1617
/.dump

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"dev": "vite",
88
"l10n:build": "lingui extract --clean --overwrite && lingui compile --strict",
9-
"build": "tsc -b && npm run l10n:build && vite build",
9+
"build": "tsc -b && bun run l10n:build && vite build",
10+
"build:release": "bun ./scripts/build-release.mjs",
1011
"preview": "vite preview",
1112
"knip": "knip",
1213
"knip:fix": "knip --fix-type exports,types",

scripts/build-release.mjs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { $ } from "bun"
2+
3+
const getLatestTag = async () => {
4+
const out =
5+
await $`git describe --tags $(git rev-list --tags --max-count=1)`.quiet()
6+
return out.text().trim()
7+
}
8+
9+
const getCurrentBranch = async () => {
10+
const out = await $`git rev-parse --abbrev-ref HEAD`.quiet()
11+
return out.text().trim()
12+
}
13+
14+
const pushStash = async () => {
15+
const id = crypto.randomUUID()
16+
const out = await $`git stash push -u -m ${id}`.quiet()
17+
const noStash = out.text().includes("No local changes")
18+
19+
return async () => {
20+
if (noStash) return
21+
await $`git stash apply stash^{/${id}}`.quiet()
22+
}
23+
}
24+
25+
const build = async (name, outDir) => {
26+
console.info(`Build ${name}:`)
27+
await $`bun run l10n:build`.quiet()
28+
console.info(`√ extracted translations`)
29+
await $`vite build --outDir=${outDir}`.quiet()
30+
console.info(`√ bundled app`)
31+
console.info("")
32+
}
33+
34+
const main = async () => {
35+
const initialBranch = await getCurrentBranch()
36+
console.info("💾 Saving changes...\n")
37+
const popInitalState = await pushStash()
38+
39+
try {
40+
const tag = await getLatestTag()
41+
const devDir = "tmp-dist/main"
42+
const prodDir = `tmp-dist/${tag}`
43+
44+
await build("dev", devDir)
45+
46+
const popMainDist = await pushStash()
47+
await $`git checkout tags/${tag}`.quiet()
48+
await popMainDist()
49+
50+
await build("prod", prodDir)
51+
52+
console.info("📦️ Build final package...\n")
53+
await $`rm -rf dist`.quiet()
54+
await $`mv ${prodDir} dist`.quiet()
55+
await $`mv ${devDir} dist/dev`.quiet()
56+
} catch (error) {
57+
console.error("⚠️ Error: Somthing went wrong")
58+
console.error(error)
59+
} finally {
60+
console.info("🔄 Restoring initial state...")
61+
await $`git checkout ${initialBranch}`.quiet()
62+
await popInitalState()
63+
}
64+
}
65+
66+
void main()

tsconfig.node.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
/* Completeness */
3636
"skipLibCheck": true,
3737
},
38-
"include": ["*"]
38+
"include": ["*", "scripts/*"]
3939
}

0 commit comments

Comments
 (0)