diff --git a/build.js b/build.js index c2b0222..e476ef5 100644 --- a/build.js +++ b/build.js @@ -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' }, @@ -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/'); } @@ -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); diff --git a/package-lock.json b/package-lock.json index e84c7cc..19f7e47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,7 +117,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" }, @@ -141,7 +140,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" } @@ -1294,7 +1292,6 @@ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1762,7 +1759,6 @@ "integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -2347,7 +2343,6 @@ "integrity": "sha512-8i7LzZj7BF8uplX+ZyOlIz86V6TAsSs+np6m1kpW9u0JWi4z/1t+FzcK1aek+ybTnAC4KhBL4uXCNT0wcUIeCw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssstyle": "^4.1.0", "data-urls": "^5.0.0", @@ -2687,7 +2682,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, diff --git a/package.json b/package.json index 6edf7be..1b41f5d 100644 --- a/package.json +++ b/package.json @@ -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",