@coherent.js/cli 1.0.0-beta.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Thomas Drouvin
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 ADDED
@@ -0,0 +1,509 @@
1
+ # @coherent.js/cli
2
+
3
+ Command-line interface for Coherent.js projects. Scaffold new applications, generate components, and streamline your development workflow.
4
+
5
+ ## šŸš€ Quick Start
6
+
7
+ ```bash
8
+ # Install globally
9
+ npm install -g @coherent.js/cli
10
+
11
+ # Create a new project
12
+ coherent create my-app
13
+
14
+ # Generate components
15
+ coherent generate component Button
16
+
17
+ # Start development server
18
+ coherent dev
19
+ ```
20
+
21
+ ## šŸ“¦ Installation
22
+
23
+ ### Global Installation (Recommended)
24
+
25
+ ```bash
26
+ npm install -g @coherent.js/cli
27
+ # or
28
+ yarn global add @coherent.js/cli
29
+ # or
30
+ pnpm add -g @coherent.js/cli
31
+ ```
32
+
33
+ ### Local Installation
34
+
35
+ ```bash
36
+ npm install --save-dev @coherent.js/cli
37
+ # or
38
+ yarn add --dev @coherent.js/cli
39
+ # or
40
+ pnpm add -D @coherent.js/cli
41
+
42
+ # Use with npx
43
+ npx coherent create my-app
44
+ ```
45
+
46
+ ## šŸ› ļø Commands
47
+
48
+ ### `coherent create <name>`
49
+
50
+ Create a new Coherent.js project with scaffolding. The CLI provides an interactive setup with runtime selection, database configuration, and optional package selection.
51
+
52
+ ```bash
53
+ coherent create my-app
54
+ coherent create my-app --template express
55
+ coherent create my-app --skip-install --skip-git
56
+ ```
57
+
58
+ **Options:**
59
+ - `-t, --template <template>` - Project template
60
+ - `--skip-install` - Skip npm install
61
+ - `--skip-git` - Skip git initialization
62
+
63
+ **Available Templates:**
64
+ - `basic` - Simple Coherent.js app with routing
65
+ - `fullstack` - API + SSR with database integration (includes runtime, database, and package selection)
66
+ - `express` - Coherent.js with Express.js (deprecated - use basic with Express runtime)
67
+ - `fastify` - Coherent.js with Fastify (deprecated - use basic with Fastify runtime)
68
+ - `components` - Reusable component library
69
+ - `custom` - **New!** Choose your own runtime, database, and packages
70
+
71
+ **Interactive Setup:**
72
+
73
+ When you create a project, the CLI will guide you through:
74
+
75
+ 1. **Runtime Selection** (all templates):
76
+ - Built-in HTTP Server (Node.js http module)
77
+ - Express (popular web framework)
78
+ - Fastify (fast and low overhead)
79
+ - Koa (next generation framework)
80
+
81
+ 2. **Database Selection** (fullstack & custom):
82
+ - PostgreSQL
83
+ - MySQL
84
+ - SQLite
85
+ - MongoDB
86
+ - None
87
+
88
+ 3. **Optional Packages** (all templates):
89
+ - `@coherent.js/api` - API framework with validation & OpenAPI
90
+ - `@coherent.js/database` - Database adapters and query builder
91
+ - `@coherent.js/client` - Client-side hydration
92
+ - `@coherent.js/i18n` - Internationalization
93
+ - `@coherent.js/forms` - Form handling
94
+ - `@coherent.js/devtools` - Development tools
95
+ - `@coherent.js/seo` - SEO utilities
96
+ - `@coherent.js/testing` - Testing helpers
97
+
98
+ 4. **Authentication Scaffolding** (when database or API selected):
99
+ - JWT Authentication (token-based)
100
+ - Session Authentication (cookie-based)
101
+ - None
102
+
103
+ **Example: Custom Fullstack App**
104
+
105
+ ```bash
106
+ coherent create my-app
107
+ # Select: Custom Setup
108
+ # Runtime: Express
109
+ # Database: PostgreSQL
110
+ # Packages: api, client, i18n
111
+ # Auth: JWT
112
+
113
+ # Generated structure includes:
114
+ # - Express server setup
115
+ # - PostgreSQL configuration & models
116
+ # - API routes with validation
117
+ # - Client-side hydration setup
118
+ # - i18n configuration with example locales
119
+ # - JWT authentication middleware & routes
120
+ ```
121
+
122
+ ### `coherent generate <type> <name>`
123
+
124
+ Generate components, pages, and API routes.
125
+
126
+ ```bash
127
+ coherent generate component Button
128
+ coherent generate page Home
129
+ coherent generate api users
130
+ coherent g component UserProfile --template interactive
131
+ ```
132
+
133
+ **Aliases:** `g`, `gen`
134
+
135
+ **Types:**
136
+ - `component` (aliases: `comp`, `c`) - UI component
137
+ - `page` (alias: `p`) - Full page with routing
138
+ - `api` (aliases: `route`, `r`) - API endpoint
139
+ - `model` (alias: `m`) - Database model
140
+ - `middleware` (alias: `mw`) - Express/Fastify middleware
141
+
142
+ **Options:**
143
+ - `-p, --path <path>` - Custom output path
144
+ - `-t, --template <template>` - Template to use
145
+ - `--skip-test` - Skip generating test file
146
+ - `--skip-story` - Skip generating story file
147
+
148
+ **Component Templates:**
149
+ - `basic` - Simple component with props
150
+ - `functional` - Component with business logic
151
+ - `interactive` - Component with state management
152
+ - `layout` - Page layout component
153
+
154
+ **Page Templates:**
155
+ - `basic` - Standard page with header/footer
156
+ - `dashboard` - Dashboard with stats grid
157
+ - `form` - Form page with validation
158
+ - `list` - List page with pagination
159
+ - `detail` - Detail page for single items
160
+
161
+ **API Templates:**
162
+ - `rest` - RESTful API with CRUD operations
163
+ - `rpc` - JSON-RPC API
164
+ - `graphql` - GraphQL resolver (coming soon)
165
+ - `crud` - Full CRUD API with validation
166
+
167
+ ### `coherent build`
168
+
169
+ Build the project for production.
170
+
171
+ ```bash
172
+ coherent build
173
+ coherent build --analyze
174
+ coherent build --no-minify
175
+ ```
176
+
177
+ **Options:**
178
+ - `-w, --watch` - Watch for changes
179
+ - `--analyze` - Analyze bundle size
180
+ - `--no-minify` - Disable minification
181
+ - `--no-optimize` - Disable optimizations
182
+
183
+ ### `coherent dev`
184
+
185
+ Start development server with hot reload.
186
+
187
+ ```bash
188
+ coherent dev
189
+ coherent dev --port 8080
190
+ coherent dev --host 0.0.0.0 --open
191
+ ```
192
+
193
+ **Options:**
194
+ - `-p, --port <port>` - Port number (default: 3000)
195
+ - `-h, --host <host>` - Host address (default: localhost)
196
+ - `--open` - Open browser automatically
197
+ - `--no-hmr` - Disable hot module replacement
198
+
199
+ ## šŸ“ Generated Project Structure
200
+
201
+ The structure varies based on your selections:
202
+
203
+ ```
204
+ my-app/
205
+ ā”œā”€ā”€ src/
206
+ │ ā”œā”€ā”€ components/ # Reusable components
207
+ │ │ ā”œā”€ā”€ Button.js
208
+ │ │ ā”œā”€ā”€ HomePage.js
209
+ │ │ └── InteractiveCounter.js (if client selected)
210
+ │ ā”œā”€ā”€ pages/ # Page components
211
+ │ │ ā”œā”€ā”€ Home.js
212
+ │ │ └── Home.test.js
213
+ │ ā”œā”€ā”€ api/ # API routes (if API or auth selected)
214
+ │ │ ā”œā”€ā”€ routes.js
215
+ │ │ └── auth.js (if auth selected)
216
+ │ ā”œā”€ā”€ db/ # Database (if database selected)
217
+ │ │ ā”œā”€ā”€ config.js
218
+ │ │ ā”œā”€ā”€ index.js
219
+ │ │ └── models/
220
+ │ │ └── User.js
221
+ │ ā”œā”€ā”€ middleware/ # Middleware (Express/Koa with auth)
222
+ │ │ └── auth.js
223
+ │ ā”œā”€ā”€ plugins/ # Plugins (Fastify with auth)
224
+ │ │ └── auth.js
225
+ │ ā”œā”€ā”€ i18n/ # i18n (if i18n selected)
226
+ │ │ ā”œā”€ā”€ config.js
227
+ │ │ └── locales/
228
+ │ │ ā”œā”€ā”€ en.json
229
+ │ │ ā”œā”€ā”€ fr.json
230
+ │ │ └── es.json
231
+ │ ā”œā”€ā”€ utils/ # Utility functions
232
+ │ │ ā”œā”€ā”€ devtools.js (if devtools selected)
233
+ │ │ └── seo.js (if seo selected)
234
+ │ └── index.js # Main entry point (runtime-specific)
235
+ ā”œā”€ā”€ public/ # Static assets
236
+ │ └── js/
237
+ │ └── hydration.js (if client selected)
238
+ ā”œā”€ā”€ data/ # Data directory (if SQLite selected)
239
+ ā”œā”€ā”€ tests/ # Test files
240
+ │ ā”œā”€ā”€ basic.test.js
241
+ │ ā”œā”€ā”€ helpers/ (if testing selected)
242
+ │ │ └── testing.js
243
+ │ └── components/ (if testing selected)
244
+ │ └── HomePage.test.js
245
+ ā”œā”€ā”€ package.json
246
+ ā”œā”€ā”€ README.md
247
+ ā”œā”€ā”€ .env.example (if database or auth selected)
248
+ └── .gitignore
249
+ ```
250
+
251
+ **Note:** Only selected features generate their corresponding files and directories.
252
+
253
+ ## šŸŽØ Generated Component Example
254
+
255
+ ```javascript
256
+ // src/components/Button.js
257
+ /**
258
+ * Button Component
259
+ */
260
+ export function Button(props = {}) {
261
+ const { text = 'Click me', onClick, className = '' } = props;
262
+
263
+ return {
264
+ button: {
265
+ className: `btn ${className}`,
266
+ onclick: onClick,
267
+ text
268
+ }
269
+ };
270
+ }
271
+
272
+ // Usage
273
+ import { Button } from './components/Button.js';
274
+
275
+ Button({
276
+ text: 'Get Started',
277
+ onClick: () => console.log('Clicked!'),
278
+ className: 'btn-primary'
279
+ })
280
+ ```
281
+
282
+ ## šŸ“„ Generated Page Example
283
+
284
+ ```javascript
285
+ // src/pages/Home.js
286
+ import { createComponent } from '@coherent.js/core';
287
+
288
+ export const Home = createComponent(({ title = 'Home' }) => ({
289
+ html: {
290
+ children: [
291
+ {
292
+ head: {
293
+ children: [
294
+ { title: { text: title } },
295
+ { meta: { name: 'viewport', content: 'width=device-width, initial-scale=1.0' } }
296
+ ]
297
+ }
298
+ },
299
+ {
300
+ body: {
301
+ children: [
302
+ {
303
+ main: {
304
+ className: 'home-page',
305
+ children: [
306
+ { h1: { text: 'Welcome Home!' } },
307
+ { p: { text: 'This is your generated home page.' } }
308
+ ]
309
+ }
310
+ }
311
+ ]
312
+ }
313
+ }
314
+ ]
315
+ }
316
+ }));
317
+ ```
318
+
319
+ ## šŸ”Œ Generated API Example
320
+
321
+ ```javascript
322
+ // src/api/users.js
323
+ import { createApiRouter, withValidation } from '@coherent.js/api';
324
+
325
+ const usersAPI = createApiRouter();
326
+
327
+ const userSchema = {
328
+ type: 'object',
329
+ properties: {
330
+ name: { type: 'string', minLength: 1 },
331
+ email: { type: 'string', format: 'email' }
332
+ },
333
+ required: ['name', 'email']
334
+ };
335
+
336
+ // GET /api/users
337
+ usersAPI.get('/', (req, res) => {
338
+ return { users: [] };
339
+ });
340
+
341
+ // POST /api/users
342
+ usersAPI.post('/',
343
+ withValidation(userSchema),
344
+ (req, res) => {
345
+ const { name, email } = req.body;
346
+ return { user: { id: 1, name, email } };
347
+ }
348
+ );
349
+
350
+ export default usersAPI;
351
+ ```
352
+
353
+ ## āš™ļø Configuration
354
+
355
+ The CLI automatically detects your project setup and adapts accordingly:
356
+
357
+ - **Package.json scripts** - Uses existing `dev`, `build`, `test` scripts
358
+ - **Build tools** - Supports Vite, Webpack, Rollup, esbuild
359
+ - **Frameworks** - Works with Express, Fastify, Next.js, Koa
360
+ - **Databases** - Generates appropriate models for your database
361
+
362
+ ## 🧪 Testing
363
+
364
+ Generated components and pages include test files:
365
+
366
+ ```javascript
367
+ // Button.test.js
368
+ import { test } from 'node:test';
369
+ import assert from 'node:assert';
370
+ import { render } from '@coherent.js/core';
371
+ import { Button } from './Button.js';
372
+
373
+ test('Button renders correctly', () => {
374
+ const component = Button({ text: 'Test' });
375
+ const html = render(component);
376
+
377
+ assert(html.includes('Test'));
378
+ assert(html.includes('<button'));
379
+ });
380
+ ```
381
+
382
+ Run tests with:
383
+ ```bash
384
+ npm test
385
+ # or if using the CLI
386
+ coherent test
387
+ ```
388
+
389
+ ## šŸ“š Examples
390
+
391
+ ### Create a fullstack blog application with PostgreSQL
392
+
393
+ ```bash
394
+ # Create project with interactive setup
395
+ coherent create my-blog
396
+
397
+ # In the CLI prompts:
398
+ # - Template: Fullstack
399
+ # - Runtime: Express
400
+ # - Database: PostgreSQL
401
+ # - Packages: api, client, seo
402
+ # - Auth: JWT
403
+
404
+ # Generate components
405
+ cd my-blog
406
+ coherent g component ArticleCard
407
+ coherent g component CommentList
408
+
409
+ # Generate pages
410
+ coherent g page Article --template detail
411
+ coherent g page Dashboard --template dashboard
412
+
413
+ # Generate API
414
+ coherent g api articles --template crud
415
+ coherent g api comments --template rest
416
+
417
+ # Configure database in .env
418
+ # DB_HOST=localhost
419
+ # DB_NAME=my_blog
420
+ # DB_USER=postgres
421
+ # DB_PASSWORD=yourpassword
422
+
423
+ # Start development
424
+ coherent dev
425
+ ```
426
+
427
+ ### Create a component library
428
+
429
+ ```bash
430
+ # Create project
431
+ coherent create ui-components
432
+
433
+ # In the CLI prompts:
434
+ # - Template: Components
435
+ # - Runtime: Built-in
436
+ # - Packages: client, testing
437
+
438
+ # Generate components
439
+ cd ui-components
440
+ coherent g component Button --template interactive
441
+ coherent g component Modal --template functional
442
+ coherent g component Form --template layout
443
+
444
+ # Build for distribution
445
+ coherent build --analyze
446
+ ```
447
+
448
+ ### Create a custom API with MongoDB
449
+
450
+ ```bash
451
+ # Create project
452
+ coherent create my-api
453
+
454
+ # In the CLI prompts:
455
+ # - Template: Custom
456
+ # - Runtime: Fastify
457
+ # - Database: MongoDB
458
+ # - Packages: api
459
+ # - Auth: JWT
460
+
461
+ # Project includes:
462
+ # - Fastify server setup
463
+ # - MongoDB connection & models
464
+ # - API routes with validation
465
+ # - JWT authentication (login, register, /me routes)
466
+ # - Environment configuration (.env.example)
467
+
468
+ cd my-api
469
+ # Configure MongoDB in .env
470
+ coherent dev
471
+ ```
472
+
473
+ ## šŸ¤ Contributing
474
+
475
+ We welcome contributions! Here's how to get started:
476
+
477
+ ```bash
478
+ # Clone the repository
479
+ git clone https://github.com/Tomdrouv1/coherent.js.git
480
+ cd coherent.js/packages/cli
481
+
482
+ # Install dependencies
483
+ pnpm install
484
+
485
+ # Run tests
486
+ pnpm test
487
+
488
+ # Build the CLI
489
+ pnpm build
490
+
491
+ # Test locally
492
+ npm link
493
+ coherent --help
494
+ ```
495
+
496
+ ## šŸ“ License
497
+
498
+ MIT Ā© [Coherent.js Team](https://github.com/Tomdrouv1/coherent.js)
499
+
500
+ ## šŸ”— Links
501
+
502
+ - [Coherent.js Documentation](https://github.com/Tomdrouv1/coherent.js)
503
+ - [API Reference](https://github.com/Tomdrouv1/coherent.js/blob/main/docs/api-reference.md)
504
+ - [Examples](https://github.com/Tomdrouv1/coherent.js/tree/main/examples)
505
+ - [Issues & Bug Reports](https://github.com/Tomdrouv1/coherent.js/issues)
506
+
507
+ ---
508
+
509
+ **Happy coding with Coherent.js! šŸš€**
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Coherent.js CLI - Command-line interface for Coherent.js projects
5
+ *
6
+ * Usage:
7
+ * coherent create <project-name> - Create a new Coherent.js project
8
+ * coherent generate <type> <name> - Generate components, pages, APIs
9
+ * coherent build - Build the project
10
+ * coherent dev - Start development server
11
+ * coherent --help - Show help
12
+ */
13
+
14
+ import { fileURLToPath } from 'url';
15
+ import { dirname, join } from 'path';
16
+ import { readFileSync } from 'fs';
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = dirname(__filename);
20
+
21
+ // Import the main CLI module
22
+ try {
23
+ const { createCLI } = await import('../dist/index.js');
24
+ await createCLI();
25
+ } catch (_error) {
26
+ // Fallback to source if dist doesn't exist (development)
27
+ try {
28
+ const { createCLI } = await import('../src/index.js');
29
+ await createCLI();
30
+ } catch (fallbackError) {
31
+ console._error('āŒ Failed to load Coherent.js CLI:');
32
+ console._error(' ', fallbackError.message);
33
+ console._error('\nšŸ’” Try running: npm install');
34
+ process.exit(1);
35
+ }
36
+ }