formcn 1.0.0 → 1.0.2

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.
@@ -0,0 +1,324 @@
1
+ # Contributing to formcn
2
+
3
+ Thank you for your interest in contributing to formcn! This document provides guidelines and instructions for contributing to the project.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Code of Conduct](#code-of-conduct)
8
+ - [Getting Started](#getting-started)
9
+ - [Development Setup](#development-setup)
10
+ - [Project Structure](#project-structure)
11
+ - [Development Workflow](#development-workflow)
12
+ - [Coding Standards](#coding-standards)
13
+ - [Testing](#testing)
14
+ - [Submitting Changes](#submitting-changes)
15
+ - [Commit Message Guidelines](#commit-message-guidelines)
16
+ - [Areas for Contribution](#areas-for-contribution)
17
+
18
+ ## Code of Conduct
19
+
20
+ By participating in this project, you agree to maintain a respectful and inclusive environment for all contributors.
21
+
22
+ ## Getting Started
23
+
24
+ 1. **Fork the repository** on GitHub
25
+ 2. **Clone your fork** locally:
26
+ ```bash
27
+ git clone https://github.com/YOUR_USERNAME/formcn.git
28
+ cd formcn
29
+ ```
30
+ 3. **Add the upstream repository**:
31
+ ```bash
32
+ git remote add upstream https://github.com/F-47/formcn.git
33
+ ```
34
+
35
+ ## Development Setup
36
+
37
+ ### Prerequisites
38
+
39
+ - Node.js 18 or higher
40
+ - npm or yarn package manager
41
+ - Git
42
+
43
+ ### Installation
44
+
45
+ 1. Install dependencies:
46
+
47
+ ```bash
48
+ npm install
49
+ ```
50
+
51
+ 2. Link the package locally for testing:
52
+
53
+ ```bash
54
+ npm link
55
+ ```
56
+
57
+ 3. Test the CLI locally:
58
+
59
+ ```bash
60
+ formcn
61
+ ```
62
+
63
+ Or run directly:
64
+
65
+ ```bash
66
+ node bin/index.js
67
+ ```
68
+
69
+ ### Project Structure
70
+
71
+ ```
72
+ formcn/
73
+ ├── bin/
74
+ │ └── index.js # CLI entry point
75
+ ├── generators/
76
+ │ ├── form-generator.js # Single-step form generation
77
+ │ ├── multi-form-generator.js # Multi-step form generation
78
+ │ ├── schema-generator.js # Zod schema generation
79
+ │ └── form-ui-templates.js # UI component templates
80
+ ├── utils/
81
+ │ ├── ensurePackages.js # Dependency checking
82
+ │ ├── lib.js # Utility functions
83
+ │ ├── prompts.js # CLI prompts
84
+ │ ├── tailwind-presets.js # Style presets
85
+ │ ├── templates.js # Form templates
86
+ │ └── test.js # Test utilities
87
+ ├── package.json
88
+ └── README.md
89
+ ```
90
+
91
+ ### Key Components
92
+
93
+ - **Generators**: Create form components, schemas, and related files
94
+ - **Utils**: Helper functions for prompts, package detection, and templates
95
+ - **CLI**: Interactive workflow using `@clack/prompts` and `inquirer`
96
+
97
+ ## Development Workflow
98
+
99
+ 1. **Create a feature branch**:
100
+
101
+ ```bash
102
+ git checkout -b feature/your-feature-name
103
+ ```
104
+
105
+ Or for bug fixes:
106
+
107
+ ```bash
108
+ git checkout -b fix/your-bug-description
109
+ ```
110
+
111
+ 2. **Make your changes**:
112
+
113
+ - Write clean, maintainable code
114
+ - Follow existing code style and patterns
115
+ - Add comments for complex logic
116
+ - Update documentation if needed
117
+
118
+ 3. **Test your changes**:
119
+
120
+ - Test the CLI with various inputs
121
+ - Verify generated forms work correctly
122
+ - Test edge cases and error handling
123
+
124
+ 4. **Keep your branch updated**:
125
+
126
+ ```bash
127
+ git fetch upstream
128
+ git rebase upstream/main
129
+ ```
130
+
131
+ 5. **Commit your changes** (see [Commit Message Guidelines](#commit-message-guidelines))
132
+
133
+ 6. **Push to your fork**:
134
+
135
+ ```bash
136
+ git push origin feature/your-feature-name
137
+ ```
138
+
139
+ 7. **Open a Pull Request** on GitHub
140
+
141
+ ## Coding Standards
142
+
143
+ ### Code Style
144
+
145
+ - Use **ES modules** (import/export syntax)
146
+ - Follow **consistent indentation** (2 spaces)
147
+ - Use **descriptive variable names**
148
+ - Keep functions **focused and single-purpose**
149
+ - Add **JSDoc comments** for public functions
150
+
151
+ ### JavaScript Conventions
152
+
153
+ - Prefer `const` over `let`, avoid `var`
154
+ - Use async/await for asynchronous operations
155
+ - Handle errors appropriately
156
+ - Use template literals for string interpolation
157
+ - Prefer arrow functions for callbacks
158
+
159
+ ### File Organization
160
+
161
+ - Keep related functionality together
162
+ - Separate concerns (generators, utilities, CLI logic)
163
+ - Use meaningful file and directory names
164
+ - Export functions explicitly
165
+
166
+ ### Example
167
+
168
+ ```javascript
169
+ /**
170
+ * Generates a form component with the given configuration
171
+ * @param {string} formName - The name of the form
172
+ * @param {Array<Object>} fields - Array of field definitions
173
+ * @param {string} presetKey - Style preset identifier
174
+ * @returns {Promise<void>}
175
+ */
176
+ export async function generateForm(formName, fields, presetKey) {
177
+ // Implementation
178
+ }
179
+ ```
180
+
181
+ ## Testing
182
+
183
+ Currently, the project doesn't have automated tests. When contributing:
184
+
185
+ 1. **Manually test your changes** in a real React project
186
+ 2. **Test various form configurations**:
187
+ - Single-step forms
188
+ - Multi-step forms
189
+ - Different field types
190
+ - Different templates and presets
191
+ 3. **Test edge cases**:
192
+ - Invalid inputs
193
+ - Missing dependencies
194
+ - Existing form directories
195
+ - Various project structures
196
+
197
+ ### Testing Checklist
198
+
199
+ - [ ] CLI runs without errors
200
+ - [ ] Generated forms compile in TypeScript
201
+ - [ ] Form validation works correctly
202
+ - [ ] All field types render properly
203
+ - [ ] Templates generate expected output
204
+ - [ ] Presets apply correctly
205
+ - [ ] Error messages are clear and helpful
206
+
207
+ **Note**: Adding automated tests would be a valuable contribution!
208
+
209
+ ## Submitting Changes
210
+
211
+ ### Pull Request Process
212
+
213
+ 1. **Update documentation** if you change functionality
214
+ 2. **Keep PRs focused** - one feature or fix per PR
215
+ 3. **Write a clear PR description**:
216
+
217
+ - What changes were made
218
+ - Why they were made
219
+ - How to test them
220
+ - Screenshots/examples if applicable
221
+
222
+ 4. **Reference issues** if your PR closes them:
223
+
224
+ ```
225
+ Closes #123
226
+ ```
227
+
228
+ 5. **Wait for review** - maintainers will review and may request changes
229
+
230
+ ### PR Checklist
231
+
232
+ - [ ] Code follows project style guidelines
233
+ - [ ] Changes are tested
234
+ - [ ] Documentation is updated (if needed)
235
+ - [ ] Commit messages follow guidelines
236
+ - [ ] No breaking changes (or clearly documented)
237
+
238
+ ## Commit Message Guidelines
239
+
240
+ Follow conventional commit format:
241
+
242
+ ```
243
+ <type>(<scope>): <subject>
244
+
245
+ <body>
246
+
247
+ <footer>
248
+ ```
249
+
250
+ ### Types
251
+
252
+ - `feat`: New feature
253
+ - `fix`: Bug fix
254
+ - `docs`: Documentation changes
255
+ - `style`: Code style changes (formatting, etc.)
256
+ - `refactor`: Code refactoring
257
+ - `test`: Adding or updating tests
258
+ - `chore`: Maintenance tasks
259
+
260
+ ### Examples
261
+
262
+ ```
263
+ feat(generators): add support for file upload fields
264
+
265
+ Adds file upload field type to the form generator with
266
+ proper Zod schema validation and shadcn/ui component integration.
267
+
268
+ Closes #45
269
+ ```
270
+
271
+ ```
272
+ fix(prompts): handle cancelled form name input gracefully
273
+
274
+ Prevents the CLI from crashing when users cancel the form
275
+ name prompt. Now exits cleanly with a cancellation message.
276
+ ```
277
+
278
+ ## Areas for Contribution
279
+
280
+ We welcome contributions in the following areas:
281
+
282
+ ### Features
283
+
284
+ - New field types (file upload, color picker, etc.)
285
+ - Additional form templates
286
+ - New style presets
287
+ - Custom validation rules
288
+ - Form builder improvements
289
+
290
+ ### Improvements
291
+
292
+ - Better error handling and messages
293
+ - Enhanced CLI prompts and UX
294
+ - Performance optimizations
295
+ - Code refactoring
296
+ - Documentation improvements
297
+
298
+ ### Testing
299
+
300
+ - Unit tests for generators
301
+ - Integration tests for CLI workflow
302
+ - Test utilities and helpers
303
+
304
+ ### Documentation
305
+
306
+ - Code comments and JSDoc
307
+ - README improvements
308
+ - Usage examples
309
+ - Tutorial guides
310
+
311
+ ### Bug Fixes
312
+
313
+ - Report bugs via GitHub Issues
314
+ - Include steps to reproduce
315
+ - Provide expected vs actual behavior
316
+ - Test environment details
317
+
318
+ ## Questions?
319
+
320
+ - Open an issue for bugs or feature requests
321
+ - Check existing issues before creating new ones
322
+ - Be patient and respectful in discussions
323
+
324
+ Thank you for contributing to formcn! 🎉
package/bin/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  import { intro, outro, select } from "@clack/prompts";
2
4
  import {
3
5
  askFormType,
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "formcn",
3
- "version": "1.0.0",
4
- "description": "Schema-driven React form generator using React Hook Form, Zod, and shadcn/ui",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "bin": {
11
- "formcn": "./bin/index.js"
12
- },
13
- "keywords": [
14
- "react",
15
- "forms",
16
- "typescript",
17
- "react-hook-form",
18
- "zod",
19
- "shadcn",
20
- "cli",
21
- "generator"
22
- ],
23
- "author": "Fares Galal",
24
- "license": "MIT",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/F-47/formcn.git"
28
- },
29
- "bugs": {
30
- "url": "https://github.com/F-47/formcn/issues"
31
- },
32
- "homepage": "https://github.com/F-47/formcn#readme",
33
- "dependencies": {
34
- "@clack/prompts": "^0.11.0",
35
- "@hookform/resolvers": "^5.2.2",
36
- "chalk": "^5.6.2",
37
- "chalk-animation": "^2.0.3",
38
- "commander": "^14.0.2",
39
- "figlet": "^1.9.4",
40
- "fs-extra": "^11.3.3",
41
- "inquirer": "^13.1.0",
42
- "nanospinner": "^1.2.2",
43
- "react-hook-form": "^7.69.0",
44
- "zod": "^4.2.1"
45
- }
46
- }
1
+ {
2
+ "name": "formcn",
3
+ "version": "1.0.2",
4
+ "description": "Schema-driven React form generator using React Hook Form, Zod, and shadcn/ui",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "bin": {
11
+ "formcn": "./bin/index.js"
12
+ },
13
+ "keywords": [
14
+ "react",
15
+ "forms",
16
+ "typescript",
17
+ "react-hook-form",
18
+ "zod",
19
+ "shadcn",
20
+ "cli",
21
+ "generator"
22
+ ],
23
+ "author": "Fares Galal",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/F-47/formcn.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/F-47/formcn/issues"
31
+ },
32
+ "homepage": "https://github.com/F-47/formcn#readme",
33
+ "dependencies": {
34
+ "@clack/prompts": "^0.11.0",
35
+ "@hookform/resolvers": "^5.2.2",
36
+ "chalk": "^5.6.2",
37
+ "chalk-animation": "^2.0.3",
38
+ "commander": "^14.0.2",
39
+ "figlet": "^1.9.4",
40
+ "fs-extra": "^11.3.3",
41
+ "inquirer": "^13.1.0",
42
+ "nanospinner": "^1.2.2",
43
+ "react-hook-form": "^7.69.0",
44
+ "zod": "^4.2.1"
45
+ }
46
+ }
@@ -49,7 +49,6 @@ export const MULTI_STEP_TEMPLATES = {
49
49
  options: [
50
50
  { label: "Male", value: "male" },
51
51
  { label: "Female", value: "female" },
52
- { label: "Other", value: "other" },
53
52
  ],
54
53
  },
55
54
  { name: "birthdate", type: "date", label: "Birthdate", required: true },
package/test/README.md DELETED
@@ -1,73 +0,0 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## React Compiler
11
-
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
-
14
- ## Expanding the ESLint configuration
15
-
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
-
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
25
-
26
- // Remove tseslint.configs.recommended and replace with this
27
- tseslint.configs.recommendedTypeChecked,
28
- // Alternatively, use this for stricter rules
29
- tseslint.configs.strictTypeChecked,
30
- // Optionally, add this for stylistic rules
31
- tseslint.configs.stylisticTypeChecked,
32
-
33
- // Other configs...
34
- ],
35
- languageOptions: {
36
- parserOptions: {
37
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
- tsconfigRootDir: import.meta.dirname,
39
- },
40
- // other options...
41
- },
42
- },
43
- ])
44
- ```
45
-
46
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
-
48
- ```js
49
- // eslint.config.js
50
- import reactX from 'eslint-plugin-react-x'
51
- import reactDom from 'eslint-plugin-react-dom'
52
-
53
- export default defineConfig([
54
- globalIgnores(['dist']),
55
- {
56
- files: ['**/*.{ts,tsx}'],
57
- extends: [
58
- // Other configs...
59
- // Enable lint rules for React
60
- reactX.configs['recommended-typescript'],
61
- // Enable lint rules for React DOM
62
- reactDom.configs.recommended,
63
- ],
64
- languageOptions: {
65
- parserOptions: {
66
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
- tsconfigRootDir: import.meta.dirname,
68
- },
69
- // other options...
70
- },
71
- },
72
- ])
73
- ```
@@ -1,22 +0,0 @@
1
- {
2
- "$schema": "https://ui.shadcn.com/schema.json",
3
- "style": "new-york",
4
- "rsc": false,
5
- "tsx": true,
6
- "tailwind": {
7
- "config": "",
8
- "css": "src/index.css",
9
- "baseColor": "neutral",
10
- "cssVariables": true,
11
- "prefix": ""
12
- },
13
- "iconLibrary": "lucide",
14
- "aliases": {
15
- "components": "@/components",
16
- "utils": "@/lib/utils",
17
- "ui": "@/components/ui",
18
- "lib": "@/lib",
19
- "hooks": "@/hooks"
20
- },
21
- "registries": {}
22
- }
@@ -1,23 +0,0 @@
1
- import js from '@eslint/js'
2
- import globals from 'globals'
3
- import reactHooks from 'eslint-plugin-react-hooks'
4
- import reactRefresh from 'eslint-plugin-react-refresh'
5
- import tseslint from 'typescript-eslint'
6
- import { defineConfig, globalIgnores } from 'eslint/config'
7
-
8
- export default defineConfig([
9
- globalIgnores(['dist']),
10
- {
11
- files: ['**/*.{ts,tsx}'],
12
- extends: [
13
- js.configs.recommended,
14
- tseslint.configs.recommended,
15
- reactHooks.configs.flat.recommended,
16
- reactRefresh.configs.vite,
17
- ],
18
- languageOptions: {
19
- ecmaVersion: 2020,
20
- globals: globals.browser,
21
- },
22
- },
23
- ])
package/test/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>test</title>
8
- </head>
9
- <body>
10
- <div id="root"></div>
11
- <script type="module" src="/src/main.tsx"></script>
12
- </body>
13
- </html>