mirror of
https://github.com/Automattic/harper.git
synced 2025-08-04 18:48:02 +00:00
feat(chrome-plugin): set up build system for Firefox (#1408)
This commit is contained in:
parent
9969826901
commit
6d47edca6c
8 changed files with 65 additions and 14 deletions
11
.github/workflows/build_chrome_plugin.yml
vendored
11
.github/workflows/build_chrome_plugin.yml
vendored
|
@ -25,10 +25,17 @@ jobs:
|
||||||
run: sudo apt-get update && sudo apt-get install pandoc -y
|
run: sudo apt-get update && sudo apt-get install pandoc -y
|
||||||
- name: Install `wasm-pack`
|
- name: Install `wasm-pack`
|
||||||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
- name: Build
|
- name: Build Chrome Plugin
|
||||||
run: just build-chrome-plugin
|
run: just build-chrome-plugin
|
||||||
- name: Upload extension
|
- name: Build Firefox Plugin
|
||||||
|
run: just build-firefox-plugin
|
||||||
|
- name: Upload Chrome extension
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: harper-chrome-plugin.zip
|
name: harper-chrome-plugin.zip
|
||||||
path: "packages/chrome-plugin/package/harper-chrome-plugin.zip"
|
path: "packages/chrome-plugin/package/harper-chrome-plugin.zip"
|
||||||
|
- name: Upload Firefox extension
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: harper-firefox-plugin.zip
|
||||||
|
path: "packages/chrome-plugin/package/harper-firefox-plugin.zip"
|
||||||
|
|
13
.github/workflows/release_chrome_plugin.yml
vendored
13
.github/workflows/release_chrome_plugin.yml
vendored
|
@ -23,15 +23,22 @@ jobs:
|
||||||
run: sudo apt-get update && sudo apt-get install pandoc -y
|
run: sudo apt-get update && sudo apt-get install pandoc -y
|
||||||
- name: Install `wasm-pack`
|
- name: Install `wasm-pack`
|
||||||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
- name: Build
|
- name: Build Chrome Plugin
|
||||||
run: just build-chrome-plugin
|
run: just build-chrome-plugin
|
||||||
- name: Upload extension
|
- name: Build Firefox Plugin
|
||||||
|
run: just build-firefox-plugin
|
||||||
|
- name: Upload Chrome extension
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: harper-chrome-plugin.zip
|
name: harper-chrome-plugin.zip
|
||||||
path: "packages/chrome-plugin/package/harper-chrome-plugin.zip"
|
path: "packages/chrome-plugin/package/harper-chrome-plugin.zip"
|
||||||
|
- name: Upload Firefox extension
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: harper-firefox-plugin.zip
|
||||||
|
path: "packages/chrome-plugin/package/harper-firefox-plugin.zip"
|
||||||
- uses: ncipollo/release-action@v1
|
- uses: ncipollo/release-action@v1
|
||||||
with:
|
with:
|
||||||
artifacts: "packages/chrome-plugin/package/harper-chrome-plugin.zip"
|
artifacts: "packages/chrome-plugin/package/*.zip"
|
||||||
allowUpdates: true
|
allowUpdates: true
|
||||||
draft: true
|
draft: true
|
||||||
|
|
14
justfile
14
justfile
|
@ -102,7 +102,17 @@ build-chrome-plugin: build-harperjs
|
||||||
cd "{{justfile_directory()}}/packages/chrome-plugin"
|
cd "{{justfile_directory()}}/packages/chrome-plugin"
|
||||||
|
|
||||||
pnpm install
|
pnpm install
|
||||||
pnpm zip
|
pnpm zip-for-chrome
|
||||||
|
|
||||||
|
# Build the Firefox extension.
|
||||||
|
build-firefox-plugin: build-harperjs
|
||||||
|
#! /bin/bash
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
cd "{{justfile_directory()}}/packages/chrome-plugin"
|
||||||
|
|
||||||
|
pnpm install
|
||||||
|
pnpm zip-for-firefox
|
||||||
|
|
||||||
test-chrome-plugin: build-chrome-plugin
|
test-chrome-plugin: build-chrome-plugin
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
@ -225,7 +235,7 @@ check: check-rust build-web
|
||||||
setup: build-harperjs test-harperjs test-vscode build-web build-wp build-obsidian build-chrome-plugin
|
setup: build-harperjs test-harperjs test-vscode build-web build-wp build-obsidian build-chrome-plugin
|
||||||
|
|
||||||
# Perform full format and type checking, build all projects and run all tests. Run this before pushing your code.
|
# Perform full format and type checking, build all projects and run all tests. Run this before pushing your code.
|
||||||
precommit: check test build-harperjs build-obsidian build-web build-wp build-chrome-plugin
|
precommit: check test build-harperjs build-obsidian build-web build-wp build-firefox-plugin build-chrome-plugin
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"fmt": "prettier --write '**/*.{svelte,ts,json,css,scss,md}'",
|
"fmt": "prettier --write '**/*.{svelte,ts,json,css,scss,md}'",
|
||||||
"zip": "npm run build && node src/zip.js",
|
"zip-for-chrome": "TARGET_BROWSER=chrome npm run build && node src/zip.js harper-chrome-plugin.zip",
|
||||||
|
"zip-for-firefox": "TARGET_BROWSER=firefox npm run build && node src/zip.js harper-firefox-plugin.zip",
|
||||||
"test": "playwright test"
|
"test": "playwright test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -40,8 +40,15 @@ export default defineManifest({
|
||||||
default_popup: 'popup.html',
|
default_popup: 'popup.html',
|
||||||
},
|
},
|
||||||
options_page: 'options.html',
|
options_page: 'options.html',
|
||||||
|
browser_specific_settings: {
|
||||||
|
gecko: {
|
||||||
|
id: 'harper@writewithharper.com',
|
||||||
|
strict_min_version: '135.0',
|
||||||
|
},
|
||||||
|
},
|
||||||
background: {
|
background: {
|
||||||
service_worker: 'src/background/index.ts',
|
service_worker: 'src/background/index.ts',
|
||||||
|
scripts: ['src/background/index.ts'],
|
||||||
type: 'module',
|
type: 'module',
|
||||||
},
|
},
|
||||||
content_scripts: [
|
content_scripts: [
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import { createRequire } from 'module';
|
import { createRequire } from 'module';
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
import zip from 'gulp-zip';
|
import zip from 'gulp-zip';
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
const manifest = require('../build/manifest.json');
|
const manifest = require('../build/manifest.json');
|
||||||
|
|
||||||
gulp
|
const [, , target] = process.argv;
|
||||||
.src('build/**', { encoding: false })
|
if (!target) {
|
||||||
.pipe(zip('harper-chrome-plugin.zip'))
|
process.stderr.write('Specify a target filename as the first argument.\n');
|
||||||
.pipe(gulp.dest('package'));
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
gulp.src('build/**', { encoding: false }).pipe(zip(target)).pipe(gulp.dest('package'));
|
||||||
|
|
|
@ -4,10 +4,20 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||||
import tailwindcss from '@tailwindcss/vite';
|
import tailwindcss from '@tailwindcss/vite';
|
||||||
import copy from 'rollup-plugin-copy';
|
import copy from 'rollup-plugin-copy';
|
||||||
import sveltePreprocess from 'svelte-preprocess';
|
import sveltePreprocess from 'svelte-preprocess';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import manifest from './src/manifest';
|
import manifest from './src/manifest';
|
||||||
|
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
|
const env = loadEnv(mode, process.cwd(), '');
|
||||||
|
|
||||||
|
const browser = env.TARGET_BROWSER ?? 'chrome';
|
||||||
|
|
||||||
|
if (!['chrome', 'firefox'].includes(browser)) {
|
||||||
|
throw new Error('UNSUPPORTED BROWSER TYPE');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Building for ${browser}`);
|
||||||
|
|
||||||
const production = mode === 'production';
|
const production = mode === 'production';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -31,7 +41,7 @@ export default defineConfig(({ mode }) => {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
crx({ manifest }),
|
crx({ manifest, browser }),
|
||||||
svelte({
|
svelte({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
dev: !production,
|
dev: !production,
|
||||||
|
|
|
@ -52,6 +52,11 @@ It:
|
||||||
- Rules
|
- Rules
|
||||||
- Domain toggling
|
- Domain toggling
|
||||||
|
|
||||||
|
## The Firefox Extension
|
||||||
|
|
||||||
|
Despite the name of the package, the `chrome-plugin` also supports Firefox.
|
||||||
|
To build for Firefox, just use `pnpm zip-for-firefox` or otherwise compile with the environment variable `TARGET_BROWSER=firefox`.
|
||||||
|
|
||||||
## Other Reading
|
## Other Reading
|
||||||
|
|
||||||
- [Putting Harper in the Browser: Technical Details](https://elijahpotter.dev/articles/putting_harper_in_your_browser)
|
- [Putting Harper in the Browser: Technical Details](https://elijahpotter.dev/articles/putting_harper_in_your_browser)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue