-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-all.cjs
67 lines (55 loc) · 2.05 KB
/
build-all.cjs
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
67
const { rimrafSync } = require('rimraf')
const { spawn } = require('cross-spawn')
const fs = require('fs').promises
const path = require('path')
const outputDir = path.join('dists', '')
const cleanOutputDir = () => {
console.log(`Cleaning output directory: ${outputDir}`)
rimrafSync(outputDir + '/*', { glob: true })
}
const spawnPromise = (command, args) => {
return new Promise((resolve, reject) => {
const process = spawn(command, args, { stdio: 'inherit' })
process.on('close', (code) => {
if (code !== 0) {
return reject(new Error(`Process exited with code ${code}`))
}
resolve()
})
process.on('error', (err) => {
reject(err)
})
})
}
const copyDirectory = async (source, destination) => {
await fs.mkdir(destination, { recursive: true })
const entries = await fs.readdir(source, { withFileTypes: true })
for (const entry of entries) {
const srcPath = path.join(source, entry.name)
const destPath = path.join(destination, entry.name)
if (entry.isDirectory()) {
await copyDirectory(srcPath, destPath)
} else {
await fs.copyFile(srcPath, destPath)
}
}
}
const runBuild = async () => {
try {
console.log('Running build...')
await spawnPromise('pnpm', ['vite', 'build', '--mode', 'Timeline'])
console.log('Copying Timeline build to distribution directory...')
await copyDirectory('dist/assets', 'dists')
console.log('Running build:tester...')
await spawnPromise('pnpm', ['vite', 'build', '--mode', 'Tester'])
console.log('Copying Tester build to distribution directory...')
await copyDirectory('dist/assets', 'dists')
console.log('Build process completed successfully.')
} catch (error) {
console.error(`Build process failed: ${error.message}`)
} finally {
console.log('Completed all.')
}
}
cleanOutputDir()
runBuild()