85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
// Simple build script for browser extension
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Paths
|
|
const sourceDir = __dirname;
|
|
const distDir = path.join(sourceDir, 'dist');
|
|
|
|
// Make sure the dist directory exists
|
|
if (!fs.existsSync(distDir)) {
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
}
|
|
|
|
// Helper function to copy a file
|
|
function copyFile(src, dest) {
|
|
// Create destination directory if it doesn't exist
|
|
const destDir = path.dirname(dest);
|
|
if (!fs.existsSync(destDir)) {
|
|
fs.mkdirSync(destDir, { recursive: true });
|
|
}
|
|
|
|
// Copy the file
|
|
fs.copyFileSync(src, dest);
|
|
console.log(`Copied: ${path.relative(sourceDir, src)} -> ${path.relative(sourceDir, dest)}`);
|
|
}
|
|
|
|
// Helper function to copy an entire directory
|
|
function copyDir(src, dest) {
|
|
// Create destination directory
|
|
if (!fs.existsSync(dest)) {
|
|
fs.mkdirSync(dest, { recursive: true });
|
|
}
|
|
|
|
// Get list of files
|
|
const files = fs.readdirSync(src);
|
|
|
|
// Copy each file
|
|
for (const file of files) {
|
|
const srcPath = path.join(src, file);
|
|
const destPath = path.join(dest, file);
|
|
|
|
const stat = fs.statSync(srcPath);
|
|
|
|
if (stat.isDirectory()) {
|
|
// Recursively copy directories
|
|
copyDir(srcPath, destPath);
|
|
} else {
|
|
// Copy file
|
|
copyFile(srcPath, destPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Copy manifest
|
|
copyFile(
|
|
path.join(sourceDir, 'manifest.json'),
|
|
path.join(distDir, 'manifest.json')
|
|
);
|
|
|
|
// Copy assets
|
|
copyDir(
|
|
path.join(sourceDir, 'assets'),
|
|
path.join(distDir, 'assets')
|
|
);
|
|
|
|
// Copy popup files
|
|
copyDir(
|
|
path.join(sourceDir, 'popup'),
|
|
path.join(distDir, 'popup')
|
|
);
|
|
|
|
// Copy background script
|
|
copyDir(
|
|
path.join(sourceDir, 'background'),
|
|
path.join(distDir, 'background')
|
|
);
|
|
|
|
// Copy WebAssembly files
|
|
copyDir(
|
|
path.join(sourceDir, 'wasm'),
|
|
path.join(distDir, 'wasm')
|
|
);
|
|
|
|
console.log('Build complete! Extension files copied to dist directory.');
|