-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
57 lines (45 loc) · 1.66 KB
/
Copy pathbuild.ts
File metadata and controls
57 lines (45 loc) · 1.66 KB
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
import { build, context } from 'esbuild';
import { promises as fs } from 'fs';
import { watch } from 'fs';
import path from 'path';
const watchFlag = process.argv.includes('--watch');
const devFlag = process.argv.includes('--dev') || watchFlag;
const distDir = 'dist';
const distPath = (relPath: string) => path.join(distDir, relPath);
const copyStaticFiles = async () => {
await fs.copyFile('manifest.json', distPath('manifest.json'));
await fs.copyFile('src/content_scripts/style.css', distPath('content_scripts/style.css'));
await fs.cp('src/icons', distPath('icons'), { recursive: true });
};
const buildExtension = async () => {
await fs.mkdir(distPath('icons'), { recursive: true });
await fs.mkdir(distPath('content_scripts'), { recursive: true });
if (watchFlag) {
const ctx = await context({
entryPoints: ['src/content_scripts/index.ts'],
bundle: true,
outdir: distPath('content_scripts'),
sourcemap: 'inline',
});
await ctx.watch();
console.log('Watching for TypeScript changes...');
await copyStaticFiles();
watch('src/content_scripts/style.css', async () => {
await fs.copyFile('src/content_scripts/style.css', distPath('content_scripts/style.css'));
console.log('Copied style.css');
});
watch('manifest.json', async () => {
await fs.copyFile('manifest.json', distPath('manifest.json'));
console.log('Copied manifest.json');
});
} else {
await build({
entryPoints: ['src/content_scripts/index.ts'],
bundle: true,
outdir: distPath('content_scripts'),
sourcemap: devFlag ? 'inline' : false,
});
await copyStaticFiles();
}
};
buildExtension();