Skip to content

Commit 7e7e900

Browse files
committed
chore(build-release): Clean up tmp build files
1 parent c9be91b commit 7e7e900

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

scripts/build-release.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@ import { $ } from "bun"
44

55
const ROOT_DIR = resolve("./")
66
const BUILD_DIR = "dist"
7+
const TMP_DIR = "_tmp_release_build"
78

89
const getAbsolutePath = (path: string) => {
910
const pwd = resolve(path)
1011

1112
if (!pwd.includes(ROOT_DIR)) {
1213
// to protect you and me from big oopsies when running `rm -rf ${pwd}`
13-
console.error(`Cannot escape project directory. pwd: ${pwd}\n`)
14+
console.error(`Cannot escape project directory. path: ${pwd}\n`)
1415
process.exit(1)
1516
}
1617

1718
return pwd
1819
}
1920

21+
const rm = async (path: string) => {
22+
const pwd = resolve(path)
23+
24+
if (!pwd.includes(ROOT_DIR)) {
25+
// to protect you and me from big oopsies when running `rm -rf ${pwd}`
26+
console.error(
27+
`Cannot delete files outside of project directory. path: ${pwd}\n`
28+
)
29+
process.exit(1)
30+
}
31+
32+
await $`rm -rf ${pwd}`.quiet()
33+
}
34+
2035
const getLatestTag = async () =>
2136
$`git describe --tags $(git rev-list --tags --max-count=1)`
2237
.text()
@@ -42,7 +57,7 @@ const createWorktree = async (path: string, name: string) => {
4257
$`mv -f "${join(pwd, source)}" "${join(ROOT_DIR, target)}"`.quiet(),
4358
rm: async () => {
4459
await $`git worktree remove -f ${pwd}`.quiet()
45-
//await $`rm -rf ${pwd}`.quiet()
60+
await rm(pwd)
4661
},
4762
}
4863
}
@@ -62,8 +77,14 @@ const main = async () => {
6277
try {
6378
const tag = await getLatestTag()
6479

65-
const prod = await createWorktree("./worktree-clocktopus-prod/", tag)
66-
const main = await createWorktree("./worktree-clocktopus-main/", "main")
80+
const prod = await createWorktree(
81+
`./${TMP_DIR}/worktree-clocktopus-prod/`,
82+
tag
83+
)
84+
const main = await createWorktree(
85+
`./${TMP_DIR}/worktree-clocktopus-main/`,
86+
"main"
87+
)
6788

6889
await build(main.$, main.name)
6990
await build(prod.$, prod.name)
@@ -76,6 +97,7 @@ const main = async () => {
7697
console.info("🧼 Cleaning up...")
7798
await prod.rm()
7899
await main.rm()
100+
await rm(TMP_DIR)
79101
} catch (error) {
80102
console.error("⚠️ Error: Something went wrong\n")
81103
console.error(error)

0 commit comments

Comments
 (0)