-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
625 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ lerna-debug.log* | |
|
||
node_modules | ||
dist | ||
dist-firefox | ||
dist-ssr | ||
*.local | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
apps/joplin-search-integration/src/options/utils/loadConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apps/joplin-search-integration/src/utils/__tests__/convertManifest3To2.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { expect, it } from 'vitest' | ||
import { convertManifest3To2 } from '../convertManifest3To2' | ||
|
||
const v3 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 3, | ||
background: { | ||
service_worker: 'background.js', | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], | ||
permissions: ['storage'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_page: 'options/index.html', | ||
} | ||
|
||
const v2 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 2, | ||
background: { | ||
scripts: ['background.js'], | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
browser_action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', '<all_urls>'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_ui: { | ||
page: 'options/index.html', | ||
browser_style: true, | ||
}, | ||
} | ||
|
||
it('convertManifestChromeToFirefox', () => { | ||
expect(convertManifest3To2(v3)).deep.eq(v2) | ||
}) |
18 changes: 18 additions & 0 deletions
18
apps/joplin-search-integration/src/utils/convertManifest3To2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import manifest3 from '../manifest.json' | ||
|
||
export function convertManifest3To2(manifest: typeof manifest3) { | ||
const { background, action, manifest_version, host_permissions, permissions, options_page, ...other } = manifest | ||
return { | ||
...other, | ||
background: { | ||
scripts: [background.service_worker], | ||
}, | ||
browser_action: action, | ||
manifest_version: 2, | ||
permissions: [...permissions, ...(host_permissions ? [...host_permissions, '<all_urls>'] : [])], | ||
options_ui: { | ||
page: options_page, | ||
browser_style: true, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
libs/vite-plugin-chrome-extension-dist-firefox/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@liuli-util/vite-plugin-chrome-extension-dist-firefox", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format esm --dts", | ||
"setup": "pnpm build", | ||
"dev": "pnpm build --watch", | ||
"test": "vitest run" | ||
}, | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"@types/node": "^18.11.18", | ||
"tsup": "^6.2.3", | ||
"tsx": "^3.9.0", | ||
"typescript": "^4.8.4", | ||
"vite": "^4.0.3", | ||
"vitest": "^0.23.4" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"dependencies": { | ||
"@liuli-util/fs-extra": "^0.1.0" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
libs/vite-plugin-chrome-extension-dist-firefox/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { copy, readJson, remove, writeJson } from '@liuli-util/fs-extra' | ||
import path from 'node:path' | ||
import { Plugin, ResolvedConfig } from 'vite' | ||
import { convertManifest3To2 } from './utils/convertManifest3To2' | ||
|
||
export function firefoxOutput(): Plugin { | ||
let c: ResolvedConfig | ||
return { | ||
name: 'vite-plugin-firefox-dist', | ||
configResolved(config) { | ||
c = config | ||
}, | ||
async closeBundle() { | ||
const firefoxDist = path.resolve(c.root, './dist-firefox') | ||
await remove(firefoxDist) | ||
await copy(path.resolve(c.root, './dist'), firefoxDist) | ||
const jsonPath = path.resolve(firefoxDist, 'manifest.json') | ||
await writeJson(jsonPath, convertManifest3To2(await readJson(jsonPath)), { spaces: 2 }) | ||
}, | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "Joplin Search Integration", | ||
"version": "0.2.1", | ||
"description": "When using search, related Joplin notes are also displayed in the search results.", | ||
"manifest_version": 3, | ||
"background": { | ||
"service_worker": "background.ts" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["content-scripts/main.ts"] | ||
} | ||
], | ||
"action": { | ||
"default_popup": "popup/index.html" | ||
}, | ||
"host_permissions": ["http://localhost:27583/*", "http://localhost:41184/*"], | ||
"permissions": ["storage"], | ||
"icons": { | ||
"16": "assets/icon-16.png", | ||
"32": "assets/icon-32.png", | ||
"48": "assets/icon-48.png", | ||
"128": "assets/icon-128.png" | ||
}, | ||
"options_page": "options/index.html" | ||
} |
64 changes: 64 additions & 0 deletions
64
...vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { expect, it } from 'vitest' | ||
import { convertManifest3To2 } from '../convertManifest3To2' | ||
|
||
const v3 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 3, | ||
background: { | ||
service_worker: 'background.js', | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], | ||
permissions: ['storage'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_page: 'options/index.html', | ||
} | ||
|
||
const v2 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 2, | ||
background: { | ||
scripts: ['background.js'], | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
browser_action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', '<all_urls>'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_ui: { | ||
page: 'options/index.html', | ||
browser_style: true, | ||
}, | ||
} | ||
|
||
it('convertManifestChromeToFirefox', () => { | ||
expect(convertManifest3To2(v3)).deep.eq(v2) | ||
}) |
Oops, something went wrong.