Skip to content

Commit 636c1bd

Browse files
committed
feat: add starlight dev server & plop
1 parent be3b018 commit 636c1bd

35 files changed

+3152
-1151
lines changed

.gitignore

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
1+
# Dependencies
2+
node_modules/
3+
.pnp
4+
.pnp.js
5+
6+
# Build outputs
17
dist/
8+
.stencil/
9+
.turbo/
10+
.astro/
211

3-
*~
4-
*.sw[mnpcod]
12+
# Testing
13+
coverage/
14+
*.spec.js.map
15+
16+
# Logs
517
*.log
6-
*.lock
7-
*.tmp
8-
*.tmp.*
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
pnpm-debug.log*
22+
lerna-debug.log*
923
log.txt
24+
25+
# Editor
26+
*~
27+
*.sw[mnpcod]
1028
*.sublime-project
1129
*.sublime-workspace
30+
.vscode/*
31+
!.vscode/extensions.json
32+
!.vscode/settings.json
33+
.idea/
1234

13-
.stencil/
35+
# Temporary
36+
*.tmp
37+
*.tmp.*
38+
*.lock
39+
40+
# Cache
1441
.sass-cache/
1542
.versions/
16-
node_modules/
17-
$RECYCLE.BIN/
43+
.cache/
1844

45+
# OS
1946
.DS_Store
2047
Thumbs.db
2148
UserInterfaceState.xcuserstate
49+
$RECYCLE.BIN/
50+
51+
# Environment
2252
.env
53+
.env.local
54+
.env.production
55+
56+
# Storybook
57+
storybook-static/

README.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# J26 Web Components
2+
3+
A monorepo containing Stencil web components, design tokens, and Astro Starlight documentation.
4+
5+
## Prerequisites
6+
7+
- Node.js (v18 or higher)
8+
- pnpm (v10.7.0 or higher)
9+
10+
## Getting Started
11+
12+
```bash
13+
# Install dependencies
14+
pnpm install
15+
16+
# Start development (builds tokens & components, starts hot reload for all packages)
17+
pnpm dev
18+
```
19+
20+
The dev server will start:
21+
- Design tokens watch mode (rebuilds on changes)
22+
- Components watch mode (rebuilds on changes)
23+
- Astro Starlight docs (http://localhost:4321)
24+
25+
## Available Scripts
26+
27+
All commands should be run from the **root directory**.
28+
29+
### Development
30+
31+
```bash
32+
# Start full development environment with hot reloading
33+
# (Builds tokens & components, then starts watch mode for all)
34+
pnpm dev
35+
36+
# Fast component-only dev with Stencil's built-in HMR server
37+
# (Faster rebuilds, but components shown in Stencil's UI, not Astro)
38+
pnpm dev:components
39+
40+
# Start only docs (components must be built first)
41+
pnpm docs:dev
42+
43+
# Start Storybook (legacy, use docs instead)
44+
pnpm storybook
45+
```
46+
47+
**Hot Reloading Performance:**
48+
- **Token changes**: ~50-200ms rebuild time
49+
- **Component changes**: ~1-3s rebuild time (optimized with incremental builds)
50+
- **Astro doc changes**: Instant HMR
51+
- Use `pnpm dev:components` for fastest component iteration (Stencil's dev server with native HMR)
52+
53+
### Building
54+
55+
```bash
56+
# Build tokens and components only
57+
pnpm build
58+
59+
# Build everything (tokens, components, and docs)
60+
pnpm build:all
61+
62+
# Build specific packages
63+
pnpm tokens:build
64+
pnpm components:build
65+
pnpm docs:build
66+
67+
# Preview production docs build
68+
pnpm docs:preview
69+
```
70+
71+
### Testing
72+
73+
```bash
74+
# Run unit tests
75+
pnpm test
76+
77+
# Run tests in watch mode
78+
pnpm test:watch
79+
80+
# Run E2E tests
81+
pnpm test:e2e
82+
```
83+
84+
### Code Quality
85+
86+
```bash
87+
# Check code with Biome
88+
pnpm lint
89+
90+
# Fix linting issues
91+
pnpm lint:fix
92+
93+
# Format code
94+
pnpm format
95+
```
96+
97+
### Generating Components
98+
99+
```bash
100+
# Generate a new component with plop
101+
pnpm plop
102+
103+
# Or use Stencil's generator
104+
pnpm generate
105+
```
106+
107+
The plop generator will:
108+
- Create component files (.tsx, .css, .spec.ts, .e2e.ts, .stories.tsx)
109+
- Generate Starlight documentation (with consistent structure)
110+
- Update package.json exports automatically
111+
112+
### Cleanup
113+
114+
```bash
115+
# Remove all node_modules and build artifacts
116+
pnpm clean
117+
118+
# Clean and reinstall dependencies
119+
pnpm clean:install
120+
121+
# Clean build artifacts and rebuild
122+
pnpm clean:build
123+
```
124+
125+
## Project Structure
126+
127+
```
128+
j26-web-components/
129+
├── packages/
130+
│ ├── design-tokens/ # Design tokens (CSS custom properties)
131+
│ ├── ui-webc/ # Stencil web components
132+
│ └── docs/ # Astro Starlight documentation
133+
├── package.json # Root package with scripts
134+
└── pnpm-workspace.yaml # Workspace configuration
135+
```
136+
137+
## Creating a New Component
138+
139+
1. Run the plop generator:
140+
```bash
141+
pnpm plop
142+
```
143+
144+
2. Follow the prompts:
145+
- Component name (e.g., `my-button`)
146+
- Component description
147+
148+
3. The generator creates:
149+
- Component files in `packages/ui-webc/src/components/`
150+
- Documentation in `packages/docs/src/content/docs/components/`
151+
152+
4. Customize the generated files:
153+
- Update component logic in `.tsx` file
154+
- Add styles in `.css` file
155+
- Update documentation with real examples
156+
- Customize API reference (props, events)
157+
- Add variants and examples
158+
159+
5. Test your component:
160+
```bash
161+
pnpm dev
162+
```
163+
Navigate to http://localhost:4321 to see your component documentation.
164+
165+
## Documentation Structure
166+
167+
All component documentation follows this structure:
168+
169+
1. **Overview** - Brief description of the component
170+
2. **Installation** - How to install the package
171+
3. **Usage** - TypeScript and HTML examples
172+
4. **API Reference** - Properties and Events tables
173+
5. **Examples** - Default example with preview
174+
6. **Variants** - Different component variations
175+
176+
## Development Workflow
177+
178+
1. **Start development**: `pnpm dev`
179+
2. **Make changes** to components in `packages/ui-webc/src/components/`
180+
3. **View changes** in Astro docs at http://localhost:4321
181+
4. **Add/update documentation** in `packages/docs/src/content/docs/`
182+
5. **Test** with `pnpm test`
183+
6. **Lint** with `pnpm lint:fix`
184+
7. **Build** with `pnpm build` before committing
185+
186+
## Using Components
187+
188+
### Installation
189+
190+
```bash
191+
npm install @scouterna/ui-webc
192+
```
193+
194+
### Usage
195+
196+
```typescript
197+
// Import and register the components
198+
import { defineCustomElements } from '@scouterna/ui-webc/loader';
199+
200+
defineCustomElements();
201+
```
202+
203+
```html
204+
<!-- Use components in your HTML -->
205+
<scout-button variant="primary">Click me</scout-button>
206+
```
207+
208+
## Troubleshooting
209+
210+
### Components not loading in docs
211+
212+
Make sure you've built the components:
213+
```bash
214+
pnpm components:build
215+
```
216+
217+
### Design tokens not found
218+
219+
Build tokens first:
220+
```bash
221+
pnpm tokens:build
222+
```
223+
224+
### Clean start
225+
226+
If you encounter issues, try a clean rebuild:
227+
```bash
228+
pnpm clean:install
229+
pnpm dev
230+
```
231+
232+
## Contributing
233+
234+
1. Create a new component with `pnpm plop`
235+
2. Follow the existing component structure
236+
3. Update documentation with real examples
237+
4. Add tests for your component
238+
5. Run `pnpm lint:fix` before committing
239+
6. Ensure `pnpm build` succeeds

package.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
"private": true,
44
"license": "MIT",
55
"scripts": {
6+
"dev": "pnpm tokens:build && pnpm components:build && pnpm -r --parallel --filter=\"@scouterna/design-tokens\" --filter=\"@scouterna/ui-webc\" --filter=\"docs\" dev",
7+
"dev:components": "pnpm tokens:build && pnpm --filter @scouterna/ui-webc dev",
8+
"build": "pnpm -r --filter @scouterna/design-tokens --filter @scouterna/ui-webc build",
9+
"build:all": "pnpm -r --filter @scouterna/design-tokens --filter @scouterna/ui-webc --filter docs build",
10+
"tokens:build": "pnpm --filter @scouterna/design-tokens build",
11+
"components:build": "pnpm --filter @scouterna/ui-webc build",
12+
"docs:dev": "pnpm --filter docs dev",
13+
"docs:build": "pnpm --filter docs build",
14+
"docs:preview": "pnpm --filter docs preview",
15+
"test": "pnpm --filter @scouterna/ui-webc test",
16+
"test:watch": "pnpm --filter @scouterna/ui-webc test.watch",
17+
"test:e2e": "pnpm --filter @scouterna/ui-webc test.e2e",
618
"lint": "biome check",
7-
"lint:fix": "biome check --write"
19+
"lint:fix": "biome check --write",
20+
"format": "biome format --write .",
21+
"plop": "pnpm --filter @scouterna/ui-webc plop",
22+
"generate": "pnpm --filter @scouterna/ui-webc generate",
23+
"storybook": "pnpm tokens:build && pnpm -r --parallel --filter=\"@scouterna/design-tokens\" --filter=\"@scouterna/ui-webc\" dev",
24+
"clean": "pnpm -r exec rm -rf node_modules dist .turbo .stencil .astro && rm -rf node_modules",
25+
"clean:install": "pnpm clean && pnpm install",
26+
"clean:build": "pnpm -r exec rm -rf dist .turbo .stencil .astro && pnpm build:all"
827
},
928
"devDependencies": {
1029
"@biomejs/biome": "2.2.0",

packages/design-tokens/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
],
1212
"type": "module",
1313
"scripts": {
14-
"build": "node build-tokens.mjs"
14+
"build": "node build-tokens.mjs",
15+
"watch": "node --watch build-tokens.mjs",
16+
"dev": "node --watch build-tokens.mjs"
1517
},
1618
"keywords": [],
1719
"author": "",

packages/docs/astro.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,21 @@ export default defineConfig({
1717
customCss: [
1818
"@scouterna/design-tokens/tokens.css",
1919
"./src/styles/global.css",
20+
"./src/styles/components.css",
21+
"./src/styles/highlight.css",
2022
],
23+
head: [
24+
{
25+
tag: 'script',
26+
attrs: {
27+
src: '/component-loader.js',
28+
type: 'module',
29+
},
30+
},
31+
],
32+
components: {
33+
Head: './src/components/ComponentLoader.astro',
34+
},
2135
social: [
2236
{
2337
icon: "github",
@@ -33,6 +47,10 @@ export default defineConfig({
3347
{ label: "Example Guide", slug: "guides/example" },
3448
],
3549
},
50+
{
51+
label: "Components",
52+
autogenerate: { directory: "components" },
53+
},
3654
{
3755
label: "Reference",
3856
autogenerate: { directory: "reference" },
@@ -47,5 +65,19 @@ export default defineConfig({
4765

4866
vite: {
4967
plugins: [tailwindcss()],
68+
server: {
69+
watch: {
70+
// Watch the ui-webc source files for faster HMR
71+
ignored: ['!**/node_modules/@scouterna/ui-webc/**'],
72+
},
73+
fs: {
74+
// Allow serving files from the monorepo root
75+
allow: ['../..'],
76+
},
77+
},
78+
optimizeDeps: {
79+
// Don't pre-bundle the components so changes are picked up faster
80+
exclude: ['@scouterna/ui-webc'],
81+
},
5082
},
5183
});

0 commit comments

Comments
 (0)