uniweb 0.1.5 → 0.1.6
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 +62 -29
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -351,6 +351,18 @@ subtitle: Your subtitle
|
|
|
351
351
|
Optional body content here.
|
|
352
352
|
\`\`\`
|
|
353
353
|
|
|
354
|
+
## Configuration
|
|
355
|
+
|
|
356
|
+
Each site has a \`site.yml\` that configures which foundation it uses:
|
|
357
|
+
|
|
358
|
+
\`\`\`yaml
|
|
359
|
+
name: site
|
|
360
|
+
defaultLanguage: en
|
|
361
|
+
foundation: foundation # References packages/foundation
|
|
362
|
+
\`\`\`
|
|
363
|
+
|
|
364
|
+
To add multiple sites or foundations, create new packages and update each site's \`site.yml\`.
|
|
365
|
+
|
|
354
366
|
## What is Uniweb?
|
|
355
367
|
|
|
356
368
|
Uniweb is a **Component Web Platform** that bridges content and components.
|
|
@@ -362,9 +374,6 @@ Learn more:
|
|
|
362
374
|
- [CLI Documentation](https://github.com/uniweb/cli)
|
|
363
375
|
- [uniweb.app](https://uniweb.app) — Full publishing platform
|
|
364
376
|
|
|
365
|
-
## License
|
|
366
|
-
|
|
367
|
-
MIT
|
|
368
377
|
`)
|
|
369
378
|
|
|
370
379
|
// Create site package
|
|
@@ -405,6 +414,7 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
405
414
|
devDependencies: {
|
|
406
415
|
'@vitejs/plugin-react': '^4.2.1',
|
|
407
416
|
autoprefixer: '^10.4.18',
|
|
417
|
+
'js-yaml': '^4.1.0',
|
|
408
418
|
postcss: '^8.4.35',
|
|
409
419
|
react: '^18.2.0',
|
|
410
420
|
'react-dom': '^18.2.0',
|
|
@@ -415,13 +425,24 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
415
425
|
},
|
|
416
426
|
})
|
|
417
427
|
|
|
418
|
-
// Foundation import name
|
|
428
|
+
// Foundation import name (used for initial site.yml)
|
|
419
429
|
const foundationImport = isWorkspace ? 'foundation' : 'foundation-example'
|
|
420
430
|
|
|
421
|
-
// tailwind.config.js -
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
431
|
+
// tailwind.config.js - reads foundation from site.yml
|
|
432
|
+
writeFile(join(projectDir, 'tailwind.config.js'), `import { readFileSync, existsSync } from 'fs'
|
|
433
|
+
import yaml from 'js-yaml'
|
|
434
|
+
|
|
435
|
+
// Read foundation from site.yml
|
|
436
|
+
const siteConfig = yaml.load(readFileSync('./site.yml', 'utf8'))
|
|
437
|
+
const foundation = siteConfig.foundation || 'foundation'
|
|
438
|
+
|
|
439
|
+
// Resolve foundation path (workspace sibling or node_modules)
|
|
440
|
+
const workspacePath = \`../\${foundation}/src/**/*.{js,jsx,ts,tsx}\`
|
|
441
|
+
const npmPath = \`./node_modules/\${foundation}/src/**/*.{js,jsx,ts,tsx}\`
|
|
442
|
+
const contentPath = existsSync(\`../\${foundation}\`) ? workspacePath : npmPath
|
|
443
|
+
|
|
444
|
+
export default {
|
|
445
|
+
content: [contentPath],
|
|
425
446
|
theme: {
|
|
426
447
|
extend: {
|
|
427
448
|
colors: {
|
|
@@ -443,15 +464,31 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
443
464
|
}
|
|
444
465
|
`)
|
|
445
466
|
|
|
446
|
-
// vite.config.js
|
|
467
|
+
// vite.config.js - reads foundation from site.yml
|
|
447
468
|
writeFile(join(projectDir, 'vite.config.js'), `import { defineConfig } from 'vite'
|
|
469
|
+
import { readFileSync, existsSync } from 'fs'
|
|
470
|
+
import yaml from 'js-yaml'
|
|
448
471
|
import react from '@vitejs/plugin-react'
|
|
449
472
|
import svgr from 'vite-plugin-svgr'
|
|
450
473
|
import { siteContentPlugin, foundationPlugin } from '@uniweb/runtime/vite'
|
|
451
474
|
|
|
475
|
+
// Read foundation from site.yml
|
|
476
|
+
const siteConfig = yaml.load(readFileSync('./site.yml', 'utf8'))
|
|
477
|
+
const foundation = siteConfig.foundation || 'foundation'
|
|
478
|
+
|
|
479
|
+
// Check if foundation is a workspace sibling or npm package
|
|
480
|
+
const isWorkspaceFoundation = existsSync(\`../\${foundation}\`)
|
|
481
|
+
const foundationPath = isWorkspaceFoundation ? \`../\${foundation}\` : \`./node_modules/\${foundation}\`
|
|
482
|
+
|
|
452
483
|
const useRuntimeLoading = process.env.VITE_FOUNDATION_MODE === 'runtime'
|
|
453
484
|
|
|
454
485
|
export default defineConfig({
|
|
486
|
+
resolve: {
|
|
487
|
+
alias: {
|
|
488
|
+
// Alias #foundation to the actual foundation package
|
|
489
|
+
'#foundation': foundation,
|
|
490
|
+
},
|
|
491
|
+
},
|
|
455
492
|
plugins: [
|
|
456
493
|
react(),
|
|
457
494
|
svgr(),
|
|
@@ -460,8 +497,8 @@ export default defineConfig({
|
|
|
460
497
|
inject: true,
|
|
461
498
|
}),
|
|
462
499
|
useRuntimeLoading && foundationPlugin({
|
|
463
|
-
name:
|
|
464
|
-
path:
|
|
500
|
+
name: foundation,
|
|
501
|
+
path: foundationPath,
|
|
465
502
|
serve: '/foundation',
|
|
466
503
|
watch: true,
|
|
467
504
|
}),
|
|
@@ -494,7 +531,7 @@ export default defineConfig({
|
|
|
494
531
|
</html>
|
|
495
532
|
`)
|
|
496
533
|
|
|
497
|
-
// main.jsx
|
|
534
|
+
// main.jsx - uses #foundation alias (configured in vite.config.js from site.yml)
|
|
498
535
|
writeFile(join(projectDir, 'src/main.jsx'), `import { initRuntime } from '@uniweb/runtime'
|
|
499
536
|
|
|
500
537
|
const useRuntimeLoading = import.meta.env.VITE_FOUNDATION_MODE === 'runtime'
|
|
@@ -506,8 +543,9 @@ async function start() {
|
|
|
506
543
|
cssUrl: '/foundation/assets/style.css'
|
|
507
544
|
})
|
|
508
545
|
} else {
|
|
509
|
-
|
|
510
|
-
await import('
|
|
546
|
+
// #foundation alias is resolved by Vite based on site.yml config
|
|
547
|
+
const foundation = await import('#foundation')
|
|
548
|
+
await import('#foundation/styles')
|
|
511
549
|
initRuntime(foundation)
|
|
512
550
|
}
|
|
513
551
|
}
|
|
@@ -518,6 +556,9 @@ start().catch(console.error)
|
|
|
518
556
|
// site.yml
|
|
519
557
|
writeFile(join(projectDir, 'site.yml'), `name: ${projectName}
|
|
520
558
|
defaultLanguage: en
|
|
559
|
+
|
|
560
|
+
# Foundation to use for this site
|
|
561
|
+
foundation: ${foundationImport}
|
|
521
562
|
`)
|
|
522
563
|
|
|
523
564
|
// pages/home/page.yml
|
|
@@ -596,19 +637,17 @@ Optional markdown content here.
|
|
|
596
637
|
- The \`component\` field specifies which Foundation component renders the section
|
|
597
638
|
- Other frontmatter fields become the component's content
|
|
598
639
|
|
|
599
|
-
##
|
|
640
|
+
## Configuration
|
|
600
641
|
|
|
601
|
-
|
|
642
|
+
The \`site.yml\` file configures your site:
|
|
602
643
|
|
|
603
|
-
\`\`\`
|
|
604
|
-
{
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
}
|
|
644
|
+
\`\`\`yaml
|
|
645
|
+
name: ${projectName}
|
|
646
|
+
defaultLanguage: en
|
|
647
|
+
foundation: ${foundationImport} # Which foundation to use
|
|
609
648
|
\`\`\`
|
|
610
649
|
|
|
611
|
-
|
|
650
|
+
To use a different foundation, update the \`foundation\` field and install the package.
|
|
612
651
|
|
|
613
652
|
## Building for Production
|
|
614
653
|
|
|
@@ -623,9 +662,6 @@ Output is in \`dist/\` — ready to deploy to any static host.
|
|
|
623
662
|
- [Uniweb on GitHub](https://github.com/uniweb)
|
|
624
663
|
- [uniweb.app](https://uniweb.app)
|
|
625
664
|
|
|
626
|
-
## License
|
|
627
|
-
|
|
628
|
-
MIT
|
|
629
665
|
`)
|
|
630
666
|
}
|
|
631
667
|
|
|
@@ -963,9 +999,6 @@ A Foundation defines the vocabulary for Uniweb sites:
|
|
|
963
999
|
|
|
964
1000
|
Learn more at [github.com/uniweb](https://github.com/uniweb)
|
|
965
1001
|
|
|
966
|
-
## License
|
|
967
|
-
|
|
968
|
-
MIT
|
|
969
1002
|
`)
|
|
970
1003
|
}
|
|
971
1004
|
|