Skip to content

Commit b598284

Browse files
authored
feat: Compatibility table (#2742)
1 parent ee173bb commit b598284

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+864
-247
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"dev": "astro dev",
1313
"format": "prettier -w --cache --plugin prettier-plugin-astro .",
1414
"format:check": "prettier -c --cache --plugin prettier-plugin-astro .",
15+
"build:compatibility-table": "pnpm --filter compatibility-table run build",
1516
"build:references": "pnpm --filter js-api-generator run build",
1617
"build:releases": "pnpm --filter releases-generator run build",
1718
"build:config": "pnpm --filter config-generator run build",
1819
"build:cli": "pnpm --filter cli-generator run build",
1920
"build:astro": "astro build",
2021
"build:i18n": "pnpm --filter docs-i18n-tracker run build",
21-
"build": "pnpm dev:setup && pnpm build:references && pnpm build:config && pnpm build:cli && pnpm build:releases && pnpm build:astro && pnpm build:i18n",
22+
"build": "pnpm dev:setup && pnpm build:references && pnpm build:config && pnpm build:cli && pnpm build:releases && pnpm build:compatibility-table && pnpm build:astro && pnpm build:i18n",
2223
"preview": "astro preview"
2324
},
2425
"dependencies": {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { readdir, readFile } from 'fs/promises';
2+
import { writeFileSync } from 'node:fs';
3+
import TOML from '@iarna/toml';
4+
import path from 'path';
5+
6+
// todo: resolve dir
7+
const baseDir = '../plugins-workspace';
8+
const pluginDir = '../plugins-workspace/plugins';
9+
10+
async function main() {
11+
const plugins = await readdir(pluginDir);
12+
13+
const workspaceCargo = TOML.parse(await readFile(path.join(baseDir, 'Cargo.toml'), 'utf-8'));
14+
const baseRustVersion = workspaceCargo.workspace.package['rust-version'];
15+
16+
const tables: Record<string, any> = {};
17+
for (const plugin of plugins) {
18+
// using Record<string, any> but it's not reaaaally safe, might as well use any
19+
const pluginPath = path.join(pluginDir, plugin, 'Cargo.toml');
20+
try {
21+
const data = TOML.parse(await readFile(pluginPath, 'utf-8'));
22+
const pkg = data.package as Record<string, any>;
23+
24+
const hasSpecificRustVersion = pkg['rust-version'] && !pkg['rust-version'].workspace;
25+
const platformsSupport: Record<string, any> = pkg.metadata.platforms.support;
26+
27+
// todo: fix platforms case iOS, Windows...
28+
const support = Object.entries(platformsSupport).map(([platform, supportInfo]) => ({
29+
platform,
30+
...supportInfo,
31+
}));
32+
33+
tables[plugin] = {
34+
rustVersion: hasSpecificRustVersion ? pkg['rust-version'] : baseRustVersion,
35+
support,
36+
};
37+
} catch (error) {
38+
continue;
39+
}
40+
}
41+
42+
writeFileSync('../../src/components/plugins/_tableContent.json', JSON.stringify(tables, null, 2));
43+
}
44+
45+
main();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "compatibility-table",
3+
"version": "1.0.0",
4+
"private": "true",
5+
"description": "",
6+
"main": "index.js",
7+
"type": "module",
8+
"scripts": {
9+
"build": "tsm ./build.ts"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "MIT",
14+
"dependencies": {
15+
"@iarna/toml": "^2.2.5",
16+
"@types/node": "^20.11.20",
17+
"tsm": "^2.3.0",
18+
"typescript": "^5.3.3"
19+
}
20+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"strict": true,
5+
"skipLibCheck": true
6+
}
7+
}

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ packages:
55
- 'packages/cli-generator'
66
- 'packages/tauri-typedoc-theme'
77
- 'packages/releases-generator'
8+
- 'packages/compatibility-table'

public/assets/platforms.svg

Lines changed: 10 additions & 0 deletions
Loading

src/components/list/Directory.astro

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import {
44
stripLeadingAndTrailingSlashes,
55
ensureTrailingSlash,
66
} from 'node_modules/@astrojs/starlight/utils/path';
7-
import { LinkCard, CardGrid } from '@astrojs/starlight/components';
7+
import { CardGrid } from '@astrojs/starlight/components';
88
import { routes, type Route } from 'node_modules/@astrojs/starlight/utils/routing';
99
10+
// custom component copied from starlight/components/LinkCard
11+
import CustomLinkCard from '@components/plugins/CustomLinkCard.astro';
12+
1013
interface Props {
1114
/**
1215
* Slug relative to /src - e.g "/zh-cn/features"
@@ -28,6 +31,11 @@ interface Props {
2831
* Use this to ignore sidebar order
2932
*/
3033
sortAlphabetically?: boolean;
34+
35+
/*
36+
* specifically to support compatibility footer in CustomLink card
37+
*/
38+
callback?: Function;
3139
}
3240
3341
function hasSidebarOrder(page: Route): number | undefined {
@@ -43,7 +51,12 @@ function compareOrder(a: Route, b: Route): boolean {
4351
}
4452
4553
let { slug } = Astro.props;
46-
const { filterOutByTitle = [], filterOutByFileName = [], sortAlphabetically = false } = Astro.props;
54+
const {
55+
filterOutByTitle = [],
56+
filterOutByFileName = [],
57+
sortAlphabetically = false,
58+
callback,
59+
} = Astro.props;
4760
4861
const defaultLocale = config.defaultLocale.lang || 'en';
4962
const localesList = config.isMultilingual ? Object.keys(config.locales) : [defaultLocale];
@@ -137,22 +150,26 @@ if (!sortAlphabetically) {
137150

138151
<CardGrid>
139152
{
140-
mainList.map((item) => (
141-
<LinkCard
142-
title={item.entry.data.title}
143-
href={`/${item.slug}`}
144-
description={item.entry.data.description}
145-
/>
146-
))
153+
mainList.map((item) => {
154+
return (
155+
<CustomLinkCard
156+
title={item.entry.data.title}
157+
href={`/${item.slug}/`}
158+
description={item.entry.data.description}
159+
footer={callback instanceof Function && callback(item.slug)}
160+
/>
161+
);
162+
})
147163
}
148164
{
149165
locale !== defaultLocale &&
150166
fallbackList.map((item) => (
151-
<LinkCard
167+
<CustomLinkCard
152168
class="fallback-badge"
153169
title={item.entry.data.title}
154-
href={`/${item.slug}`}
170+
href={`/${item.slug}/`}
155171
description={item.entry.data.description}
172+
footer={callback instanceof Function && callback(item.slug)}
156173
/>
157174
))
158175
}

src/components/list/Features.astro

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
---
22
import Directory from './Directory.astro';
3+
4+
import { type PluginData, getPlatformSupportIcon } from 'src/components/plugins/_helpers';
5+
import data from 'src/components/plugins/_tableContent.json';
6+
7+
const fallBackNames: Record<string, string> = {
8+
clipboard: 'clipboard-manager',
9+
'deep-linking': 'deep-link',
10+
dialog: 'dialog',
11+
'file-system': 'fs',
12+
'http-client': 'http',
13+
localhost: 'localhost',
14+
logging: 'log',
15+
nfc: 'nfc',
16+
'os-info': 'os',
17+
};
18+
19+
function fetchData(pluginSlug: string) {
20+
// assuming slug is "locale?/plugin/{pluginName}"
21+
const plugin = pluginSlug.split('plugin/')[1];
22+
let pluginData: PluginData = data[plugin];
23+
if (!pluginData) {
24+
pluginData = data[fallBackNames[plugin]];
25+
if (!pluginData) {
26+
console.log(
27+
`[Plugin Support] '${plugin}' data is missing or it's name doesn't match any existing plugin`
28+
);
29+
return '';
30+
}
31+
}
32+
return pluginData.support.map((plat) => getPlatformSupportIcon(plat.level, plat.platform));
33+
}
334
---
435

5-
<Directory slug="features" />
36+
<Directory slug="plugin" callback={fetchData} />

src/components/plugins/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_tableContent.json

0 commit comments

Comments
 (0)