#!/usr/bin/env -S node -r esbin
import "dotenv/config"
import fs from "fs"
import { resolve } from "path"
import type { Manifest } from "webextension-polyfill"

const manifest: Manifest.WebExtensionManifest = {
  name: "__MSG_extName__",
  version: "19.11.6",
  description: "__MSG_description__",
  manifest_version: 2,
  default_locale: "en_US",
  icons: {
    64: "assets/images/64.png",
    128: "assets/images/128.png",
    256: "assets/images/256.png",
  },
  permissions: [
    "tabs",
    "downloads",
    "webNavigation",
    "storage",
    "http://*/",
    "https://*/",
    "chrome://favicon/",
  ],
  content_security_policy:
    "script-src 'unsafe-inline' 'self' http://localhost:8097/; object-src 'self'",
  minimum_chrome_version: "90.0",
  background: {
    page: "background.html",
    persistent: true,
  },
  devtools_page: "devtools.html",
  content_scripts: [
    {
      matches: ["<all_urls>"],
      run_at: "document_start",
      all_frames: true,
      js: ["app/context/index.js"],
    },
    {
      matches: ["http://userstyles.org/*", "https://userstyles.org/*"],
      run_at: "document_end",
      all_frames: false,
      js: ["app/install/index.js"],
    },
  ],
  options_ui: {
    page: "options.html",
    open_in_tab: true,
  },
  browser_action: {
    default_icon: {
      16: "assets/images/16w.png",
      19: "assets/images/19w.png",
      32: "assets/images/32w.png",
      38: "assets/images/38w.png",
    },
    default_title: "__MSG_extName__",
    default_popup: "popup.html",
  },
}

fs.writeFileSync(
  resolve(__dirname, "../dist", "manifest.json"),
  JSON.stringify(manifest, null, 2),
)
