frontend-hamroun 1.2.16 → 1.2.17

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.
Files changed (158) hide show
  1. package/README.md +4 -0
  2. package/bin/cli.js +673 -0
  3. package/dist/component.d.ts +1 -1
  4. package/dist/context.d.ts +4 -3
  5. package/dist/index.client.d.ts +11 -0
  6. package/dist/index.d.ts +9 -89
  7. package/dist/index.js +396 -67
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +392 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/jsx-runtime/jsx-runtime.d.ts +0 -1
  12. package/dist/jsx-runtime.d.ts +1 -1
  13. package/dist/renderer.d.ts +0 -10
  14. package/dist/server-renderer.d.ts +0 -3
  15. package/dist/server-types.d.ts +42 -0
  16. package/package.json +69 -41
  17. package/templates/basic-app/index.html +6 -6
  18. package/templates/basic-app/package.json +18 -7
  19. package/templates/basic-app/postcss.config.js +0 -1
  20. package/templates/basic-app/src/main.tsx +1 -10
  21. package/templates/basic-app/tailwind.config.js +2 -23
  22. package/templates/basic-app/tsconfig.json +4 -17
  23. package/templates/basic-app/vite.config.ts +3 -54
  24. package/templates/fullstack-app/api/hello.ts +18 -0
  25. package/templates/fullstack-app/api/users/[id].ts +73 -0
  26. package/templates/fullstack-app/api/users/index.ts +32 -0
  27. package/templates/fullstack-app/package.json +31 -0
  28. package/templates/fullstack-app/server.ts +46 -0
  29. package/templates/fullstack-app/src/pages/index.tsx +59 -0
  30. package/templates/ssr-template/vite.config.ts +1 -11
  31. package/bin/cli.cjs +0 -16
  32. package/bin/cli.mjs +0 -237
  33. package/dist/backend/api-utils.d.ts +0 -38
  34. package/dist/backend/api-utils.js +0 -135
  35. package/dist/backend/auth.d.ts +0 -134
  36. package/dist/backend/auth.js +0 -387
  37. package/dist/backend/database.d.ts +0 -27
  38. package/dist/backend/database.js +0 -91
  39. package/dist/backend/model.d.ts +0 -43
  40. package/dist/backend/model.js +0 -178
  41. package/dist/backend/router.d.ts +0 -27
  42. package/dist/backend/router.js +0 -137
  43. package/dist/backend/server.d.ts +0 -19
  44. package/dist/backend/server.js +0 -268
  45. package/dist/backend/types.d.ts +0 -217
  46. package/dist/backend/types.js +0 -1
  47. package/dist/batch.js +0 -22
  48. package/dist/cli/index.d.ts +0 -2
  49. package/dist/cli/index.js +0 -215
  50. package/dist/component.js +0 -84
  51. package/dist/components/Counter.js +0 -2
  52. package/dist/context.js +0 -18
  53. package/dist/frontend-hamroun.es.js +0 -1378
  54. package/dist/frontend-hamroun.umd.js +0 -66
  55. package/dist/hooks.js +0 -164
  56. package/dist/jsx-runtime/index.d.ts +0 -11
  57. package/dist/jsx-runtime/index.js +0 -19
  58. package/dist/jsx-runtime/jsx-dev-runtime.js +0 -1
  59. package/dist/jsx-runtime/jsx-runtime.js +0 -95
  60. package/dist/jsx-runtime.js +0 -192
  61. package/dist/renderer.js +0 -51
  62. package/dist/server-renderer.js +0 -102
  63. package/dist/types.js +0 -1
  64. package/dist/vdom.js +0 -27
  65. package/scripts/build-cli.js +0 -1199
  66. package/scripts/generate.js +0 -134
  67. package/src/backend/api-utils.ts +0 -178
  68. package/src/backend/auth.ts +0 -544
  69. package/src/backend/database.ts +0 -104
  70. package/src/backend/model.ts +0 -198
  71. package/src/backend/router.ts +0 -176
  72. package/src/backend/server.ts +0 -330
  73. package/src/backend/types.ts +0 -257
  74. package/src/batch.ts +0 -24
  75. package/src/cli/index.js +0 -554
  76. package/src/cli/index.ts +0 -257
  77. package/src/component.ts +0 -98
  78. package/src/components/Counter.tsx +0 -4
  79. package/src/context.ts +0 -29
  80. package/src/hooks.ts +0 -211
  81. package/src/index.ts +0 -144
  82. package/src/jsx-runtime/index.ts +0 -27
  83. package/src/jsx-runtime/jsx-dev-runtime.ts +0 -0
  84. package/src/jsx-runtime/jsx-runtime.ts +0 -104
  85. package/src/jsx-runtime.ts +0 -226
  86. package/src/renderer.ts +0 -55
  87. package/src/server-renderer.ts +0 -114
  88. package/src/shims.d.ts +0 -20
  89. package/src/types/bcrypt.d.ts +0 -30
  90. package/src/types/jsonwebtoken.d.ts +0 -55
  91. package/src/types.d.ts +0 -26
  92. package/src/types.ts +0 -21
  93. package/src/vdom.ts +0 -34
  94. package/templates/basic/.eslintignore +0 -5
  95. package/templates/basic/.eslintrc.json +0 -25
  96. package/templates/basic/docs/rapport_pfe.aux +0 -27
  97. package/templates/basic/docs/rapport_pfe.log +0 -399
  98. package/templates/basic/docs/rapport_pfe.out +0 -10
  99. package/templates/basic/docs/rapport_pfe.pdf +0 -0
  100. package/templates/basic/docs/rapport_pfe.tex +0 -68
  101. package/templates/basic/docs/rapport_pfe.toc +0 -14
  102. package/templates/basic/index.html +0 -12
  103. package/templates/basic/jsconfig.json +0 -14
  104. package/templates/basic/package.json +0 -18
  105. package/templates/basic/postcss.config.js +0 -7
  106. package/templates/basic/src/App.js +0 -105
  107. package/templates/basic/src/App.tsx +0 -65
  108. package/templates/basic/src/api.ts +0 -58
  109. package/templates/basic/src/components/Counter.tsx +0 -26
  110. package/templates/basic/src/components/Header.tsx +0 -9
  111. package/templates/basic/src/components/TodoList.tsx +0 -90
  112. package/templates/basic/src/main.css +0 -3
  113. package/templates/basic/src/main.js +0 -11
  114. package/templates/basic/src/main.ts +0 -20
  115. package/templates/basic/src/main.tsx +0 -144
  116. package/templates/basic/src/server.ts +0 -99
  117. package/templates/basic/tailwind.config.js +0 -32
  118. package/templates/basic/tsconfig.json +0 -20
  119. package/templates/basic/tsconfig.node.json +0 -10
  120. package/templates/basic/vite.config.js +0 -18
  121. package/templates/basic/vite.config.ts +0 -86
  122. package/templates/basic-app/src/App.js +0 -105
  123. package/templates/basic-app/src/App.tsx +0 -143
  124. package/templates/basic-app/src/api.ts +0 -58
  125. package/templates/basic-app/src/components/Counter.tsx +0 -26
  126. package/templates/basic-app/src/components/Header.tsx +0 -9
  127. package/templates/basic-app/src/components/TodoList.tsx +0 -90
  128. package/templates/basic-app/src/main.js +0 -10
  129. package/templates/basic-app/src/main.ts +0 -21
  130. package/templates/basic-app/src/react/index.ts +0 -35
  131. package/templates/basic-app/src/react/jsx-dev-runtime.ts +0 -13
  132. package/templates/basic-app/src/react/jsx-runtime.ts +0 -12
  133. package/templates/basic-app/src/server.ts +0 -99
  134. package/templates/basic-app/src/shims.ts +0 -9
  135. package/templates/basic-app/tsconfig.node.json +0 -10
  136. package/templates/basic-app/vite.config.js +0 -22
  137. package/templates/full-stack/.env.example +0 -11
  138. package/templates/full-stack/README.md +0 -51
  139. package/templates/full-stack/index.html +0 -12
  140. package/templates/full-stack/jsconfig.json +0 -14
  141. package/templates/full-stack/package.json +0 -21
  142. package/templates/full-stack/src/App.js +0 -105
  143. package/templates/full-stack/src/client/App.tsx +0 -50
  144. package/templates/full-stack/src/client/components/Header.tsx +0 -42
  145. package/templates/full-stack/src/client/components/UserList.tsx +0 -29
  146. package/templates/full-stack/src/client/main.tsx +0 -5
  147. package/templates/full-stack/src/main.css +0 -3
  148. package/templates/full-stack/src/main.js +0 -11
  149. package/templates/full-stack/src/main.ts +0 -20
  150. package/templates/full-stack/src/server/index.ts +0 -99
  151. package/templates/full-stack/src/server/routes/auth.ts +0 -39
  152. package/templates/full-stack/src/server/routes/users.ts +0 -48
  153. package/templates/full-stack/src/shims.ts +0 -9
  154. package/templates/full-stack/tsconfig.json +0 -20
  155. package/templates/full-stack/tsconfig.node.json +0 -10
  156. package/templates/full-stack/tsconfig.server.json +0 -15
  157. package/templates/full-stack/vite.config.js +0 -18
  158. package/templates/full-stack/vite.config.ts +0 -85
@@ -1,134 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const readline = require('readline');
6
-
7
- const rl = readline.createInterface({
8
- input: process.stdin,
9
- output: process.stdout
10
- });
11
-
12
- // Component templates
13
- const FUNCTION_COMPONENT_TEMPLATE = (name) => `import { useState, useEffect } from 'frontend-hamroun';
14
-
15
- export function ${name}(props) {
16
- // State hooks
17
- const [state, setState] = useState(null);
18
-
19
- // Effect hooks
20
- useEffect(() => {
21
- // Component mounted
22
- return () => {
23
- // Component will unmount
24
- };
25
- }, []);
26
-
27
- return (
28
- <div className="${name.toLowerCase()}">
29
- <h2>${name} Component</h2>
30
- {/* Your JSX here */}
31
- </div>
32
- );
33
- }
34
- `;
35
-
36
- const CSS_TEMPLATE = (name) => `.${name.toLowerCase()} {
37
- display: flex;
38
- flex-direction: column;
39
- padding: 1rem;
40
- margin: 0.5rem;
41
- border-radius: 4px;
42
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
43
- }
44
- `;
45
-
46
- const TEST_TEMPLATE = (name) => `import { render, screen } from '@testing-library/frontend-hamroun';
47
- import { ${name} } from './${name}';
48
-
49
- describe('${name} Component', () => {
50
- test('renders correctly', () => {
51
- render(<${name} />);
52
- const element = screen.getByText('${name} Component');
53
- expect(element).toBeInTheDocument();
54
- });
55
- });
56
- `;
57
-
58
- function createComponent(name, directory) {
59
- if (!name) {
60
- console.error('Component name is required');
61
- process.exit(1);
62
- }
63
-
64
- const targetDir = directory || process.cwd();
65
- const componentDir = path.join(targetDir, name);
66
-
67
- // Create component directory
68
- if (!fs.existsSync(componentDir)) {
69
- fs.mkdirSync(componentDir, { recursive: true });
70
- console.log(`Created directory: ${componentDir}`);
71
- }
72
-
73
- // Create component files
74
- fs.writeFileSync(
75
- path.join(componentDir, `${name}.jsx`),
76
- FUNCTION_COMPONENT_TEMPLATE(name)
77
- );
78
- console.log(`Created component: ${name}.jsx`);
79
-
80
- fs.writeFileSync(
81
- path.join(componentDir, `${name}.css`),
82
- CSS_TEMPLATE(name)
83
- );
84
- console.log(`Created styles: ${name}.css`);
85
-
86
- fs.writeFileSync(
87
- path.join(componentDir, `${name}.test.jsx`),
88
- TEST_TEMPLATE(name)
89
- );
90
- console.log(`Created test: ${name}.test.jsx`);
91
-
92
- fs.writeFileSync(
93
- path.join(componentDir, 'index.js'),
94
- `export { ${name} } from './${name}';\n`
95
- );
96
- console.log(`Created index file`);
97
-
98
- console.log(`\nComponent ${name} created successfully!`);
99
- }
100
-
101
- // CLI command handling
102
- if (process.argv.length >= 3) {
103
- const command = process.argv[2];
104
-
105
- if (command === 'component') {
106
- const name = process.argv[3];
107
- const directory = process.argv[4];
108
- createComponent(name, directory);
109
- rl.close();
110
- } else {
111
- console.log(`Unknown command: ${command}`);
112
- console.log('Available commands: component');
113
- rl.close();
114
- }
115
- } else {
116
- // Interactive mode
117
- console.log('Frontend Hamroun Generator');
118
- console.log('-------------------------');
119
-
120
- rl.question('What would you like to generate? (component): ', (type) => {
121
- if (type.toLowerCase() === 'component') {
122
- rl.question('Component name: ', (name) => {
123
- rl.question('Target directory (optional, press Enter for current directory): ', (directory) => {
124
- createComponent(name, directory || null);
125
- rl.close();
126
- });
127
- });
128
- } else {
129
- console.log(`Invalid type: ${type}`);
130
- console.log('Available types: component');
131
- rl.close();
132
- }
133
- });
134
- }
@@ -1,178 +0,0 @@
1
- import { Request, Response, NextFunction, Router } from 'express';
2
- import { ApiResponse, PaginationOptions, RouterOptions } from './types';
3
-
4
- /**
5
- * Creates a consistent API response structure
6
- */
7
- export function apiResponse<T>(
8
- success: boolean,
9
- data?: T,
10
- message?: string,
11
- error?: string,
12
- meta?: Record<string, any>
13
- ): ApiResponse<T> {
14
- const response: ApiResponse<T> = { success };
15
-
16
- if (data !== undefined) response.data = data;
17
- if (message) response.message = message;
18
- if (error) response.error = error;
19
- if (meta) response.meta = meta;
20
-
21
- return response;
22
- }
23
-
24
- /**
25
- * Helper to send successful responses
26
- */
27
- export function sendSuccess<T>(
28
- res: Response,
29
- data?: T,
30
- message?: string,
31
- statusCode = 200,
32
- meta?: Record<string, any>
33
- ): void {
34
- res.status(statusCode).json(apiResponse(true, data, message, undefined, meta));
35
- }
36
-
37
- /**
38
- * Helper to send error responses
39
- */
40
- export function sendError(
41
- res: Response,
42
- error: string | Error,
43
- statusCode = 400,
44
- meta?: Record<string, any>
45
- ): void {
46
- const errorMessage = error instanceof Error ? error.message : error;
47
- res.status(statusCode).json(apiResponse(false, undefined, undefined, errorMessage, meta));
48
- }
49
-
50
- /**
51
- * Helper to extract pagination parameters from request
52
- */
53
- export function getPaginationParams(req: Request): PaginationOptions {
54
- const page = parseInt(req.query.page as string) || 1;
55
- const limit = parseInt(req.query.limit as string) || 10;
56
- const sort = (req.query.sort as string) || 'createdAt';
57
- const order = (req.query.order as string) === 'asc' ? 'asc' : 'desc';
58
-
59
- return { page, limit, sort, order };
60
- }
61
-
62
- /**
63
- * Middleware to extract and validate pagination parameters
64
- */
65
- export function paginationMiddleware(
66
- req: Request,
67
- res: Response,
68
- next: NextFunction
69
- ): void {
70
- req.pagination = getPaginationParams(req);
71
- next();
72
- }
73
-
74
- /**
75
- * Middleware for basic request validation
76
- */
77
- export function validateRequest(schema: any) {
78
- return (req: Request, res: Response, next: NextFunction): void => {
79
- try {
80
- const { error, value } = schema.validate(req.body);
81
-
82
- if (error) {
83
- sendError(res, `Validation error: ${error.message}`, 400);
84
- return;
85
- }
86
-
87
- // Replace request body with validated value
88
- req.body = value;
89
- next();
90
- } catch (err) {
91
- sendError(res, 'Validation error', 400);
92
- }
93
- };
94
- }
95
-
96
- /**
97
- * Create a new router with common middleware and options
98
- */
99
- export function createApiRouter(options: RouterOptions = {}, auth?: any): Router {
100
- const router = Router();
101
-
102
- // Add authentication middleware if required
103
- if (options.requireAuth && auth) {
104
- router.use(auth.authenticate);
105
-
106
- // Add role check if specified
107
- if (options.requiredRole) {
108
- router.use(auth.hasRole(options.requiredRole));
109
- }
110
- }
111
-
112
- // Add rate limiting if specified
113
- if (options.rateLimit) {
114
- console.warn('Rate limiting is disabled: express-rate-limit dependency is not installed');
115
- // Note: To use rate limiting, install express-rate-limit: npm install express-rate-limit
116
- }
117
-
118
- return router;
119
- }
120
-
121
- /**
122
- * Wrap an async route handler to catch errors
123
- */
124
- export function asyncHandler(
125
- fn: (req: Request, res: Response, next: NextFunction) => Promise<any>
126
- ) {
127
- return (req: Request, res: Response, next: NextFunction): void => {
128
- fn(req, res, next).catch(next);
129
- };
130
- }
131
-
132
- /**
133
- * Create standard REST endpoints for a model
134
- */
135
- export function createRestEndpoints<T>(model: any) {
136
- const router = Router();
137
-
138
- // GET all with pagination
139
- router.get('/', paginationMiddleware, asyncHandler(async (req, res) => {
140
- const result = await model.getAll(req.pagination);
141
- sendSuccess(res, result);
142
- }));
143
-
144
- // GET by ID
145
- router.get('/:id', asyncHandler(async (req, res) => {
146
- const item = await model.getById(req.params.id);
147
- if (!item) {
148
- return sendError(res, 'Item not found', 404);
149
- }
150
- sendSuccess(res, item);
151
- }));
152
-
153
- // POST new item
154
- router.post('/', asyncHandler(async (req, res) => {
155
- const newItem = await model.create(req.body);
156
- sendSuccess(res, newItem, 'Item created successfully', 201);
157
- }));
158
-
159
- // PUT update item
160
- router.put('/:id', asyncHandler(async (req, res) => {
161
- const updatedItem = await model.update(req.params.id, req.body);
162
- if (!updatedItem) {
163
- return sendError(res, 'Item not found', 404);
164
- }
165
- sendSuccess(res, updatedItem, 'Item updated successfully');
166
- }));
167
-
168
- // DELETE item
169
- router.delete('/:id', asyncHandler(async (req, res) => {
170
- const result = await model.delete(req.params.id);
171
- if (!result) {
172
- return sendError(res, 'Item not found', 404);
173
- }
174
- sendSuccess(res, null, 'Item deleted successfully');
175
- }));
176
-
177
- return router;
178
- }