Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/check-file-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check starter file list

on:
pull_request:

jobs:
check-file-list:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- run: node scripts/update-file-list.js

- name: Check for changes
run: |
if [ -n "$(git status --porcelain starter-files.json)" ]; then
echo "::error::Please run 'npm run update-file-list' and commit the changed starter-files.json"
exit 1
fi
2 changes: 1 addition & 1 deletion .tsbuildinfo

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"update-tsbuildinfo": "npx tsgo --noEmit -p tsconfig.app.json --pretty"
"update-tsbuildinfo": "npx tsgo --noEmit -p tsconfig.app.json --pretty",
"update-file-list": "node scripts/update-file-list.js"
},
"dependencies": {
"@fillout/react": "^3.0.0",
Expand Down
31 changes: 31 additions & 0 deletions scripts/update-file-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { readdir } from "node:fs/promises";
import { join, relative } from "node:path";
import { writeFileSync } from "node:fs";

const ROOT = new URL("..", import.meta.url).pathname;
const SRC = join(ROOT, "src");
const EXCLUDE_FILES = ["App.tsx"];
const EXCLUDE_DIRS = ["__zite__"];

async function listFiles(dir) {
const entries = await readdir(dir, { withFileTypes: true });
const files = [];
for (const entry of entries) {
const full = join(dir.toString(), entry.name);
if (entry.isDirectory()) {
if (!EXCLUDE_DIRS.includes(entry.name)) {
files.push(...(await listFiles(full)));
}
} else {
const rel = relative(ROOT, full);
if (!EXCLUDE_FILES.includes(rel) && !entry.name.endsWith(".d.ts")) {
files.push(rel);
}
}
}
return files.sort();
}

const files = await listFiles(SRC);
writeFileSync(join(ROOT, "starter-files.json"), JSON.stringify(files, null, 2) + "\n");
console.log(`Wrote ${files.length} files to starter-files.json`);
52 changes: 52 additions & 0 deletions starter-files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
"src/App.tsx",
"src/NotFound.tsx",
"src/components/markdown-editor/MarkdownEditor.samples.tsx",
"src/components/markdown-editor/MarkdownEditor.tsx",
"src/components/markdown-editor/index.tsx",
"src/components/ui/accordion.tsx",
"src/components/ui/alert-dialog.tsx",
"src/components/ui/alert.tsx",
"src/components/ui/aspect-ratio.tsx",
"src/components/ui/avatar.tsx",
"src/components/ui/badge.tsx",
"src/components/ui/button.tsx",
"src/components/ui/calendar.tsx",
"src/components/ui/card.tsx",
"src/components/ui/checkbox.tsx",
"src/components/ui/collapsible.tsx",
"src/components/ui/command.tsx",
"src/components/ui/context-menu.tsx",
"src/components/ui/dialog.tsx",
"src/components/ui/dropdown-menu.tsx",
"src/components/ui/form.tsx",
"src/components/ui/hover-card.tsx",
"src/components/ui/input.tsx",
"src/components/ui/label.tsx",
"src/components/ui/menubar.tsx",
"src/components/ui/navigation-menu.tsx",
"src/components/ui/popover.tsx",
"src/components/ui/progress.tsx",
"src/components/ui/radio-group.tsx",
"src/components/ui/scroll-area.tsx",
"src/components/ui/select.tsx",
"src/components/ui/separator.tsx",
"src/components/ui/sheet.tsx",
"src/components/ui/sidebar.tsx",
"src/components/ui/skeleton.tsx",
"src/components/ui/slider.tsx",
"src/components/ui/sonner.tsx",
"src/components/ui/switch.tsx",
"src/components/ui/table.tsx",
"src/components/ui/tabs.tsx",
"src/components/ui/textarea.tsx",
"src/components/ui/toast.tsx",
"src/components/ui/toaster.tsx",
"src/components/ui/toggle.tsx",
"src/components/ui/tooltip.tsx",
"src/hooks/use-mobile.tsx",
"src/hooks/use-toast.ts",
"src/index.css",
"src/lib/utils.ts",
"src/main.tsx"
]
9 changes: 8 additions & 1 deletion ziteId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MagicString from "magic-string";
import path from "path";
import { Plugin } from "vite";
import { walk } from "estree-walker";
import starterFiles from "./starter-files.json";

const validExtensions = new Set([".jsx", ".tsx"]);

Expand Down Expand Up @@ -32,6 +33,11 @@ function isNativeElement(name: string): boolean {
return /^[a-z]/.test(name) && !name.includes(".");
}

function isStarterFile(fileName: string): boolean {
const relative = path.relative(__dirname, fileName);
return starterFiles.includes(relative);
}

export function ziteId(): Plugin {
const cwd = process.cwd();
return {
Expand All @@ -40,7 +46,8 @@ export function ziteId(): Plugin {
async transform(code, id) {
if (
!validExtensions.has(path.extname(id)) ||
id.includes("node_modules")
id.includes("node_modules") ||
isStarterFile(id)
) {
return null;
}
Expand Down