create-signet-app 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # create-signet-app
2
+
3
+ Scaffold a Vite + React 19 + TypeScript + Tailwind v4 app wired to
4
+ `@nimit9/signet-tokens`, `@nimit9/signet-ui` and `@nimit9/signet-lib`.
5
+
6
+ ```bash
7
+ bun run packages/create-signet-app/src/index.ts apps/my-app --theme cinematic
8
+ cd apps/my-app && bun install && bun dev
9
+ ```
10
+
11
+ `--theme` takes `editorial` or `cinematic` (default `editorial`).
12
+
13
+ ## Why
14
+
15
+ The audit found this exact setup rebuilt by hand 13 times across 23 products,
16
+ and the five-package eslint config copied as a block into **exactly 8 of 23**
17
+ repos — the identical count for all five packages is the signature of
18
+ copy-paste, not configuration.
19
+
20
+ ## What you get
21
+
22
+ - `dev` / `build` / `preview` / `lint` / `typecheck` — the script names already
23
+ used across the existing repos, so muscle memory carries over
24
+ - `tsconfig.json` with app/node project references, strict, path alias `@/*`
25
+ - eslint flat config, **fixed** (see below)
26
+ - `src/app.css` importing the chosen theme
27
+ - `main.tsx` with `ThemeProvider`, a `QueryClient` on Signet defaults, and a
28
+ single-redirect 401 handler
29
+ - `index.html` with a blocking script that applies the stored theme before first
30
+ paint — React mounts too late, and without it there is a visible flash
31
+ - `src/lib/api.ts` with a configured `createApiClient`
32
+
33
+ ## Two bugs this fixes in the copied setup
34
+
35
+ **`import.meta.env` did not typecheck.** The copied `tsconfig.app.json` omits
36
+ `"types": ["vite/client"]`, so `tsc -b` fails on any use of an env var.
37
+
38
+ **The eslint config is broken against current versions.** The config in the
39
+ existing repos uses `reactHooks.configs.flat.recommended`, which was removed in
40
+ `eslint-plugin-react-hooks` 5.2. Installing fresh gives:
41
+
42
+ ```
43
+ TypeError: Cannot read properties of undefined (reading 'recommended')
44
+ ```
45
+
46
+ The template uses `reactHooks.configs["recommended-latest"]`. Existing repos
47
+ only still work because their lockfiles pin older versions — copying their
48
+ config into anything new produces a crash.
49
+
50
+ ## Test
51
+
52
+ `bun run test` scaffolds a real app, installs, builds and lints it, then asserts
53
+ the chosen theme reached the production CSS bundle (`.text-sm{font-size:1rem}`
54
+ and `.rounded-lg{border-radius:.1875rem}` for cinematic, not editorial's
55
+ `0.8125rem` / `.75rem`). Both bugs above were caught by that test on its first
56
+ run.
57
+
58
+ ## Limitation
59
+
60
+ Dependencies are declared `workspace:*`, so a scaffolded app must live inside
61
+ the Signet monorepo (`apps/*`). Publishing the packages to a registry would lift
62
+ that; until then, scaffold into `apps/`.
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "create-signet-app",
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a Vite + React + Tailwind app wired to Signet.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-signet-app": "./src/index.ts"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "template"
12
+ ],
13
+ "scripts": {
14
+ "typecheck": "tsc --noEmit",
15
+ "test": "bun run test/scaffold.ts"
16
+ },
17
+ "devDependencies": {
18
+ "@types/bun": "^1.4.2",
19
+ "typescript": "^7.0.2"
20
+ }
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * create-signet-app — scaffold a Vite + React + TypeScript + Tailwind v4 app
4
+ * wired to @nimit9/signet-tokens, @nimit9/signet-ui and @nimit9/signet-lib.
5
+ *
6
+ * Exists because the audit found the same setup rebuilt by hand 13 times, and
7
+ * the five-package eslint config copied as a block into exactly 8 of 23 repos
8
+ * without ever being templated — a config that turned out to be broken against
9
+ * current plugin versions. Biome replaces the whole graph with one binary.
10
+ */
11
+
12
+ import { cp, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises"
13
+ import { existsSync } from "node:fs"
14
+ import { basename, join, resolve } from "node:path"
15
+
16
+ const THEMES = ["editorial", "cinematic"] as const
17
+ type Theme = (typeof THEMES)[number]
18
+
19
+ const DEPS = {
20
+ "@nimit9/signet-lib": "workspace:*",
21
+ "@nimit9/signet-tokens": "workspace:*",
22
+ "@nimit9/signet-ui": "workspace:*",
23
+ "@tanstack/react-query": "^5.103.2",
24
+ "class-variance-authority": "^0.7.1",
25
+ clsx: "^2.1.1",
26
+ "lucide-react": "^1.47.0",
27
+ react: "^19.3.0",
28
+ "react-dom": "^19.3.0",
29
+ "tailwind-merge": "^3.7.0",
30
+ }
31
+
32
+ const DEV_DEPS = {
33
+ "@biomejs/biome": "^2.5.14",
34
+ "@tailwindcss/vite": "^4.3.3",
35
+ "@types/node": "^26.6.2",
36
+ "@types/react": "^19.3.0",
37
+ "@types/react-dom": "^19.3.0",
38
+ "@vitejs/plugin-react": "^6.1.1",
39
+ tailwindcss: "^4.3.3",
40
+ typescript: "^7.0.2",
41
+ vite: "^8.3.0",
42
+ }
43
+
44
+ function parseArgs(argv: string[]) {
45
+ const args = argv.slice(2)
46
+ let name: string | undefined
47
+ let theme: Theme = "editorial"
48
+
49
+ for (let i = 0; i < args.length; i++) {
50
+ const a = args[i]
51
+ if (a === "--theme" || a === "-t") {
52
+ const v = args[++i]
53
+ if (!THEMES.includes(v as Theme)) {
54
+ throw new Error(`Unknown theme "${v}". Available: ${THEMES.join(", ")}`)
55
+ }
56
+ theme = v as Theme
57
+ } else if (a === "--help" || a === "-h") {
58
+ console.log(`
59
+ create-signet-app <directory> [options]
60
+
61
+ Options:
62
+ -t, --theme <name> ${THEMES.join(" | ")} (default: editorial)
63
+ -h, --help
64
+
65
+ Example:
66
+ bun create-signet-app my-app --theme cinematic
67
+ `)
68
+ process.exit(0)
69
+ } else if (!a.startsWith("-")) {
70
+ name = a
71
+ } else {
72
+ throw new Error(`Unknown option "${a}"`)
73
+ }
74
+ }
75
+
76
+ if (!name) throw new Error("Missing target directory.\nUsage: create-signet-app <directory>")
77
+ return { name, theme }
78
+ }
79
+
80
+ /** Replace placeholders in every text file under dir. */
81
+ async function substitute(dir: string, vars: Record<string, string>) {
82
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
83
+ const full = join(dir, entry.name)
84
+ if (entry.isDirectory()) {
85
+ await substitute(full, vars)
86
+ continue
87
+ }
88
+ let text = await readFile(full, "utf8")
89
+ let changed = false
90
+ for (const [k, v] of Object.entries(vars)) {
91
+ if (text.includes(k)) {
92
+ text = text.replaceAll(k, v)
93
+ changed = true
94
+ }
95
+ }
96
+ if (changed) await writeFile(full, text)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ const { name, theme } = parseArgs(process.argv)
102
+ const target = resolve(process.cwd(), name)
103
+ const appName = basename(target)
104
+
105
+ if (existsSync(target) && (await readdir(target)).length > 0) {
106
+ throw new Error(`${target} already exists and is not empty.`)
107
+ }
108
+
109
+ const templateDir = resolve(import.meta.dirname, "../template")
110
+ await mkdir(target, { recursive: true })
111
+ await cp(templateDir, target, { recursive: true })
112
+
113
+ // npm strips a file literally named .gitignore from published packages, so
114
+ // the template ships it as _gitignore and it is renamed on scaffold.
115
+ await rename(join(target, "_gitignore"), join(target, ".gitignore"))
116
+
117
+ await substitute(target, { __APP_NAME__: appName, __THEME__: theme })
118
+
119
+ await writeFile(
120
+ join(target, "package.json"),
121
+ `${JSON.stringify(
122
+ {
123
+ name: appName,
124
+ private: true,
125
+ version: "0.1.0",
126
+ type: "module",
127
+ scripts: {
128
+ dev: "vite",
129
+ build: "tsc -b && vite build",
130
+ preview: "vite preview",
131
+ lint: "biome check .",
132
+ format: "biome check --write .",
133
+ typecheck: "tsc -b --noEmit",
134
+ },
135
+ dependencies: DEPS,
136
+ devDependencies: DEV_DEPS,
137
+ },
138
+ null,
139
+ 2,
140
+ )}\n`,
141
+ )
142
+
143
+ console.log(`
144
+ Created ${appName} with the ${theme} theme.
145
+
146
+ cd ${name}
147
+ bun install
148
+ bun dev
149
+
150
+ Switch themes by editing the @nimit9/signet-tokens import in src/app.css.
151
+ `)
152
+ }
153
+
154
+ main().catch((err: unknown) => {
155
+ console.error(`\n ${err instanceof Error ? err.message : String(err)}\n`)
156
+ process.exit(1)
157
+ })
@@ -0,0 +1,3 @@
1
+ # Client vars must be prefixed VITE_ to be exposed to the browser.
2
+ # Anything here ends up in the bundle — never put a secret in this file.
3
+ VITE_API_BASE=/api
@@ -0,0 +1,8 @@
1
+ node_modules
2
+ dist
3
+ .env
4
+ .env.local
5
+ *.tsbuildinfo
6
+ .DS_Store
7
+ .wrangler
8
+ .vercel
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",
3
+ "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
4
+ "files": { "ignoreUnknown": true },
5
+ "formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2, "lineWidth": 100 },
6
+ "javascript": { "formatter": { "quoteStyle": "double", "semicolons": "asNeeded" } },
7
+ "linter": {
8
+ "enabled": true,
9
+ "rules": {
10
+ "correctness": { "useExhaustiveDependencies": "warn", "useHookAtTopLevel": "error" },
11
+ "suspicious": { "noExplicitAny": "warn" }
12
+ }
13
+ },
14
+ "assist": { "actions": { "source": { "organizeImports": "on" } } }
15
+ }
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>__APP_NAME__</title>
7
+ <!-- Applies the stored theme before first paint. React mounts too late;
8
+ without this there is a visible flash of the wrong theme on load. -->
9
+ <script>
10
+ (() => { try { const t = localStorage.getItem("signet-theme"); const d = t === "dark" || ((!t || t === "system") && matchMedia("(prefers-color-scheme: dark)").matches); document.documentElement.classList.toggle("dark", d); document.documentElement.style.colorScheme = d ? "dark" : "light" } catch {} })()
11
+ </script>
12
+ </head>
13
+ <body>
14
+ <div id="root"></div>
15
+ <script type="module" src="/src/main.tsx"></script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,32 @@
1
+ import { Badge } from "@nimit9/signet-ui/components/badge"
2
+ import { Button } from "@nimit9/signet-ui/components/button"
3
+ import { Card, CardContent, CardHeader, CardTitle } from "@nimit9/signet-ui/components/card"
4
+ import { ThemeToggle } from "@nimit9/signet-ui/components/theme-toggle"
5
+
6
+ export default function App() {
7
+ return (
8
+ <div className="min-h-dvh bg-background text-foreground">
9
+ <header className="flex items-center justify-between border-b border-border px-6 py-4">
10
+ <span className="font-medium">__APP_NAME__</span>
11
+ <ThemeToggle />
12
+ </header>
13
+
14
+ <main className="mx-auto max-w-3xl p-6">
15
+ <Card>
16
+ <CardHeader>
17
+ <CardTitle>Running on the __THEME__ theme</CardTitle>
18
+ </CardHeader>
19
+ <CardContent className="flex flex-wrap items-center gap-3">
20
+ <Button>Primary</Button>
21
+ <Button variant="outline">Outline</Button>
22
+ <Badge>Badge</Badge>
23
+ <p className="w-full text-sm text-muted-foreground">
24
+ Swap the theme import in <code>src/app.css</code> and everything here reshapes —
25
+ colour, radius, type scale and motion. No component changes.
26
+ </p>
27
+ </CardContent>
28
+ </Card>
29
+ </main>
30
+ </div>
31
+ )
32
+ }
@@ -0,0 +1,3 @@
1
+ @import "tailwindcss";
2
+ @import "@nimit9/signet-tokens/__THEME__.css";
3
+ @import "@nimit9/signet-tokens/base.css";
@@ -0,0 +1,7 @@
1
+ import { createApiClient } from "@nimit9/signet-lib/api"
2
+
3
+ export const api = createApiClient({
4
+ baseUrl: import.meta.env.VITE_API_BASE ?? "/api",
5
+ })
6
+
7
+ export { ApiError, AuthError } from "@nimit9/signet-lib/api"
@@ -0,0 +1,27 @@
1
+ import { onAuthErrorRedirect, queryDefaults } from "@nimit9/signet-lib/api/query-client"
2
+ import { ThemeProvider } from "@nimit9/signet-ui/components/theme-provider"
3
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
4
+ import { StrictMode } from "react"
5
+ import { createRoot } from "react-dom/client"
6
+ import App from "./App"
7
+ import "./app.css"
8
+
9
+ const queryClient = new QueryClient({ defaultOptions: queryDefaults() })
10
+
11
+ // One redirect on session expiry, however many requests fail at once.
12
+ onAuthErrorRedirect(queryClient, () => {
13
+ window.location.href = "/login"
14
+ })
15
+
16
+ const rootElement = document.getElementById("root")
17
+ if (!rootElement) throw new Error("Root element #root not found in index.html")
18
+
19
+ createRoot(rootElement).render(
20
+ <StrictMode>
21
+ <ThemeProvider>
22
+ <QueryClientProvider client={queryClient}>
23
+ <App />
24
+ </QueryClientProvider>
25
+ </ThemeProvider>
26
+ </StrictMode>,
27
+ )
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "noUnusedLocals": true,
10
+ "noUnusedParameters": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "skipLibCheck": true,
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "isolatedModules": true,
16
+ "moduleDetection": "force",
17
+ "resolveJsonModule": true,
18
+ "noEmit": true,
19
+ "paths": {
20
+ "@/*": ["./src/*"]
21
+ },
22
+ "types": ["vite/client"]
23
+ },
24
+ "include": ["src"]
25
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "files": [],
3
+ "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
4
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2023"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "allowImportingTsExtensions": true,
10
+ "isolatedModules": true,
11
+ "moduleDetection": "force",
12
+ "noEmit": true,
13
+ "types": ["node"]
14
+ },
15
+ "include": ["vite.config.ts"]
16
+ }
@@ -0,0 +1,11 @@
1
+ import path from "node:path"
2
+ import tailwindcss from "@tailwindcss/vite"
3
+ import react from "@vitejs/plugin-react"
4
+ import { defineConfig } from "vite"
5
+
6
+ export default defineConfig({
7
+ plugins: [react(), tailwindcss()],
8
+ resolve: {
9
+ alias: { "@": path.resolve(import.meta.dirname, "./src") },
10
+ },
11
+ })