@lifetechocms/react 0.0.0-stage → 0.1.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LifeTechOCMS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,166 @@
1
- # Temporary Holding Version
1
+ # @lifetechocms/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React and Vite integration for building and exporting [LifeTechOCMS](https://github.com/lifetechOCMS/lifetechocms) themes.
4
+
5
+ The package turns React Layouts and Views into a LifeTechOCMS theme containing HTML entry files and compiled JavaScript/CSS assets. It provides a Vite plugin and the `lt-export` command.
6
+
7
+ > **Version:** 0.1.4 — initial public-release candidate. Tested with React 19 and Vite 8. Additional environments are not yet verified.
8
+
9
+ ## Requirements
10
+
11
+ - Node.js compatible with your installed Vite 8 version
12
+ - React 19 and React DOM 19
13
+ - Vite 8 and `@vitejs/plugin-react`
14
+ - A LifeTechOCMS installation for importing and testing the exported theme
15
+
16
+ ## Install
17
+
18
+ From the root of an existing React/Vite application:
19
+
20
+ ```bash
21
+ npm install -D @lifetechocms/react@0.1.4
22
+ ```
23
+
24
+ If starting a new application:
25
+
26
+ ```bash
27
+ npm create vite@latest ThemeLtReactDemo -- --template react
28
+ cd ThemeLtReactDemo
29
+ npm install
30
+ npm install -D @lifetechocms/react@0.1.4
31
+ ```
32
+
33
+ ## Configure Vite
34
+
35
+ In `vite.config.js`:
36
+
37
+ ```js
38
+ import { defineConfig } from 'vite';
39
+ import react from '@vitejs/plugin-react';
40
+ import lifetechReact from '@lifetechocms/react/vite';
41
+
42
+ export default defineConfig({
43
+ plugins: [
44
+ react(),
45
+ lifetechReact({
46
+ themeName: 'ThemeLtReactDemo',
47
+ layoutsDirectory: 'src/Layouts',
48
+ viewsDirectory: 'src/Views'
49
+ })
50
+ ],
51
+ base: './'
52
+ });
53
+ ```
54
+
55
+ The `themeName` option is required. Layouts and Views directories can be customized. The plugin generates LifeTechOCMS build entries only when invoked by `lt-export`; ordinary Vite development/build commands remain separate.
56
+
57
+ ## Create Layouts and Views
58
+
59
+ Example project structure:
60
+
61
+ ```text
62
+ src/
63
+ ├── Layouts/
64
+ │ └── Default.jsx
65
+ └── Views/
66
+ ├── Home.jsx
67
+ ├── About.jsx
68
+ └── auth/
69
+ └── Login.jsx
70
+ ```
71
+
72
+ A Layout must **default-export** a React component that renders `children`:
73
+
74
+ ```jsx
75
+ // src/Layouts/Default.jsx
76
+ export default function Default({ children }) {
77
+ return (
78
+ <>
79
+ <header><h1>My LifeTechOCMS Site</h1></header>
80
+ <main>{children}</main>
81
+ <footer>Powered by LifeTechOCMS</footer>
82
+ </>
83
+ );
84
+ }
85
+ ```
86
+
87
+ Each View must also **default-export** a React component:
88
+
89
+ ```jsx
90
+ // src/Views/Home.jsx
91
+ export default function Home() {
92
+ return <section><h2>Welcome</h2><p>My first React View.</p></section>;
93
+ }
94
+ ```
95
+
96
+ Nested Views such as `src/Views/auth/Login.jsx` are discovered recursively. If no Layout is found, the exporter generates a minimal Default Layout automatically.
97
+
98
+ ## Export a LifeTechOCMS theme
99
+
100
+ Add an export script to your application's existing `package.json` scripts:
101
+
102
+ ```json
103
+ {
104
+ "scripts": {
105
+ "lt-export": "lt-export"
106
+ }
107
+ }
108
+ ```
109
+
110
+ Then run:
111
+
112
+ ```bash
113
+ npm run lt-export
114
+ ```
115
+
116
+ The CLI builds the React entries into `dist-lifetech/`, then creates an export at:
117
+
118
+ ```text
119
+ lt-exports/
120
+ └── ThemeLtReactDemo/
121
+ ├── Assets/
122
+ │ ├── js/
123
+ │ └── css/ (when CSS is emitted)
124
+ ├── Layouts/
125
+ │ └── Default.html
126
+ ├── Views/
127
+ │ ├── Home.html
128
+ │ ├── About.html
129
+ │ └── auth/
130
+ │ └── Login.html
131
+ └── Storage/ (when layout mappings are generated)
132
+ ```
133
+
134
+ The exact files depend on your application and generated assets. The exporter can also generate layout mapping files when applicable.
135
+
136
+ ## Install and test in LifeTechOCMS
137
+
138
+ Import the exported `ThemeLtReactDemo` theme using your LifeTechOCMS theme-management workflow. Activate or preview it, then verify that the Layout, Views, nested routes, and compiled assets load as expected.
139
+
140
+ LifeTechOCMS remains responsible for its own routing, pages, content management, and server-side processing. This package generates React-based theme resources; it does not replace the LifeTechOCMS backend.
141
+
142
+ ## Public package entry points
143
+
144
+ | Import or command | Purpose |
145
+ | --- | --- |
146
+ | `@lifetechocms/react` | React runtime exports (`LifeTechEntry`, `LifeTechDynamicContent`) |
147
+ | `@lifetechocms/react/vite` | Default-exported Vite plugin |
148
+ | `@lifetechocms/react/exporter` | Theme exporter utilities |
149
+ | `lt-export` | Build and export a LifeTechOCMS theme |
150
+
151
+ ## Development notes
152
+
153
+ - Keep the Vite plugin registered in `vite.config.js` for both ordinary builds and LifeTech exports.
154
+ - `npm run build` performs the application's standard Vite build; `npm run lt-export` creates a LifeTechOCMS theme export.
155
+ - The exporter requires the configured Views directory to exist.
156
+ - Layouts and Views must have default component exports.
157
+ - Avoid View names that generate identical flattened asset names (for example, `Admin/Dashboard.jsx` and `Admin_Dashboard.jsx`).
158
+ - This release has been tested with a separately installed npm tarball and a working LifeTechOCMS theme import; broader compatibility testing is ongoing.
159
+
160
+ ## Issues and contributions
161
+
162
+ Report bugs, compatibility issues, and feature requests at the [LifeTechOCMS issue tracker](https://github.com/lifetechOCMS/lifetechocms/issues).
163
+
164
+ ## License
165
+
166
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { build } from 'vite';
6
+ import { exportTheme } from '../exporter/index.js';
7
+
8
+ const projectRoot = process.cwd();
9
+ const buildDirectory = 'dist-lifetech';
10
+
11
+ async function main() {
12
+ try {
13
+ console.log('[LifeTechOCMS] Starting theme build...');
14
+
15
+ // Activate LifeTech build mode.
16
+ process.env.LIFETECH_BUILD = 'true';
17
+
18
+ // Run Vite build automatically.
19
+ await build({
20
+ root: projectRoot,
21
+ build: {
22
+ outDir: buildDirectory,
23
+ emptyOutDir: true
24
+ }
25
+ });
26
+
27
+ const metadataPath = path.join(
28
+ projectRoot,
29
+ buildDirectory,
30
+ 'lifetech-theme.json'
31
+ );
32
+
33
+ if (!fs.existsSync(metadataPath)) {
34
+ throw new Error(
35
+ 'Theme metadata was not generated.'
36
+ );
37
+ }
38
+
39
+ const metadata = JSON.parse(
40
+ fs.readFileSync(metadataPath, 'utf8')
41
+ );
42
+
43
+ if (!metadata.themeName) {
44
+ throw new Error(
45
+ 'Theme name is missing from build metadata.'
46
+ );
47
+ }
48
+
49
+ exportTheme({
50
+ projectRoot,
51
+ themeName: metadata.themeName,
52
+ buildDirectory,
53
+ exportDirectory: 'lt-exports'
54
+ });
55
+
56
+ console.log(
57
+ '[LifeTechOCMS] Theme export completed.'
58
+ );
59
+ } catch (error) {
60
+ console.error(
61
+ '[LifeTechOCMS] Export failed:',
62
+ error.message
63
+ );
64
+
65
+ process.exitCode = 1;
66
+ }
67
+ }
68
+
69
+ await main();
@@ -0,0 +1,169 @@
1
+
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ import { validateTheme } from './ValidateTheme.js';
6
+
7
+
8
+ function countHtmlFiles(directory) {
9
+ if (!fs.existsSync(directory)) {
10
+ return 0;
11
+ }
12
+
13
+ let count = 0;
14
+
15
+ for (const entry of fs.readdirSync(directory, {
16
+ withFileTypes: true
17
+ })) {
18
+ const fullPath = path.join(directory, entry.name);
19
+
20
+ if (entry.isDirectory()) {
21
+ count += countHtmlFiles(fullPath);
22
+ } else if (
23
+ entry.isFile() &&
24
+ path.extname(entry.name).toLowerCase() === '.html'
25
+ ) {
26
+ count++;
27
+ }
28
+ }
29
+
30
+ return count;
31
+ }
32
+
33
+ export function exportTheme({
34
+ projectRoot = process.cwd(),
35
+ themeName,
36
+ buildDirectory = 'dist',
37
+ exportDirectory = 'exports'
38
+ }) {
39
+ if (!themeName ||
40
+ !/^[A-Za-z][A-Za-z0-9_-]*$/.test(themeName)) {
41
+ throw new Error('LifeTechOCMS: Invalid theme name.');
42
+ }
43
+
44
+ const root = path.resolve(projectRoot);
45
+ const source = path.resolve(root, buildDirectory);
46
+ const exportRoot = path.resolve(root, exportDirectory);
47
+ const destination = path.join(exportRoot, themeName);
48
+
49
+ // Protect the source build and project directories.
50
+ if (source === root ||
51
+ exportRoot === root ||
52
+ destination === source ||
53
+ destination.startsWith(source + path.sep) ||
54
+ source.startsWith(destination + path.sep)) {
55
+ throw new Error(
56
+ 'LifeTechOCMS: Unsafe build or export directory.'
57
+ );
58
+ }
59
+
60
+ const resources = validateTheme(source);
61
+
62
+ fs.mkdirSync(exportRoot, { recursive: true });
63
+
64
+ // Use a temporary directory so an incomplete copy does not
65
+ // replace an existing export.
66
+ const temporary = fs.mkdtempSync(
67
+ path.join(exportRoot, '.lifetech-export-')
68
+ );
69
+
70
+ try {
71
+ // Copy generated LifeTechOCMS Theme directories
72
+ for (const folder of ['Assets', 'Layouts', 'Views', 'Storage']) {
73
+
74
+ const sourceFolder = path.join(source, folder);
75
+ const destinationFolder = path.join(temporary, folder);
76
+
77
+ // Skip directories that do not exist
78
+ if (!fs.existsSync(sourceFolder)) {
79
+ continue;
80
+ }
81
+
82
+ fs.cpSync(
83
+ sourceFolder,
84
+ destinationFolder,
85
+ { recursive: true }
86
+ );
87
+ }
88
+
89
+ // Preserve any existing export until the copy is complete.
90
+ const backup = destination + '.backup';
91
+
92
+ if (fs.existsSync(backup)) {
93
+ throw new Error(
94
+ `Remove or rename the existing backup first: ${backup}`
95
+ );
96
+ }
97
+
98
+ const hadExisting = fs.existsSync(destination);
99
+
100
+ if (hadExisting) {
101
+ fs.renameSync(destination, backup);
102
+ }
103
+
104
+ try {
105
+ //console.log('[LifeTechOCMS] Temporary:', temporary);
106
+ //console.log('[LifeTechOCMS] Destination:', destination);
107
+
108
+ console.log(
109
+ '[LifeTechOCMS] Temporary exists:',
110
+ fs.existsSync(temporary)
111
+ );
112
+
113
+ console.log(
114
+ '[LifeTechOCMS] Destination exists:',
115
+ fs.existsSync(destination)
116
+ );
117
+
118
+ console.log(
119
+ '[LifeTechOCMS] Temporary contents:',
120
+ fs.readdirSync(temporary)
121
+ );
122
+
123
+ fs.renameSync(temporary, destination);
124
+
125
+ } catch (error) {
126
+ console.error('[LifeTechOCMS] Rename error:', {
127
+ code: error.code,
128
+ syscall: error.syscall,
129
+ path: error.path,
130
+ dest: error.dest
131
+ });
132
+
133
+ if (hadExisting && fs.existsSync(backup)) {
134
+ fs.renameSync(backup, destination);
135
+ }
136
+
137
+ throw error;
138
+ }
139
+
140
+ if (hadExisting) {
141
+ fs.rmSync(backup, { recursive: true, force: true });
142
+ }
143
+
144
+ console.log(
145
+ `[LifeTechOCMS] Exported theme: ${destination}`
146
+ );
147
+ console.log(
148
+ `[LifeTechOCMS] Layouts: ${
149
+ countHtmlFiles(path.join(destination, 'Layouts'))
150
+ }`
151
+ );
152
+
153
+ console.log(
154
+ `[LifeTechOCMS] Views: ${
155
+ countHtmlFiles(path.join(destination, 'Views'))
156
+ }`
157
+ );
158
+
159
+ return destination;
160
+ }finally {
161
+ if (fs.existsSync(temporary)) {
162
+ fs.rmSync(temporary, { recursive: true, force: true });
163
+ }
164
+ }
165
+
166
+
167
+
168
+
169
+ }
@@ -0,0 +1,84 @@
1
+
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ // Discover HTML files recursively.
6
+ function discoverHtmlFiles(directory, root = directory) {
7
+ const files = [];
8
+
9
+ for (const entry of fs.readdirSync(directory, {
10
+ withFileTypes: true
11
+ })) {
12
+ const fullPath = path.join(directory, entry.name);
13
+
14
+ if (entry.isDirectory()) {
15
+ files.push(...discoverHtmlFiles(fullPath, root));
16
+ } else if (
17
+ entry.isFile() &&
18
+ path.extname(entry.name).toLowerCase() === '.html'
19
+ ) {
20
+ const relativePath = path
21
+ .relative(root, fullPath)
22
+ .replace(/\\/g, '/');
23
+
24
+ files.push(relativePath);
25
+ }
26
+ }
27
+
28
+ return files.sort();
29
+ }
30
+
31
+ export function validateTheme(buildDirectory) {
32
+
33
+ // 1. Confirm build directory exists.
34
+ if (
35
+ !fs.existsSync(buildDirectory) ||
36
+ !fs.statSync(buildDirectory).isDirectory()
37
+ ) {
38
+ throw new Error(
39
+ `LifeTechOCMS: Build directory not found: ${buildDirectory}`
40
+ );
41
+ }
42
+
43
+ // 2. Validate required directories.
44
+ for (const folder of ['Assets', 'Layouts', 'Views']) {
45
+ const location = path.join(buildDirectory, folder);
46
+
47
+ if (
48
+ !fs.existsSync(location) ||
49
+ !fs.statSync(location).isDirectory()
50
+ ) {
51
+ throw new Error(
52
+ `LifeTechOCMS: Missing build folder: ${folder}`
53
+ );
54
+ }
55
+ }
56
+
57
+ // 3. Discover Layouts and Views recursively.
58
+ const layouts = discoverHtmlFiles(
59
+ path.join(buildDirectory, 'Layouts')
60
+ );
61
+
62
+ const views = discoverHtmlFiles(
63
+ path.join(buildDirectory, 'Views')
64
+ );
65
+
66
+ // 4. Validate resource availability.
67
+ if (layouts.length === 0) {
68
+ throw new Error(
69
+ 'LifeTechOCMS: No Layout HTML files found.'
70
+ );
71
+ }
72
+
73
+ if (views.length === 0) {
74
+ throw new Error(
75
+ 'LifeTechOCMS: No View HTML files found.'
76
+ );
77
+ }
78
+
79
+ // 5. Return discovered resources.
80
+ return {
81
+ layouts,
82
+ views
83
+ };
84
+ }
@@ -0,0 +1,9 @@
1
+
2
+ import { exportTheme } from './ExportTheme.js';
3
+
4
+ export { exportTheme } from './ExportTheme.js';
5
+ export { validateTheme } from './ValidateTheme.js';
6
+
7
+ export function runExport(options = {}) {
8
+ return exportTheme(options);
9
+ }
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+
2
+ export { default as LifeTechEntry }
3
+ from './runtime/LifeTechEntry.jsx';
4
+
5
+ export { default as LifeTechDynamicContent }
6
+ from './runtime/LifeTechDynamicContent.jsx';
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
- {
2
- "name": "@lifetechocms/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@lifetechocms/react",
3
+ "version": "0.1.4",
4
+ "description": "React and Vite integration for building and exporting LifeTechOCMS themes.",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./vite": "./vite/index.js",
10
+ "./exporter": "./exporter/index.js"
11
+ },
12
+ "files": [
13
+ "index.js",
14
+ "runtime",
15
+ "vite",
16
+ "bin",
17
+ "exporter",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "keywords": [
22
+ "lifetechocms",
23
+ "react",
24
+ "vite",
25
+ "cms",
26
+ "theme",
27
+ "plugin"
28
+ ],
29
+ "license": "MIT",
30
+ "peerDependencies": {
31
+ "react": "^19.0.0",
32
+ "react-dom": "^19.0.0",
33
+ "vite": "^8.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "vite": "^8.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "bin": {
42
+ "lt-export": "bin/lt-export.js"
43
+ }
44
+ }
@@ -0,0 +1,24 @@
1
+ import { useLayoutEffect, useRef } from 'react';
2
+
3
+ export default function LifeTechDynamicContent() {
4
+ const containerRef = useRef(null);
5
+
6
+ useLayoutEffect(() => {
7
+ const source = document.getElementById('lt-dynamic-content');
8
+ const target = containerRef.current;
9
+
10
+ if (!source || !target) {
11
+ console.warn(
12
+ 'LifeTechOCMS dynamic content container not found.'
13
+ );
14
+ return;
15
+ }
16
+
17
+ // Move framework-generated content into the Layout.
18
+ while (source.firstChild) {
19
+ target.appendChild(source.firstChild);
20
+ }
21
+ }, []);
22
+
23
+ return <div ref={containerRef} />;
24
+ }
@@ -0,0 +1,24 @@
1
+
2
+ import React from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+
5
+ import LifeTechDynamicContent from './LifeTechDynamicContent.jsx';
6
+
7
+ export function mountLifeTechLayout(Layout) {
8
+ const root = document.getElementById('lt-react-layout');
9
+
10
+ if (!root) {
11
+ console.error(
12
+ 'LifeTechOCMS React mount element not found: lt-react-layout'
13
+ );
14
+ return;
15
+ }
16
+
17
+ createRoot(root).render(
18
+ <Layout>
19
+ <LifeTechDynamicContent />
20
+ </Layout>
21
+ );
22
+ }
23
+
24
+ export default mountLifeTechLayout;
@@ -0,0 +1,21 @@
1
+ import { createRoot } from 'react-dom/client';
2
+
3
+ const mountedRoots = new WeakMap();
4
+
5
+ export function mountLifeTechView(element, Component) {
6
+ if (!element || !Component) {
7
+ return null;
8
+ }
9
+
10
+ if (mountedRoots.has(element)) {
11
+ return mountedRoots.get(element);
12
+ }
13
+
14
+ const root = createRoot(element);
15
+
16
+ root.render(<Component />);
17
+
18
+ mountedRoots.set(element, root);
19
+
20
+ return root;
21
+ }