Skip to content

Commit 1c5eff2

Browse files
Merge pull request #182 from madhuramendis/test
Add marketplace
2 parents 901b953 + 98ca52d commit 1c5eff2

File tree

12 files changed

+2394
-13
lines changed

12 files changed

+2394
-13
lines changed

docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ const config: Config = {
209209
} satisfies Preset.ThemeConfig,
210210
};
211211

212-
export default config;
212+
export default config;

package-lock.json

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

package.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
7-
"start": "docusaurus start",
8-
"build": "docusaurus build",
7+
"gen:plugins": "node scripts/generate-plugin-json.mjs",
8+
"start": "npm run gen:plugins && docusaurus start",
9+
"build": "npm run gen:plugins && docusaurus build",
910
"swizzle": "docusaurus swizzle",
1011
"deploy": "docusaurus deploy",
1112
"clear": "docusaurus clear",
@@ -19,6 +20,7 @@
1920
"@docusaurus/preset-classic": "^3.9.2",
2021
"@mdx-js/react": "^3.0.0",
2122
"clsx": "^2.0.0",
23+
"lucide-react": "^0.555.0",
2224
"prism-react-renderer": "^2.3.0",
2325
"react": "^19.0.0",
2426
"react-dom": "^19.0.0"
@@ -30,16 +32,8 @@
3032
"typescript": "~5.6.2"
3133
},
3234
"browserslist": {
33-
"production": [
34-
">0.5%",
35-
"not dead",
36-
"not op_mini all"
37-
],
38-
"development": [
39-
"last 3 chrome version",
40-
"last 3 firefox version",
41-
"last 5 safari version"
42-
]
35+
"production": [">0.5%", "not dead", "not op_mini all"],
36+
"development": ["last 3 chrome version", "last 3 firefox version", "last 5 safari version"]
4337
},
4438
"engines": {
4539
"node": ">=18.0"

scripts/generate-plugin-json.mjs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
4+
function toOwnerRepo(repo) {
5+
if (!repo) return null;
6+
7+
let s = String(repo).trim().replace(/\/+$/, "");
8+
9+
// strip github prefixes
10+
s = s.replace(/^https?:\/\/(www\.)?github\.com\//i, "");
11+
s = s.replace(/^(www\.)?github\.com\//i, "");
12+
13+
// remove /tree/... or /blob/... if pasted
14+
const parts = s.split("/").filter(Boolean);
15+
if (parts.length < 2) return null;
16+
17+
return `${parts[0]}/${parts[1]}`;
18+
}
19+
20+
async function getStars(ownerRepo) {
21+
const res = await fetch(`https://api.github.com/repos/${ownerRepo}`, {
22+
headers: {
23+
Accept: "application/vnd.github+json",
24+
"User-Agent": "openchoreo-stars-generator",
25+
...(process.env.GITHUB_TOKEN
26+
? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` }
27+
: {}),
28+
},
29+
});
30+
31+
if (!res.ok) {
32+
let body = "";
33+
try {
34+
body = await res.text();
35+
} catch {
36+
// ignore
37+
}
38+
return { ok: false, status: res.status, body };
39+
}
40+
41+
const data = await res.json();
42+
const count = data?.stargazers_count;
43+
return { ok: true, stars: typeof count === "number" ? count : 0 };
44+
}
45+
46+
async function main() {
47+
const inputPath = path.join("src", "data", "marketplace-plugins.source.json");
48+
const outputPath = path.join("src", "data", "marketplace-plugins.json");
49+
50+
const raw = await fs.readFile(inputPath, "utf8");
51+
const plugins = JSON.parse(raw);
52+
53+
const out = [];
54+
for (const p of plugins) {
55+
const ownerRepo = toOwnerRepo(p.repo);
56+
57+
if (!ownerRepo) {
58+
console.warn(` Invalid repo for "${p.name}": ${p.repo}`);
59+
out.push({ ...p, stars: 0 });
60+
continue;
61+
}
62+
63+
const result = await getStars(ownerRepo);
64+
65+
if (!result.ok) {
66+
console.warn(
67+
` Stars fetch failed for ${ownerRepo} (${result.status}). Setting stars=0.`
68+
);
69+
// uncomment next line if you want full error text
70+
// console.warn(result.body);
71+
out.push({ ...p, stars: 0 });
72+
continue;
73+
}
74+
75+
out.push({ ...p, stars: result.stars });
76+
}
77+
78+
await fs.writeFile(outputPath, JSON.stringify(out, null, 2) + "\n", "utf8");
79+
console.log(`Generated: ${outputPath}`);
80+
}
81+
82+
main().catch((e) => {
83+
console.error(" Failed generating plugin JSON:", e);
84+
process.exit(1);
85+
});

0 commit comments

Comments
 (0)