frontend-hamroun 1.2.11 → 1.2.13

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/bin/cli.mjs CHANGED
@@ -34,7 +34,7 @@ function printBanner() {
34
34
  ${colors.blue}${colors.bright}╔══════════════════════════════════════════════╗
35
35
  ║ ║
36
36
  ║ Frontend Hamroun v${packageJson.version.padEnd(25)}║
37
- ║ A lightweight frontend & backend framework
37
+ ║ A lightweight frontend & backend framework
38
38
  ║ ║
39
39
  ╚══════════════════════════════════════════════╝${colors.reset}
40
40
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "A lightweight frontend and backend framework for building modern web applications",
5
5
  "type": "module",
6
6
  "main": "dist/frontend-hamroun.umd.js",
@@ -50,7 +50,7 @@ function printBanner() {
50
50
  \${colors.blue}\${colors.bright}╔══════════════════════════════════════════════╗
51
51
  ║ ║
52
52
  ║ Frontend Hamroun v\${packageJson.version.padEnd(25)}║
53
- ║ A lightweight frontend & backend framework
53
+ ║ A lightweight frontend & backend framework
54
54
  ║ ║
55
55
  ╚══════════════════════════════════════════════╝\${colors.reset}
56
56
  \`);
@@ -732,6 +732,95 @@ export default defineConfig({
732
732
  );
733
733
 
734
734
  console.log(`✅ Created minimal basic template at ${templateDir}`);
735
+
736
+ // Create React compatibility layer
737
+ createReactCompatibilityLayer(templateDir);
738
+ }
739
+
740
+ // Create React compatibility layer
741
+ function createReactCompatibilityLayer(templateDir) {
742
+ // Create React compatibility directory
743
+ const reactDir = path.join(templateDir, 'src/react');
744
+ if (!fs.existsSync(reactDir)) {
745
+ fs.mkdirSync(reactDir, { recursive: true });
746
+ }
747
+
748
+ // Create jsx-dev-runtime.ts
749
+ fs.writeFileSync(
750
+ path.join(reactDir, 'jsx-dev-runtime.ts'),
751
+ `import { jsx } from 'frontend-hamroun';
752
+
753
+ // Export jsx as jsxDEV for React compatibility
754
+ export const jsxDEV = jsx;
755
+ export const Fragment = Symbol('Fragment');
756
+ export const jsxs = jsx;
757
+
758
+ // Default export
759
+ export default {
760
+ jsxDEV,
761
+ Fragment,
762
+ jsxs
763
+ };`
764
+ );
765
+
766
+ // Create jsx-runtime.ts
767
+ fs.writeFileSync(
768
+ path.join(reactDir, 'jsx-runtime.ts'),
769
+ `import { jsx } from 'frontend-hamroun';
770
+
771
+ // Export jsx functions for React compatibility
772
+ export const jsxs = jsx;
773
+ export const Fragment = Symbol('Fragment');
774
+
775
+ // Default export
776
+ export default {
777
+ jsx,
778
+ jsxs,
779
+ Fragment
780
+ };`
781
+ );
782
+
783
+ // Create index.ts
784
+ fs.writeFileSync(
785
+ path.join(reactDir, 'index.ts'),
786
+ `import {
787
+ useState,
788
+ useEffect,
789
+ useRef,
790
+ useMemo,
791
+ useContext,
792
+ createContext,
793
+ jsx
794
+ } from 'frontend-hamroun';
795
+
796
+ // Provide React compatibility layer
797
+ const React = {
798
+ createElement: jsx,
799
+ Fragment: Symbol('Fragment'),
800
+ useState,
801
+ useEffect,
802
+ useRef,
803
+ useMemo,
804
+ useContext,
805
+ createContext
806
+ };
807
+
808
+ // Export hooks directly for named imports
809
+ export {
810
+ useState,
811
+ useEffect,
812
+ useRef,
813
+ useMemo,
814
+ useContext,
815
+ createContext,
816
+ jsx as createElement
817
+ };
818
+
819
+ // Default export
820
+ export default React;`
821
+ );
822
+
823
+ console.log(`✅ Created React compatibility layer in ${templateDir}`);
735
824
  }
736
825
 
737
826
  // Create React compatibility shims
@@ -766,5 +855,253 @@ export default {
766
855
  console.log(`✅ Created React compatibility shims in ${templateDir}`);
767
856
  }
768
857
 
858
+ // Create a function to create a pure non-JSX template
859
+ function createPureTemplate(templateDir) {
860
+ console.log(`📝 Creating pure JS template at ${templateDir}`);
861
+
862
+ // Create package.json without React dependencies
863
+ const packageJson = {
864
+ "name": "frontend-hamroun-app",
865
+ "private": true,
866
+ "version": "0.1.0",
867
+ "type": "module",
868
+ "scripts": {
869
+ "dev": "vite",
870
+ "build": "tsc && vite build",
871
+ "preview": "vite preview"
872
+ },
873
+ "dependencies": {
874
+ "frontend-hamroun": "latest"
875
+ },
876
+ "devDependencies": {
877
+ "@types/node": "^20.10.0",
878
+ "typescript": "^5.3.2",
879
+ "vite": "^5.0.0",
880
+ "vite-plugin-node-polyfills": "^0.21.0"
881
+ }
882
+ };
883
+
884
+ fs.writeFileSync(
885
+ path.join(templateDir, 'package.json'),
886
+ JSON.stringify(packageJson, null, 2)
887
+ );
888
+
889
+ // Create index.html
890
+ fs.writeFileSync(
891
+ path.join(templateDir, 'index.html'),
892
+ `<!DOCTYPE html>
893
+ <html lang="en">
894
+ <head>
895
+ <meta charset="UTF-8">
896
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
897
+ <title>Frontend Hamroun App</title>
898
+ </head>
899
+ <body>
900
+ <div id="app"></div>
901
+ <script type="module" src="/src/main.js"></script>
902
+ </body>
903
+ </html>`
904
+ );
905
+
906
+ // Create src directory
907
+ const srcDir = path.join(templateDir, 'src');
908
+ fs.mkdirSync(srcDir, { recursive: true });
909
+
910
+ // Create pure JS main.js without any JSX
911
+ fs.writeFileSync(
912
+ path.join(srcDir, 'main.js'),
913
+ `import { render } from 'frontend-hamroun';
914
+ import { App } from './App.js';
915
+
916
+ document.addEventListener('DOMContentLoaded', () => {
917
+ const rootElement = document.getElementById('app');
918
+ if (rootElement) {
919
+ // Call App as a function to create the VDOM structure
920
+ render(App(), rootElement);
921
+ console.log('App rendered successfully');
922
+ }
923
+ });`
924
+ );
925
+
926
+ // Create App.js with pure JS (no JSX or TS)
927
+ fs.writeFileSync(
928
+ path.join(srcDir, 'App.js'),
929
+ `import { useState, useRef } from 'frontend-hamroun';
930
+
931
+ export function App() {
932
+ const [count, setCount] = useState(0);
933
+ const renderCount = useRef(0);
934
+
935
+ renderCount.current++;
936
+
937
+ // Return a plain JavaScript object representation of the UI
938
+ return {
939
+ type: 'div',
940
+ props: {
941
+ style: {
942
+ fontFamily: 'Arial, sans-serif',
943
+ maxWidth: '600px',
944
+ margin: '0 auto',
945
+ padding: '2rem'
946
+ },
947
+ children: [
948
+ {
949
+ type: 'h1',
950
+ props: {
951
+ style: { textAlign: 'center' },
952
+ children: 'Frontend Hamroun App'
953
+ }
954
+ },
955
+ {
956
+ type: 'p',
957
+ props: {
958
+ style: { textAlign: 'center' },
959
+ children: \`Render count: \${renderCount.current}\`
960
+ }
961
+ },
962
+ {
963
+ type: 'div',
964
+ props: {
965
+ style: {
966
+ display: 'flex',
967
+ flexDirection: 'column',
968
+ alignItems: 'center',
969
+ padding: '1rem',
970
+ border: '1px solid #ccc',
971
+ borderRadius: '8px'
972
+ },
973
+ children: [
974
+ {
975
+ type: 'h2',
976
+ props: {
977
+ children: 'Counter Example'
978
+ }
979
+ },
980
+ {
981
+ type: 'p',
982
+ props: {
983
+ children: \`Count: \${count}\`
984
+ }
985
+ },
986
+ {
987
+ type: 'div',
988
+ props: {
989
+ style: {
990
+ display: 'flex',
991
+ gap: '8px'
992
+ },
993
+ children: [
994
+ {
995
+ type: 'button',
996
+ props: {
997
+ onClick: () => setCount(count - 1),
998
+ style: {
999
+ padding: '8px 16px',
1000
+ backgroundColor: '#ff4d4d',
1001
+ color: 'white',
1002
+ border: 'none',
1003
+ borderRadius: '4px',
1004
+ cursor: 'pointer'
1005
+ },
1006
+ children: 'Decrement'
1007
+ }
1008
+ },
1009
+ {
1010
+ type: 'button',
1011
+ props: {
1012
+ onClick: () => setCount(count + 1),
1013
+ style: {
1014
+ padding: '8px 16px',
1015
+ backgroundColor: '#4d79ff',
1016
+ color: 'white',
1017
+ border: 'none',
1018
+ borderRadius: '4px',
1019
+ cursor: 'pointer'
1020
+ },
1021
+ children: 'Increment'
1022
+ }
1023
+ }
1024
+ ]
1025
+ }
1026
+ }
1027
+ ]
1028
+ }
1029
+ }
1030
+ ]
1031
+ }
1032
+ };
1033
+ }`
1034
+ );
1035
+
1036
+ // Create vite.config.js - No TypeScript, no JSX
1037
+ fs.writeFileSync(
1038
+ path.join(templateDir, 'vite.config.js'),
1039
+ `import { defineConfig } from 'vite';
1040
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
1041
+
1042
+ export default defineConfig({
1043
+ build: {
1044
+ outDir: 'dist',
1045
+ emptyOutDir: true
1046
+ },
1047
+ server: {
1048
+ port: 3000,
1049
+ open: true
1050
+ },
1051
+ plugins: [
1052
+ nodePolyfills({
1053
+ protocolImports: true,
1054
+ }),
1055
+ ]
1056
+ });`
1057
+ );
1058
+
1059
+ // Create jsconfig.json instead of tsconfig.json
1060
+ fs.writeFileSync(
1061
+ path.join(templateDir, 'jsconfig.json'),
1062
+ `{
1063
+ "compilerOptions": {
1064
+ "target": "ES2020",
1065
+ "useDefineForClassFields": true,
1066
+ "module": "ESNext",
1067
+ "moduleResolution": "node",
1068
+ "allowSyntheticDefaultImports": true,
1069
+ "resolveJsonModule": true,
1070
+ "checkJs": false,
1071
+ "strict": false
1072
+ },
1073
+ "include": ["src/**/*.js"],
1074
+ "exclude": ["node_modules"]
1075
+ }`
1076
+ );
1077
+
1078
+ console.log(`✅ Created pure JS template at ${templateDir}`);
1079
+ }
1080
+
1081
+ // Update the main CLI function to create only pure JS templates
1082
+ console.log('🔍 Checking template directories...');
1083
+ for (const template of templateList) {
1084
+ const templateDir = path.join(templatesDir, template);
1085
+
1086
+ if (!fs.existsSync(templateDir)) {
1087
+ console.log(`⚠️ Template directory "${template}" not found at: ${templateDir}`);
1088
+ console.log(`📁 Creating template directory: ${template}`);
1089
+ fs.mkdirSync(templateDir, { recursive: true });
1090
+
1091
+ // Create a pure JS template (no React, no JSX)
1092
+ createPureTemplate(templateDir);
1093
+ } else {
1094
+ console.log(`✅ Template found: ${template}`);
1095
+
1096
+ // Update existing template to use pure JS
1097
+ const mainFile = path.join(templateDir, 'src/main.js');
1098
+ if (!fs.existsSync(mainFile)) {
1099
+ console.log(`⚠️ Updating template ${template} to use pure JS`);
1100
+ // Create a pure JS template in this location
1101
+ createPureTemplate(templateDir);
1102
+ }
1103
+ }
1104
+ }
1105
+
769
1106
  // Call this function when creating templates
770
1107
  // ...existing code...
@@ -1,12 +1,12 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>My Frontend App</title>
7
- </head>
8
- <body class="bg-gray-100 min-h-screen">
9
- <div id="root"></div>
10
- <script type="module" src="/src/main.tsx"></script>
11
- </body>
12
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Frontend Hamroun App</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "node",
7
+ "allowSyntheticDefaultImports": true,
8
+ "resolveJsonModule": true,
9
+ "checkJs": false,
10
+ "strict": false
11
+ },
12
+ "include": ["src/**/*.js"],
13
+ "exclude": ["node_modules"]
14
+ }
@@ -1,30 +1,20 @@
1
- {
2
- "name": "front-package-app",
3
- "private": true,
4
- "version": "0.1.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "tsc && vite build",
9
- "preview": "vite preview",
10
- "start": "node dist/server.js",
11
- "dev:full": "concurrently \"npm run dev\" \"npm run dev:server\"",
12
- "dev:server": "tsx watch src/server.ts"
13
- },
14
- "dependencies": {
15
- "frontend-hamroun": "latest"
16
- },
17
- "devDependencies": {
18
- "@tailwindcss/forms": "^0.5.7",
19
- "@tailwindcss/typography": "^0.5.10",
20
- "@types/node": "^20.10.0",
21
- "autoprefixer": "^10.4.16",
22
- "concurrently": "^8.2.2",
23
- "cssnano": "^6.0.1",
24
- "postcss": "^8.4.31",
25
- "tailwindcss": "^3.3.5",
26
- "tsx": "^4.6.0",
27
- "typescript": "^5.3.2",
28
- "vite": "^5.0.0"
29
- }
30
- }
1
+ {
2
+ "name": "frontend-hamroun-app",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "frontend-hamroun": "latest"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^20.10.0",
16
+ "typescript": "^5.3.2",
17
+ "vite": "^5.0.0",
18
+ "vite-plugin-node-polyfills": "^0.21.0"
19
+ }
20
+ }
@@ -0,0 +1,105 @@
1
+ import { useState, useRef } from 'frontend-hamroun';
2
+
3
+ export function App() {
4
+ const [count, setCount] = useState(0);
5
+ const renderCount = useRef(0);
6
+
7
+ renderCount.current++;
8
+
9
+ // Return a plain JavaScript object representation of the UI
10
+ return {
11
+ type: 'div',
12
+ props: {
13
+ style: {
14
+ fontFamily: 'Arial, sans-serif',
15
+ maxWidth: '600px',
16
+ margin: '0 auto',
17
+ padding: '2rem'
18
+ },
19
+ children: [
20
+ {
21
+ type: 'h1',
22
+ props: {
23
+ style: { textAlign: 'center' },
24
+ children: 'Frontend Hamroun App'
25
+ }
26
+ },
27
+ {
28
+ type: 'p',
29
+ props: {
30
+ style: { textAlign: 'center' },
31
+ children: `Render count: ${renderCount.current}`
32
+ }
33
+ },
34
+ {
35
+ type: 'div',
36
+ props: {
37
+ style: {
38
+ display: 'flex',
39
+ flexDirection: 'column',
40
+ alignItems: 'center',
41
+ padding: '1rem',
42
+ border: '1px solid #ccc',
43
+ borderRadius: '8px'
44
+ },
45
+ children: [
46
+ {
47
+ type: 'h2',
48
+ props: {
49
+ children: 'Counter Example'
50
+ }
51
+ },
52
+ {
53
+ type: 'p',
54
+ props: {
55
+ children: `Count: ${count}`
56
+ }
57
+ },
58
+ {
59
+ type: 'div',
60
+ props: {
61
+ style: {
62
+ display: 'flex',
63
+ gap: '8px'
64
+ },
65
+ children: [
66
+ {
67
+ type: 'button',
68
+ props: {
69
+ onClick: () => setCount(count - 1),
70
+ style: {
71
+ padding: '8px 16px',
72
+ backgroundColor: '#ff4d4d',
73
+ color: 'white',
74
+ border: 'none',
75
+ borderRadius: '4px',
76
+ cursor: 'pointer'
77
+ },
78
+ children: 'Decrement'
79
+ }
80
+ },
81
+ {
82
+ type: 'button',
83
+ props: {
84
+ onClick: () => setCount(count + 1),
85
+ style: {
86
+ padding: '8px 16px',
87
+ backgroundColor: '#4d79ff',
88
+ color: 'white',
89
+ border: 'none',
90
+ borderRadius: '4px',
91
+ cursor: 'pointer'
92
+ },
93
+ children: 'Increment'
94
+ }
95
+ }
96
+ ]
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ };
105
+ }
@@ -0,0 +1,11 @@
1
+ import { render } from 'frontend-hamroun';
2
+ import { App } from './App.js';
3
+
4
+ document.addEventListener('DOMContentLoaded', () => {
5
+ const rootElement = document.getElementById('app');
6
+ if (rootElement) {
7
+ // Call App as a function to create the VDOM structure
8
+ render(App(), rootElement);
9
+ console.log('App rendered successfully');
10
+ }
11
+ });
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'vite';
2
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
3
+
4
+ export default defineConfig({
5
+ build: {
6
+ outDir: 'dist',
7
+ emptyOutDir: true
8
+ },
9
+ server: {
10
+ port: 3000,
11
+ open: true
12
+ },
13
+ plugins: [
14
+ nodePolyfills({
15
+ protocolImports: true,
16
+ }),
17
+ ]
18
+ });
@@ -16,5 +16,9 @@
16
16
  "typescript": "^5.3.2",
17
17
  "vite": "^5.0.0",
18
18
  "vite-plugin-node-polyfills": "^0.21.0"
19
+ },
20
+ "overrides": {
21
+ "react": "npm:@empty-npm-package/react@1.0.0",
22
+ "react-dom": "npm:@empty-npm-package/react-dom@1.0.0"
19
23
  }
20
24
  }
@@ -0,0 +1,35 @@
1
+ import {
2
+ useState,
3
+ useEffect,
4
+ useRef,
5
+ useMemo,
6
+ useContext,
7
+ createContext,
8
+ jsx
9
+ } from 'frontend-hamroun';
10
+
11
+ // Provide React compatibility layer
12
+ const React = {
13
+ createElement: jsx,
14
+ Fragment: Symbol('Fragment'),
15
+ useState,
16
+ useEffect,
17
+ useRef,
18
+ useMemo,
19
+ useContext,
20
+ createContext
21
+ };
22
+
23
+ // Export hooks directly for named imports
24
+ export {
25
+ useState,
26
+ useEffect,
27
+ useRef,
28
+ useMemo,
29
+ useContext,
30
+ createContext,
31
+ jsx as createElement
32
+ };
33
+
34
+ // Default export
35
+ export default React;
@@ -0,0 +1,13 @@
1
+ import { jsx } from 'frontend-hamroun';
2
+
3
+ // Export jsx as jsxDEV for React compatibility
4
+ export const jsxDEV = jsx;
5
+ export const Fragment = Symbol('Fragment');
6
+ export const jsxs = jsx;
7
+
8
+ // Default export
9
+ export default {
10
+ jsxDEV,
11
+ Fragment,
12
+ jsxs
13
+ };
@@ -0,0 +1,12 @@
1
+ import { jsx } from 'frontend-hamroun';
2
+
3
+ // Export jsx functions for React compatibility
4
+ export const jsxs = jsx;
5
+ export const Fragment = Symbol('Fragment');
6
+
7
+ // Default export
8
+ export default {
9
+ jsx,
10
+ jsxs,
11
+ Fragment
12
+ };
@@ -35,7 +35,8 @@ export default defineConfig({
35
35
  define: {
36
36
  global: 'globalThis'
37
37
  }
38
- }
38
+ },
39
+ include: ['frontend-hamroun']
39
40
  },
40
41
  plugins: [
41
42
  nodePolyfills({
@@ -48,11 +49,11 @@ export default defineConfig({
48
49
  'bcrypt': 'frontend-hamroun',
49
50
  'jsonwebtoken': 'frontend-hamroun',
50
51
  'mongoose': 'frontend-hamroun',
51
- // Alias React imports to empty modules
52
- 'react': path.resolve(__dirname, 'src/shims.ts'),
52
+ // Map React imports to our compatibility layer
53
+ 'react': path.resolve(__dirname, 'src/react/index.ts'),
53
54
  'react-dom': 'frontend-hamroun',
54
- 'react/jsx-runtime': path.resolve(__dirname, 'src/shims.ts'),
55
- 'react/jsx-dev-runtime': path.resolve(__dirname, 'src/shims.ts')
55
+ 'react/jsx-runtime': path.resolve(__dirname, 'src/react/jsx-runtime.ts'),
56
+ 'react/jsx-dev-runtime': path.resolve(__dirname, 'src/react/jsx-dev-runtime.ts')
56
57
  }
57
58
  }
58
59
  });
@@ -1,13 +1,12 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Frontend Hamroun App</title>
7
- <link rel="stylesheet" href="/src/main.css">
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/main.ts"></script>
12
- </body>
13
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Frontend Hamroun App</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "node",
7
+ "allowSyntheticDefaultImports": true,
8
+ "resolveJsonModule": true,
9
+ "checkJs": false,
10
+ "strict": false
11
+ },
12
+ "include": ["src/**/*.js"],
13
+ "exclude": ["node_modules"]
14
+ }
@@ -1,33 +1,20 @@
1
- {
2
- "name": "frontend-hamroun-app",
3
- "private": true,
4
- "version": "0.1.0",
5
- "description": "{{description}}",
6
- "author": "{{author}}",
7
- "license": "MIT",
8
- "type": "module",
9
- "scripts": {
10
- "dev": "vite",
11
- "build": "tsc && vite build",
12
- "preview": "vite preview",
13
- "start": "node dist/server.js",
14
- "dev:server": "ts-node-esm --transpile-only src/server.ts",
15
- "dev:full": "concurrently \"npm run dev\" \"npm run dev:server\""
16
- },
17
- "dependencies": {
18
- "frontend-hamroun": "latest",
19
- "express": "^4.18.2",
20
- "compression": "^1.7.4",
21
- "helmet": "^7.0.0",
22
- "morgan": "^1.10.0"
23
- },
24
- "devDependencies": {
25
- "@types/express": "^4.17.21",
26
- "@types/node": "^20.10.0",
27
- "concurrently": "^8.2.2",
28
- "ts-node": "^10.9.1",
29
- "typescript": "^5.3.2",
30
- "vite": "^5.0.0",
31
- "vite-plugin-node-polyfills": "^0.21.0"
32
- }
33
- }
1
+ {
2
+ "name": "frontend-hamroun-app",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "frontend-hamroun": "latest"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^20.10.0",
16
+ "typescript": "^5.3.2",
17
+ "vite": "^5.0.0",
18
+ "vite-plugin-node-polyfills": "^0.21.0"
19
+ }
20
+ }
@@ -0,0 +1,105 @@
1
+ import { useState, useRef } from 'frontend-hamroun';
2
+
3
+ export function App() {
4
+ const [count, setCount] = useState(0);
5
+ const renderCount = useRef(0);
6
+
7
+ renderCount.current++;
8
+
9
+ // Return a plain JavaScript object representation of the UI
10
+ return {
11
+ type: 'div',
12
+ props: {
13
+ style: {
14
+ fontFamily: 'Arial, sans-serif',
15
+ maxWidth: '600px',
16
+ margin: '0 auto',
17
+ padding: '2rem'
18
+ },
19
+ children: [
20
+ {
21
+ type: 'h1',
22
+ props: {
23
+ style: { textAlign: 'center' },
24
+ children: 'Frontend Hamroun App'
25
+ }
26
+ },
27
+ {
28
+ type: 'p',
29
+ props: {
30
+ style: { textAlign: 'center' },
31
+ children: `Render count: ${renderCount.current}`
32
+ }
33
+ },
34
+ {
35
+ type: 'div',
36
+ props: {
37
+ style: {
38
+ display: 'flex',
39
+ flexDirection: 'column',
40
+ alignItems: 'center',
41
+ padding: '1rem',
42
+ border: '1px solid #ccc',
43
+ borderRadius: '8px'
44
+ },
45
+ children: [
46
+ {
47
+ type: 'h2',
48
+ props: {
49
+ children: 'Counter Example'
50
+ }
51
+ },
52
+ {
53
+ type: 'p',
54
+ props: {
55
+ children: `Count: ${count}`
56
+ }
57
+ },
58
+ {
59
+ type: 'div',
60
+ props: {
61
+ style: {
62
+ display: 'flex',
63
+ gap: '8px'
64
+ },
65
+ children: [
66
+ {
67
+ type: 'button',
68
+ props: {
69
+ onClick: () => setCount(count - 1),
70
+ style: {
71
+ padding: '8px 16px',
72
+ backgroundColor: '#ff4d4d',
73
+ color: 'white',
74
+ border: 'none',
75
+ borderRadius: '4px',
76
+ cursor: 'pointer'
77
+ },
78
+ children: 'Decrement'
79
+ }
80
+ },
81
+ {
82
+ type: 'button',
83
+ props: {
84
+ onClick: () => setCount(count + 1),
85
+ style: {
86
+ padding: '8px 16px',
87
+ backgroundColor: '#4d79ff',
88
+ color: 'white',
89
+ border: 'none',
90
+ borderRadius: '4px',
91
+ cursor: 'pointer'
92
+ },
93
+ children: 'Increment'
94
+ }
95
+ }
96
+ ]
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ };
105
+ }
@@ -0,0 +1,11 @@
1
+ import { render } from 'frontend-hamroun';
2
+ import { App } from './App.js';
3
+
4
+ document.addEventListener('DOMContentLoaded', () => {
5
+ const rootElement = document.getElementById('app');
6
+ if (rootElement) {
7
+ // Call App as a function to create the VDOM structure
8
+ render(App(), rootElement);
9
+ console.log('App rendered successfully');
10
+ }
11
+ });
@@ -1,34 +1,18 @@
1
- import { defineConfig } from 'vite';
2
- import path from 'path';
3
-
4
- export default defineConfig({
5
- root: 'src/client',
6
- publicDir: 'public',
7
- build: {
8
- outDir: '../../dist/client',
9
- emptyOutDir: true,
10
- rollupOptions: {
11
- // Mark testing dependencies as external so they won't be included in the bundle
12
- external: [
13
- 'mock-aws-s3',
14
- 'aws-sdk',
15
- 'nock',
16
- 'jest',
17
- 'jest-mock',
18
- '@testing-library/react',
19
- '@testing-library/jest-dom'
20
- ]
21
- }
22
- },
23
- server: {
24
- port: 3001,
25
- proxy: {
26
- '/api': 'http://localhost:3000'
27
- }
28
- },
29
- resolve: {
30
- alias: {
31
- '@': path.resolve(__dirname, 'src/client')
32
- }
33
- }
34
- });
1
+ import { defineConfig } from 'vite';
2
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
3
+
4
+ export default defineConfig({
5
+ build: {
6
+ outDir: 'dist',
7
+ emptyOutDir: true
8
+ },
9
+ server: {
10
+ port: 3000,
11
+ open: true
12
+ },
13
+ plugins: [
14
+ nodePolyfills({
15
+ protocolImports: true,
16
+ }),
17
+ ]
18
+ });