uniweb 0.1.5 → 0.1.7
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/package.json +1 -1
- package/src/index.js +122 -35
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -243,8 +243,7 @@ async function createWorkspace(projectDir, projectName) {
|
|
|
243
243
|
scripts: {
|
|
244
244
|
dev: 'pnpm --filter site dev',
|
|
245
245
|
'dev:runtime': 'VITE_FOUNDATION_MODE=runtime pnpm --filter site dev',
|
|
246
|
-
|
|
247
|
-
build: 'pnpm build:foundation && pnpm --filter site build',
|
|
246
|
+
build: 'pnpm -r build',
|
|
248
247
|
},
|
|
249
248
|
pnpm: {
|
|
250
249
|
onlyBuiltDependencies: ['esbuild', 'sharp'],
|
|
@@ -318,13 +317,20 @@ Use this to debug issues that only appear in production.
|
|
|
318
317
|
## Building for Production
|
|
319
318
|
|
|
320
319
|
\`\`\`bash
|
|
321
|
-
# Build
|
|
320
|
+
# Build all packages (foundations and sites)
|
|
322
321
|
pnpm build
|
|
322
|
+
|
|
323
|
+
# Build a specific package
|
|
324
|
+
pnpm --filter foundation build
|
|
325
|
+
pnpm --filter site build
|
|
326
|
+
|
|
327
|
+
# Build only certain packages
|
|
328
|
+
pnpm --filter marketing-site --filter docs-site build
|
|
323
329
|
\`\`\`
|
|
324
330
|
|
|
325
|
-
Output
|
|
326
|
-
- \`packages/foundation/dist/\` — Bundled
|
|
327
|
-
- \`packages/site/dist/\` — Production-ready site
|
|
331
|
+
**Output:**
|
|
332
|
+
- \`packages/[foundation]/dist/\` — Bundled components, CSS, and schema.json
|
|
333
|
+
- \`packages/[site]/dist/\` — Production-ready static site
|
|
328
334
|
|
|
329
335
|
## Adding Components
|
|
330
336
|
|
|
@@ -351,6 +357,66 @@ subtitle: Your subtitle
|
|
|
351
357
|
Optional body content here.
|
|
352
358
|
\`\`\`
|
|
353
359
|
|
|
360
|
+
## Configuration
|
|
361
|
+
|
|
362
|
+
Each site has a \`site.yml\` that configures which foundation it uses:
|
|
363
|
+
|
|
364
|
+
\`\`\`yaml
|
|
365
|
+
name: site
|
|
366
|
+
defaultLanguage: en
|
|
367
|
+
foundation: foundation # References packages/foundation
|
|
368
|
+
\`\`\`
|
|
369
|
+
|
|
370
|
+
## Multiple Sites and Foundations
|
|
371
|
+
|
|
372
|
+
This workspace supports multiple sites and foundations. The \`packages/*\` pattern includes any package you add.
|
|
373
|
+
|
|
374
|
+
**Adding another foundation:**
|
|
375
|
+
|
|
376
|
+
\`\`\`bash
|
|
377
|
+
npx uniweb create packages/docs-foundation --template foundation
|
|
378
|
+
\`\`\`
|
|
379
|
+
|
|
380
|
+
**Adding another site:**
|
|
381
|
+
|
|
382
|
+
\`\`\`bash
|
|
383
|
+
npx uniweb create packages/docs-site --template site
|
|
384
|
+
\`\`\`
|
|
385
|
+
|
|
386
|
+
Then edit \`packages/docs-site/site.yml\` to use the new foundation:
|
|
387
|
+
|
|
388
|
+
\`\`\`yaml
|
|
389
|
+
foundation: docs-foundation
|
|
390
|
+
\`\`\`
|
|
391
|
+
|
|
392
|
+
**Running a specific site:**
|
|
393
|
+
|
|
394
|
+
\`\`\`bash
|
|
395
|
+
pnpm --filter docs-site dev
|
|
396
|
+
\`\`\`
|
|
397
|
+
|
|
398
|
+
## Sharing Components
|
|
399
|
+
|
|
400
|
+
For components shared across multiple foundations, create a shared package:
|
|
401
|
+
|
|
402
|
+
\`\`\`
|
|
403
|
+
packages/
|
|
404
|
+
├── shared/ # Shared React components
|
|
405
|
+
│ ├── package.json
|
|
406
|
+
│ └── src/
|
|
407
|
+
│ └── Button.jsx
|
|
408
|
+
├── marketing-foundation/
|
|
409
|
+
├── docs-foundation/
|
|
410
|
+
└── site/
|
|
411
|
+
\`\`\`
|
|
412
|
+
|
|
413
|
+
Foundations can import from the shared package:
|
|
414
|
+
|
|
415
|
+
\`\`\`js
|
|
416
|
+
// packages/marketing-foundation/src/components/Hero/index.jsx
|
|
417
|
+
import { Button } from 'shared'
|
|
418
|
+
\`\`\`
|
|
419
|
+
|
|
354
420
|
## What is Uniweb?
|
|
355
421
|
|
|
356
422
|
Uniweb is a **Component Web Platform** that bridges content and components.
|
|
@@ -362,9 +428,6 @@ Learn more:
|
|
|
362
428
|
- [CLI Documentation](https://github.com/uniweb/cli)
|
|
363
429
|
- [uniweb.app](https://uniweb.app) — Full publishing platform
|
|
364
430
|
|
|
365
|
-
## License
|
|
366
|
-
|
|
367
|
-
MIT
|
|
368
431
|
`)
|
|
369
432
|
|
|
370
433
|
// Create site package
|
|
@@ -405,6 +468,7 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
405
468
|
devDependencies: {
|
|
406
469
|
'@vitejs/plugin-react': '^4.2.1',
|
|
407
470
|
autoprefixer: '^10.4.18',
|
|
471
|
+
'js-yaml': '^4.1.0',
|
|
408
472
|
postcss: '^8.4.35',
|
|
409
473
|
react: '^18.2.0',
|
|
410
474
|
'react-dom': '^18.2.0',
|
|
@@ -415,13 +479,24 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
415
479
|
},
|
|
416
480
|
})
|
|
417
481
|
|
|
418
|
-
// Foundation import name
|
|
482
|
+
// Foundation import name (used for initial site.yml)
|
|
419
483
|
const foundationImport = isWorkspace ? 'foundation' : 'foundation-example'
|
|
420
484
|
|
|
421
|
-
// tailwind.config.js -
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
485
|
+
// tailwind.config.js - reads foundation from site.yml
|
|
486
|
+
writeFile(join(projectDir, 'tailwind.config.js'), `import { readFileSync, existsSync } from 'fs'
|
|
487
|
+
import yaml from 'js-yaml'
|
|
488
|
+
|
|
489
|
+
// Read foundation from site.yml
|
|
490
|
+
const siteConfig = yaml.load(readFileSync('./site.yml', 'utf8'))
|
|
491
|
+
const foundation = siteConfig.foundation || 'foundation'
|
|
492
|
+
|
|
493
|
+
// Resolve foundation path (workspace sibling or node_modules)
|
|
494
|
+
const workspacePath = \`../\${foundation}/src/**/*.{js,jsx,ts,tsx}\`
|
|
495
|
+
const npmPath = \`./node_modules/\${foundation}/src/**/*.{js,jsx,ts,tsx}\`
|
|
496
|
+
const contentPath = existsSync(\`../\${foundation}\`) ? workspacePath : npmPath
|
|
497
|
+
|
|
498
|
+
export default {
|
|
499
|
+
content: [contentPath],
|
|
425
500
|
theme: {
|
|
426
501
|
extend: {
|
|
427
502
|
colors: {
|
|
@@ -443,15 +518,31 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
443
518
|
}
|
|
444
519
|
`)
|
|
445
520
|
|
|
446
|
-
// vite.config.js
|
|
521
|
+
// vite.config.js - reads foundation from site.yml
|
|
447
522
|
writeFile(join(projectDir, 'vite.config.js'), `import { defineConfig } from 'vite'
|
|
523
|
+
import { readFileSync, existsSync } from 'fs'
|
|
524
|
+
import yaml from 'js-yaml'
|
|
448
525
|
import react from '@vitejs/plugin-react'
|
|
449
526
|
import svgr from 'vite-plugin-svgr'
|
|
450
527
|
import { siteContentPlugin, foundationPlugin } from '@uniweb/runtime/vite'
|
|
451
528
|
|
|
529
|
+
// Read foundation from site.yml
|
|
530
|
+
const siteConfig = yaml.load(readFileSync('./site.yml', 'utf8'))
|
|
531
|
+
const foundation = siteConfig.foundation || 'foundation'
|
|
532
|
+
|
|
533
|
+
// Check if foundation is a workspace sibling or npm package
|
|
534
|
+
const isWorkspaceFoundation = existsSync(\`../\${foundation}\`)
|
|
535
|
+
const foundationPath = isWorkspaceFoundation ? \`../\${foundation}\` : \`./node_modules/\${foundation}\`
|
|
536
|
+
|
|
452
537
|
const useRuntimeLoading = process.env.VITE_FOUNDATION_MODE === 'runtime'
|
|
453
538
|
|
|
454
539
|
export default defineConfig({
|
|
540
|
+
resolve: {
|
|
541
|
+
alias: {
|
|
542
|
+
// Alias #foundation to the actual foundation package
|
|
543
|
+
'#foundation': foundation,
|
|
544
|
+
},
|
|
545
|
+
},
|
|
455
546
|
plugins: [
|
|
456
547
|
react(),
|
|
457
548
|
svgr(),
|
|
@@ -460,8 +551,8 @@ export default defineConfig({
|
|
|
460
551
|
inject: true,
|
|
461
552
|
}),
|
|
462
553
|
useRuntimeLoading && foundationPlugin({
|
|
463
|
-
name:
|
|
464
|
-
path:
|
|
554
|
+
name: foundation,
|
|
555
|
+
path: foundationPath,
|
|
465
556
|
serve: '/foundation',
|
|
466
557
|
watch: true,
|
|
467
558
|
}),
|
|
@@ -494,7 +585,7 @@ export default defineConfig({
|
|
|
494
585
|
</html>
|
|
495
586
|
`)
|
|
496
587
|
|
|
497
|
-
// main.jsx
|
|
588
|
+
// main.jsx - uses #foundation alias (configured in vite.config.js from site.yml)
|
|
498
589
|
writeFile(join(projectDir, 'src/main.jsx'), `import { initRuntime } from '@uniweb/runtime'
|
|
499
590
|
|
|
500
591
|
const useRuntimeLoading = import.meta.env.VITE_FOUNDATION_MODE === 'runtime'
|
|
@@ -506,8 +597,9 @@ async function start() {
|
|
|
506
597
|
cssUrl: '/foundation/assets/style.css'
|
|
507
598
|
})
|
|
508
599
|
} else {
|
|
509
|
-
|
|
510
|
-
await import('
|
|
600
|
+
// #foundation alias is resolved by Vite based on site.yml config
|
|
601
|
+
const foundation = await import('#foundation')
|
|
602
|
+
await import('#foundation/styles')
|
|
511
603
|
initRuntime(foundation)
|
|
512
604
|
}
|
|
513
605
|
}
|
|
@@ -518,6 +610,9 @@ start().catch(console.error)
|
|
|
518
610
|
// site.yml
|
|
519
611
|
writeFile(join(projectDir, 'site.yml'), `name: ${projectName}
|
|
520
612
|
defaultLanguage: en
|
|
613
|
+
|
|
614
|
+
# Foundation to use for this site
|
|
615
|
+
foundation: ${foundationImport}
|
|
521
616
|
`)
|
|
522
617
|
|
|
523
618
|
// pages/home/page.yml
|
|
@@ -596,19 +691,17 @@ Optional markdown content here.
|
|
|
596
691
|
- The \`component\` field specifies which Foundation component renders the section
|
|
597
692
|
- Other frontmatter fields become the component's content
|
|
598
693
|
|
|
599
|
-
##
|
|
694
|
+
## Configuration
|
|
600
695
|
|
|
601
|
-
|
|
696
|
+
The \`site.yml\` file configures your site:
|
|
602
697
|
|
|
603
|
-
\`\`\`
|
|
604
|
-
{
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
}
|
|
698
|
+
\`\`\`yaml
|
|
699
|
+
name: ${projectName}
|
|
700
|
+
defaultLanguage: en
|
|
701
|
+
foundation: ${foundationImport} # Which foundation to use
|
|
609
702
|
\`\`\`
|
|
610
703
|
|
|
611
|
-
|
|
704
|
+
To use a different foundation, update the \`foundation\` field and install the package.
|
|
612
705
|
|
|
613
706
|
## Building for Production
|
|
614
707
|
|
|
@@ -623,9 +716,6 @@ Output is in \`dist/\` — ready to deploy to any static host.
|
|
|
623
716
|
- [Uniweb on GitHub](https://github.com/uniweb)
|
|
624
717
|
- [uniweb.app](https://uniweb.app)
|
|
625
718
|
|
|
626
|
-
## License
|
|
627
|
-
|
|
628
|
-
MIT
|
|
629
719
|
`)
|
|
630
720
|
}
|
|
631
721
|
|
|
@@ -963,9 +1053,6 @@ A Foundation defines the vocabulary for Uniweb sites:
|
|
|
963
1053
|
|
|
964
1054
|
Learn more at [github.com/uniweb](https://github.com/uniweb)
|
|
965
1055
|
|
|
966
|
-
## License
|
|
967
|
-
|
|
968
|
-
MIT
|
|
969
1056
|
`)
|
|
970
1057
|
}
|
|
971
1058
|
|