Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Oct 8, 2024
1 parent c541017 commit 2dbf224
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 274 deletions.
2 changes: 2 additions & 0 deletions js/apps/docs/contents/blog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ import BlogPosts from "../../components/BlogPosts.vue";

# Blog

Things we want to share along the way.

<BlogPosts />
2 changes: 1 addition & 1 deletion js/apps/docs/contents/blog/web-context-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Building Plugins in the DOM with Web Components
date: 2024-10-08
author: Yujong Lee
draft: true
draft: false

next: false
sidebar: false
Expand Down
90 changes: 0 additions & 90 deletions js/apps/docs/contents/docs/common/customization/builtin.md

This file was deleted.

29 changes: 0 additions & 29 deletions js/apps/docs/contents/docs/common/customization/styling.parts.md

This file was deleted.

This file was deleted.

105 changes: 0 additions & 105 deletions js/packages/web/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,4 @@
import * as fs from "fs";
import * as path from "path";
import { execSync } from "child_process";

import type { Plugin as CEMPlugin } from "@custom-elements-manifest/analyzer";
import type { Plugin as VitePlugin } from "vite";

export const cssVariablesReportPlugin = (): VitePlugin => {
const regex = /--canary-[\w-]+/g;
const set = new Set<string>();
let root = "";

return {
name: "css-variables-report",
configResolved(config) {
root = config.root;
if (!root) {
throw new Error();
}
},
transform(code, path) {
if (!path.startsWith(root)) {
return code;
}

code.match(regex)?.forEach((match) => {
set.add(match);
});

return code;
},
buildEnd() {
const outfile = path.resolve(
root,
"../../apps/docs/contents/docs/common/customization/styling.variables.md",
);

const content =
Array.from(set)
.sort()
.map((variable) => `- \`${variable}\``)
.join("\n") + "\n";

fs.writeFileSync(outfile, content);
},
};
};

export const partsReportPlugin = (): VitePlugin => {
const components: Record<string, Set<string>> = {};
let root = "";

return {
name: "parts-report",
configResolved(config) {
root = config.root;
if (!root) {
throw new Error("Root directory not found in config");
}
},
transform(code, filePath) {
if (!filePath.startsWith(root)) {
return code;
}

const match = filePath.match(/\/(canary-[^\/]+)\.(ts|js)$/);
if (!match) {
return code;
}

const parts = [...code.matchAll(/part="([\w-]+)"/g)].map((m) => m[1]);
if (parts.length === 0) {
return code;
}

components[match[1]] = new Set(parts);

return code;
},
buildEnd() {
const outfile = path.resolve(
root,
"../../apps/docs/contents/docs/common/customization/styling.parts.md",
);

const content = Object.entries(components)
.sort(([a], [b]) => a.localeCompare(b))
.map(([component, parts]) => {
const partsRendered = Array.from(parts)
.sort()
.map((p) => ` - \`${p}\``)
.join("\n");

return `- \`${component}\`\n${partsRendered}`;
})
.join("\n");

try {
fs.writeFileSync(outfile, content);
execSync(`npm run format -w=@getcanary/web`, { stdio: "inherit" });
} catch (e) {
console.error(e);
}
},
};
};

type Import = {
name: string;
Expand Down
8 changes: 1 addition & 7 deletions js/packages/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import unocss from "unocss/vite";

import dts from "vite-plugin-dts";
import cem from "vite-plugin-cem";
import {
partsReportPlugin,
cssVariablesReportPlugin,
canaryImportPlugin,
} from "./plugins";
import { canaryImportPlugin } from "./plugins";

const components = [
...["canary-root", "canary-styles"],
Expand Down Expand Up @@ -68,8 +64,6 @@ export default defineConfig({
environmentMatchGlobs: [["./src/store/*.test.ts", "happy-dom"]],
},
plugins: [
process.env.GENERATE_DOCS === "1" && partsReportPlugin(),
process.env.GENERATE_DOCS === "1" && cssVariablesReportPlugin(),
unocss({ mode: "shadow-dom" }),
dts({
include: ["src/**/*.ts"],
Expand Down

0 comments on commit 2dbf224

Please sign in to comment.