@forinda/kickjs 0.2.0 → 1.5.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/package.json +50 -79
- package/README.md +0 -560
- package/dist/cli.js +0 -1324
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts +0 -613
- package/dist/index.js +0 -883
- package/dist/index.js.map +0 -1
package/dist/cli.js
DELETED
|
@@ -1,1324 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// src/cli/cli.ts
|
|
28
|
-
var import_commander = require("commander");
|
|
29
|
-
|
|
30
|
-
// package.json
|
|
31
|
-
var package_default = {
|
|
32
|
-
name: "@forinda/kickjs",
|
|
33
|
-
version: "0.2.0",
|
|
34
|
-
description: "Express + TypeScript + Inversify starter with reactive state, request telemetry, and Spring Boot-style decorators.",
|
|
35
|
-
main: "dist/index.js",
|
|
36
|
-
types: "dist/index.d.ts",
|
|
37
|
-
exports: {
|
|
38
|
-
".": {
|
|
39
|
-
require: "./dist/index.js",
|
|
40
|
-
types: "./dist/index.d.ts"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
files: [
|
|
44
|
-
"dist",
|
|
45
|
-
"LICENSE",
|
|
46
|
-
"README.md"
|
|
47
|
-
],
|
|
48
|
-
bin: {
|
|
49
|
-
kick: "dist/cli.js"
|
|
50
|
-
},
|
|
51
|
-
scripts: {
|
|
52
|
-
clean: "rm -rf dist",
|
|
53
|
-
dev: "tsup --watch src/index.ts",
|
|
54
|
-
check: "tsc --noEmit",
|
|
55
|
-
build: "tsup",
|
|
56
|
-
start: "node dist/index.js",
|
|
57
|
-
prepublishOnly: "npm run build && npm run check && npm test",
|
|
58
|
-
test: "vitest run",
|
|
59
|
-
"test:watch": "vitest",
|
|
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")"`
|
|
68
|
-
},
|
|
69
|
-
keywords: [
|
|
70
|
-
"express",
|
|
71
|
-
"typescript",
|
|
72
|
-
"inversify",
|
|
73
|
-
"decorators",
|
|
74
|
-
"starter"
|
|
75
|
-
],
|
|
76
|
-
author: "Felix Orinda",
|
|
77
|
-
license: "MIT",
|
|
78
|
-
engines: {
|
|
79
|
-
node: ">=20.0"
|
|
80
|
-
},
|
|
81
|
-
publishConfig: {
|
|
82
|
-
access: "public"
|
|
83
|
-
},
|
|
84
|
-
dependencies: {
|
|
85
|
-
commander: "^11.1.0"
|
|
86
|
-
},
|
|
87
|
-
peerDependencies: {
|
|
88
|
-
express: "^5.1.0",
|
|
89
|
-
inversify: "^7.10.0",
|
|
90
|
-
"reflect-metadata": "^0.2.2"
|
|
91
|
-
},
|
|
92
|
-
devDependencies: {
|
|
93
|
-
"@swc/core": "^1.7.28",
|
|
94
|
-
"@types/express": "^5.0.3",
|
|
95
|
-
"@types/node": "^24.5.2",
|
|
96
|
-
"@types/supertest": "^6.0.3",
|
|
97
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
98
|
-
express: "^5.1.0",
|
|
99
|
-
husky: "^9.1.7",
|
|
100
|
-
inversify: "^7.10.0",
|
|
101
|
-
joi: "^18.0.1",
|
|
102
|
-
"node-mocks-http": "^1.17.2",
|
|
103
|
-
"reflect-metadata": "^0.2.2",
|
|
104
|
-
supertest: "^7.1.4",
|
|
105
|
-
"ts-node": "^10.9.2",
|
|
106
|
-
"ts-node-dev": "^2.0.0",
|
|
107
|
-
tsup: "^8.5.0",
|
|
108
|
-
tsx: "^4.20.6",
|
|
109
|
-
typescript: "^5.9.2",
|
|
110
|
-
vitest: "^3.2.4",
|
|
111
|
-
zod: "^4.1.9"
|
|
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"
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// src/cli/tasks/init-project.ts
|
|
129
|
-
var import_node_path2 = __toESM(require("path"));
|
|
130
|
-
|
|
131
|
-
// src/cli/utils/fs.ts
|
|
132
|
-
var import_node_fs = require("fs");
|
|
133
|
-
var import_node_path = __toESM(require("path"));
|
|
134
|
-
async function ensureDirectory(target) {
|
|
135
|
-
await import_node_fs.promises.mkdir(target, {
|
|
136
|
-
recursive: true
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
__name(ensureDirectory, "ensureDirectory");
|
|
140
|
-
async function writeFileSafe(filePath, content, options = {}) {
|
|
141
|
-
const { force = false } = options;
|
|
142
|
-
try {
|
|
143
|
-
if (!force) {
|
|
144
|
-
await import_node_fs.promises.access(filePath);
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
} catch (error) {
|
|
148
|
-
}
|
|
149
|
-
await ensureDirectory(import_node_path.default.dirname(filePath));
|
|
150
|
-
await import_node_fs.promises.writeFile(filePath, content, "utf8");
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
__name(writeFileSafe, "writeFileSafe");
|
|
154
|
-
async function fileExists(filePath) {
|
|
155
|
-
try {
|
|
156
|
-
await import_node_fs.promises.access(filePath);
|
|
157
|
-
return true;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
__name(fileExists, "fileExists");
|
|
163
|
-
async function readJsonFile(filePath) {
|
|
164
|
-
try {
|
|
165
|
-
const raw = await import_node_fs.promises.readFile(filePath, "utf8");
|
|
166
|
-
return JSON.parse(raw);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
return void 0;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
__name(readJsonFile, "readJsonFile");
|
|
172
|
-
async function writeJsonFile(filePath, data, options = {}) {
|
|
173
|
-
await writeFileSafe(filePath, `${JSON.stringify(data, null, 2)}
|
|
174
|
-
`, options);
|
|
175
|
-
}
|
|
176
|
-
__name(writeJsonFile, "writeJsonFile");
|
|
177
|
-
|
|
178
|
-
// src/cli/tasks/init-project.ts
|
|
179
|
-
async function initProject(options) {
|
|
180
|
-
const targetDir = import_node_path2.default.resolve(process.cwd(), options.targetDirectory || ".");
|
|
181
|
-
const force = options.force ?? false;
|
|
182
|
-
const createdFiles = [];
|
|
183
|
-
const skippedFiles = [];
|
|
184
|
-
await ensureDirectory(targetDir);
|
|
185
|
-
const packageJsonPath = import_node_path2.default.join(targetDir, "package.json");
|
|
186
|
-
const packageJson = await readJsonFile(packageJsonPath) ?? {};
|
|
187
|
-
if (Object.keys(packageJson).length === 0) {
|
|
188
|
-
const name = options.packageName ?? (import_node_path2.default.basename(targetDir).replace(/[^a-zA-Z0-9-_]/g, "-") || "kick-app");
|
|
189
|
-
await writeJsonFile(packageJsonPath, {
|
|
190
|
-
name,
|
|
191
|
-
version: "1.0.0",
|
|
192
|
-
private: true,
|
|
193
|
-
type: "commonjs",
|
|
194
|
-
main: "dist/index.js",
|
|
195
|
-
scripts: {
|
|
196
|
-
dev: "kick dev",
|
|
197
|
-
build: "kick build",
|
|
198
|
-
start: "kick start",
|
|
199
|
-
typecheck: "tsc --noEmit",
|
|
200
|
-
clean: "rimraf dist"
|
|
201
|
-
},
|
|
202
|
-
dependencies: {
|
|
203
|
-
"@forinda/kickjs": "latest",
|
|
204
|
-
express: "^5.1.0",
|
|
205
|
-
inversify: "^7.10.0",
|
|
206
|
-
"reflect-metadata": "^0.2.2"
|
|
207
|
-
},
|
|
208
|
-
devDependencies: {
|
|
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"
|
|
219
|
-
}
|
|
220
|
-
}, {
|
|
221
|
-
force: true
|
|
222
|
-
});
|
|
223
|
-
createdFiles.push("package.json");
|
|
224
|
-
} else {
|
|
225
|
-
skippedFiles.push("package.json");
|
|
226
|
-
}
|
|
227
|
-
const tsconfigPath = import_node_path2.default.join(targetDir, "tsconfig.json");
|
|
228
|
-
const tsconfigExists = await fileExists(tsconfigPath);
|
|
229
|
-
if (!tsconfigExists || force) {
|
|
230
|
-
await writeJsonFile(tsconfigPath, {
|
|
231
|
-
compilerOptions: {
|
|
232
|
-
target: "ES2022",
|
|
233
|
-
module: "CommonJS",
|
|
234
|
-
moduleResolution: "node",
|
|
235
|
-
lib: [
|
|
236
|
-
"ES2022"
|
|
237
|
-
],
|
|
238
|
-
rootDir: "src",
|
|
239
|
-
outDir: "dist",
|
|
240
|
-
allowSyntheticDefaultImports: true,
|
|
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,
|
|
252
|
-
skipLibCheck: true,
|
|
253
|
-
resolveJsonModule: true,
|
|
254
|
-
experimentalDecorators: true,
|
|
255
|
-
emitDecoratorMetadata: true,
|
|
256
|
-
declaration: true,
|
|
257
|
-
declarationMap: true,
|
|
258
|
-
sourceMap: true
|
|
259
|
-
},
|
|
260
|
-
include: [
|
|
261
|
-
"src/**/*"
|
|
262
|
-
],
|
|
263
|
-
exclude: [
|
|
264
|
-
"node_modules",
|
|
265
|
-
"dist",
|
|
266
|
-
"**/*.test.ts",
|
|
267
|
-
"**/*.spec.ts"
|
|
268
|
-
]
|
|
269
|
-
}, {
|
|
270
|
-
force: true
|
|
271
|
-
});
|
|
272
|
-
createdFiles.push("tsconfig.json");
|
|
273
|
-
} else {
|
|
274
|
-
skippedFiles.push("tsconfig.json");
|
|
275
|
-
}
|
|
276
|
-
const mainFilePath = import_node_path2.default.join(targetDir, "src", "index.ts");
|
|
277
|
-
const mainCreated = await writeFileSafe(mainFilePath, `import 'reflect-metadata';
|
|
278
|
-
import express from 'express';
|
|
279
|
-
import { createKickAppWithConfig } from '@forinda/kickjs';
|
|
280
|
-
import { AppModule } from './app.module';
|
|
281
|
-
|
|
282
|
-
async function startApp() {
|
|
283
|
-
const app = express();
|
|
284
|
-
app.use(express.json());
|
|
285
|
-
|
|
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
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
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]
|
|
320
|
-
});
|
|
321
|
-
`, {
|
|
322
|
-
force
|
|
323
|
-
});
|
|
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
|
-
]) {
|
|
335
|
-
const folderPath = import_node_path2.default.join(domainBase, folder);
|
|
336
|
-
const exists = await fileExists(folderPath);
|
|
337
|
-
await ensureDirectory(folderPath);
|
|
338
|
-
const relativePath = import_node_path2.default.relative(targetDir, folderPath);
|
|
339
|
-
if (!exists) {
|
|
340
|
-
createdFiles.push(relativePath);
|
|
341
|
-
} else {
|
|
342
|
-
skippedFiles.push(relativePath);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
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';
|
|
354
|
-
|
|
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
|
-
});
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
`, {
|
|
393
|
-
force
|
|
394
|
-
});
|
|
395
|
-
const relativeControllerPath = import_node_path2.default.relative(targetDir, controllerPath);
|
|
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
|
-
`, {
|
|
436
|
-
force
|
|
437
|
-
});
|
|
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;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
export interface CreateUserRequest {
|
|
453
|
-
name: string;
|
|
454
|
-
email: string;
|
|
455
|
-
}
|
|
456
|
-
|
|
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'
|
|
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:*'
|
|
487
|
-
}
|
|
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
|
-
}
|
|
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");
|
|
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']
|
|
713
|
-
});
|
|
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
|
-
};
|
|
726
|
-
}
|
|
727
|
-
__name(initProject, "initProject");
|
|
728
|
-
|
|
729
|
-
// src/cli/commands/init.ts
|
|
730
|
-
function registerInitCommand(program, defaults = {}) {
|
|
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) => {
|
|
732
|
-
const targetDirectory = directory ?? ".";
|
|
733
|
-
console.log("\u{1F680} Initializing KickJS project...");
|
|
734
|
-
console.log(`\u{1F4C1} Target directory: ${targetDirectory}`);
|
|
735
|
-
const result = await initProject({
|
|
736
|
-
targetDirectory,
|
|
737
|
-
force: options.force,
|
|
738
|
-
packageName: options.name,
|
|
739
|
-
structure: defaults.structure
|
|
740
|
-
});
|
|
741
|
-
if (result.createdFiles.length > 0) {
|
|
742
|
-
console.log("\n\u2705 Created files:");
|
|
743
|
-
result.createdFiles.forEach((file) => console.log(` \u2713 ${file}`));
|
|
744
|
-
}
|
|
745
|
-
if (result.skippedFiles.length > 0) {
|
|
746
|
-
console.log("\n\u26A0\uFE0F Skipped existing files:");
|
|
747
|
-
result.skippedFiles.forEach((file) => console.log(` - ${file}`));
|
|
748
|
-
}
|
|
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");
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
__name(registerInitCommand, "registerInitCommand");
|
|
765
|
-
|
|
766
|
-
// src/cli/tasks/generate-controller.ts
|
|
767
|
-
var import_node_path3 = __toESM(require("path"));
|
|
768
|
-
var SUPPORTED_METHODS = [
|
|
769
|
-
"get",
|
|
770
|
-
"post",
|
|
771
|
-
"put",
|
|
772
|
-
"patch",
|
|
773
|
-
"delete"
|
|
774
|
-
];
|
|
775
|
-
async function generateController(options) {
|
|
776
|
-
const method = normalizeMethod(options.method);
|
|
777
|
-
const root = options.root ?? "src/http";
|
|
778
|
-
const rootPath = import_node_path3.default.isAbsolute(root) ? root : import_node_path3.default.join(process.cwd(), root);
|
|
779
|
-
const normalizedName = options.name.replace(/\\/g, "/");
|
|
780
|
-
const segments = normalizedName.split("/").filter(Boolean);
|
|
781
|
-
const fileSegment = segments.pop() ?? "index";
|
|
782
|
-
const relativeDir = segments.join("/");
|
|
783
|
-
const fileName = `${fileSegment}.${method}.controller.ts`;
|
|
784
|
-
const targetFile = import_node_path3.default.join(rootPath, relativeDir, fileName);
|
|
785
|
-
const className = buildClassName([
|
|
786
|
-
...segments,
|
|
787
|
-
fileSegment
|
|
788
|
-
], method);
|
|
789
|
-
const methodController = `${capitalize(method)}Controller`;
|
|
790
|
-
const template = buildTemplate({
|
|
791
|
-
className,
|
|
792
|
-
methodController,
|
|
793
|
-
method,
|
|
794
|
-
tags: options.tags
|
|
795
|
-
});
|
|
796
|
-
const created = await writeFileSafe(targetFile, template, {
|
|
797
|
-
force: options.force
|
|
798
|
-
});
|
|
799
|
-
return {
|
|
800
|
-
filePath: targetFile,
|
|
801
|
-
created
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
__name(generateController, "generateController");
|
|
805
|
-
function normalizeMethod(raw) {
|
|
806
|
-
const method = (raw ?? "get").toLowerCase();
|
|
807
|
-
if (!SUPPORTED_METHODS.includes(method)) {
|
|
808
|
-
throw new Error(`Unsupported method "${raw}". Supported methods: ${SUPPORTED_METHODS.join(", ")}`);
|
|
809
|
-
}
|
|
810
|
-
return method;
|
|
811
|
-
}
|
|
812
|
-
__name(normalizeMethod, "normalizeMethod");
|
|
813
|
-
function buildTemplate(params) {
|
|
814
|
-
const tagsBlock = params.tags && params.tags.length > 0 ? ` static tags = ${JSON.stringify(params.tags)};
|
|
815
|
-
|
|
816
|
-
` : "";
|
|
817
|
-
const requestType = params.method === "get" || params.method === "delete" ? "Request" : "Request";
|
|
818
|
-
return `import type { Request, Response } from 'express';
|
|
819
|
-
import { ${params.methodController} } from '@forinda/kickjs';
|
|
820
|
-
|
|
821
|
-
export default class ${params.className} extends ${params.methodController} {
|
|
822
|
-
${tagsBlock} handle(_req: ${requestType}, res: Response) {
|
|
823
|
-
return this.ok(res, { message: '${humanize(params.method)} ${params.className}' });
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
`;
|
|
827
|
-
}
|
|
828
|
-
__name(buildTemplate, "buildTemplate");
|
|
829
|
-
function humanize(method) {
|
|
830
|
-
return method.toUpperCase();
|
|
831
|
-
}
|
|
832
|
-
__name(humanize, "humanize");
|
|
833
|
-
function buildClassName(segments, method) {
|
|
834
|
-
const normalizedSegments = segments.map((segment) => segment.replace(/\.\.\./g, "Rest")).map((segment) => segment.replace(/\[(.+?)]/g, "$1")).flatMap((segment) => segment.split(/[^a-zA-Z0-9]+/g)).filter(Boolean).map(capitalize);
|
|
835
|
-
if (normalizedSegments.length === 0) {
|
|
836
|
-
normalizedSegments.push("Root");
|
|
837
|
-
}
|
|
838
|
-
normalizedSegments.push(capitalize(method), "Controller");
|
|
839
|
-
return normalizedSegments.join("");
|
|
840
|
-
}
|
|
841
|
-
__name(buildClassName, "buildClassName");
|
|
842
|
-
function capitalize(value) {
|
|
843
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
844
|
-
}
|
|
845
|
-
__name(capitalize, "capitalize");
|
|
846
|
-
|
|
847
|
-
// src/cli/tasks/generate-domain.ts
|
|
848
|
-
var import_node_path4 = __toESM(require("path"));
|
|
849
|
-
async function generateDomain(options) {
|
|
850
|
-
const structure = options.structure ?? {
|
|
851
|
-
domainRoot: "src/domains",
|
|
852
|
-
domainFolders: [
|
|
853
|
-
"controllers",
|
|
854
|
-
"services",
|
|
855
|
-
"domain"
|
|
856
|
-
],
|
|
857
|
-
defaultDomain: "app"
|
|
858
|
-
};
|
|
859
|
-
const domainRoot = structure.domainRoot ?? "src/domains";
|
|
860
|
-
const domainRootBase = import_node_path4.default.isAbsolute(domainRoot) ? domainRoot : import_node_path4.default.join(process.cwd(), domainRoot);
|
|
861
|
-
const folders = structure.domainFolders && structure.domainFolders.length > 0 ? structure.domainFolders : [
|
|
862
|
-
"controllers"
|
|
863
|
-
];
|
|
864
|
-
const targetRoot = import_node_path4.default.join(domainRootBase, options.name);
|
|
865
|
-
const createdFolders = [];
|
|
866
|
-
const existingFolders = [];
|
|
867
|
-
for (const folder of folders) {
|
|
868
|
-
const folderPath = import_node_path4.default.join(targetRoot, folder);
|
|
869
|
-
const alreadyExists = await fileExists(folderPath);
|
|
870
|
-
await ensureDirectory(folderPath);
|
|
871
|
-
if (alreadyExists) {
|
|
872
|
-
existingFolders.push(import_node_path4.default.relative(process.cwd(), folderPath));
|
|
873
|
-
} else {
|
|
874
|
-
createdFolders.push(import_node_path4.default.relative(process.cwd(), folderPath));
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
let controllerPath;
|
|
878
|
-
let controllerCreated;
|
|
879
|
-
if (options.withController !== false && folders.includes("controllers")) {
|
|
880
|
-
controllerPath = import_node_path4.default.join(targetRoot, "controllers", "index.get.controller.ts");
|
|
881
|
-
controllerCreated = await writeFileSafe(controllerPath, `import type { Request, Response } from 'express';
|
|
882
|
-
import { GetController } from '@forinda/kickjs';
|
|
883
|
-
|
|
884
|
-
export default class ${capitalize2(options.name)}IndexGetController extends GetController {
|
|
885
|
-
handle(_req: Request, res: Response) {
|
|
886
|
-
return this.ok(res, { domain: '${options.name}', message: 'Hello from ${options.name}' });
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
`, {
|
|
890
|
-
force: options.force
|
|
891
|
-
});
|
|
892
|
-
if (controllerCreated) {
|
|
893
|
-
createdFolders.push(import_node_path4.default.relative(process.cwd(), controllerPath));
|
|
894
|
-
} else if (controllerPath) {
|
|
895
|
-
existingFolders.push(import_node_path4.default.relative(process.cwd(), controllerPath));
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return {
|
|
899
|
-
root: targetRoot,
|
|
900
|
-
createdFolders,
|
|
901
|
-
existingFolders,
|
|
902
|
-
controllerPath,
|
|
903
|
-
controllerCreated
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
__name(generateDomain, "generateDomain");
|
|
907
|
-
function capitalize2(value) {
|
|
908
|
-
if (!value) {
|
|
909
|
-
return "Domain";
|
|
910
|
-
}
|
|
911
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
912
|
-
}
|
|
913
|
-
__name(capitalize2, "capitalize");
|
|
914
|
-
|
|
915
|
-
// src/cli/commands/generate-controller.ts
|
|
916
|
-
function registerGeneratorCommands(program, defaults = {}) {
|
|
917
|
-
const generate = program.command("generate").description("Generate Kick resources");
|
|
918
|
-
generate.command("domain <name>").description("Scaffold a domain folder with optional default files").option("-f, --force", "Overwrite existing generated files", false).option("--no-controller", "Do not create a default controller").action(async (name, options) => {
|
|
919
|
-
const result = await generateDomain({
|
|
920
|
-
name,
|
|
921
|
-
structure: defaults.structure,
|
|
922
|
-
force: options.force,
|
|
923
|
-
withController: options.controller
|
|
924
|
-
});
|
|
925
|
-
console.log(`Domain root: ${result.root}`);
|
|
926
|
-
if (result.createdFolders.length > 0) {
|
|
927
|
-
console.log(`Created:
|
|
928
|
-
- ${result.createdFolders.join("\n - ")}`);
|
|
929
|
-
}
|
|
930
|
-
if (result.existingFolders.length > 0) {
|
|
931
|
-
console.log(`Existing:
|
|
932
|
-
- ${result.existingFolders.join("\n - ")}`);
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
generate.command("controller <name>").description("Generate a file-system discovered controller").option("-m, --method <verb>", "HTTP verb to use (get, post, put, patch, delete)", "get").option("-r, --root <path>", "Root directory for generated controllers", defaults.controllerRoot ?? "src/http").option("-f, --force", "Overwrite the controller if it already exists", false).option("--tags <tags>", "Comma separated tags to assign to the controller").action(async (name, options) => {
|
|
936
|
-
const tags = options.tags ? options.tags.split(",").map((tag) => tag.trim()).filter(Boolean) : void 0;
|
|
937
|
-
const defaultRoot = computeDefaultControllerRoot(defaults, name);
|
|
938
|
-
const result = await generateController({
|
|
939
|
-
name,
|
|
940
|
-
method: options.method,
|
|
941
|
-
root: options.root ?? defaultRoot,
|
|
942
|
-
force: options.force,
|
|
943
|
-
tags
|
|
944
|
-
});
|
|
945
|
-
if (result.created) {
|
|
946
|
-
console.log(`Created controller at ${result.filePath}`);
|
|
947
|
-
} else {
|
|
948
|
-
console.log(`Controller already exists at ${result.filePath}`);
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
__name(registerGeneratorCommands, "registerGeneratorCommands");
|
|
953
|
-
function computeDefaultControllerRoot(defaults, name) {
|
|
954
|
-
if (defaults.controllerRoot) {
|
|
955
|
-
return defaults.controllerRoot;
|
|
956
|
-
}
|
|
957
|
-
const structure = defaults.structure;
|
|
958
|
-
if (!structure) {
|
|
959
|
-
return "src/http";
|
|
960
|
-
}
|
|
961
|
-
const domainRoot = structure.domainRoot ?? "src/domains";
|
|
962
|
-
const defaultDomain = structure.defaultDomain ?? "app";
|
|
963
|
-
if (name.includes("/")) {
|
|
964
|
-
const [maybeDomain] = name.split("/");
|
|
965
|
-
return `${domainRoot}/${maybeDomain}/controllers`;
|
|
966
|
-
}
|
|
967
|
-
return `${domainRoot}/${defaultDomain}/controllers`;
|
|
968
|
-
}
|
|
969
|
-
__name(computeDefaultControllerRoot, "computeDefaultControllerRoot");
|
|
970
|
-
|
|
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"));
|
|
975
|
-
|
|
976
|
-
// src/utils/errors.ts
|
|
977
|
-
var AppError = class extends Error {
|
|
978
|
-
static {
|
|
979
|
-
__name(this, "AppError");
|
|
980
|
-
}
|
|
981
|
-
code;
|
|
982
|
-
status;
|
|
983
|
-
details;
|
|
984
|
-
constructor(code, message, options = {}) {
|
|
985
|
-
super(message);
|
|
986
|
-
this.code = code;
|
|
987
|
-
this.status = options.status;
|
|
988
|
-
this.details = options.details;
|
|
989
|
-
if (options.cause) {
|
|
990
|
-
this.cause = options.cause;
|
|
991
|
-
}
|
|
992
|
-
this.name = "AppError";
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
function createError(code, message, options = {}) {
|
|
996
|
-
return new AppError(code, message, options);
|
|
997
|
-
}
|
|
998
|
-
__name(createError, "createError");
|
|
999
|
-
|
|
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 = [
|
|
1004
|
-
"kick.config.ts",
|
|
1005
|
-
"kick.config.js",
|
|
1006
|
-
"kick.config.mjs",
|
|
1007
|
-
"kickjs.config.ts",
|
|
1008
|
-
"kickjs.config.js",
|
|
1009
|
-
"kickjs.config.mjs"
|
|
1010
|
-
];
|
|
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
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
return getDefaultConfig();
|
|
1029
|
-
}
|
|
1030
|
-
__name(loadKickConfig, "loadKickConfig");
|
|
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"
|
|
1047
|
-
}
|
|
1048
|
-
},
|
|
1049
|
-
start: {
|
|
1050
|
-
port: 3e3,
|
|
1051
|
-
host: "0.0.0.0",
|
|
1052
|
-
entry: "dist/index.js",
|
|
1053
|
-
env: {
|
|
1054
|
-
NODE_ENV: "production"
|
|
1055
|
-
}
|
|
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}`);
|
|
1107
|
-
}
|
|
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
|
-
}
|
|
1144
|
-
}
|
|
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");
|
|
1147
|
-
}
|
|
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
|
-
});
|
|
1180
|
-
}
|
|
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
|
|
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
|
-
});
|
|
1230
|
-
}
|
|
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");
|
|
1253
|
-
|
|
1254
|
-
// src/cli/utils/shell.ts
|
|
1255
|
-
var import_node_child_process2 = require("child_process");
|
|
1256
|
-
function runShellCommand(command, options = {}) {
|
|
1257
|
-
return new Promise((resolve, reject) => {
|
|
1258
|
-
const child = (0, import_node_child_process2.spawn)(command, {
|
|
1259
|
-
cwd: options.cwd,
|
|
1260
|
-
stdio: "inherit",
|
|
1261
|
-
shell: true
|
|
1262
|
-
});
|
|
1263
|
-
child.on("exit", (code) => {
|
|
1264
|
-
if (code === 0) {
|
|
1265
|
-
resolve();
|
|
1266
|
-
} else {
|
|
1267
|
-
reject(new Error(`Command failed with exit code ${code}: ${command}`));
|
|
1268
|
-
}
|
|
1269
|
-
});
|
|
1270
|
-
child.on("error", (error) => {
|
|
1271
|
-
reject(error);
|
|
1272
|
-
});
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
__name(runShellCommand, "runShellCommand");
|
|
1276
|
-
|
|
1277
|
-
// src/cli/commands/custom.ts
|
|
1278
|
-
function registerCustomCommands(program, config) {
|
|
1279
|
-
if (!config?.commands) {
|
|
1280
|
-
return;
|
|
1281
|
-
}
|
|
1282
|
-
config.commands.forEach((command) => {
|
|
1283
|
-
const cmd = program.command(command.name).description(command.description ?? "Custom command defined in kick.config");
|
|
1284
|
-
cmd.action(async () => {
|
|
1285
|
-
if (!command.steps || command.steps.length === 0) {
|
|
1286
|
-
console.warn(`No steps defined for command "${command.name}".`);
|
|
1287
|
-
return;
|
|
1288
|
-
}
|
|
1289
|
-
for (const step of command.steps) {
|
|
1290
|
-
await runShellCommand(step);
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
__name(registerCustomCommands, "registerCustomCommands");
|
|
1296
|
-
|
|
1297
|
-
// src/cli/cli.ts
|
|
1298
|
-
async function main() {
|
|
1299
|
-
const program = new import_commander.Command();
|
|
1300
|
-
program.name("kick").description("Kick project CLI").version(package_default.version ?? "0.0.0");
|
|
1301
|
-
const config = await loadKickConfig(process.cwd());
|
|
1302
|
-
registerInitCommand(program, {
|
|
1303
|
-
structure: config?.structure
|
|
1304
|
-
});
|
|
1305
|
-
registerGeneratorCommands(program, {
|
|
1306
|
-
controllerRoot: config?.generators?.controllerRoot,
|
|
1307
|
-
structure: config?.structure
|
|
1308
|
-
});
|
|
1309
|
-
registerRunCommands(program);
|
|
1310
|
-
registerCustomCommands(program, config);
|
|
1311
|
-
program.showHelpAfterError();
|
|
1312
|
-
try {
|
|
1313
|
-
await program.parseAsync(process.argv);
|
|
1314
|
-
} catch (error) {
|
|
1315
|
-
console.error(error instanceof Error ? error.message : error);
|
|
1316
|
-
process.exitCode = 1;
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
__name(main, "main");
|
|
1320
|
-
main().catch((error) => {
|
|
1321
|
-
console.error(error instanceof Error ? error.message : error);
|
|
1322
|
-
process.exitCode = 1;
|
|
1323
|
-
});
|
|
1324
|
-
//# sourceMappingURL=cli.js.map
|