@forinda/kickjs 0.1.4 → 0.2.0

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/dist/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- #!/usr/bin/env node
3
2
  "use strict";
4
3
  var __create = Object.create;
5
4
  var __defProp = Object.defineProperty;
@@ -31,7 +30,7 @@ var import_commander = require("commander");
31
30
  // package.json
32
31
  var package_default = {
33
32
  name: "@forinda/kickjs",
34
- version: "0.1.4",
33
+ version: "0.2.0",
35
34
  description: "Express + TypeScript + Inversify starter with reactive state, request telemetry, and Spring Boot-style decorators.",
36
35
  main: "dist/index.js",
37
36
  types: "dist/index.d.ts",
@@ -42,21 +41,30 @@ var package_default = {
42
41
  }
43
42
  },
44
43
  files: [
45
- "dist"
44
+ "dist",
45
+ "LICENSE",
46
+ "README.md"
46
47
  ],
47
48
  bin: {
48
49
  kick: "dist/cli.js"
49
50
  },
50
51
  scripts: {
51
52
  clean: "rm -rf dist",
52
- dev: "ts-node-dev --respawn --transpile-only src/main.ts",
53
+ dev: "tsup --watch src/index.ts",
53
54
  check: "tsc --noEmit",
54
55
  build: "tsup",
55
56
  start: "node dist/index.js",
56
57
  prepublishOnly: "npm run build && npm run check && npm test",
57
58
  test: "vitest run",
58
59
  "test:watch": "vitest",
59
- prepare: "husky"
60
+ prepare: "husky",
61
+ prerelease: "npm run clean && npm run build && npm run check && npm test",
62
+ "release:patch": "node scripts/release.js patch",
63
+ "release:minor": "node scripts/release.js minor",
64
+ "release:major": "node scripts/release.js major",
65
+ "release:prerelease": "node scripts/release.js prerelease",
66
+ "release:dry": "node scripts/release.js patch --dry-run",
67
+ version: `git add package.json && git commit -m "chore: bump version to $(node -p "require('./package.json').version")"`
60
68
  },
61
69
  keywords: [
62
70
  "express",
@@ -65,16 +73,18 @@ var package_default = {
65
73
  "decorators",
66
74
  "starter"
67
75
  ],
68
- author: "",
76
+ author: "Felix Orinda",
69
77
  license: "MIT",
70
78
  engines: {
71
- node: ">=18.17"
79
+ node: ">=20.0"
72
80
  },
73
81
  publishConfig: {
74
82
  access: "public"
75
83
  },
76
84
  dependencies: {
77
- commander: "^11.1.0",
85
+ commander: "^11.1.0"
86
+ },
87
+ peerDependencies: {
78
88
  express: "^5.1.0",
79
89
  inversify: "^7.10.0",
80
90
  "reflect-metadata": "^0.2.2"
@@ -83,17 +93,36 @@ var package_default = {
83
93
  "@swc/core": "^1.7.28",
84
94
  "@types/express": "^5.0.3",
85
95
  "@types/node": "^24.5.2",
96
+ "@types/supertest": "^6.0.3",
86
97
  "@vitest/coverage-v8": "^3.2.4",
98
+ express: "^5.1.0",
87
99
  husky: "^9.1.7",
100
+ inversify: "^7.10.0",
88
101
  joi: "^18.0.1",
89
102
  "node-mocks-http": "^1.17.2",
103
+ "reflect-metadata": "^0.2.2",
104
+ supertest: "^7.1.4",
90
105
  "ts-node": "^10.9.2",
91
106
  "ts-node-dev": "^2.0.0",
92
107
  tsup: "^8.5.0",
108
+ tsx: "^4.20.6",
93
109
  typescript: "^5.9.2",
94
110
  vitest: "^3.2.4",
95
111
  zod: "^4.1.9"
96
- }
112
+ },
113
+ directories: {
114
+ doc: "docs",
115
+ example: "examples",
116
+ test: "tests"
117
+ },
118
+ repository: {
119
+ type: "git",
120
+ url: "git+https://github.com/forinda/kick-js.git"
121
+ },
122
+ bugs: {
123
+ url: "https://github.com/forinda/kick-js/issues"
124
+ },
125
+ homepage: "https://github.com/forinda/kick-js#readme"
97
126
  };
98
127
 
99
128
  // src/cli/tasks/init-project.ts
@@ -150,7 +179,6 @@ __name(writeJsonFile, "writeJsonFile");
150
179
  async function initProject(options) {
151
180
  const targetDir = import_node_path2.default.resolve(process.cwd(), options.targetDirectory || ".");
152
181
  const force = options.force ?? false;
153
- const structure = normalizeStructure(options.structure);
154
182
  const createdFiles = [];
155
183
  const skippedFiles = [];
156
184
  await ensureDirectory(targetDir);
@@ -160,23 +188,34 @@ async function initProject(options) {
160
188
  const name = options.packageName ?? (import_node_path2.default.basename(targetDir).replace(/[^a-zA-Z0-9-_]/g, "-") || "kick-app");
161
189
  await writeJsonFile(packageJsonPath, {
162
190
  name,
163
- version: "0.1.0",
191
+ version: "1.0.0",
164
192
  private: true,
165
193
  type: "commonjs",
194
+ main: "dist/index.js",
166
195
  scripts: {
167
- dev: "tsx watch src/main.ts",
168
- build: "tsup",
169
- start: "node dist/main.js",
170
- test: "vitest"
196
+ dev: "kick dev",
197
+ build: "kick build",
198
+ start: "kick start",
199
+ typecheck: "tsc --noEmit",
200
+ clean: "rimraf dist"
171
201
  },
172
202
  dependencies: {
173
- "@forinda/kickjs": "latest"
203
+ "@forinda/kickjs": "latest",
204
+ express: "^5.1.0",
205
+ inversify: "^7.10.0",
206
+ "reflect-metadata": "^0.2.2"
174
207
  },
175
208
  devDependencies: {
176
- typescript: "^5.4.0",
177
- tsx: "^4.7.0",
178
- tsup: "^8.0.0",
179
- vitest: "^3.0.0"
209
+ "@types/express": "^5.0.3",
210
+ "@types/node": "^24.5.2",
211
+ rimraf: "^5.0.0",
212
+ "ts-node-dev": "^2.0.0",
213
+ tsup: "^8.5.0",
214
+ tsx: "^4.20.6",
215
+ typescript: "^5.9.2"
216
+ },
217
+ engines: {
218
+ node: ">=20.0.0"
180
219
  }
181
220
  }, {
182
221
  force: true
@@ -190,23 +229,42 @@ async function initProject(options) {
190
229
  if (!tsconfigExists || force) {
191
230
  await writeJsonFile(tsconfigPath, {
192
231
  compilerOptions: {
193
- target: "es2021",
194
- module: "commonjs",
232
+ target: "ES2022",
233
+ module: "CommonJS",
195
234
  moduleResolution: "node",
196
235
  lib: [
197
- "es2021"
236
+ "ES2022"
198
237
  ],
199
238
  rootDir: "src",
200
239
  outDir: "dist",
201
- strict: true,
240
+ allowSyntheticDefaultImports: true,
202
241
  esModuleInterop: true,
242
+ forceConsistentCasingInFileNames: true,
243
+ strict: true,
244
+ noImplicitAny: true,
245
+ strictNullChecks: true,
246
+ strictFunctionTypes: true,
247
+ noImplicitReturns: true,
248
+ noFallthroughCasesInSwitch: true,
249
+ noUncheckedIndexedAccess: true,
250
+ noImplicitOverride: true,
251
+ exactOptionalPropertyTypes: true,
203
252
  skipLibCheck: true,
204
253
  resolveJsonModule: true,
205
254
  experimentalDecorators: true,
206
- emitDecoratorMetadata: true
255
+ emitDecoratorMetadata: true,
256
+ declaration: true,
257
+ declarationMap: true,
258
+ sourceMap: true
207
259
  },
208
260
  include: [
209
- "src"
261
+ "src/**/*"
262
+ ],
263
+ exclude: [
264
+ "node_modules",
265
+ "dist",
266
+ "**/*.test.ts",
267
+ "**/*.spec.ts"
210
268
  ]
211
269
  }, {
212
270
  force: true
@@ -215,140 +273,465 @@ async function initProject(options) {
215
273
  } else {
216
274
  skippedFiles.push("tsconfig.json");
217
275
  }
218
- const mainFilePath = import_node_path2.default.join(targetDir, "src", "main.ts");
276
+ const mainFilePath = import_node_path2.default.join(targetDir, "src", "index.ts");
219
277
  const mainCreated = await writeFileSafe(mainFilePath, `import 'reflect-metadata';
220
- import { bootstrap, configureApp } from '@forinda/kickjs';
278
+ import express from 'express';
279
+ import { createKickAppWithConfig } from '@forinda/kickjs';
280
+ import { AppModule } from './app.module';
221
281
 
222
- configureApp({ prefix: '/api' });
282
+ async function startApp() {
283
+ const app = express();
284
+ app.use(express.json());
223
285
 
224
- async function main() {
225
- const { shutdown } = await bootstrap({ port: process.env.PORT ?? 3000 });
226
- process.on('SIGINT', shutdown);
227
- process.on('SIGTERM', shutdown);
286
+ const server = await createKickAppWithConfig({
287
+ app,
288
+ modules: [AppModule]
289
+ });
290
+
291
+ const port = server.kickApp.getConfig('port') || 3000;
292
+ const host = server.kickApp.getConfig('host') || 'localhost';
293
+
294
+ server.listen(port, () => {
295
+ console.log(\`\u{1F680} \${server.kickApp.getConfig('name')} running on http://\${host}:\${port}\`);
296
+ console.log(\`\u{1F4CA} App Stats:\`, server.getStats());
297
+ });
228
298
  }
229
299
 
230
- main().catch((error) => {
231
- console.error('Failed to bootstrap Kick app', error);
232
- process.exitCode = 1;
300
+ startApp().catch((error) => {
301
+ console.error('Failed to start application:', error);
302
+ process.exit(1);
303
+ });
304
+ `, {
305
+ force
306
+ });
307
+ if (mainCreated) {
308
+ createdFiles.push("src/index.ts");
309
+ } else {
310
+ skippedFiles.push("src/index.ts");
311
+ }
312
+ const appModulePath = import_node_path2.default.join(targetDir, "src", "app.module.ts");
313
+ const appModuleCreated = await writeFileSafe(appModulePath, `import { createModule } from '@forinda/kickjs';
314
+ import { UserController } from './controllers/user.controller';
315
+ import { UserService } from './services/user.service';
316
+
317
+ export const AppModule = createModule('app', {
318
+ controllers: [UserController],
319
+ services: [UserService]
233
320
  });
234
321
  `, {
235
322
  force
236
323
  });
237
- mainCreated ? createdFiles.push("src/main.ts") : skippedFiles.push("src/main.ts");
238
- const domainBase = import_node_path2.default.join(targetDir, structure.domainRoot, structure.defaultDomain);
239
- for (const folder of structure.domainFolders) {
324
+ if (appModuleCreated) {
325
+ createdFiles.push("src/app.module.ts");
326
+ } else {
327
+ skippedFiles.push("src/app.module.ts");
328
+ }
329
+ const domainBase = import_node_path2.default.join(targetDir, "src");
330
+ for (const folder of [
331
+ "controllers",
332
+ "services",
333
+ "types"
334
+ ]) {
240
335
  const folderPath = import_node_path2.default.join(domainBase, folder);
241
336
  const exists = await fileExists(folderPath);
242
337
  await ensureDirectory(folderPath);
243
338
  const relativePath = import_node_path2.default.relative(targetDir, folderPath);
244
- if (exists) {
245
- skippedFiles.push(relativePath);
246
- } else {
339
+ if (!exists) {
247
340
  createdFiles.push(relativePath);
341
+ } else {
342
+ skippedFiles.push(relativePath);
248
343
  }
249
344
  }
250
- const controllerFolder = structure.domainFolders.includes("controllers") ? "controllers" : structure.domainFolders[0];
251
- const controllerPath = import_node_path2.default.join(domainBase, controllerFolder, "hello.get.controller.ts");
252
- const controllerCreated = await writeFileSafe(controllerPath, `import type { Request, Response } from 'express';
253
- import { GetController } from '@forinda/kickjs';
345
+ const controllerPath = import_node_path2.default.join(targetDir, "src", "controllers", "user.controller.ts");
346
+ const controllerCreated = await writeFileSafe(controllerPath, `import {
347
+ KickController,
348
+ KickGet,
349
+ KickPost,
350
+ KickRequestContext,
351
+ KickInject
352
+ } from '@forinda/kickjs';
353
+ import { UserService } from '../services/user.service';
254
354
 
255
- export default class HelloGetController extends GetController {
256
- handle(_req: Request, res: Response) {
257
- return this.ok(res, { message: 'Hello from Kick!' });
355
+ @KickController('/users')
356
+ export class UserController {
357
+ constructor(
358
+ @KickInject(UserService)
359
+ private readonly userService: UserService
360
+ ) {}
361
+
362
+ @KickGet('/')
363
+ async getUsers(context: KickRequestContext) {
364
+ const { res } = context;
365
+ const users = await this.userService.findAll();
366
+
367
+ res.json({
368
+ users,
369
+ requestId: context.meta.requestId,
370
+ timestamp: context.meta.startTime
371
+ });
372
+ }
373
+
374
+ @KickPost('/')
375
+ async createUser(context: KickRequestContext) {
376
+ const { req, res } = context;
377
+
378
+ if (!req.body.name || !req.body.email) {
379
+ return res.status(400).json({
380
+ error: 'Name and email are required',
381
+ requestId: context.meta.requestId
382
+ });
383
+ }
384
+
385
+ const user = await this.userService.create(req.body);
386
+ res.status(201).json({
387
+ user,
388
+ requestId: context.meta.requestId
389
+ });
258
390
  }
259
391
  }
260
392
  `, {
261
393
  force
262
394
  });
263
395
  const relativeControllerPath = import_node_path2.default.relative(targetDir, controllerPath);
264
- controllerCreated ? createdFiles.push(relativeControllerPath) : skippedFiles.push(relativeControllerPath);
265
- const appConfigDir = import_node_path2.default.join(targetDir, "src", "config");
266
- await ensureDirectory(appConfigDir);
267
- const appConfigPath = import_node_path2.default.join(appConfigDir, "kick.config.ts");
268
- const appConfigCreated = await writeFileSafe(appConfigPath, buildAppConfigFile(structure), {
269
- force
270
- });
271
- const relativeAppConfig = import_node_path2.default.relative(targetDir, appConfigPath);
272
- appConfigCreated ? createdFiles.push(relativeAppConfig) : skippedFiles.push(relativeAppConfig);
273
- const configPath = import_node_path2.default.join(targetDir, "kick.config.ts");
274
- const configCreated = await writeFileSafe(configPath, buildConfigFile(structure), {
396
+ if (controllerCreated) {
397
+ createdFiles.push(relativeControllerPath);
398
+ } else {
399
+ skippedFiles.push(relativeControllerPath);
400
+ }
401
+ const servicePath = import_node_path2.default.join(targetDir, "src", "services", "user.service.ts");
402
+ const serviceCreated = await writeFileSafe(servicePath, `import { KickInjectable } from '@forinda/kickjs';
403
+
404
+ export interface User {
405
+ id: string;
406
+ name: string;
407
+ email: string;
408
+ createdAt: Date;
409
+ }
410
+
411
+ @KickInjectable()
412
+ export class UserService {
413
+ private users: User[] = [];
414
+
415
+ async findAll(): Promise<User[]> {
416
+ return this.users;
417
+ }
418
+
419
+ async create(userData: { name: string; email: string }): Promise<User> {
420
+ const user: User = {
421
+ id: Math.random().toString(36).substr(2, 9),
422
+ name: userData.name,
423
+ email: userData.email,
424
+ createdAt: new Date()
425
+ };
426
+
427
+ this.users.push(user);
428
+ return user;
429
+ }
430
+
431
+ async findById(id: string): Promise<User | undefined> {
432
+ return this.users.find(user => user.id === id);
433
+ }
434
+ }
435
+ `, {
275
436
  force
276
437
  });
277
- configCreated ? createdFiles.push("kick.config.ts") : skippedFiles.push("kick.config.ts");
278
- return {
279
- createdFiles,
280
- skippedFiles
281
- };
438
+ const relativeServicePath = import_node_path2.default.relative(targetDir, servicePath);
439
+ if (serviceCreated) {
440
+ createdFiles.push(relativeServicePath);
441
+ } else {
442
+ skippedFiles.push(relativeServicePath);
443
+ }
444
+ const typesPath = import_node_path2.default.join(targetDir, "src", "types", "user.types.ts");
445
+ const typesCreated = await writeFileSafe(typesPath, `export interface User {
446
+ id: string;
447
+ name: string;
448
+ email: string;
449
+ createdAt: Date;
282
450
  }
283
- __name(initProject, "initProject");
284
- function normalizeStructure(structure) {
285
- return {
286
- domainRoot: structure?.domainRoot ?? "src/domains",
287
- domainFolders: structure?.domainFolders && structure.domainFolders.length > 0 ? [
288
- ...structure.domainFolders
289
- ] : [
290
- "controllers",
291
- "services",
292
- "domain"
293
- ],
294
- defaultDomain: structure?.defaultDomain ?? "app"
295
- };
451
+
452
+ export interface CreateUserRequest {
453
+ name: string;
454
+ email: string;
296
455
  }
297
- __name(normalizeStructure, "normalizeStructure");
298
- function buildConfigFile(structure) {
299
- const controllerRoot = `${structure.domainRoot}/${structure.defaultDomain}/controllers`;
300
- const structureSnippet = JSON.stringify(structure, null, 2).split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
301
- return `import type { KickConfig } from '@forinda/kickjs';
302
456
 
303
- const config: KickConfig = {
304
- structure: ${structureSnippet},
305
- generators: {
306
- controllerRoot: '${controllerRoot}'
457
+ export interface UserResponse {
458
+ user: User;
459
+ requestId: string;
460
+ }
461
+ `, {
462
+ force
463
+ });
464
+ const relativeTypesPath = import_node_path2.default.relative(targetDir, typesPath);
465
+ if (typesCreated) {
466
+ createdFiles.push(relativeTypesPath);
467
+ } else {
468
+ skippedFiles.push(relativeTypesPath);
469
+ }
470
+ const configPath = import_node_path2.default.join(targetDir, "kick.config.js");
471
+ const configCreated = await writeFileSafe(configPath, `module.exports = {
472
+ app: {
473
+ name: '${options.packageName || "kick-app"}',
474
+ port: 3000,
475
+ host: 'localhost',
476
+ prefix: '/api/v1',
477
+ env: 'development'
307
478
  },
308
- commands: [
309
- {
310
- name: 'dev',
311
- description: 'Run the Kick dev server',
312
- steps: 'npm run dev'
479
+ dev: {
480
+ port: 3000,
481
+ host: 'localhost',
482
+ entry: 'src/index.ts',
483
+ watch: true,
484
+ env: {
485
+ NODE_ENV: 'development',
486
+ DEBUG: 'app:*'
313
487
  }
314
- ]
488
+ },
489
+ start: {
490
+ port: 3000,
491
+ host: '0.0.0.0',
492
+ entry: 'dist/index.js',
493
+ env: {
494
+ NODE_ENV: 'production'
495
+ }
496
+ }
315
497
  };
498
+ `, {
499
+ force
500
+ });
501
+ if (configCreated) {
502
+ createdFiles.push("kick.config.js");
503
+ } else {
504
+ skippedFiles.push("kick.config.js");
505
+ }
506
+ const gitignorePath = import_node_path2.default.join(targetDir, ".gitignore");
507
+ const gitignoreCreated = await writeFileSafe(gitignorePath, `# Dependencies
508
+ node_modules/
509
+ npm-debug.log*
510
+ yarn-debug.log*
511
+ yarn-error.log*
512
+ pnpm-debug.log*
316
513
 
317
- export default config;
318
- `;
319
- }
320
- __name(buildConfigFile, "buildConfigFile");
321
- function buildAppConfigFile(structure) {
322
- const controllerRoot = `${structure.domainRoot}/${structure.defaultDomain}/controllers`;
323
- const roots = [
324
- controllerRoot,
325
- "src/http"
326
- ].map((root) => `'${root}'`).join(", ");
327
- return `import { createKickConfig } from '@forinda/kickjs';
328
-
329
- export default createKickConfig({
330
- defaults: {
331
- prefix: '/api',
332
- api: {
333
- discovery: {
334
- roots: [${roots}]
335
- }
336
- }
337
- },
338
- env: {
339
- KICK_PREFIX: 'prefix',
340
- KICK_HEALTH: 'healthEndpoint',
341
- KICK_LOG_LEVEL: { path: 'logging.level' }
514
+ # Build outputs
515
+ dist/
516
+ build/
517
+ *.tsbuildinfo
518
+
519
+ # Environment variables
520
+ .env
521
+ .env.local
522
+ .env.development.local
523
+ .env.test.local
524
+ .env.production.local
525
+
526
+ # IDE files
527
+ .vscode/
528
+ .idea/
529
+ *.swp
530
+ *.swo
531
+ *~
532
+
533
+ # OS files
534
+ .DS_Store
535
+ .DS_Store?
536
+ ._*
537
+ .Spotlight-V100
538
+ .Trashes
539
+ ehthumbs.db
540
+ Thumbs.db
541
+
542
+ # Logs
543
+ logs/
544
+ *.log
545
+
546
+ # Runtime data
547
+ pids/
548
+ *.pid
549
+ *.seed
550
+ *.pid.lock
551
+
552
+ # Coverage directory used by tools like istanbul
553
+ coverage/
554
+ *.lcov
555
+
556
+ # nyc test coverage
557
+ .nyc_output
558
+
559
+ # Dependency directories
560
+ jspm_packages/
561
+
562
+ # Optional npm cache directory
563
+ .npm
564
+
565
+ # Optional eslint cache
566
+ .eslintcache
567
+
568
+ # Optional REPL history
569
+ .node_repl_history
570
+
571
+ # Output of 'npm pack'
572
+ *.tgz
573
+
574
+ # Yarn Integrity file
575
+ .yarn-integrity
576
+
577
+ # parcel-bundler cache (https://parceljs.org/)
578
+ .cache
579
+ .parcel-cache
580
+
581
+ # next.js build output
582
+ .next
583
+
584
+ # nuxt.js build output
585
+ .nuxt
586
+
587
+ # vuepress build output
588
+ .vuepress/dist
589
+
590
+ # Serverless directories
591
+ .serverless
592
+
593
+ # FuseBox cache
594
+ .fusebox/
595
+
596
+ # DynamoDB Local files
597
+ .dynamodb/
598
+
599
+ # TernJS port file
600
+ .tern-port
601
+ `, {
602
+ force
603
+ });
604
+ if (gitignoreCreated) {
605
+ createdFiles.push(".gitignore");
606
+ } else {
607
+ skippedFiles.push(".gitignore");
342
608
  }
609
+ const readmePath = import_node_path2.default.join(targetDir, "README.md");
610
+ const readmeCreated = await writeFileSafe(readmePath, `# ${options.packageName || "kick-app"}
611
+
612
+ A modern TypeScript API built with KickJS framework.
613
+
614
+ ## \u{1F680} Quick Start
615
+
616
+ ### Prerequisites
617
+
618
+ - Node.js 18+
619
+ - npm, pnpm, or yarn
620
+
621
+ ### Installation
622
+
623
+ \`\`\`bash
624
+ npm install
625
+ \`\`\`
626
+
627
+ ### Development
628
+
629
+ \`\`\`bash
630
+ # Start development server with hot reload
631
+ npm run dev
632
+ \`\`\`
633
+
634
+ ### Building
635
+
636
+ \`\`\`bash
637
+ # Build for production
638
+ npm run build
639
+ \`\`\`
640
+
641
+ ### Running in Production
642
+
643
+ \`\`\`bash
644
+ # Start production server
645
+ npm start
646
+ \`\`\`
647
+
648
+ ## \u{1F4C1} Project Structure
649
+
650
+ \`\`\`
651
+ src/
652
+ \u251C\u2500\u2500 controllers/ # HTTP route controllers
653
+ \u251C\u2500\u2500 services/ # Business logic services
654
+ \u251C\u2500\u2500 types/ # TypeScript type definitions
655
+ \u251C\u2500\u2500 app.module.ts # Main application module
656
+ \u2514\u2500\u2500 index.ts # Application entry point
657
+ \`\`\`
658
+
659
+ ## \u{1F6E0}\uFE0F Available Scripts
660
+
661
+ - \`npm run dev\` - Start development server with hot reload
662
+ - \`npm run build\` - Build for production
663
+ - \`npm start\` - Start production server
664
+ - \`npm run typecheck\` - Type check without building
665
+ - \`npm run clean\` - Clean build directory
666
+
667
+ ## \u{1F4DA} Learn More
668
+
669
+ - [KickJS Documentation](https://github.com/forinda/kick-js)
670
+ - [Express.js](https://expressjs.com/)
671
+ - [TypeScript](https://www.typescriptlang.org/)
672
+ - [Inversify](https://inversify.io/)
673
+
674
+ ## \u{1F3AF} API Endpoints
675
+
676
+ ### Users
677
+
678
+ - \`GET /api/v1/users\` - Get all users
679
+ - \`POST /api/v1/users\` - Create a new user
680
+
681
+ Example request:
682
+ \`\`\`bash
683
+ curl -X POST http://localhost:3000/api/v1/users \\
684
+ -H "Content-Type: application/json" \\
685
+ -d '{"name": "John Doe", "email": "john@example.com"}'
686
+ \`\`\`
687
+
688
+ ## \u{1F4C4} License
689
+
690
+ MIT
691
+ `, {
692
+ force
693
+ });
694
+ if (readmeCreated) {
695
+ createdFiles.push("README.md");
696
+ } else {
697
+ skippedFiles.push("README.md");
698
+ }
699
+ const tsupConfigPath = import_node_path2.default.join(targetDir, "tsup.config.ts");
700
+ const tsupConfigCreated = await writeFileSafe(tsupConfigPath, `import { defineConfig } from 'tsup';
701
+
702
+ export default defineConfig({
703
+ entry: ['src/index.ts'],
704
+ format: ['esm'],
705
+ dts: true,
706
+ clean: true,
707
+ sourcemap: true,
708
+ target: 'node18',
709
+ outDir: 'dist',
710
+ splitting: false,
711
+ minify: false,
712
+ external: ['express']
343
713
  });
344
- `;
714
+ `, {
715
+ force
716
+ });
717
+ if (tsupConfigCreated) {
718
+ createdFiles.push("tsup.config.ts");
719
+ } else {
720
+ skippedFiles.push("tsup.config.ts");
721
+ }
722
+ return {
723
+ createdFiles,
724
+ skippedFiles
725
+ };
345
726
  }
346
- __name(buildAppConfigFile, "buildAppConfigFile");
727
+ __name(initProject, "initProject");
347
728
 
348
729
  // src/cli/commands/init.ts
349
730
  function registerInitCommand(program, defaults = {}) {
350
- program.command("init [directory]").description("Scaffold a new Kick project in the target directory").option("-f, --force", "Overwrite existing files when scaffolding", false).option("-n, --name <packageName>", "Package name to use in package.json").action(async (directory, options) => {
731
+ program.command("init [directory]").description("Scaffold a new KickJS project with complete setup").option("-f, --force", "Overwrite existing files when scaffolding", false).option("-n, --name <packageName>", "Package name to use in package.json").action(async (directory, options) => {
351
732
  const targetDirectory = directory ?? ".";
733
+ console.log("\u{1F680} Initializing KickJS project...");
734
+ console.log(`\u{1F4C1} Target directory: ${targetDirectory}`);
352
735
  const result = await initProject({
353
736
  targetDirectory,
354
737
  force: options.force,
@@ -356,14 +739,26 @@ function registerInitCommand(program, defaults = {}) {
356
739
  structure: defaults.structure
357
740
  });
358
741
  if (result.createdFiles.length > 0) {
359
- console.log(`Created files:
360
- - ${result.createdFiles.join("\n - ")}`);
742
+ console.log("\n\u2705 Created files:");
743
+ result.createdFiles.forEach((file) => console.log(` \u2713 ${file}`));
361
744
  }
362
745
  if (result.skippedFiles.length > 0) {
363
- console.log(`Skipped existing files:
364
- - ${result.skippedFiles.join("\n - ")}`);
746
+ console.log("\n\u26A0\uFE0F Skipped existing files:");
747
+ result.skippedFiles.forEach((file) => console.log(` - ${file}`));
365
748
  }
366
- console.log('Project scaffold complete. Run "npm install" to install dependencies.');
749
+ console.log("\n\u{1F389} Project scaffold complete!");
750
+ console.log("\n\u{1F4E6} Next steps:");
751
+ console.log(" 1. Install dependencies:");
752
+ console.log(" npm install");
753
+ console.log("\n 2. Start development server:");
754
+ console.log(" npm run dev");
755
+ console.log("\n 3. Build for production:");
756
+ console.log(" npm run build");
757
+ console.log("\n 4. Run production server:");
758
+ console.log(" npm start");
759
+ console.log("\n 5. Type check your code:");
760
+ console.log(" npm run typecheck");
761
+ console.log("\n\u{1F4DA} Learn more at: https://github.com/forinda/kick-js");
367
762
  });
368
763
  }
369
764
  __name(registerInitCommand, "registerInitCommand");
@@ -573,9 +968,10 @@ function computeDefaultControllerRoot(defaults, name) {
573
968
  }
574
969
  __name(computeDefaultControllerRoot, "computeDefaultControllerRoot");
575
970
 
576
- // src/cli/config.ts
577
- var import_node_fs2 = require("fs");
578
- var import_node_path5 = __toESM(require("path"));
971
+ // src/cli/commands/run.ts
972
+ var import_node_child_process = require("child_process");
973
+ var import_node_fs3 = require("fs");
974
+ var import_node_path6 = __toESM(require("path"));
579
975
 
580
976
  // src/utils/errors.ts
581
977
  var AppError = class extends Error {
@@ -601,103 +997,265 @@ function createError(code, message, options = {}) {
601
997
  }
602
998
  __name(createError, "createError");
603
999
 
604
- // src/cli/config.ts
605
- var CONFIG_FILE_CANDIDATES = [
1000
+ // src/cli/utils/config-loader.ts
1001
+ var import_node_fs2 = require("fs");
1002
+ var import_node_path5 = __toESM(require("path"));
1003
+ var CONFIG_FILE_NAMES = [
606
1004
  "kick.config.ts",
607
1005
  "kick.config.js",
608
1006
  "kick.config.mjs",
609
- "kick.config.cjs",
610
- "kick.config.json"
1007
+ "kickjs.config.ts",
1008
+ "kickjs.config.js",
1009
+ "kickjs.config.mjs"
611
1010
  ];
612
- var tsNodeRegistered = false;
613
- async function loadKickConfig(cwd = process.cwd()) {
614
- for (const file of CONFIG_FILE_CANDIDATES) {
615
- const absolute = import_node_path5.default.join(cwd, file);
616
- if (!(0, import_node_fs2.existsSync)(absolute)) {
617
- continue;
618
- }
619
- if (file.endsWith(".json")) {
620
- const raw = await import_node_fs2.promises.readFile(absolute, "utf8");
621
- return normalizeConfig(JSON.parse(raw));
622
- }
623
- if (file.endsWith(".ts")) {
624
- ensureTsNode();
1011
+ async function loadKickConfig(cwd) {
1012
+ const workingDir = cwd || process.cwd();
1013
+ for (const configFileName of CONFIG_FILE_NAMES) {
1014
+ const configPath = import_node_path5.default.resolve(workingDir, configFileName);
1015
+ if ((0, import_node_fs2.existsSync)(configPath)) {
1016
+ try {
1017
+ const configModule = await import(configPath);
1018
+ const config = configModule.default || configModule;
1019
+ return {
1020
+ ...config,
1021
+ configPath
1022
+ };
1023
+ } catch (error) {
1024
+ console.warn(`\u26A0\uFE0F Failed to load config from ${configPath}:`, error);
1025
+ }
625
1026
  }
626
- const loaded = require(absolute);
627
- const config = loaded?.default ?? loaded;
628
- return normalizeConfig(config);
629
1027
  }
630
- return void 0;
1028
+ return getDefaultConfig();
631
1029
  }
632
1030
  __name(loadKickConfig, "loadKickConfig");
633
- function ensureTsNode() {
634
- if (tsNodeRegistered) {
635
- return;
636
- }
637
- try {
638
- require("ts-node/register");
639
- tsNodeRegistered = true;
640
- } catch (error) {
641
- throw createError("TS_NODE_REQUIRED", "Custom CLI config requires ts-node for TypeScript configuration files.");
642
- }
643
- }
644
- __name(ensureTsNode, "ensureTsNode");
645
- function normalizeConfig(raw) {
646
- if (!raw || typeof raw !== "object") {
647
- throw createError("INVALID_CLI_CONFIG", "kick.config must export an object");
648
- }
649
- const config = raw;
650
- const normalized = {};
651
- if (Array.isArray(config.commands)) {
652
- normalized.commands = config.commands.map((command) => {
653
- if (!command || typeof command !== "object") {
654
- throw createError("INVALID_CLI_COMMAND", "Command entries must be objects");
1031
+ function getDefaultConfig() {
1032
+ return {
1033
+ app: {
1034
+ name: "KickJS App",
1035
+ port: 3e3,
1036
+ host: "localhost",
1037
+ prefix: "",
1038
+ env: "development"
1039
+ },
1040
+ dev: {
1041
+ port: 3e3,
1042
+ host: "localhost",
1043
+ entry: "src/index.ts",
1044
+ watch: true,
1045
+ env: {
1046
+ NODE_ENV: "development"
655
1047
  }
656
- if (!command.name) {
657
- throw createError("INVALID_CLI_COMMAND", "Command entries must include a name");
1048
+ },
1049
+ start: {
1050
+ port: 3e3,
1051
+ host: "0.0.0.0",
1052
+ entry: "dist/index.js",
1053
+ env: {
1054
+ NODE_ENV: "production"
658
1055
  }
659
- return {
660
- name: command.name,
661
- description: command.description,
662
- steps: Array.isArray(command.steps) ? [
663
- ...command.steps
664
- ] : command.steps ? [
665
- command.steps
666
- ] : []
667
- };
668
- });
1056
+ },
1057
+ structure: {
1058
+ domainRoot: "src/domains",
1059
+ domainFolders: [
1060
+ "controllers",
1061
+ "services",
1062
+ "domain"
1063
+ ],
1064
+ defaultDomain: "app"
1065
+ },
1066
+ generators: {
1067
+ controllerRoot: "src/domains/app/controllers"
1068
+ },
1069
+ commands: []
1070
+ };
1071
+ }
1072
+ __name(getDefaultConfig, "getDefaultConfig");
1073
+ function mergeConfigWithOptions(config, cliOptions, command) {
1074
+ const defaultConfig = getDefaultConfig();
1075
+ const baseConfig = command === "dev" ? config.dev || defaultConfig.dev : config.start || defaultConfig.start;
1076
+ return {
1077
+ ...baseConfig,
1078
+ port: cliOptions.port ? parseInt(cliOptions.port) : baseConfig?.port,
1079
+ host: cliOptions.host || baseConfig?.host,
1080
+ entry: cliOptions.entry || baseConfig?.entry,
1081
+ env: {
1082
+ ...baseConfig?.env,
1083
+ ...cliOptions.env
1084
+ }
1085
+ };
1086
+ }
1087
+ __name(mergeConfigWithOptions, "mergeConfigWithOptions");
1088
+
1089
+ // src/cli/commands/run.ts
1090
+ function registerRunCommands(program) {
1091
+ program.command("dev").description("Start the application in development mode with hot reload").option("-p, --port <port>", "Port to run the server on").option("-h, --host <host>", "Host to bind the server to").option("-e, --entry <entry>", "Entry file path").action(async (options) => {
1092
+ await runDev(options);
1093
+ });
1094
+ program.command("start").description("Start the application in production mode").option("-p, --port <port>", "Port to run the server on").option("-h, --host <host>", "Host to bind the server to").option("-e, --entry <entry>", "Entry file path").action(async (options) => {
1095
+ await runStart(options);
1096
+ });
1097
+ }
1098
+ __name(registerRunCommands, "registerRunCommands");
1099
+ async function runDev(options) {
1100
+ const kickConfig = await loadKickConfig();
1101
+ const config = mergeConfigWithOptions(kickConfig, options, "dev");
1102
+ const entryFile = config.entry;
1103
+ const cwd = process.cwd();
1104
+ const entryPath = import_node_path6.default.resolve(cwd, entryFile);
1105
+ if (!(0, import_node_fs3.existsSync)(entryPath)) {
1106
+ throw createError("ENTRY_FILE_NOT_FOUND", `Entry file not found: ${entryPath}`);
669
1107
  }
670
- if (config.generators) {
671
- normalized.generators = {
672
- controllerRoot: config.generators.controllerRoot ?? void 0
673
- };
1108
+ console.log(`\u{1F680} Starting development server...`);
1109
+ if (kickConfig.configPath) {
1110
+ console.log(`\u2699\uFE0F Config: ${import_node_path6.default.relative(cwd, kickConfig.configPath)}`);
1111
+ }
1112
+ console.log(`\u{1F4C1} Entry: ${entryFile}`);
1113
+ console.log(`\u{1F310} Port: ${config.port}`);
1114
+ console.log(`\u{1F3E0} Host: ${config.host}`);
1115
+ const runners = [
1116
+ {
1117
+ cmd: "tsx",
1118
+ args: [
1119
+ "watch",
1120
+ entryFile
1121
+ ]
1122
+ },
1123
+ {
1124
+ cmd: "ts-node-dev",
1125
+ args: [
1126
+ "--respawn",
1127
+ "--transpile-only",
1128
+ entryFile
1129
+ ]
1130
+ },
1131
+ {
1132
+ cmd: "ts-node",
1133
+ args: [
1134
+ entryFile
1135
+ ]
1136
+ }
1137
+ ];
1138
+ let runner = null;
1139
+ for (const r of runners) {
1140
+ if (await commandExists(r.cmd)) {
1141
+ runner = r;
1142
+ break;
1143
+ }
674
1144
  }
675
- if (config.structure) {
676
- normalized.structure = normalizeStructureConfig(config.structure);
1145
+ if (!runner) {
1146
+ throw createError("DEV_RUNNER_NOT_FOUND", "No development runner found. Please install one of: tsx, ts-node-dev, or ts-node\nnpm install --save-dev tsx\n# or\nnpm install --save-dev ts-node-dev\n# or\nnpm install --save-dev ts-node");
677
1147
  }
678
- return normalized;
1148
+ const env = {
1149
+ ...process.env,
1150
+ ...config.env,
1151
+ PORT: config.port?.toString(),
1152
+ HOST: config.host
1153
+ };
1154
+ console.log(`\u{1F527} Using runner: ${runner.cmd}`);
1155
+ const localBinPath = import_node_path6.default.resolve(cwd, "node_modules", ".bin", runner.cmd);
1156
+ const commandToRun = (0, import_node_fs3.existsSync)(localBinPath) ? localBinPath : runner.cmd;
1157
+ const child = (0, import_node_child_process.spawn)(commandToRun, runner.args, {
1158
+ stdio: "inherit",
1159
+ env,
1160
+ cwd
1161
+ });
1162
+ child.on("error", (error) => {
1163
+ console.error(`\u274C Failed to start development server: ${error.message}`);
1164
+ process.exit(1);
1165
+ });
1166
+ child.on("exit", (code) => {
1167
+ if (code !== 0) {
1168
+ console.error(`\u274C Development server exited with code ${code}`);
1169
+ process.exit(code || 1);
1170
+ }
1171
+ });
1172
+ process.on("SIGINT", () => {
1173
+ console.log("\n\u{1F6D1} Shutting down development server...");
1174
+ child.kill("SIGINT");
1175
+ });
1176
+ process.on("SIGTERM", () => {
1177
+ console.log("\n\u{1F6D1} Shutting down development server...");
1178
+ child.kill("SIGTERM");
1179
+ });
679
1180
  }
680
- __name(normalizeConfig, "normalizeConfig");
681
- function normalizeStructureConfig(raw) {
682
- return {
683
- domainRoot: raw.domainRoot ?? "src/domains",
684
- domainFolders: Array.isArray(raw.domainFolders) && raw.domainFolders.length > 0 ? [
685
- ...raw.domainFolders
686
- ] : [
687
- "controllers",
688
- "services",
689
- "domain"
690
- ],
691
- defaultDomain: raw.defaultDomain ?? "app"
1181
+ __name(runDev, "runDev");
1182
+ async function runStart(options) {
1183
+ const kickConfig = await loadKickConfig();
1184
+ const config = mergeConfigWithOptions(kickConfig, options, "start");
1185
+ const entryFile = config.entry;
1186
+ const cwd = process.cwd();
1187
+ const entryPath = import_node_path6.default.resolve(cwd, entryFile);
1188
+ if (!(0, import_node_fs3.existsSync)(entryPath)) {
1189
+ throw createError("ENTRY_FILE_NOT_FOUND", `Entry file not found: ${entryPath}
1190
+ Make sure to build your application first with: npm run build`);
1191
+ }
1192
+ console.log(`\u{1F680} Starting production server...`);
1193
+ if (kickConfig.configPath) {
1194
+ console.log(`\u2699\uFE0F Config: ${import_node_path6.default.relative(cwd, kickConfig.configPath)}`);
1195
+ }
1196
+ console.log(`\u{1F4C1} Entry: ${entryFile}`);
1197
+ console.log(`\u{1F310} Port: ${config.port}`);
1198
+ console.log(`\u{1F3E0} Host: ${config.host}`);
1199
+ const env = {
1200
+ ...process.env,
1201
+ ...config.env,
1202
+ PORT: config.port?.toString(),
1203
+ HOST: config.host
692
1204
  };
1205
+ const child = (0, import_node_child_process.spawn)("node", [
1206
+ entryFile
1207
+ ], {
1208
+ stdio: "inherit",
1209
+ env,
1210
+ cwd
1211
+ });
1212
+ child.on("error", (error) => {
1213
+ console.error(`\u274C Failed to start production server: ${error.message}`);
1214
+ process.exit(1);
1215
+ });
1216
+ child.on("exit", (code) => {
1217
+ if (code !== 0) {
1218
+ console.error(`\u274C Production server exited with code ${code}`);
1219
+ process.exit(code || 1);
1220
+ }
1221
+ });
1222
+ process.on("SIGINT", () => {
1223
+ console.log("\n\u{1F6D1} Shutting down production server...");
1224
+ child.kill("SIGINT");
1225
+ });
1226
+ process.on("SIGTERM", () => {
1227
+ console.log("\n\u{1F6D1} Shutting down production server...");
1228
+ child.kill("SIGTERM");
1229
+ });
693
1230
  }
694
- __name(normalizeStructureConfig, "normalizeStructureConfig");
1231
+ __name(runStart, "runStart");
1232
+ async function commandExists(command) {
1233
+ return new Promise((resolve) => {
1234
+ const localBinPath = import_node_path6.default.resolve(process.cwd(), "node_modules", ".bin", command);
1235
+ if ((0, import_node_fs3.existsSync)(localBinPath)) {
1236
+ resolve(true);
1237
+ return;
1238
+ }
1239
+ const child = (0, import_node_child_process.spawn)("which", [
1240
+ command
1241
+ ], {
1242
+ stdio: "ignore"
1243
+ });
1244
+ child.on("close", (code) => {
1245
+ resolve(code === 0);
1246
+ });
1247
+ child.on("error", () => {
1248
+ resolve(false);
1249
+ });
1250
+ });
1251
+ }
1252
+ __name(commandExists, "commandExists");
695
1253
 
696
1254
  // src/cli/utils/shell.ts
697
- var import_node_child_process = require("child_process");
1255
+ var import_node_child_process2 = require("child_process");
698
1256
  function runShellCommand(command, options = {}) {
699
1257
  return new Promise((resolve, reject) => {
700
- const child = (0, import_node_child_process.spawn)(command, {
1258
+ const child = (0, import_node_child_process2.spawn)(command, {
701
1259
  cwd: options.cwd,
702
1260
  stdio: "inherit",
703
1261
  shell: true
@@ -748,6 +1306,7 @@ async function main() {
748
1306
  controllerRoot: config?.generators?.controllerRoot,
749
1307
  structure: config?.structure
750
1308
  });
1309
+ registerRunCommands(program);
751
1310
  registerCustomCommands(program, config);
752
1311
  program.showHelpAfterError();
753
1312
  try {