Files
mediago-dev--mediago/scripts/pack-extension.ts
caorushizi 19048f6ead feat(extension): add MediaGo browser extension for media URL sniffing
A Manifest V3 extension that sniffs downloadable video / audio URLs
across every site the user visits and hands captured sources to a
MediaGo server in one click. Ships unlisted (load-unpacked .zip), no
Chrome Web Store.

Dispatch modes (user-picked in options, no silent fallback):
- desktop-schema: navigates the current tab to
  `mediago-community://index.html/?n=1&silent=1&url=…` using the
  cat-catch `chrome.tabs.update` pattern. Reuses the existing
  `useUrlInvoke` hook in apps/ui — no new deeplink plumbing.
- desktop-http: POST http://127.0.0.1:9900/api/downloads against the
  Go Core bundled in a running Desktop.
- docker-http: same POST against a user-configured host, with an
  optional X-API-Key header for `--enable-auth` deployments.

UI is React 19 + Tailwind v4 + shadcn/ui (new-york, neutral), matched
to apps/ui's stack. Popup shows per-tab sources with a red badge count;
options page has a 3-mode radio + per-mode field panel.

Supporting changes:
- Abstract sniff filter rules into @mediago/shared-common/sniff and
  point the Electron sniffing helper at the same exports so desktop
  and extension stay in lock-step.
- Tighten the YouTube host rule to actual video / short / live / embed
  URLs (drops the homepage and feed false-positives).
- Fix the macOS electron-builder config: CFBundleURLSchemes was
  hard-coded to a test string "mediagoaaa" — now sourced from
  process.env.APP_NAME (mediago-community in .env) like everywhere
  else. Also add a top-level `protocols` entry for clarity.
- Vite build pulls APP_NAME from the repo root .env via loadEnv() +
  `define`, so the scheme name stays single-sourced.
- Root scripts: `pnpm dev:extension`, `pnpm build:extension`,
  `pnpm pack:extension` (+ scripts/pack-extension.ts that cross-
  platform-zips dist/ into release/).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 23:54:31 +08:00

69 lines
2.1 KiB
TypeScript

/**
* Zip the built Chromium extension into `release/` so the user can
* share a single file. Matches the cross-platform pattern in
* `scripts/download-deps.ts` (PowerShell on Windows, `zip` on Unix).
*
* Run via:
* pnpm build:extension
* tsx scripts/pack-extension.ts
* (or `pnpm pack:extension` which chains both).
*/
import { execSync } from "node:child_process";
import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const extDir = join(root, "packages", "mediago-extension");
const distDir = join(extDir, "dist");
const releaseDir = join(root, "release");
interface PkgJson {
version?: string;
}
function readVersion(): string {
const pkg = JSON.parse(
readFileSync(join(extDir, "package.json"), "utf8"),
) as PkgJson;
return pkg.version ?? "0.0.0";
}
function zipDirectory(sourceDir: string, outputZip: string): void {
// Make sure any stale zip at the target path is gone — Windows'
// Compress-Archive refuses to overwrite silently.
if (existsSync(outputZip)) rmSync(outputZip);
if (process.platform === "win32") {
const ps = `Compress-Archive -Path '${sourceDir}\\*' -DestinationPath '${outputZip}' -Force`;
execSync(`powershell -NoProfile -Command "${ps}"`, { stdio: "inherit" });
} else {
// -r recursive, run inside sourceDir so paths are relative, use -q
// to silence per-file output.
execSync(`cd "${sourceDir}" && zip -r -q "${outputZip}" .`, {
stdio: "inherit",
});
}
}
function main(): void {
if (!existsSync(distDir)) {
console.error(
`[pack-extension] ${distDir} does not exist. Run \`pnpm build:extension\` first.`,
);
process.exit(1);
}
mkdirSync(releaseDir, { recursive: true });
const version = readVersion();
const outputZip = join(releaseDir, `mediago-extension-v${version}.zip`);
console.log(`[pack-extension] zipping ${distDir}${outputZip}`);
zipDirectory(distDir, outputZip);
console.log(`[pack-extension] ✓ created ${outputZip}`);
}
main();