ATlast — you'll never need to find your favorites on another platform again. Find your favs in the ATmosphere.
atproto
1import * as esbuild from 'esbuild';
2import * as fs from 'fs';
3import * as path from 'path';
4import { fileURLToPath } from 'url';
5
6const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
8const watch = process.argv.includes('--watch');
9
10// Clean dist directory
11const distDir = path.join(__dirname, 'dist', 'chrome');
12if (fs.existsSync(distDir)) {
13 fs.rmSync(distDir, { recursive: true });
14}
15fs.mkdirSync(distDir, { recursive: true });
16
17// Build configuration base
18const buildConfigBase = {
19 bundle: true,
20 minify: !watch,
21 sourcemap: watch ? 'inline' : false,
22 target: 'es2020',
23 format: 'esm',
24};
25
26// Build scripts
27const scripts = [
28 {
29 ...buildConfigBase,
30 entryPoints: ['src/content/index.ts'],
31 outfile: path.join(distDir, 'content', 'index.js'),
32 },
33 {
34 ...buildConfigBase,
35 entryPoints: ['src/background/service-worker.ts'],
36 outfile: path.join(distDir, 'background', 'service-worker.js'),
37 },
38 {
39 ...buildConfigBase,
40 entryPoints: ['src/popup/popup.ts'],
41 outfile: path.join(distDir, 'popup', 'popup.js'),
42 },
43];
44
45// Build function
46async function build() {
47 try {
48 console.log('🔨 Building extension...');
49
50 // Build all scripts
51 for (const config of scripts) {
52 if (watch) {
53 const ctx = await esbuild.context(config);
54 await ctx.watch();
55 console.log(`👀 Watching ${path.basename(config.entryPoints[0])}...`);
56 } else {
57 await esbuild.build(config);
58 console.log(`✅ Built ${path.basename(config.entryPoints[0])}`);
59 }
60 }
61
62 // Copy static files
63 copyStaticFiles();
64
65 if (!watch) {
66 console.log('✨ Build complete!');
67 }
68 } catch (error) {
69 console.error('❌ Build failed:', error);
70 process.exit(1);
71 }
72}
73
74// Copy static files
75function copyStaticFiles() {
76 const filesToCopy = [
77 { from: 'manifest.json', to: 'manifest.json' },
78 { from: 'src/popup/popup.html', to: 'popup/popup.html' },
79 { from: 'src/popup/popup.css', to: 'popup/popup.css' },
80 ];
81
82 for (const file of filesToCopy) {
83 const srcPath = path.join(__dirname, file.from);
84 const destPath = path.join(distDir, file.to);
85
86 // Create directory if it doesn't exist
87 const destDir = path.dirname(destPath);
88 if (!fs.existsSync(destDir)) {
89 fs.mkdirSync(destDir, { recursive: true });
90 }
91
92 fs.copyFileSync(srcPath, destPath);
93 }
94
95 // Create placeholder icons (TODO: replace with actual icons)
96 const assetsDir = path.join(distDir, 'assets');
97 if (!fs.existsSync(assetsDir)) {
98 fs.mkdirSync(assetsDir, { recursive: true });
99 }
100
101 // Create simple text files as placeholder icons
102 const sizes = [16, 48, 128];
103 for (const size of sizes) {
104 const iconPath = path.join(assetsDir, `icon-${size}.png`);
105 if (!fs.existsSync(iconPath)) {
106 // TODO: Generate actual PNG icons
107 fs.writeFileSync(iconPath, `Placeholder ${size}x${size} icon`);
108 }
109 }
110
111 console.log('📋 Copied static files');
112}
113
114// Run build
115build();