@forinda/kickjs 0.1.6 → 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/LICENSE +21 -0
- package/README.md +4 -10
- package/dist/cli.js +505 -218
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +16 -3
package/dist/cli.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_commander = require("commander");
|
|
|
30
30
|
// package.json
|
|
31
31
|
var package_default = {
|
|
32
32
|
name: "@forinda/kickjs",
|
|
33
|
-
version: "0.
|
|
33
|
+
version: "0.2.0",
|
|
34
34
|
description: "Express + TypeScript + Inversify starter with reactive state, request telemetry, and Spring Boot-style decorators.",
|
|
35
35
|
main: "dist/index.js",
|
|
36
36
|
types: "dist/index.d.ts",
|
|
@@ -73,7 +73,7 @@ var package_default = {
|
|
|
73
73
|
"decorators",
|
|
74
74
|
"starter"
|
|
75
75
|
],
|
|
76
|
-
author: "",
|
|
76
|
+
author: "Felix Orinda",
|
|
77
77
|
license: "MIT",
|
|
78
78
|
engines: {
|
|
79
79
|
node: ">=20.0"
|
|
@@ -109,7 +109,20 @@ var package_default = {
|
|
|
109
109
|
typescript: "^5.9.2",
|
|
110
110
|
vitest: "^3.2.4",
|
|
111
111
|
zod: "^4.1.9"
|
|
112
|
-
}
|
|
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"
|
|
113
126
|
};
|
|
114
127
|
|
|
115
128
|
// src/cli/tasks/init-project.ts
|
|
@@ -166,7 +179,6 @@ __name(writeJsonFile, "writeJsonFile");
|
|
|
166
179
|
async function initProject(options) {
|
|
167
180
|
const targetDir = import_node_path2.default.resolve(process.cwd(), options.targetDirectory || ".");
|
|
168
181
|
const force = options.force ?? false;
|
|
169
|
-
const structure = normalizeStructure(options.structure);
|
|
170
182
|
const createdFiles = [];
|
|
171
183
|
const skippedFiles = [];
|
|
172
184
|
await ensureDirectory(targetDir);
|
|
@@ -176,23 +188,34 @@ async function initProject(options) {
|
|
|
176
188
|
const name = options.packageName ?? (import_node_path2.default.basename(targetDir).replace(/[^a-zA-Z0-9-_]/g, "-") || "kick-app");
|
|
177
189
|
await writeJsonFile(packageJsonPath, {
|
|
178
190
|
name,
|
|
179
|
-
version: "
|
|
191
|
+
version: "1.0.0",
|
|
180
192
|
private: true,
|
|
181
193
|
type: "commonjs",
|
|
194
|
+
main: "dist/index.js",
|
|
182
195
|
scripts: {
|
|
183
|
-
dev: "
|
|
184
|
-
build: "
|
|
185
|
-
start: "
|
|
186
|
-
|
|
196
|
+
dev: "kick dev",
|
|
197
|
+
build: "kick build",
|
|
198
|
+
start: "kick start",
|
|
199
|
+
typecheck: "tsc --noEmit",
|
|
200
|
+
clean: "rimraf dist"
|
|
187
201
|
},
|
|
188
202
|
dependencies: {
|
|
189
|
-
"@forinda/kickjs": "latest"
|
|
203
|
+
"@forinda/kickjs": "latest",
|
|
204
|
+
express: "^5.1.0",
|
|
205
|
+
inversify: "^7.10.0",
|
|
206
|
+
"reflect-metadata": "^0.2.2"
|
|
190
207
|
},
|
|
191
208
|
devDependencies: {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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"
|
|
196
219
|
}
|
|
197
220
|
}, {
|
|
198
221
|
force: true
|
|
@@ -206,23 +229,42 @@ async function initProject(options) {
|
|
|
206
229
|
if (!tsconfigExists || force) {
|
|
207
230
|
await writeJsonFile(tsconfigPath, {
|
|
208
231
|
compilerOptions: {
|
|
209
|
-
target: "
|
|
210
|
-
module: "
|
|
232
|
+
target: "ES2022",
|
|
233
|
+
module: "CommonJS",
|
|
211
234
|
moduleResolution: "node",
|
|
212
235
|
lib: [
|
|
213
|
-
"
|
|
236
|
+
"ES2022"
|
|
214
237
|
],
|
|
215
238
|
rootDir: "src",
|
|
216
239
|
outDir: "dist",
|
|
217
|
-
|
|
240
|
+
allowSyntheticDefaultImports: true,
|
|
218
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,
|
|
219
252
|
skipLibCheck: true,
|
|
220
253
|
resolveJsonModule: true,
|
|
221
254
|
experimentalDecorators: true,
|
|
222
|
-
emitDecoratorMetadata: true
|
|
255
|
+
emitDecoratorMetadata: true,
|
|
256
|
+
declaration: true,
|
|
257
|
+
declarationMap: true,
|
|
258
|
+
sourceMap: true
|
|
223
259
|
},
|
|
224
260
|
include: [
|
|
225
|
-
"src"
|
|
261
|
+
"src/**/*"
|
|
262
|
+
],
|
|
263
|
+
exclude: [
|
|
264
|
+
"node_modules",
|
|
265
|
+
"dist",
|
|
266
|
+
"**/*.test.ts",
|
|
267
|
+
"**/*.spec.ts"
|
|
226
268
|
]
|
|
227
269
|
}, {
|
|
228
270
|
force: true
|
|
@@ -231,140 +273,465 @@ async function initProject(options) {
|
|
|
231
273
|
} else {
|
|
232
274
|
skippedFiles.push("tsconfig.json");
|
|
233
275
|
}
|
|
234
|
-
const mainFilePath = import_node_path2.default.join(targetDir, "src", "
|
|
276
|
+
const mainFilePath = import_node_path2.default.join(targetDir, "src", "index.ts");
|
|
235
277
|
const mainCreated = await writeFileSafe(mainFilePath, `import 'reflect-metadata';
|
|
236
|
-
import
|
|
278
|
+
import express from 'express';
|
|
279
|
+
import { createKickAppWithConfig } from '@forinda/kickjs';
|
|
280
|
+
import { AppModule } from './app.module';
|
|
237
281
|
|
|
238
|
-
|
|
282
|
+
async function startApp() {
|
|
283
|
+
const app = express();
|
|
284
|
+
app.use(express.json());
|
|
239
285
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
+
});
|
|
244
298
|
}
|
|
245
299
|
|
|
246
|
-
|
|
247
|
-
console.error('Failed to
|
|
248
|
-
process.
|
|
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]
|
|
249
320
|
});
|
|
250
321
|
`, {
|
|
251
322
|
force
|
|
252
323
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
+
]) {
|
|
256
335
|
const folderPath = import_node_path2.default.join(domainBase, folder);
|
|
257
336
|
const exists = await fileExists(folderPath);
|
|
258
337
|
await ensureDirectory(folderPath);
|
|
259
338
|
const relativePath = import_node_path2.default.relative(targetDir, folderPath);
|
|
260
|
-
if (exists) {
|
|
261
|
-
skippedFiles.push(relativePath);
|
|
262
|
-
} else {
|
|
339
|
+
if (!exists) {
|
|
263
340
|
createdFiles.push(relativePath);
|
|
341
|
+
} else {
|
|
342
|
+
skippedFiles.push(relativePath);
|
|
264
343
|
}
|
|
265
344
|
}
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
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';
|
|
270
354
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
+
});
|
|
274
390
|
}
|
|
275
391
|
}
|
|
276
392
|
`, {
|
|
277
393
|
force
|
|
278
394
|
});
|
|
279
395
|
const relativeControllerPath = import_node_path2.default.relative(targetDir, controllerPath);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
`, {
|
|
291
436
|
force
|
|
292
437
|
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
createdFiles
|
|
296
|
-
|
|
297
|
-
|
|
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;
|
|
298
450
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
domainFolders: structure?.domainFolders && structure.domainFolders.length > 0 ? [
|
|
304
|
-
...structure.domainFolders
|
|
305
|
-
] : [
|
|
306
|
-
"controllers",
|
|
307
|
-
"services",
|
|
308
|
-
"domain"
|
|
309
|
-
],
|
|
310
|
-
defaultDomain: structure?.defaultDomain ?? "app"
|
|
311
|
-
};
|
|
451
|
+
|
|
452
|
+
export interface CreateUserRequest {
|
|
453
|
+
name: string;
|
|
454
|
+
email: string;
|
|
312
455
|
}
|
|
313
|
-
__name(normalizeStructure, "normalizeStructure");
|
|
314
|
-
function buildConfigFile(structure) {
|
|
315
|
-
const controllerRoot = `${structure.domainRoot}/${structure.defaultDomain}/controllers`;
|
|
316
|
-
const structureSnippet = JSON.stringify(structure, null, 2).split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
|
|
317
|
-
return `import type { KickConfig } from '@forinda/kickjs';
|
|
318
|
-
|
|
319
|
-
const config: KickConfig = {
|
|
320
|
-
structure: ${structureSnippet},
|
|
321
|
-
generators: {
|
|
322
|
-
controllerRoot: '${controllerRoot}'
|
|
323
|
-
},
|
|
324
|
-
commands: [
|
|
325
|
-
{
|
|
326
|
-
name: 'dev',
|
|
327
|
-
description: 'Run the Kick dev server',
|
|
328
|
-
steps: 'npm run dev'
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
};
|
|
332
456
|
|
|
333
|
-
export
|
|
334
|
-
|
|
457
|
+
export interface UserResponse {
|
|
458
|
+
user: User;
|
|
459
|
+
requestId: string;
|
|
335
460
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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'
|
|
478
|
+
},
|
|
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:*'
|
|
352
487
|
}
|
|
353
488
|
},
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
489
|
+
start: {
|
|
490
|
+
port: 3000,
|
|
491
|
+
host: '0.0.0.0',
|
|
492
|
+
entry: 'dist/index.js',
|
|
493
|
+
env: {
|
|
494
|
+
NODE_ENV: 'production'
|
|
495
|
+
}
|
|
496
|
+
}
|
|
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*
|
|
513
|
+
|
|
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");
|
|
358
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']
|
|
359
713
|
});
|
|
360
|
-
|
|
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
|
+
};
|
|
361
726
|
}
|
|
362
|
-
__name(
|
|
727
|
+
__name(initProject, "initProject");
|
|
363
728
|
|
|
364
729
|
// src/cli/commands/init.ts
|
|
365
730
|
function registerInitCommand(program, defaults = {}) {
|
|
366
|
-
program.command("init [directory]").description("Scaffold a new
|
|
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) => {
|
|
367
732
|
const targetDirectory = directory ?? ".";
|
|
733
|
+
console.log("\u{1F680} Initializing KickJS project...");
|
|
734
|
+
console.log(`\u{1F4C1} Target directory: ${targetDirectory}`);
|
|
368
735
|
const result = await initProject({
|
|
369
736
|
targetDirectory,
|
|
370
737
|
force: options.force,
|
|
@@ -372,14 +739,26 @@ function registerInitCommand(program, defaults = {}) {
|
|
|
372
739
|
structure: defaults.structure
|
|
373
740
|
});
|
|
374
741
|
if (result.createdFiles.length > 0) {
|
|
375
|
-
console.log(
|
|
376
|
-
|
|
742
|
+
console.log("\n\u2705 Created files:");
|
|
743
|
+
result.createdFiles.forEach((file) => console.log(` \u2713 ${file}`));
|
|
377
744
|
}
|
|
378
745
|
if (result.skippedFiles.length > 0) {
|
|
379
|
-
console.log(
|
|
380
|
-
|
|
746
|
+
console.log("\n\u26A0\uFE0F Skipped existing files:");
|
|
747
|
+
result.skippedFiles.forEach((file) => console.log(` - ${file}`));
|
|
381
748
|
}
|
|
382
|
-
console.log(
|
|
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");
|
|
383
762
|
});
|
|
384
763
|
}
|
|
385
764
|
__name(registerInitCommand, "registerInitCommand");
|
|
@@ -686,12 +1065,14 @@ function getDefaultConfig() {
|
|
|
686
1065
|
},
|
|
687
1066
|
generators: {
|
|
688
1067
|
controllerRoot: "src/domains/app/controllers"
|
|
689
|
-
}
|
|
1068
|
+
},
|
|
1069
|
+
commands: []
|
|
690
1070
|
};
|
|
691
1071
|
}
|
|
692
1072
|
__name(getDefaultConfig, "getDefaultConfig");
|
|
693
1073
|
function mergeConfigWithOptions(config, cliOptions, command) {
|
|
694
|
-
const
|
|
1074
|
+
const defaultConfig = getDefaultConfig();
|
|
1075
|
+
const baseConfig = command === "dev" ? config.dev || defaultConfig.dev : config.start || defaultConfig.start;
|
|
695
1076
|
return {
|
|
696
1077
|
...baseConfig,
|
|
697
1078
|
port: cliOptions.port ? parseInt(cliOptions.port) : baseConfig?.port,
|
|
@@ -870,100 +1251,6 @@ async function commandExists(command) {
|
|
|
870
1251
|
}
|
|
871
1252
|
__name(commandExists, "commandExists");
|
|
872
1253
|
|
|
873
|
-
// src/cli/config.ts
|
|
874
|
-
var import_node_fs4 = require("fs");
|
|
875
|
-
var import_node_path7 = __toESM(require("path"));
|
|
876
|
-
var CONFIG_FILE_CANDIDATES = [
|
|
877
|
-
"kick.config.ts",
|
|
878
|
-
"kick.config.js",
|
|
879
|
-
"kick.config.mjs",
|
|
880
|
-
"kick.config.cjs",
|
|
881
|
-
"kick.config.json"
|
|
882
|
-
];
|
|
883
|
-
var tsNodeRegistered = false;
|
|
884
|
-
async function loadKickConfig2(cwd = process.cwd()) {
|
|
885
|
-
for (const file of CONFIG_FILE_CANDIDATES) {
|
|
886
|
-
const absolute = import_node_path7.default.join(cwd, file);
|
|
887
|
-
if (!(0, import_node_fs4.existsSync)(absolute)) {
|
|
888
|
-
continue;
|
|
889
|
-
}
|
|
890
|
-
if (file.endsWith(".json")) {
|
|
891
|
-
const raw = await import_node_fs4.promises.readFile(absolute, "utf8");
|
|
892
|
-
return normalizeConfig(JSON.parse(raw));
|
|
893
|
-
}
|
|
894
|
-
if (file.endsWith(".ts")) {
|
|
895
|
-
ensureTsNode();
|
|
896
|
-
}
|
|
897
|
-
const loaded = require(absolute);
|
|
898
|
-
const config = loaded?.default ?? loaded;
|
|
899
|
-
return normalizeConfig(config);
|
|
900
|
-
}
|
|
901
|
-
return void 0;
|
|
902
|
-
}
|
|
903
|
-
__name(loadKickConfig2, "loadKickConfig");
|
|
904
|
-
function ensureTsNode() {
|
|
905
|
-
if (tsNodeRegistered) {
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
try {
|
|
909
|
-
require("ts-node/register");
|
|
910
|
-
tsNodeRegistered = true;
|
|
911
|
-
} catch (error) {
|
|
912
|
-
throw createError("TS_NODE_REQUIRED", "Custom CLI config requires ts-node for TypeScript configuration files.");
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
__name(ensureTsNode, "ensureTsNode");
|
|
916
|
-
function normalizeConfig(raw) {
|
|
917
|
-
if (!raw || typeof raw !== "object") {
|
|
918
|
-
throw createError("INVALID_CLI_CONFIG", "kick.config must export an object");
|
|
919
|
-
}
|
|
920
|
-
const config = raw;
|
|
921
|
-
const normalized = {};
|
|
922
|
-
if (Array.isArray(config.commands)) {
|
|
923
|
-
normalized.commands = config.commands.map((command) => {
|
|
924
|
-
if (!command || typeof command !== "object") {
|
|
925
|
-
throw createError("INVALID_CLI_COMMAND", "Command entries must be objects");
|
|
926
|
-
}
|
|
927
|
-
if (!command.name) {
|
|
928
|
-
throw createError("INVALID_CLI_COMMAND", "Command entries must include a name");
|
|
929
|
-
}
|
|
930
|
-
return {
|
|
931
|
-
name: command.name,
|
|
932
|
-
description: command.description,
|
|
933
|
-
steps: Array.isArray(command.steps) ? [
|
|
934
|
-
...command.steps
|
|
935
|
-
] : command.steps ? [
|
|
936
|
-
command.steps
|
|
937
|
-
] : []
|
|
938
|
-
};
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
if (config.generators) {
|
|
942
|
-
normalized.generators = {
|
|
943
|
-
controllerRoot: config.generators.controllerRoot ?? void 0
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
if (config.structure) {
|
|
947
|
-
normalized.structure = normalizeStructureConfig(config.structure);
|
|
948
|
-
}
|
|
949
|
-
return normalized;
|
|
950
|
-
}
|
|
951
|
-
__name(normalizeConfig, "normalizeConfig");
|
|
952
|
-
function normalizeStructureConfig(raw) {
|
|
953
|
-
return {
|
|
954
|
-
domainRoot: raw.domainRoot ?? "src/domains",
|
|
955
|
-
domainFolders: Array.isArray(raw.domainFolders) && raw.domainFolders.length > 0 ? [
|
|
956
|
-
...raw.domainFolders
|
|
957
|
-
] : [
|
|
958
|
-
"controllers",
|
|
959
|
-
"services",
|
|
960
|
-
"domain"
|
|
961
|
-
],
|
|
962
|
-
defaultDomain: raw.defaultDomain ?? "app"
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
__name(normalizeStructureConfig, "normalizeStructureConfig");
|
|
966
|
-
|
|
967
1254
|
// src/cli/utils/shell.ts
|
|
968
1255
|
var import_node_child_process2 = require("child_process");
|
|
969
1256
|
function runShellCommand(command, options = {}) {
|
|
@@ -1011,7 +1298,7 @@ __name(registerCustomCommands, "registerCustomCommands");
|
|
|
1011
1298
|
async function main() {
|
|
1012
1299
|
const program = new import_commander.Command();
|
|
1013
1300
|
program.name("kick").description("Kick project CLI").version(package_default.version ?? "0.0.0");
|
|
1014
|
-
const config = await
|
|
1301
|
+
const config = await loadKickConfig(process.cwd());
|
|
1015
1302
|
registerInitCommand(program, {
|
|
1016
1303
|
structure: config?.structure
|
|
1017
1304
|
});
|