71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
#!/usr/bin/env bun
|
|
import plugin from 'bun-plugin-tailwind';
|
|
import { config as dotenv } from 'dotenv';
|
|
import { existsSync } from 'fs';
|
|
import { rm } from 'fs/promises';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { buildConfig } from './helpers';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const envPath = path.resolve(__dirname, '../../.env');
|
|
dotenv({ path: envPath });
|
|
|
|
const outdir = path.join(process.cwd(), 'build/landing');
|
|
|
|
if (existsSync(outdir)) {
|
|
console.log(`🗑️ Cleaning previous build at ${outdir}`);
|
|
await rm(outdir, { recursive: true, force: true });
|
|
}
|
|
|
|
const start = performance.now();
|
|
|
|
const configPath = 'src/workspaces/config/src/index.ts';
|
|
if (existsSync(configPath)) {
|
|
console.log('🔧 Generating config with environment values...');
|
|
buildConfig(configPath, 'landing');
|
|
}
|
|
|
|
const entrypoints = [...new Bun.Glob('**.html').scanSync('src/apps/officer-web')]
|
|
.map((a) => path.resolve('src/apps/officer-web', a))
|
|
.filter((dir) => !dir.includes('node_modules'));
|
|
console.log(`📄 Found ${entrypoints.length} HTML ${entrypoints.length === 1 ? 'file' : 'files'} to process\n`);
|
|
|
|
const formatFileSize = (bytes: number): string => {
|
|
const units = ['B', 'KB', 'MB', 'GB'];
|
|
let size = bytes;
|
|
let unitIndex = 0;
|
|
|
|
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
size /= 1024;
|
|
unitIndex++;
|
|
}
|
|
|
|
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
};
|
|
|
|
const result = await Bun.build({
|
|
entrypoints,
|
|
outdir,
|
|
plugins: [plugin],
|
|
minify: true,
|
|
target: 'browser',
|
|
sourcemap: 'linked',
|
|
define: {
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
},
|
|
});
|
|
|
|
const end = performance.now();
|
|
|
|
const outputTable = result.outputs.map((output) => ({
|
|
File: path.relative(process.cwd(), output.path),
|
|
Type: output.kind,
|
|
Size: formatFileSize(output.size),
|
|
}));
|
|
|
|
console.table(outputTable);
|
|
const buildTime = (end - start).toFixed(2);
|
|
|
|
console.log(`\n✅ Build completed in ${buildTime}ms\n`);
|