Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

feat: add public gallery recipes for the Pake apps

Tw931f383db627a6
diff --git a/AGENTS.md b/AGENTS.md
index 24f3a3b9..02079564 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -30,6 +30,7 @@ Pake/
│ ├── cli-usage.md # CLI parameters
│ ├── advanced-usage.md # Customization guide
│ └── faq.md # Troubleshooting
+├── gallery/ # Site recipes for the Pake apps' gallery (schema.json, tests/unit/gallery.test.ts)
├── schema/ # pake.schema.json: --config JSON schema (public contract)
├── plugins/ # Claude Code and Codex plugin source (shared user-facing pake skill)
├── llms.txt # Agent-facing contract summary (--json, --config, exit codes)
diff --git a/gallery/README.md b/gallery/README.md
new file mode 100644
index 00000000..55634a64
--- /dev/null
+++ b/gallery/README.md
@@ -0,0 +1,42 @@
+# Pake Gallery
+
+Ready-made recipes for sites that work well as desktop apps. The Pake apps for Mac and Windows show them as a gallery, so picking one creates the app with the window size and options the recipe sets.
+
+Pake is not affiliated with any of these sites. Names, logos and icons belong to their owners, and a recipe only describes how to open the public website in a window.
+
+## Layout
+
+- `apps/<id>.json`: one recipe per site, validated by `schema.json`.
+- `apps/<name>.css`, `apps/<name>.js`: optional files a recipe injects through `inject_css` or `inject_js`.
+
+```json
+{
+ "id": "excalidraw",
+ "version": 1,
+ "name": { "en": "Excalidraw", "zh-Hans": "Excalidraw" },
+ "url": "https://excalidraw.com/",
+ "category": "productivity",
+ "description": {
+ "en": "Sketch diagrams in a hand-drawn style",
+ "zh-Hans": "手绘风格的白板和示意图"
+ },
+ "icon": "https://excalidraw.com/android-chrome-512x512.png"
+}
+```
+
+- `id`: lowercase letters, digits and hyphens, equal to the file name. It never changes once published, because generated apps remember it.
+- `version`: starts at 1. Bump it only when a change affects the built app, that is `url`, `window` or the inject files, so installed apps offer the update. Name, description and icon fixes need no bump, because installed apps keep their own name and icon.
+- `category`: one of `ai`, `productivity`, `social`, `media`, `reading`, `developer`.
+- `name` and `description`: both `en` and `zh-Hans`. The description is one short line on what the site does, without a trailing period.
+- `icon`: the site's own apple-touch-icon or largest app icon over https, ideally 512 px. It is downloaded once when the apps are built, not at runtime.
+- `window`: only options that differ from Pake's defaults, using the window option names of `src-tauri/pake.json` (`width`, `height`, `hide_title_bar`, `incognito` and the others listed in the schema). `user_agent` is a single string used on every platform. Options a platform cannot apply are ignored there.
+- `platforms`: set to `["mac"]` or `["windows"]` only when the site is known not to work on the other one.
+
+## Proposing a site
+
+1. Package the site with the Pake CLI and use it for a few days: sign in, open links, download a file, and check that it is still logged in after a restart.
+2. Add `apps/<id>.json`. Keep `window` empty unless an option fixed a problem you saw, and keep inject files to the smallest change that fixes it.
+3. Run `npx vitest run tests/unit/gallery.test.ts`.
+4. Open a pull request saying what you tested and on which platform.
+
+Keep the copy honest: describe what the site does in plain words, without ratings, slogans or claims the site itself would not make. Sites that need a paid account are fine; sites that mainly serve ads or ask for credentials of another service are not accepted.
diff --git a/gallery/apps/chatgpt.json b/gallery/apps/chatgpt.json
new file mode 100644
index 00000000..c9095566
--- /dev/null
+++ b/gallery/apps/chatgpt.json
@@ -0,0 +1,15 @@
+{
+ "id": "chatgpt",
+ "version": 1,
+ "name": {
+ "en": "ChatGPT",
+ "zh-Hans": "ChatGPT"
+ },
+ "url": "https://chatgpt.com/",
+ "category": "ai",
+ "description": {
+ "en": "OpenAI's assistant for chat, writing and code",
+ "zh-Hans": "OpenAI 的对话助手,写作和编程都能用"
+ },
+ "icon": "https://cdn.oaistatic.com/assets/apple-touch-icon-mz9nytnj.webp"
+}
diff --git a/gallery/apps/claude.json b/gallery/apps/claude.json
new file mode 100644
index 00000000..80478acf
--- /dev/null
+++ b/gallery/apps/claude.json
@@ -0,0 +1,15 @@
+{
+ "id": "claude",
+ "version": 1,
+ "name": {
+ "en": "Claude",
+ "zh-Hans": "Claude"
+ },
+ "url": "https://claude.ai/",
+ "category": "ai",
+ "description": {
+ "en": "Anthropic's assistant for writing, analysis and code",
+ "zh-Hans": "Anthropic 的 AI 助手,适合写作、分析和编程"
+ },
+ "icon": "https://claude.ai/apple-touch-icon.png"
+}
diff --git a/gallery/apps/deepseek.json b/gallery/apps/deepseek.json
new file mode 100644
index 00000000..cfa64ebb
--- /dev/null
+++ b/gallery/apps/deepseek.json
@@ -0,0 +1,15 @@
+{
+ "id": "deepseek",
+ "version": 1,
+ "name": {
+ "en": "DeepSeek",
+ "zh-Hans": "DeepSeek"
+ },
+ "url": "https://chat.deepseek.com/",
+ "category": "ai",
+ "description": {
+ "en": "Chat with DeepSeek models",
+ "zh-Hans": "和 DeepSeek 模型对话"
+ },
+ "icon": "https://fe-static.deepseek.com/chat/icon-512.png"
+}
diff --git a/gallery/apps/devdocs.json b/gallery/apps/devdocs.json
new file mode 100644
index 00000000..11c48261
--- /dev/null
+++ b/gallery/apps/devdocs.json
@@ -0,0 +1,15 @@
+{
+ "id": "devdocs",
+ "version": 1,
+ "name": {
+ "en": "DevDocs",
+ "zh-Hans": "DevDocs"
+ },
+ "url": "https://devdocs.io/",
+ "category": "developer",
+ "description": {
+ "en": "API docs for many languages in one place",
+ "zh-Hans": "多种语言和框架的 API 文档合集"
+ },
+ "icon": "https://devdocs.io/images/webapp-icon-512.png"
+}
diff --git a/gallery/apps/excalidraw.json b/gallery/apps/excalidraw.json
new file mode 100644
index 00000000..8ebb92d2
--- /dev/null
+++ b/gallery/apps/excalidraw.json
@@ -0,0 +1,15 @@
+{
+ "id": "excalidraw",
+ "version": 1,
+ "name": {
+ "en": "Excalidraw",
+ "zh-Hans": "Excalidraw"
+ },
+ "url": "https://excalidraw.com/",
+ "category": "productivity",
+ "description": {
+ "en": "Sketch diagrams in a hand-drawn style",
+ "zh-Hans": "手绘风格的白板和示意图"
+ },
+ "icon": "https://excalidraw.com/android-chrome-512x512.png"
+}
diff --git a/gallery/apps/figma.json b/gallery/apps/figma.json
new file mode 100644
index 00000000..301296ca
--- /dev/null
+++ b/gallery/apps/figma.json
@@ -0,0 +1,15 @@
+{
+ "id": "figma",
+ "version": 1,
+ "name": {
+ "en": "Figma",
+ "zh-Hans": "Figma"
+ },
+ "url": "https://www.figma.com/",
+ "category": "productivity",
+ "description": {
+ "en": "Design interfaces together",
+ "zh-Hans": "多人协作的界面设计工具"
+ },
+ "icon": "https://static.figma.com/app/icon/2/icon-512.png"
+}
diff --git a/gallery/apps/flomo.json b/gallery/apps/flomo.json
new file mode 100644
index 00000000..1c4000bd
--- /dev/null
+++ b/gallery/apps/flomo.json
@@ -0,0 +1,15 @@
+{
+ "id": "flomo",
+ "version": 1,
+ "name": {
+ "en": "flomo",
+ "zh-Hans": "flomo 浮墨"
+ },
+ "url": "https://v.flomoapp.com/mine",
+ "category": "productivity",
+ "description": {
+ "en": "Jot down short notes and ideas",
+ "zh-Hans": "随手记录想法的卡片笔记"
+ },
+ "icon": "https://v.flomoapp.com/img/icons/android-chrome-512x512.png"
+}
diff --git a/gallery/apps/gemini.json b/gallery/apps/gemini.json
new file mode 100644
index 00000000..f6a4480b
--- /dev/null
+++ b/gallery/apps/gemini.json
@@ -0,0 +1,15 @@
+{
+ "id": "gemini",
+ "version": 1,
+ "name": {
+ "en": "Gemini",
+ "zh-Hans": "Gemini"
+ },
+ "url": "https://gemini.google.com/",
+ "category": "ai",
+ "description": {
+ "en": "Google's AI assistant",
+ "zh-Hans": "Google 的 AI 助手"
+ },
+ "icon": "https://www.gstatic.com/lamda/images/gemini_sparkle_4g_512_lt_f94943af3be039176192d.png"
+}
diff --git a/gallery/apps/github.json b/gallery/apps/github.json
new file mode 100644
index 00000000..323a9853
--- /dev/null
+++ b/gallery/apps/github.json
@@ -0,0 +1,15 @@
+{
+ "id": "github",
+ "version": 1,
+ "name": {
+ "en": "GitHub",
+ "zh-Hans": "GitHub"
+ },
+ "url": "https://github.com/",
+ "category": "developer",
+ "description": {
+ "en": "Code, issues and pull requests",
+ "zh-Hans": "代码、Issue 和 Pull Request"
+ },
+ "icon": "https://github.com/fluidicon.png"
+}
diff --git a/gallery/apps/grok.json b/gallery/apps/grok.json
new file mode 100644
index 00000000..534ee114
--- /dev/null
+++ b/gallery/apps/grok.json
@@ -0,0 +1,15 @@
+{
+ "id": "grok",
+ "version": 1,
+ "name": {
+ "en": "Grok",
+ "zh-Hans": "Grok"
+ },
+ "url": "https://grok.com/",
+ "category": "ai",
+ "description": {
+ "en": "xAI's assistant",
+ "zh-Hans": "xAI 的 AI 助手"
+ },
+ "icon": "https://grok.com/images/android-chrome-512x512.png"
+}
diff --git a/gallery/apps/linear.json b/gallery/apps/linear.json
new file mode 100644
index 00000000..817dec58
--- /dev/null
+++ b/gallery/apps/linear.json
@@ -0,0 +1,15 @@
+{
+ "id": "linear",
+ "version": 1,
+ "name": {
+ "en": "Linear",
+ "zh-Hans": "Linear"
+ },
+ "url": "https://linear.app/",
+ "category": "productivity",
+ "description": {
+ "en": "Plan and track product work",
+ "zh-Hans": "规划和跟踪产品开发"
+ },
+ "icon": "https://static.linear.app/assets/pwa/icon_512.png?v=3"
+}
diff --git a/gallery/apps/lizhi.json b/gallery/apps/lizhi.json
new file mode 100644
index 00000000..0787a7ba
--- /dev/null
+++ b/gallery/apps/lizhi.json
@@ -0,0 +1,15 @@
+{
+ "id": "lizhi",
+ "version": 1,
+ "name": {
+ "en": "LiZhi",
+ "zh-Hans": "李志"
+ },
+ "url": "https://lizhi.dengdengju.com/?from=pake",
+ "category": "media",
+ "description": {
+ "en": "A web player for Li Zhi's songs",
+ "zh-Hans": "李志音乐作品的网页播放器"
+ },
+ "icon": "https://lizhi.dengdengju.com/favicon.png"
+}
diff --git a/gallery/apps/music-for-programming.json b/gallery/apps/music-for-programming.json
new file mode 100644
index 00000000..61634b07
--- /dev/null
+++ b/gallery/apps/music-for-programming.json
@@ -0,0 +1,15 @@
+{
+ "id": "music-for-programming",
+ "version": 1,
+ "name": {
+ "en": "Music For Programming",
+ "zh-Hans": "Music For Programming"
+ },
+ "url": "https://musicforprogramming.net/",
+ "category": "media",
+ "description": {
+ "en": "Long mixes to stay focused while you code",
+ "zh-Hans": "适合写代码时专注听的长混音"
+ },
+ "icon": "https://musicforprogramming.net/favicon.png"
+}
diff --git a/gallery/apps/notion.json b/gallery/apps/notion.json
new file mode 100644
index 00000000..17aad15c
--- /dev/null
+++ b/gallery/apps/notion.json
@@ -0,0 +1,15 @@
+{
+ "id": "notion",
+ "version": 1,
+ "name": {
+ "en": "Notion",
+ "zh-Hans": "Notion"
+ },
+ "url": "https://app.notion.com/",
+ "category": "productivity",
+ "description": {
+ "en": "Docs, notes and wikis in one workspace",
+ "zh-Hans": "文档、笔记和知识库放在一个工作区"
+ },
+ "icon": "https://www.notion.com/front-static/logo-ios.png"
+}
diff --git a/gallery/apps/perplexity.json b/gallery/apps/perplexity.json
new file mode 100644
index 00000000..88b803eb
--- /dev/null
+++ b/gallery/apps/perplexity.json
@@ -0,0 +1,15 @@
+{
+ "id": "perplexity",
+ "version": 1,
+ "name": {
+ "en": "Perplexity",
+ "zh-Hans": "Perplexity"
+ },
+ "url": "https://www.perplexity.ai/",
+ "category": "ai",
+ "description": {
+ "en": "Ask questions and get answers with sources",
+ "zh-Hans": "提问后给出带来源的回答"
+ },
+ "icon": "https://www.perplexity.ai/apple-touch-icon.png"
+}
diff --git a/gallery/apps/qwerty-learner.json b/gallery/apps/qwerty-learner.json
new file mode 100644
index 00000000..2527ebaa
--- /dev/null
+++ b/gallery/apps/qwerty-learner.json
@@ -0,0 +1,15 @@
+{
+ "id": "qwerty-learner",
+ "version": 1,
+ "name": {
+ "en": "Qwerty Learner",
+ "zh-Hans": "Qwerty Learner"
+ },
+ "url": "https://qwerty.kaiyi.cool/",
+ "category": "developer",
+ "description": {
+ "en": "Typing practice for English words, made for programmers",
+ "zh-Hans": "给程序员的英语单词打字练习"
+ },
+ "icon": "https://qwerty.kaiyi.cool/android-chrome-512x512.png"
+}
diff --git a/gallery/apps/readwise-reader.json b/gallery/apps/readwise-reader.json
new file mode 100644
index 00000000..22e02cb0
--- /dev/null
+++ b/gallery/apps/readwise-reader.json
@@ -0,0 +1,15 @@
+{
+ "id": "readwise-reader",
+ "version": 1,
+ "name": {
+ "en": "Readwise Reader",
+ "zh-Hans": "Readwise Reader"
+ },
+ "url": "https://read.readwise.io/",
+ "category": "reading",
+ "description": {
+ "en": "Save articles and read them later",
+ "zh-Hans": "收藏文章,稍后阅读"
+ },
+ "icon": "https://read.readwise.io/logo-dock-icon-with-padding/512x512.png"
+}
diff --git a/gallery/apps/telegram.json b/gallery/apps/telegram.json
new file mode 100644
index 00000000..b8c4188d
--- /dev/null
+++ b/gallery/apps/telegram.json
@@ -0,0 +1,15 @@
+{
+ "id": "telegram",
+ "version": 1,
+ "name": {
+ "en": "Telegram",
+ "zh-Hans": "Telegram"
+ },
+ "url": "https://web.telegram.org/a/",
+ "category": "social",
+ "description": {
+ "en": "Telegram on the web",
+ "zh-Hans": "网页版 Telegram"
+ },
+ "icon": "https://web.telegram.org/a/icon-512x512.png"
+}
diff --git a/gallery/apps/wechat.json b/gallery/apps/wechat.json
new file mode 100644
index 00000000..a9dcc3b9
--- /dev/null
+++ b/gallery/apps/wechat.json
@@ -0,0 +1,20 @@
+{
+ "id": "wechat",
+ "version": 1,
+ "name": {
+ "en": "WeChat",
+ "zh-Hans": "微信"
+ },
+ "url": "https://wx.qq.com/",
+ "category": "social",
+ "description": {
+ "en": "WeChat on the web, signed in by scanning a QR code each time",
+ "zh-Hans": "网页版微信,每次打开都要扫码登录"
+ },
+ "icon": "https://res.wx.qq.com/a/wx_fed/assets/res/OTE0YTAw.png",
+ "window": {
+ "width": 1000,
+ "height": 720,
+ "incognito": true
+ }
+}
diff --git a/gallery/apps/weread.json b/gallery/apps/weread.json
new file mode 100644
index 00000000..52bddd55
--- /dev/null
+++ b/gallery/apps/weread.json
@@ -0,0 +1,15 @@
+{
+ "id": "weread",
+ "version": 1,
+ "name": {
+ "en": "WeRead",
+ "zh-Hans": "微信读书"
+ },
+ "url": "https://weread.qq.com/",
+ "category": "reading",
+ "description": {
+ "en": "Read your WeRead books on the desktop",
+ "zh-Hans": "在电脑上读微信读书"
+ },
+ "icon": "https://rescdn.qqmail.com/node/wr/wrpage/style/images/independent/appleTouchIcon/apple-touch-icon-152x152.png"
+}
diff --git a/gallery/apps/x.json b/gallery/apps/x.json
new file mode 100644
index 00000000..b5b8929d
--- /dev/null
+++ b/gallery/apps/x.json
@@ -0,0 +1,15 @@
+{
+ "id": "x",
+ "version": 1,
+ "name": {
+ "en": "X",
+ "zh-Hans": "X"
+ },
+ "url": "https://x.com/",
+ "category": "social",
+ "description": {
+ "en": "Follow posts and conversations",
+ "zh-Hans": "看动态和讨论"
+ },
+ "icon": "https://x.com/apple-touch-icon.png"
+}
diff --git a/gallery/apps/xiaohongshu.json b/gallery/apps/xiaohongshu.json
new file mode 100644
index 00000000..2c26fbee
--- /dev/null
+++ b/gallery/apps/xiaohongshu.json
@@ -0,0 +1,15 @@
+{
+ "id": "xiaohongshu",
+ "version": 1,
+ "name": {
+ "en": "Xiaohongshu",
+ "zh-Hans": "小红书"
+ },
+ "url": "https://www.xiaohongshu.com/explore",
+ "category": "social",
+ "description": {
+ "en": "Lifestyle notes and recommendations",
+ "zh-Hans": "生活方式笔记和分享"
+ },
+ "icon": "https://picasso-static.xiaohongshu.com/fe-platform/f43dc4a8baf03678996c62d8db6ebc01a82256ff.png"
+}
diff --git a/gallery/apps/youtube-music.json b/gallery/apps/youtube-music.json
new file mode 100644
index 00000000..5bddd802
--- /dev/null
+++ b/gallery/apps/youtube-music.json
@@ -0,0 +1,15 @@
+{
+ "id": "youtube-music",
+ "version": 1,
+ "name": {
+ "en": "YouTube Music",
+ "zh-Hans": "YouTube Music"
+ },
+ "url": "https://music.youtube.com/",
+ "category": "media",
+ "description": {
+ "en": "Songs, albums and playlists",
+ "zh-Hans": "听歌、专辑和歌单"
+ },
+ "icon": "https://www.gstatic.com/youtube/media/ytm/images/applauncher/music_icon_512x512.png"
+}
diff --git a/gallery/apps/youtube.json b/gallery/apps/youtube.json
new file mode 100644
index 00000000..a56fd2ca
--- /dev/null
+++ b/gallery/apps/youtube.json
@@ -0,0 +1,15 @@
+{
+ "id": "youtube",
+ "version": 1,
+ "name": {
+ "en": "YouTube",
+ "zh-Hans": "YouTube"
+ },
+ "url": "https://www.youtube.com/",
+ "category": "media",
+ "description": {
+ "en": "Watch videos and follow channels",
+ "zh-Hans": "看视频和订阅频道"
+ },
+ "icon": "https://www.gstatic.com/youtube/img/web/maskable/logo_512x512.png"
+}
diff --git a/gallery/schema.json b/gallery/schema.json
new file mode 100644
index 00000000..3673d6b3
--- /dev/null
+++ b/gallery/schema.json
@@ -0,0 +1,103 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "https://raw.githubusercontent.com/tw93/Pake/main/gallery/schema.json",
+ "title": "Pake gallery recipe",
+ "description": "One site in the Pake gallery. Bump version on any change to the recipe or its inject files.",
+ "type": "object",
+ "additionalProperties": false,
+ "required": [
+ "id",
+ "version",
+ "name",
+ "url",
+ "category",
+ "description",
+ "icon"
+ ],
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Stable identifier, equal to the file name without .json.",
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
+ "maxLength": 40
+ },
+ "version": {
+ "type": "integer",
+ "description": "Recipe version, bumped only for changes that affect the built app (url, window, inject files) so installed apps can offer an update.",
+ "minimum": 1
+ },
+ "name": {
+ "$ref": "#/definitions/localized",
+ "description": "Display name, which is also the generated app's name."
+ },
+ "url": {
+ "type": "string",
+ "description": "Start page of the app.",
+ "pattern": "^https://[^\\s]+$"
+ },
+ "category": {
+ "type": "string",
+ "enum": ["ai", "productivity", "social", "media", "reading", "developer"]
+ },
+ "description": {
+ "$ref": "#/definitions/localized",
+ "description": "One short line on what the site does."
+ },
+ "icon": {
+ "type": "string",
+ "description": "The site's own apple-touch-icon or largest app icon, PNG, JPEG, WebP or ICO.",
+ "pattern": "^https://[^\\s]+$"
+ },
+ "window": {
+ "type": "object",
+ "description": "Options that differ from Pake's defaults, using the snake_case names of src-tauri/pake.json.",
+ "additionalProperties": false,
+ "minProperties": 1,
+ "properties": {
+ "width": { "type": "integer", "minimum": 320, "maximum": 4000 },
+ "height": { "type": "integer", "minimum": 320, "maximum": 4000 },
+ "min_width": { "type": "integer", "minimum": 0, "maximum": 4000 },
+ "min_height": { "type": "integer", "minimum": 0, "maximum": 4000 },
+ "hide_title_bar": { "type": "boolean" },
+ "dark_mode": { "type": "boolean" },
+ "incognito": { "type": "boolean" },
+ "maximize": { "type": "boolean" },
+ "always_on_top": { "type": "boolean" },
+ "new_window": { "type": "boolean" },
+ "enable_find": { "type": "boolean" },
+ "force_internal_navigation": { "type": "boolean" },
+ "internal_url_regex": { "type": "string", "minLength": 1 },
+ "zoom": { "type": "integer", "minimum": 50, "maximum": 200 },
+ "user_agent": { "type": "string", "minLength": 1 }
+ }
+ },
+ "inject_css": {
+ "type": "string",
+ "description": "A .css file next to the recipe in gallery/apps/.",
+ "pattern": "^[a-z0-9-]+\\.css$"
+ },
+ "inject_js": {
+ "type": "string",
+ "description": "A .js file next to the recipe in gallery/apps/.",
+ "pattern": "^[a-z0-9-]+\\.js$"
+ },
+ "platforms": {
+ "type": "array",
+ "description": "Platforms the recipe is known to work on. Omit when it works on both.",
+ "minItems": 1,
+ "uniqueItems": true,
+ "items": { "type": "string", "enum": ["mac", "windows"] }
+ }
+ },
+ "definitions": {
+ "localized": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": ["en", "zh-Hans"],
+ "properties": {
+ "en": { "type": "string", "minLength": 1, "maxLength": 80 },
+ "zh-Hans": { "type": "string", "minLength": 1, "maxLength": 80 }
+ }
+ }
+ }
+}
diff --git a/tests/unit/gallery.test.ts b/tests/unit/gallery.test.ts
new file mode 100644
index 00000000..86076ed6
--- /dev/null
+++ b/tests/unit/gallery.test.ts
@@ -0,0 +1,238 @@
+import fs from 'fs';
+import path from 'path';
+import { describe, it, expect } from 'vitest';
+import schema from '../../gallery/schema.json';
+
+const APPS_DIR = path.resolve(__dirname, '../../gallery/apps');
+
+type Schema = Record<string, any>;
+
+// A small validator for the JSON Schema keywords gallery/schema.json uses, so
+// the schema file stays the single source of truth without a new dependency.
+// Unknown keywords fail loudly instead of being silently ignored.
+const KNOWN_KEYWORDS = new Set([
+ '$schema',
+ '$id',
+ '$ref',
+ 'title',
+ 'description',
+ 'definitions',
+ 'type',
+ 'properties',
+ 'required',
+ 'additionalProperties',
+ 'minProperties',
+ 'enum',
+ 'pattern',
+ 'minLength',
+ 'maxLength',
+ 'minimum',
+ 'maximum',
+ 'items',
+ 'minItems',
+ 'uniqueItems',
+]);
+
+function resolveRef(ref: string): Schema {
+ const match = /^#\/definitions\/([A-Za-z0-9_-]+)$/.exec(ref);
+ if (!match) throw new Error(`unsupported $ref ${ref}`);
+ return (schema as Schema).definitions[match[1]];
+}
+
+function typeOf(value: unknown): string {
+ if (Array.isArray(value)) return 'array';
+ if (value === null) return 'null';
+ if (typeof value === 'number') {
+ return Number.isInteger(value) ? 'integer' : 'number';
+ }
+ return typeof value;
+}
+
+function validate(value: unknown, node: Schema, at = '$'): string[] {
+ for (const key of Object.keys(node)) {
+ if (!KNOWN_KEYWORDS.has(key)) {
+ throw new Error(`validator does not support keyword "${key}" at ${at}`);
+ }
+ }
+ if (node.$ref) return validate(value, resolveRef(node.$ref), at);
+
+ const errors: string[] = [];
+ const actual = typeOf(value);
+ if (node.type) {
+ const ok =
+ actual === node.type || (node.type === 'number' && actual === 'integer');
+ if (!ok) return [`${at}: expected ${node.type}, got ${actual}`];
+ }
+ if (node.enum && !node.enum.includes(value)) {
+ errors.push(`${at}: ${JSON.stringify(value)} is not one of ${node.enum}`);
+ }
+ if (typeof value === 'string') {
+ if (node.pattern && !new RegExp(node.pattern).test(value)) {
+ errors.push(`${at}: "${value}" does not match ${node.pattern}`);
+ }
+ if (node.minLength !== undefined && value.length < node.minLength) {
+ errors.push(`${at}: shorter than ${node.minLength}`);
+ }
+ if (node.maxLength !== undefined && value.length > node.maxLength) {
+ errors.push(`${at}: longer than ${node.maxLength}`);
+ }
+ }
+ if (typeof value === 'number') {
+ if (node.minimum !== undefined && value < node.minimum) {
+ errors.push(`${at}: below ${node.minimum}`);
+ }
+ if (node.maximum !== undefined && value > node.maximum) {
+ errors.push(`${at}: above ${node.maximum}`);
+ }
+ }
+ if (Array.isArray(value)) {
+ if (node.minItems !== undefined && value.length < node.minItems) {
+ errors.push(`${at}: fewer than ${node.minItems} items`);
+ }
+ if (node.uniqueItems && new Set(value).size !== value.length) {
+ errors.push(`${at}: items are not unique`);
+ }
+ if (node.items) {
+ value.forEach((item, i) =>
+ errors.push(...validate(item, node.items, `${at}[${i}]`)),
+ );
+ }
+ }
+ if (actual === 'object') {
+ const obj = value as Record<string, unknown>;
+ const props: Schema = node.properties ?? {};
+ for (const key of node.required ?? []) {
+ if (!(key in obj)) errors.push(`${at}: missing "${key}"`);
+ }
+ if (
+ node.minProperties !== undefined &&
+ Object.keys(obj).length < node.minProperties
+ ) {
+ errors.push(`${at}: fewer than ${node.minProperties} properties`);
+ }
+ for (const [key, child] of Object.entries(obj)) {
+ if (props[key]) {
+ errors.push(...validate(child, props[key], `${at}.${key}`));
+ } else if (node.additionalProperties === false) {
+ errors.push(`${at}: unknown field "${key}"`);
+ }
+ }
+ }
+ return errors;
+}
+
+const recipeFiles = fs
+ .readdirSync(APPS_DIR)
+ .filter((file) => file.endsWith('.json'))
+ .sort();
+
+const recipes = recipeFiles.map((file) => ({
+ file,
+ recipe: JSON.parse(fs.readFileSync(path.join(APPS_DIR, file), 'utf8')),
+}));
+
+const validRecipe = {
+ id: 'example',
+ version: 1,
+ name: { en: 'Example', 'zh-Hans': '示例' },
+ url: 'https://example.com/',
+ category: 'reading',
+ description: { en: 'An example site', 'zh-Hans': '一个示例网站' },
+ icon: 'https://example.com/apple-touch-icon.png',
+};
+
+describe('gallery schema validator', () => {
+ it('accepts a minimal recipe', () => {
+ expect(validate(validRecipe, schema)).toEqual([]);
+ });
+
+ it.each([
+ ['a missing locale', { name: { en: 'Example' } }, 'missing "zh-Hans"'],
+ ['an uppercase id', { id: 'Example' }, 'does not match'],
+ ['an http url', { url: 'http://example.com/' }, 'does not match'],
+ ['an unknown category', { category: 'games' }, 'is not one of'],
+ ['a fractional version', { version: 1.5 }, 'expected integer'],
+ ['an unknown window field', { window: { title: 'x' } }, 'unknown field'],
+ ['an out-of-range zoom', { window: { zoom: 400 } }, 'above 200'],
+ ['an inject path', { inject_css: '../evil.css' }, 'does not match'],
+ ['an unknown top-level field', { homepage: 'x' }, 'unknown field'],
+ ])('rejects %s', (_, patch, message) => {
+ const errors = validate({ ...validRecipe, ...patch }, schema);
+ expect(errors.join('\n')).toContain(message);
+ });
+});
+
+describe('gallery recipes', () => {
+ it('has recipes to check', () => {
+ expect(recipes.length).toBeGreaterThan(0);
+ });
+
+ it.each(recipes)('$file matches the schema', ({ recipe }) => {
+ expect(validate(recipe, schema)).toEqual([]);
+ });
+
+ it.each(recipes)('$file is named after its id', ({ file, recipe }) => {
+ expect(file).toBe(`${recipe.id}.json`);
+ });
+
+ it('uses unique ids and names', () => {
+ const ids = recipes.map(({ recipe }) => recipe.id);
+ expect(new Set(ids).size).toBe(ids.length);
+ for (const locale of ['en', 'zh-Hans']) {
+ const names = recipes.map(({ recipe }) =>
+ recipe.name[locale].toLowerCase(),
+ );
+ expect(new Set(names).size, locale).toBe(names.length);
+ }
+ });
+
+ // The apps match an address to a recipe by host, so a second recipe on the
+ // same host would never be found.
+ it('uses one recipe per site host', () => {
+ const hosts = recipes.map(({ recipe }) =>
+ new URL(recipe.url).hostname.replace(/^www\./, ''),
+ );
+ expect(new Set(hosts).size).toBe(hosts.length);
+ });
+
+ it.each(recipes)('$file uses https urls', ({ recipe }) => {
+ expect(new URL(recipe.url).protocol).toBe('https:');
+ expect(new URL(recipe.icon).protocol).toBe('https:');
+ });
+
+ it.each(recipes)('$file has text in both locales', ({ recipe }) => {
+ for (const field of ['name', 'description']) {
+ for (const locale of ['en', 'zh-Hans']) {
+ const text: string = recipe[field][locale];
+ expect(text.trim(), `${field}.${locale}`).toBe(text);
+ expect(text.length, `${field}.${locale}`).toBeGreaterThan(0);
+ expect(text, `${field}.${locale}`).not.toMatch(/[—→↓]/);
+ if (field === 'description') {
+ expect(text, `${field}.${locale}`).not.toMatch(/[.。]$/);
+ }
+ }
+ }
+ });
+
+ it.each(recipes)('$file points at inject files that exist', ({ recipe }) => {
+ for (const field of ['inject_css', 'inject_js']) {
+ if (recipe[field] === undefined) continue;
+ expect(
+ fs.existsSync(path.join(APPS_DIR, recipe[field])),
+ `${recipe.id}.${field}`,
+ ).toBe(true);
+ }
+ });
+
+ it('has no inject file that no recipe uses', () => {
+ const used = new Set(
+ recipes.flatMap(({ recipe }) =>
+ [recipe.inject_css, recipe.inject_js].filter(Boolean),
+ ),
+ );
+ const extra = fs
+ .readdirSync(APPS_DIR)
+ .filter((file) => !file.endsWith('.json') && !used.has(file));
+ expect(extra).toEqual([]);
+ });
+});