Skip to content

Commit b8cc416

Browse files
committed
chore: only push readme to remote
1 parent 7c6ac32 commit b8cc416

File tree

4 files changed

+21
-52
lines changed

4 files changed

+21
-52
lines changed

.github/sync.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
magicbell/magicbell:
22
- source: docs-dist
3-
dest: src/go/app/site/docs/mdx/03-libraries/magicbell-swift-user-client
3+
dest: src/go/app/site/docs/mdx/03-libraries/magicbell-swift-user-client
4+
deleteOrphaned: true
5+

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@types/node": "^22.10.2",
1616
"glob": "^11.0.0",
1717
"replace-in-file": "^8.2.0",
18-
"tsx": "^4.19.2"
18+
"tsx": "^4.19.2",
19+
"url-join": "^5.0.0"
1920
}
2021
}

scripts/docs.ts

+11-50
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1+
#! /usr/bin/env node --experimental-strip-types
12
import fs from "node:fs/promises";
23
import path from "node:path";
34

4-
import { exists, getDirs } from "@magicbell/codegen/fs";
55
import * as md from "@magicbell/codegen/markdown";
66
import * as glob from "glob";
7+
import urlJoin from 'url-join';
78

89
function pascalToHyphenCase(str: string): string {
910
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1011
}
1112

12-
function rewriteHref(url: string) {
13-
if (!url.endsWith(".md")) return url;
14-
return url
15-
.replace(/^documentation\//, "")
16-
.replace(/([^/]+)\.md$/, (_, fileName) => pascalToHyphenCase(fileName));
17-
}
18-
1913
const root = process.cwd();
2014
const outdir = path.join(root, "docs-dist");
2115
await fs.rm(outdir, { recursive: true, force: true });
2216

2317
const pkg = JSON.parse(await fs.readFile("package.json", "utf-8"));
18+
const repoUrl = 'https://github.com/magicbell/magicbell-swift-user-client/blob/main'
19+
function rewriteHref(url: string) {
20+
if (url.startsWith('http://') || url.startsWith('https://')) return url;
21+
console.log('join', repoUrl, url);
22+
return urlJoin(repoUrl, 'documentation', url);
23+
}
2424

25-
// process readmes
25+
// process readme
2626
const [readme] = glob.sync("README.md", { cwd: root });
2727
const rootIndexAst = await md.read(path.join(root, readme));
2828
md.removeAllBeforeHeading(rootIndexAst, "Setup & Configuration");
2929

30-
const [reference] = glob.sync("**/README.md", {
31-
cwd: path.join(root, "documentation"),
32-
});
33-
const referenceAst = await md.read(path.join(root, "documentation", reference));
30+
const [reference] = glob.sync("documentation/**/README.md", { cwd: root });
31+
const referenceAst = await md.read(path.join(root, reference));
3432
md.reIndentHeadings(referenceAst, 2);
3533
// append references to root index
3634
rootIndexAst.children = rootIndexAst.children.concat(referenceAst.children);
@@ -39,40 +37,3 @@ md.reIndentHeadings(rootIndexAst, 1);
3937
md.mapLinks(rootIndexAst, rewriteHref);
4038
md.insertFrontMatter(rootIndexAst, { title: pkg.name });
4139
await md.write(rootIndexAst, path.join(outdir, "index.mdx"));
42-
43-
// process pages
44-
const docs = glob.sync("**/*.md", {
45-
cwd: path.join(root, "documentation"),
46-
});
47-
48-
for (const file of docs) {
49-
if (file === "README.md") continue;
50-
const ast = await md.read(path.join(root, "documentation", file));
51-
52-
md.reIndentHeadings(ast, 1);
53-
md.mapLinks(ast, rewriteHref);
54-
55-
let titleComponents = path.parse(file).name.split(".");
56-
// Removing noisy namespaces
57-
if (titleComponents.length > 1 && titleComponents[0] === "Components") {
58-
titleComponents.shift();
59-
}
60-
if (titleComponents.length > 1 && titleComponents[0] === "Schemas") {
61-
titleComponents.shift();
62-
}
63-
if (titleComponents.length > 1 && titleComponents[0] === "Operations") {
64-
titleComponents.shift();
65-
}
66-
md.insertFrontMatter(ast, { title: titleComponents.join(".") });
67-
md.removeFirstHeading(ast);
68-
69-
await md.write(ast, path.join(outdir, pascalToHyphenCase(file) + "x"));
70-
}
71-
72-
for (const dir of getDirs(docs)) {
73-
const file = path.join(outdir, dir, "index.mdx");
74-
if (await exists(file)) continue;
75-
const ast: md.Root = { type: "root", children: [] };
76-
md.insertFrontMatter(ast, { title: path.basename(dir) });
77-
await md.write(ast, pascalToHyphenCase(file));
78-
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,11 @@ uri-js@^4.2.2:
23262326
dependencies:
23272327
punycode "^2.1.0"
23282328

2329+
url-join@^5.0.0:
2330+
version "5.0.0"
2331+
resolved "https://registry.yarnpkg.com/url-join/-/url-join-5.0.0.tgz#c2f1e5cbd95fa91082a93b58a1f42fecb4bdbcf1"
2332+
integrity sha512-n2huDr9h9yzd6exQVnH/jU5mr+Pfx08LRXXZhkLLetAMESRj+anQsTAh940iMrIetKAmry9coFuZQ2jY8/p3WA==
2333+
23292334
validate.io-array@^1.0.3:
23302335
version "1.0.6"
23312336
resolved "https://registry.yarnpkg.com/validate.io-array/-/validate.io-array-1.0.6.tgz#5b5a2cafd8f8b85abb2f886ba153f2d93a27774d"

0 commit comments

Comments
 (0)