-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.ts
66 lines (53 loc) · 1.68 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fs from 'fs/promises'
import { join } from 'path'
const copyDir = async (srcDir: string, destDir: string): Promise<void> => {
await fs.mkdir(destDir, {recursive: true})
const entries = await fs.readdir(srcDir, {withFileTypes: true})
for (const entry of entries) {
const srcPath = join(srcDir, entry.name)
const destPath = join(destDir, entry.name)
if (entry.isDirectory()) {
await copyDir(srcPath, destPath)
} else {
await Bun.write(Bun.file(destPath), Bun.file(srcPath))
}
}
}
async function buildPlatform(platform: 'instagram' | 'facebook' | 'messenger') {
try {
const platformPath = `platform-${platform}`
console.log(`✅ built ${platformPath}`)
} catch (e) {
console.error('failed to build', platform, e)
}
}
async function main() {
const drizzleKitGenerate = Bun.spawnSync(["bunx", "drizzle-kit", "generate:sqlite"])
if (!drizzleKitGenerate.success) {
console.error(drizzleKitGenerate.stdout.toString())
throw new Error('failed to run bunx drizzle-kit generate:sqlite')
}
console.log('✅ drizzled')
const tsc = Bun.spawnSync(["tsc"])
if (!tsc.success) {
console.error(tsc.stdout.toString())
throw new Error('failed to run tsc')
}
console.log('✅ tsc')
await Promise.all([
buildPlatform('instagram'),
buildPlatform('messenger'),
buildPlatform('facebook'),
])
}
function lint() {
const lint = Bun.spawnSync(["bun", "run", "lint"])
if (!lint.success) {
console.error(lint.stdout.toString())
throw new Error('failed to lint')
}
console.log('✅ no lint issues, you are amazing')
}
await main()
// lint after so it doesn't slow down the build, faster feedback loop
lint()