2021-11-05 20:31:20 +00:00
|
|
|
/* eslint-disable no-undef */
|
|
|
|
import fs from 'fs'
|
2021-11-11 11:37:57 +00:00
|
|
|
import path from 'path'
|
2021-11-05 20:31:20 +00:00
|
|
|
import esbuildServe from 'esbuild-serve'
|
2021-11-08 14:21:37 +00:00
|
|
|
import dotenv from 'dotenv'
|
|
|
|
|
|
|
|
dotenv.config()
|
2021-11-05 20:31:20 +00:00
|
|
|
|
|
|
|
async function main() {
|
2021-11-11 11:37:57 +00:00
|
|
|
if (fs.existsSync('./dist')) {
|
|
|
|
fs.rmSync('./dist', { recursive: true }, (e) => {
|
|
|
|
if (e) {
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
})
|
2021-11-05 20:31:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 11:37:57 +00:00
|
|
|
fs.mkdirSync('./dist')
|
|
|
|
|
|
|
|
fs.readdirSync('./src/public').forEach((file) =>
|
|
|
|
fs.copyFile(path.join('./src/public', file), path.join('./dist', file), (err) => {
|
|
|
|
if (err) throw err
|
|
|
|
})
|
|
|
|
)
|
2021-11-05 20:31:20 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await esbuildServe(
|
|
|
|
{
|
|
|
|
entryPoints: ['src/index.tsx'],
|
2021-11-05 21:14:12 +00:00
|
|
|
outfile: 'dist/index.js',
|
2021-11-05 20:31:20 +00:00
|
|
|
minify: false,
|
2021-11-06 16:09:38 +00:00
|
|
|
bundle: true,
|
2021-11-05 20:31:20 +00:00
|
|
|
sourcemap: true,
|
|
|
|
incremental: true,
|
2021-11-08 14:21:37 +00:00
|
|
|
format: 'cjs',
|
|
|
|
target: 'es6',
|
2021-11-05 20:31:20 +00:00
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': '"development"',
|
2021-11-08 14:21:37 +00:00
|
|
|
'process.env.LIVEBLOCKS_PUBLIC_API_KEY': `"${process.env.LIVEBLOCKS_PUBLIC_API_KEY}"`,
|
2021-11-05 20:31:20 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
onRebuild(err) {
|
|
|
|
err ? error('❌ Failed') : log('✅ Updated')
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-11-07 14:29:24 +00:00
|
|
|
port: 5420,
|
2021-11-05 20:31:20 +00:00
|
|
|
root: './dist',
|
|
|
|
live: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|