Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as esbuild from 'esbuild';
import { cpSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const isWatch = process.argv.includes('--watch');
const isPackage = process.argv.includes('--package');

const entries = [
{ in: 'src/content/index.js', out: 'dist/content.js' },
Expand Down Expand Up @@ -32,12 +34,19 @@ async function build() {
// Copy static assets
cpSync('static/icons', 'dist/icons', { recursive: true });
cpSync('static/overlay.css', 'dist/overlay.css');
cpSync('src/debug/debug.js', 'dist/debug.js');
cpSync('src/popup/popup.html', 'dist/popup.html');
cpSync('src/popup/popup.css', 'dist/popup.css');

// Copy manifest.json
cpSync('manifest.json', 'dist/manifest.json');
// Copy manifest.json, stripping debug content script for production
const manifest = JSON.parse(readFileSync('manifest.json', 'utf8'));
if (isPackage) {
manifest.content_scripts = manifest.content_scripts.filter(
(cs) => !cs.js.includes('debug.js'),
);
} else {
cpSync('src/debug/debug.js', 'dist/debug.js');
}
writeFileSync('dist/manifest.json', JSON.stringify(manifest, null, 2));

console.log('Build complete → dist/');
}
Expand All @@ -64,8 +73,23 @@ async function watch() {
console.log('Watching for changes...');
}

async function packageExtension() {
await build();

const manifest = JSON.parse(readFileSync('dist/manifest.json', 'utf8'));
const zipName = `cesar-v${manifest.version}.zip`;

execSync(`cd dist && zip -r ../${zipName} .`);
console.log(`Packaged → ${zipName}`);
}

if (isWatch) {
watch().catch(console.error);
} else if (isPackage) {
packageExtension().catch((err) => {
console.error(err);
process.exit(1);
});
} else {
build().catch((err) => {
console.error(err);
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"format": "prettier --write \"src/**/*.{js,css,html}\"",
"test": "vitest run",
"test:watch": "vitest",
"ci": "npm run lint && npm run test && npm run build"
"ci": "npm run lint && npm run test && npm run build",
"package": "node build.js --package"
},
"devDependencies": {
"esbuild": "^0.25.0",
Expand Down
Loading