@uniweb/build 0.7.4 → 0.7.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 +2 -2
- package/src/foundation/config.js +5 -5
- package/src/generate-entry.js +4 -4
- package/src/schema.js +26 -27
- package/src/vite-foundation-plugin.js +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"optionalDependencies": {
|
|
53
53
|
"@uniweb/content-reader": "1.1.2",
|
|
54
54
|
"@uniweb/schemas": "0.2.1",
|
|
55
|
-
"@uniweb/runtime": "0.6.
|
|
55
|
+
"@uniweb/runtime": "0.6.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
package/src/foundation/config.js
CHANGED
|
@@ -48,9 +48,9 @@ const DEFAULT_EXTERNALS = [
|
|
|
48
48
|
* @param {Object} [options={}] - Configuration options
|
|
49
49
|
* @param {string} [options.entry] - Entry point path (default: 'src/_entry.generated.js')
|
|
50
50
|
* @param {string} [options.fileName] - Output file name (default: 'foundation')
|
|
51
|
-
* @param {string[]} [options.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* @param {string[]} [options.sections] - Paths to scan for section types (relative to src/).
|
|
52
|
+
* Default: ['sections']
|
|
53
|
+
* Example: ['sections', 'sections/marketing']
|
|
54
54
|
* @param {string[]} [options.externals] - Additional packages to externalize
|
|
55
55
|
* @param {boolean} [options.includeDefaultExternals] - Include default externals (default: true)
|
|
56
56
|
* @param {Array} [options.plugins] - Additional Vite plugins
|
|
@@ -63,7 +63,7 @@ export async function defineFoundationConfig(options = {}) {
|
|
|
63
63
|
const {
|
|
64
64
|
entry = 'src/_entry.generated.js',
|
|
65
65
|
fileName = 'foundation',
|
|
66
|
-
|
|
66
|
+
sections: sectionPaths,
|
|
67
67
|
externals: additionalExternals = [],
|
|
68
68
|
includeDefaultExternals = true,
|
|
69
69
|
plugins: extraPlugins = [],
|
|
@@ -108,7 +108,7 @@ export async function defineFoundationConfig(options = {}) {
|
|
|
108
108
|
// Build the plugins array
|
|
109
109
|
// foundationPlugin handles entry generation and schema building
|
|
110
110
|
const plugins = [
|
|
111
|
-
foundationPlugin({ srcDir: 'src',
|
|
111
|
+
foundationPlugin({ srcDir: 'src', sections: sectionPaths }),
|
|
112
112
|
tailwind && tailwindcss(),
|
|
113
113
|
react(),
|
|
114
114
|
svgr(),
|
package/src/generate-entry.js
CHANGED
|
@@ -189,13 +189,13 @@ function detectComponentEntry(srcDir, componentPath, componentName) {
|
|
|
189
189
|
* @param {string} srcDir - Source directory
|
|
190
190
|
* @param {string} [outputPath] - Output file path (default: srcDir/_entry.generated.js)
|
|
191
191
|
* @param {Object} [options] - Options
|
|
192
|
-
* @param {string[]} [options.
|
|
192
|
+
* @param {string[]} [options.sectionPaths] - Paths to scan for section types (relative to srcDir)
|
|
193
193
|
*/
|
|
194
194
|
export async function generateEntryPoint(srcDir, outputPath = null, options = {}) {
|
|
195
|
-
const {
|
|
195
|
+
const { sectionPaths } = options
|
|
196
196
|
|
|
197
|
-
// Discover
|
|
198
|
-
const components = await discoverComponents(srcDir,
|
|
197
|
+
// Discover section types (includes meta from meta.js files)
|
|
198
|
+
const components = await discoverComponents(srcDir, sectionPaths)
|
|
199
199
|
const componentNames = Object.keys(components).sort()
|
|
200
200
|
|
|
201
201
|
if (componentNames.length === 0) {
|
package/src/schema.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Schema Discovery and Loading Utilities
|
|
3
3
|
*
|
|
4
|
-
* Discovers
|
|
4
|
+
* Discovers section type meta files and loads them for schema.json generation.
|
|
5
5
|
* Schema data is for editor-time only, not runtime.
|
|
6
6
|
*
|
|
7
7
|
* Discovery rules:
|
|
8
8
|
* - sections/ root: bare files and folders are addressable by default (implicit empty meta)
|
|
9
9
|
* - sections/ nested: meta.js required for addressability
|
|
10
|
-
* -
|
|
10
|
+
* - Additional paths (via config): meta.js required for addressability
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { readdir, readFile } from 'node:fs/promises'
|
|
@@ -22,9 +22,8 @@ const META_FILE_NAME = 'meta.js'
|
|
|
22
22
|
// Foundation config file name
|
|
23
23
|
const FOUNDATION_FILE_NAME = 'foundation.js'
|
|
24
24
|
|
|
25
|
-
// Default paths to scan for
|
|
26
|
-
|
|
27
|
-
const DEFAULT_COMPONENT_PATHS = ['sections', 'components']
|
|
25
|
+
// Default paths to scan for section types (relative to srcDir)
|
|
26
|
+
const DEFAULT_SECTION_PATHS = ['sections']
|
|
28
27
|
|
|
29
28
|
// Extensions recognized as component entry files
|
|
30
29
|
const COMPONENT_EXTENSIONS = new Set(['.jsx', '.tsx', '.js', '.ts'])
|
|
@@ -383,13 +382,13 @@ async function discoverNestedSections(srcDir, parentFullPath, parentRelPath, com
|
|
|
383
382
|
}
|
|
384
383
|
|
|
385
384
|
/**
|
|
386
|
-
* Discover
|
|
385
|
+
* Discover section types in a non-sections path (meta.js required)
|
|
387
386
|
*
|
|
388
387
|
* @param {string} srcDir - Source directory (e.g., 'src')
|
|
389
|
-
* @param {string} relativePath - Path relative to srcDir
|
|
390
|
-
* @returns {Object} Map of
|
|
388
|
+
* @param {string} relativePath - Path relative to srcDir
|
|
389
|
+
* @returns {Object} Map of sectionTypeName -> { name, path, ...meta }
|
|
391
390
|
*/
|
|
392
|
-
async function
|
|
391
|
+
async function discoverExplicitSectionsInPath(srcDir, relativePath) {
|
|
393
392
|
const fullPath = join(srcDir, relativePath)
|
|
394
393
|
|
|
395
394
|
if (!existsSync(fullPath)) {
|
|
@@ -426,30 +425,30 @@ async function discoverExplicitComponentsInPath(srcDir, relativePath) {
|
|
|
426
425
|
* For other paths: strict discovery (meta.js required).
|
|
427
426
|
*
|
|
428
427
|
* @param {string} srcDir - Source directory (e.g., 'src')
|
|
429
|
-
* @param {string[]} [
|
|
430
|
-
*
|
|
428
|
+
* @param {string[]} [sectionPaths] - Paths to scan for section types (relative to srcDir).
|
|
429
|
+
* Default: ['sections']
|
|
431
430
|
* @returns {Object} Map of sectionTypeName -> { name, path, ...meta }
|
|
432
431
|
*/
|
|
433
|
-
export async function discoverComponents(srcDir,
|
|
434
|
-
const
|
|
432
|
+
export async function discoverComponents(srcDir, sectionPaths = DEFAULT_SECTION_PATHS) {
|
|
433
|
+
const sections = {}
|
|
435
434
|
|
|
436
|
-
for (const relativePath of
|
|
435
|
+
for (const relativePath of sectionPaths) {
|
|
437
436
|
// Use relaxed discovery for the primary sections path
|
|
438
437
|
const found = relativePath === SECTIONS_PATH
|
|
439
438
|
? await discoverSectionsInPath(srcDir, relativePath)
|
|
440
|
-
: await
|
|
439
|
+
: await discoverExplicitSectionsInPath(srcDir, relativePath)
|
|
441
440
|
|
|
442
441
|
for (const [name, meta] of Object.entries(found)) {
|
|
443
|
-
if (
|
|
444
|
-
//
|
|
445
|
-
console.warn(`Warning:
|
|
442
|
+
if (sections[name]) {
|
|
443
|
+
// Section type already found in an earlier path — skip (first wins)
|
|
444
|
+
console.warn(`Warning: Section type "${name}" found in multiple paths. Using ${sections[name].path}, ignoring ${meta.path}`)
|
|
446
445
|
continue
|
|
447
446
|
}
|
|
448
|
-
|
|
447
|
+
sections[name] = meta
|
|
449
448
|
}
|
|
450
449
|
}
|
|
451
450
|
|
|
452
|
-
return
|
|
451
|
+
return sections
|
|
453
452
|
}
|
|
454
453
|
|
|
455
454
|
/**
|
|
@@ -461,17 +460,17 @@ export async function discoverComponents(srcDir, componentPaths = DEFAULT_COMPON
|
|
|
461
460
|
* - Configuration from foundation.js (vars, Layout, etc.)
|
|
462
461
|
*
|
|
463
462
|
* @param {string} srcDir - Source directory
|
|
464
|
-
* @param {string[]} [
|
|
463
|
+
* @param {string[]} [sectionPaths] - Paths to scan for section types
|
|
465
464
|
*/
|
|
466
|
-
export async function buildSchema(srcDir,
|
|
465
|
+
export async function buildSchema(srcDir, sectionPaths) {
|
|
467
466
|
// Load identity from package.json
|
|
468
467
|
const identity = await loadPackageJson(srcDir)
|
|
469
468
|
|
|
470
469
|
// Load configuration from foundation.js
|
|
471
470
|
const foundationConfig = await loadFoundationConfig(srcDir)
|
|
472
471
|
|
|
473
|
-
// Discover
|
|
474
|
-
const components = await discoverComponents(srcDir,
|
|
472
|
+
// Discover section types
|
|
473
|
+
const components = await discoverComponents(srcDir, sectionPaths)
|
|
475
474
|
|
|
476
475
|
// Discover layouts from src/layouts/
|
|
477
476
|
const layouts = await discoverLayoutsInPath(srcDir)
|
|
@@ -512,9 +511,9 @@ export async function buildSchema(srcDir, componentPaths) {
|
|
|
512
511
|
* Get list of section type names
|
|
513
512
|
*
|
|
514
513
|
* @param {string} srcDir - Source directory
|
|
515
|
-
* @param {string[]} [
|
|
514
|
+
* @param {string[]} [sectionPaths] - Paths to scan for section types
|
|
516
515
|
*/
|
|
517
|
-
export async function getExposedComponents(srcDir,
|
|
518
|
-
const components = await discoverComponents(srcDir,
|
|
516
|
+
export async function getExposedComponents(srcDir, sectionPaths) {
|
|
517
|
+
const components = await discoverComponents(srcDir, sectionPaths)
|
|
519
518
|
return Object.keys(components)
|
|
520
519
|
}
|
|
@@ -16,8 +16,8 @@ import { processAllPreviews } from './images.js'
|
|
|
16
16
|
/**
|
|
17
17
|
* Build schema.json with preview image references
|
|
18
18
|
*/
|
|
19
|
-
async function buildSchemaWithPreviews(srcDir, outDir, isProduction,
|
|
20
|
-
const schema = await buildSchema(srcDir,
|
|
19
|
+
async function buildSchemaWithPreviews(srcDir, outDir, isProduction, sectionPaths) {
|
|
20
|
+
const schema = await buildSchema(srcDir, sectionPaths)
|
|
21
21
|
|
|
22
22
|
// Process preview images
|
|
23
23
|
const { schema: schemaWithImages, totalImages } = await processAllPreviews(
|
|
@@ -42,7 +42,7 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
42
42
|
srcDir = 'src',
|
|
43
43
|
generateEntry = true,
|
|
44
44
|
entryFileName = '_entry.generated.js',
|
|
45
|
-
|
|
45
|
+
sections: sectionPaths,
|
|
46
46
|
} = options
|
|
47
47
|
|
|
48
48
|
let resolvedSrcDir
|
|
@@ -59,7 +59,7 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
59
59
|
const root = config.root || process.cwd()
|
|
60
60
|
const srcPath = resolve(root, srcDir)
|
|
61
61
|
const entryPath = join(srcPath, entryFileName)
|
|
62
|
-
await generateEntryPoint(srcPath, entryPath, {
|
|
62
|
+
await generateEntryPoint(srcPath, entryPath, { sectionPaths })
|
|
63
63
|
},
|
|
64
64
|
|
|
65
65
|
async configResolved(config) {
|
|
@@ -80,7 +80,7 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
80
80
|
resolvedSrcDir,
|
|
81
81
|
outDir,
|
|
82
82
|
isProduction,
|
|
83
|
-
|
|
83
|
+
sectionPaths
|
|
84
84
|
)
|
|
85
85
|
|
|
86
86
|
const schemaPath = join(metaDir, 'schema.json')
|
|
@@ -99,7 +99,7 @@ export function foundationDevPlugin(options = {}) {
|
|
|
99
99
|
const {
|
|
100
100
|
srcDir = 'src',
|
|
101
101
|
entryFileName = '_entry.generated.js',
|
|
102
|
-
|
|
102
|
+
sections: sectionPaths,
|
|
103
103
|
} = options
|
|
104
104
|
|
|
105
105
|
let resolvedSrcDir
|
|
@@ -112,7 +112,7 @@ export function foundationDevPlugin(options = {}) {
|
|
|
112
112
|
const root = config.root || process.cwd()
|
|
113
113
|
const srcPath = resolve(root, srcDir)
|
|
114
114
|
const entryPath = join(srcPath, entryFileName)
|
|
115
|
-
await generateEntryPoint(srcPath, entryPath, {
|
|
115
|
+
await generateEntryPoint(srcPath, entryPath, { sectionPaths })
|
|
116
116
|
},
|
|
117
117
|
|
|
118
118
|
configResolved(config) {
|
|
@@ -124,7 +124,7 @@ export function foundationDevPlugin(options = {}) {
|
|
|
124
124
|
if (reason) {
|
|
125
125
|
console.log(`[foundation] ${reason}, regenerating entry...`)
|
|
126
126
|
const entryPath = join(resolvedSrcDir, entryFileName)
|
|
127
|
-
await generateEntryPoint(resolvedSrcDir, entryPath, {
|
|
127
|
+
await generateEntryPoint(resolvedSrcDir, entryPath, { sectionPaths })
|
|
128
128
|
server.ws.send({ type: 'full-reload' })
|
|
129
129
|
}
|
|
130
130
|
},
|