@lifetechocms/react 0.1.4 → 0.1.5
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/vite/GenerateEntries.js +11 -0
- package/vite/index.js +95 -8
package/package.json
CHANGED
package/vite/GenerateEntries.js
CHANGED
|
@@ -163,6 +163,16 @@ export function generateEntries(
|
|
|
163
163
|
entries[entryName] = resolvedId;
|
|
164
164
|
|
|
165
165
|
modules[resolvedId] = `
|
|
166
|
+
// LifeTechOCMS View: ${relativeName}
|
|
167
|
+
// Source: ${normalize(file)}
|
|
168
|
+
//
|
|
169
|
+
// This View must provide a default export.
|
|
170
|
+
//
|
|
171
|
+
// Example:
|
|
172
|
+
// export default function Home() {
|
|
173
|
+
// return <h1>Welcome</h1>;
|
|
174
|
+
// }
|
|
175
|
+
|
|
166
176
|
import View from ${JSON.stringify(
|
|
167
177
|
normalize(file)
|
|
168
178
|
)};
|
|
@@ -180,6 +190,7 @@ export function generateEntries(
|
|
|
180
190
|
mountLifeTechView(element, View);
|
|
181
191
|
});
|
|
182
192
|
`;
|
|
193
|
+
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
return {
|
package/vite/index.js
CHANGED
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { generateEntries} from './GenerateEntries.js';
|
|
4
|
+
//import { generateEntries} from './GenerateEntries.js';
|
|
5
|
+
import { generateEntries, discoverReactFiles,getRelativeName} from './GenerateEntries.js';
|
|
5
6
|
import { generateLayoutHtml} from './GenerateLayoutHtml.js';
|
|
6
7
|
import { discoverLayouts} from './DiscoverLayouts.js';
|
|
7
8
|
import { generateLayoutMapping} from './GenerateLayoutMapping.js';
|
|
8
9
|
import { generateThemeMetadata} from './GenerateThemeMetadata.js';
|
|
9
10
|
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
function validateReactComponents(files, type) {
|
|
15
|
+
for (const [name, filePath] of Object.entries(files)) {
|
|
16
|
+
// Skip virtual modules generated by LifeTechOCMS.
|
|
17
|
+
if (filePath.startsWith('virtual:')) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const source = fs.readFileSync(filePath, 'utf8');
|
|
22
|
+
|
|
23
|
+
// Check common default-export syntaxes.
|
|
24
|
+
const hasDefaultExport =
|
|
25
|
+
/\bexport\s+default\b/.test(source) ||
|
|
26
|
+
/\bexport\s*\{[^}]*\bas\s+default\b[^}]*\}/s.test(source);
|
|
27
|
+
|
|
28
|
+
if (!hasDefaultExport) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
'\n[LifeTechOCMS] Invalid React ' + type + '\n' +
|
|
31
|
+
'Component: ' + name + '\n' +
|
|
32
|
+
'File: ' + filePath + '\n\n' +
|
|
33
|
+
'Reason: No default export was found.\n\n' +
|
|
34
|
+
'Every LifeTechOCMS React ' + type +
|
|
35
|
+
' must export a default component.\n\n' +
|
|
36
|
+
'Example:\n' +
|
|
37
|
+
'export default function ' +
|
|
38
|
+
(type === 'View' ? 'Home' : 'Default') +
|
|
39
|
+
'() {\n' +
|
|
40
|
+
' return <h1>Welcome</h1>;\n' +
|
|
41
|
+
'}\n'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
10
48
|
export default function lifetechReact(options = {}) {
|
|
11
49
|
|
|
12
50
|
// 1. Plugin options
|
|
@@ -40,6 +78,7 @@ export default function lifetechReact(options = {}) {
|
|
|
40
78
|
let projectRoot;
|
|
41
79
|
let buildOutputDirectory;
|
|
42
80
|
let discoveredLayouts = {};
|
|
81
|
+
let discoveredViews = {};
|
|
43
82
|
let virtualModules = {};
|
|
44
83
|
|
|
45
84
|
return {
|
|
@@ -88,6 +127,20 @@ export default function lifetechReact(options = {}) {
|
|
|
88
127
|
// Retain Layouts for HTML generation.
|
|
89
128
|
discoveredLayouts = layouts;
|
|
90
129
|
|
|
130
|
+
const viewsPath = path.resolve(
|
|
131
|
+
projectRoot,
|
|
132
|
+
viewsDirectory
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const viewFiles = discoverReactFiles(viewsPath);
|
|
136
|
+
|
|
137
|
+
discoveredViews = Object.fromEntries(
|
|
138
|
+
viewFiles.map(file => [
|
|
139
|
+
getRelativeName(viewsPath, file),
|
|
140
|
+
file
|
|
141
|
+
])
|
|
142
|
+
);
|
|
143
|
+
|
|
91
144
|
const pluginRoot = path.resolve(
|
|
92
145
|
import.meta.dirname,
|
|
93
146
|
'..'
|
|
@@ -154,6 +207,27 @@ export default function lifetechReact(options = {}) {
|
|
|
154
207
|
);
|
|
155
208
|
},
|
|
156
209
|
|
|
210
|
+
// 6. Validate React Layouts and Views.
|
|
211
|
+
buildStart() {
|
|
212
|
+
console.log(
|
|
213
|
+
'[LifeTechOCMS] Validating React Layouts and Views...'
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
validateReactComponents(
|
|
217
|
+
discoveredLayouts,
|
|
218
|
+
'Layout'
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
validateReactComponents(
|
|
222
|
+
discoveredViews,
|
|
223
|
+
'View'
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
console.log(
|
|
227
|
+
'[LifeTechOCMS] React component validation passed.'
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
|
|
157
231
|
// 6. Resolve virtual modules.
|
|
158
232
|
resolveId(id) {
|
|
159
233
|
if (id === viewsVirtualId) {
|
|
@@ -214,7 +288,21 @@ export default function lifetechReact(options = {}) {
|
|
|
214
288
|
|
|
215
289
|
// 8. Generate LifeTech HTML and metadata.
|
|
216
290
|
/*
|
|
291
|
+
// 8. Generate LifeTech HTML and metadata.
|
|
217
292
|
async closeBundle() {
|
|
293
|
+
const manifestPath = path.join(
|
|
294
|
+
buildOutputDirectory,
|
|
295
|
+
'.vite',
|
|
296
|
+
'manifest.json'
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (!fs.existsSync(manifestPath)) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
'LifeTechOCMS: Vite manifest not found. ' +
|
|
302
|
+
'Theme generation cannot continue.'
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
218
306
|
generateLayoutHtml({
|
|
219
307
|
outputDirectory: buildOutputDirectory,
|
|
220
308
|
projectRoot,
|
|
@@ -233,12 +321,10 @@ export default function lifetechReact(options = {}) {
|
|
|
233
321
|
outputDirectory: buildOutputDirectory,
|
|
234
322
|
themeName
|
|
235
323
|
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// 8. Generate LifeTech HTML and metadata.
|
|
241
|
-
async closeBundle() {
|
|
324
|
+
}*/
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
async writeBundle() {
|
|
242
328
|
const manifestPath = path.join(
|
|
243
329
|
buildOutputDirectory,
|
|
244
330
|
'.vite',
|
|
@@ -270,7 +356,8 @@ export default function lifetechReact(options = {}) {
|
|
|
270
356
|
outputDirectory: buildOutputDirectory,
|
|
271
357
|
themeName
|
|
272
358
|
});
|
|
273
|
-
}
|
|
359
|
+
},
|
|
360
|
+
|
|
274
361
|
|
|
275
362
|
|
|
276
363
|
|