kastrick 1.0.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.
Files changed (57) hide show
  1. package/README.md +38 -0
  2. package/examples/01-hello-world/api/hello.ts +19 -0
  3. package/examples/02-users-api/README.md +39 -0
  4. package/examples/02-users-api/api/users/[id].ts +80 -0
  5. package/examples/02-users-api/api/users/index.ts +50 -0
  6. package/examples/03-configuration/README.md +39 -0
  7. package/examples/03-configuration/kastrick.config.json +22 -0
  8. package/examples/03-configuration/tsconfig.json +20 -0
  9. package/examples/README.md +48 -0
  10. package/lib/cli/compile.d.ts +5 -0
  11. package/lib/cli/compile.d.ts.map +1 -0
  12. package/lib/cli/compile.js +25 -0
  13. package/lib/cli/compile.js.map +1 -0
  14. package/lib/cli/dev.d.ts +5 -0
  15. package/lib/cli/dev.d.ts.map +1 -0
  16. package/lib/cli/dev.js +79 -0
  17. package/lib/cli/dev.js.map +1 -0
  18. package/lib/cli/index.d.ts +3 -0
  19. package/lib/cli/index.d.ts.map +1 -0
  20. package/lib/cli/index.js +63 -0
  21. package/lib/cli/index.js.map +1 -0
  22. package/lib/cli/serve.d.ts +5 -0
  23. package/lib/cli/serve.d.ts.map +1 -0
  24. package/lib/cli/serve.js +106 -0
  25. package/lib/cli/serve.js.map +1 -0
  26. package/lib/core/compiler.d.ts +29 -0
  27. package/lib/core/compiler.d.ts.map +1 -0
  28. package/lib/core/compiler.js +153 -0
  29. package/lib/core/compiler.js.map +1 -0
  30. package/lib/core/router.d.ts +31 -0
  31. package/lib/core/router.d.ts.map +1 -0
  32. package/lib/core/router.js +106 -0
  33. package/lib/core/router.js.map +1 -0
  34. package/lib/core/scanner.d.ts +29 -0
  35. package/lib/core/scanner.d.ts.map +1 -0
  36. package/lib/core/scanner.js +88 -0
  37. package/lib/core/scanner.js.map +1 -0
  38. package/lib/index.d.ts +12 -0
  39. package/lib/index.d.ts.map +1 -0
  40. package/lib/index.js +35 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/server/expressServer.d.ts +28 -0
  43. package/lib/server/expressServer.d.ts.map +1 -0
  44. package/lib/server/expressServer.js +96 -0
  45. package/lib/server/expressServer.js.map +1 -0
  46. package/package.json +34 -0
  47. package/src/cli/compile.ts +27 -0
  48. package/src/cli/dev.ts +49 -0
  49. package/src/cli/index.ts +64 -0
  50. package/src/cli/serve.ts +81 -0
  51. package/src/core/compiler.ts +147 -0
  52. package/src/core/router.ts +88 -0
  53. package/src/core/scanner.ts +72 -0
  54. package/src/index.ts +38 -0
  55. package/src/server/expressServer.ts +107 -0
  56. package/templates/tsconfig.json +20 -0
  57. package/tsconfig.json +20 -0
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Kastrick
2
+
3
+ A simple API logic package for handling API requests and responses.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install kastrick
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import ApiHandler from 'kastrick';
15
+
16
+ const api = new ApiHandler('https://api.example.com');
17
+ const response = await api.request('/users', { method: 'GET' });
18
+
19
+ if (response.success) {
20
+ console.log(response.data);
21
+ } else {
22
+ console.error(response.error);
23
+ }
24
+ ```
25
+
26
+ ## Development
27
+
28
+ ```bash
29
+ # Build
30
+ npm run build
31
+
32
+ # Watch mode
33
+ npm run dev
34
+ ```
35
+
36
+ ## License
37
+
38
+ ISC
@@ -0,0 +1,19 @@
1
+ export function GET(req: any) {
2
+ return {
3
+ status: 200,
4
+ body: {
5
+ message: "Hello World!",
6
+ timestamp: new Date().toISOString()
7
+ }
8
+ };
9
+ }
10
+
11
+ export function POST(req: any) {
12
+ return {
13
+ status: 201,
14
+ body: {
15
+ message: "Hello from POST",
16
+ received: req.body
17
+ }
18
+ };
19
+ }
@@ -0,0 +1,39 @@
1
+ # Users Example
2
+
3
+ This example shows how to create dynamic routes with parameters.
4
+
5
+ ## Routes Created
6
+
7
+ - `GET /users` — List all users
8
+ - `POST /users` — Create a user
9
+ - `GET /users/:id` — Get specific user
10
+ - `PUT /users/:id` — Update a user
11
+ - `DELETE /users/:id` — Delete a user
12
+
13
+ ## File Structure
14
+
15
+ ```
16
+ api/
17
+ users/
18
+ index.ts → /users
19
+ [id].ts → /users/:id
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```bash
25
+ # GET all users
26
+ curl http://localhost:3000/users
27
+
28
+ # Create user
29
+ curl -X POST http://localhost:3000/users -d '{"name":"Kate"}' -H "Content-Type: application/json"
30
+
31
+ # Get user by ID
32
+ curl http://localhost:3000/users/1
33
+
34
+ # Update user
35
+ curl -X PUT http://localhost:3000/users/1 -d '{"name":"Updated"}' -H "Content-Type: application/json"
36
+
37
+ # Delete user
38
+ curl -X DELETE http://localhost:3000/users/1
39
+ ```
@@ -0,0 +1,80 @@
1
+ interface User {
2
+ id: number;
3
+ name: string;
4
+ email: string;
5
+ }
6
+
7
+ // Mock database (shared with index.ts in real scenario)
8
+ let users: User[] = [
9
+ { id: 1, name: "Kate", email: "kate@example.com" },
10
+ { id: 2, name: "Dev", email: "dev@example.com" }
11
+ ];
12
+
13
+ export function GET(req: any, context: any) {
14
+ const { id } = context.params;
15
+ const user = users.find(u => u.id === parseInt(id));
16
+
17
+ if (!user) {
18
+ return {
19
+ status: 404,
20
+ body: {
21
+ error: "User not found"
22
+ }
23
+ };
24
+ }
25
+
26
+ return {
27
+ status: 200,
28
+ body: user
29
+ };
30
+ }
31
+
32
+ export function PUT(req: any, context: any) {
33
+ const { id } = context.params;
34
+ const { name, email } = req.body;
35
+ const user = users.find(u => u.id === parseInt(id));
36
+
37
+ if (!user) {
38
+ return {
39
+ status: 404,
40
+ body: {
41
+ error: "User not found"
42
+ }
43
+ };
44
+ }
45
+
46
+ if (name) user.name = name;
47
+ if (email) user.email = email;
48
+
49
+ return {
50
+ status: 200,
51
+ body: {
52
+ message: "User updated",
53
+ user
54
+ }
55
+ };
56
+ }
57
+
58
+ export function DELETE(req: any, context: any) {
59
+ const { id } = context.params;
60
+ const index = users.findIndex(u => u.id === parseInt(id));
61
+
62
+ if (index === -1) {
63
+ return {
64
+ status: 404,
65
+ body: {
66
+ error: "User not found"
67
+ }
68
+ };
69
+ }
70
+
71
+ const [deletedUser] = users.splice(index, 1);
72
+
73
+ return {
74
+ status: 200,
75
+ body: {
76
+ message: "User deleted",
77
+ user: deletedUser
78
+ }
79
+ };
80
+ }
@@ -0,0 +1,50 @@
1
+ interface User {
2
+ id: number;
3
+ name: string;
4
+ email: string;
5
+ }
6
+
7
+ // Mock database
8
+ let users: User[] = [
9
+ { id: 1, name: "Kate", email: "kate@example.com" },
10
+ { id: 2, name: "Dev", email: "dev@example.com" }
11
+ ];
12
+
13
+ export function GET(req: any) {
14
+ return {
15
+ status: 200,
16
+ body: {
17
+ users,
18
+ total: users.length
19
+ }
20
+ };
21
+ }
22
+
23
+ export function POST(req: any) {
24
+ const { name, email } = req.body;
25
+
26
+ if (!name || !email) {
27
+ return {
28
+ status: 400,
29
+ body: {
30
+ error: "name and email required"
31
+ }
32
+ };
33
+ }
34
+
35
+ const newUser: User = {
36
+ id: Math.max(...users.map(u => u.id), 0) + 1,
37
+ name,
38
+ email
39
+ };
40
+
41
+ users.push(newUser);
42
+
43
+ return {
44
+ status: 201,
45
+ body: {
46
+ message: "User created",
47
+ user: newUser
48
+ }
49
+ };
50
+ }
@@ -0,0 +1,39 @@
1
+ # Configuration Example
2
+
3
+ Shows how to configure a kastrick API project.
4
+
5
+ ## kastrick.config.json
6
+
7
+ Main config file for your API project with options for:
8
+
9
+ - **apiDir** — Where API files are located (default: `./api`)
10
+ - **outputDir** — Compiled output directory (default: `./output`)
11
+ - **devPort** — Port for dev server (default: `3000`)
12
+ - **environment** — `development` or `production`
13
+ - **middleware** — Enable/configure Express middleware
14
+ - **headers** — Custom headers to add to all responses
15
+ - **logging** — Logging configuration
16
+
17
+ ## tsconfig.json
18
+
19
+ Custom TypeScript configuration. Kastrick provides defaults but you can override:
20
+
21
+ - **target** — JavaScript target version
22
+ - **strict** — Enable strict type checking
23
+ - **rootDir** — API source directory
24
+ - **outDir** — Compiled output directory
25
+
26
+ ## Usage
27
+
28
+ ```bash
29
+ # Dev mode with custom config
30
+ npx kastrick dev
31
+
32
+ # Compile with custom config
33
+ npx kastrick compile
34
+
35
+ # Serve with custom config
36
+ npx kastrick serve 3000
37
+ ```
38
+
39
+ Kastrick automatically reads both config files if present!
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "my-api",
3
+ "version": "1.0.0",
4
+ "apiDir": "./api",
5
+ "outputDir": "./output",
6
+ "devPort": 3000,
7
+ "environment": "development",
8
+ "middleware": {
9
+ "cors": true,
10
+ "bodyParser": {
11
+ "limit": "10mb"
12
+ }
13
+ },
14
+ "headers": {
15
+ "X-API-Version": "1.0.0",
16
+ "X-Powered-By": "kastrick"
17
+ },
18
+ "logging": {
19
+ "enabled": true,
20
+ "level": "info"
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "rootDir": "./api",
7
+ "outDir": "./output",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "resolveJsonModule": true,
16
+ "moduleResolution": "node"
17
+ },
18
+ "include": ["api/**/*"],
19
+ "exclude": ["node_modules", "output"]
20
+ }
@@ -0,0 +1,48 @@
1
+ # Kastrick Examples
2
+
3
+ Clean examples of how developers use kastrick to build APIs.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ mkdir my-api
9
+ cd my-api
10
+ npm init -y
11
+ npm install kastrick
12
+ npx kastrick --version
13
+ ```
14
+
15
+ ## Project Structure
16
+
17
+ ```
18
+ my-api/
19
+ api/
20
+ hello.ts
21
+ users/
22
+ index.ts
23
+ [id].ts
24
+ kastrick.config.json
25
+ tsconfig.json (optional - kastrick provides defaults)
26
+ package.json
27
+ ```
28
+
29
+ ## Running
30
+
31
+ ```bash
32
+ # Dev mode (auto-compile + hot reload)
33
+ npx kastrick dev
34
+
35
+ # Compile only
36
+ npx kastrick compile
37
+
38
+ # Serve compiled output
39
+ npx kastrick serve 3000
40
+ ```
41
+
42
+ ## Examples Included
43
+
44
+ - **Basic Route** — `hello.ts` - Simple GET endpoint
45
+ - **Users API** — Dynamic routes with parameters
46
+ - **Configuration** — Setting up your API with config file
47
+
48
+ See each folder for complete examples!
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Compile command - builds the /output folder
3
+ */
4
+ export declare function compile(rootDir?: string): Promise<void>;
5
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cli/compile.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAsB,OAAO,CAAC,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB5E"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compile = compile;
4
+ const scanner_1 = require("../core/scanner");
5
+ const compiler_1 = require("../core/compiler");
6
+ /**
7
+ * Compile command - builds the /output folder
8
+ */
9
+ async function compile(rootDir = process.cwd()) {
10
+ console.log("🔨 Compiling kastrick project...\n");
11
+ const scanner = new scanner_1.Scanner(rootDir);
12
+ const compiler = new compiler_1.Compiler(rootDir);
13
+ // Scan API folder
14
+ const files = scanner.scanApiFolder();
15
+ if (files.length === 0) {
16
+ console.log("⚠️ No API files found. Create files in /api folder first.");
17
+ return;
18
+ }
19
+ console.log(`📁 Found ${files.length} API files`);
20
+ files.forEach((f) => console.log(` - ${f.relativePath}`));
21
+ console.log();
22
+ // Compile
23
+ compiler.compile(files);
24
+ }
25
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/cli/compile.ts"],"names":[],"mappings":";;AAMA,0BAoBC;AA1BD,6CAA0C;AAC1C,+CAA4C;AAE5C;;GAEG;AACI,KAAK,UAAU,OAAO,CAAC,UAAkB,OAAO,CAAC,GAAG,EAAE;IAC3D,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAI,mBAAQ,CAAC,OAAO,CAAC,CAAC;IAEvC,kBAAkB;IAClB,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAEtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;QAC1E,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,MAAM,YAAY,CAAC,CAAC;IAClD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,EAAE,CAAC;IAEd,UAAU;IACV,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Dev command - starts dev server with hot reload
3
+ */
4
+ export declare function dev(port?: number, rootDir?: string): Promise<void>;
5
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAsB,GAAG,CAAC,IAAI,GAAE,MAAa,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC7F"}
package/lib/cli/dev.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.dev = dev;
37
+ const scanner_1 = require("../core/scanner");
38
+ const expressServer_1 = require("../server/expressServer");
39
+ const chokidar = __importStar(require("chokidar"));
40
+ const path = __importStar(require("path"));
41
+ /**
42
+ * Dev command - starts dev server with hot reload
43
+ */
44
+ async function dev(port = 3000, rootDir = process.cwd()) {
45
+ console.log("🚀 Starting kastrick dev server...\n");
46
+ const scanner = new scanner_1.Scanner(rootDir);
47
+ const server = new expressServer_1.ExpressServer(port);
48
+ // Initial register
49
+ const files = scanner.scanApiFolder();
50
+ if (files.length > 0) {
51
+ server.registerRoutes(files);
52
+ }
53
+ else {
54
+ console.log("⚠️ No API files found. Create files in /api folder.\n");
55
+ }
56
+ server.start();
57
+ // Watch for changes
58
+ const apiPath = path.join(rootDir, "api");
59
+ const watcher = chokidar.watch(apiPath, {
60
+ ignored: /(^|[\/\\])\.|node_modules/,
61
+ persistent: true,
62
+ });
63
+ watcher.on("change", () => {
64
+ console.log("\n♻️ Files changed, reloading routes...\n");
65
+ const updatedFiles = scanner.scanApiFolder();
66
+ server.registerRoutes(updatedFiles);
67
+ });
68
+ watcher.on("add", () => {
69
+ console.log("\n♻️ Files added, reloading routes...\n");
70
+ const updatedFiles = scanner.scanApiFolder();
71
+ server.registerRoutes(updatedFiles);
72
+ });
73
+ watcher.on("unlink", () => {
74
+ console.log("\n♻️ Files removed, reloading routes...\n");
75
+ const updatedFiles = scanner.scanApiFolder();
76
+ server.registerRoutes(updatedFiles);
77
+ });
78
+ }
79
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,kBAwCC;AAhDD,6CAA0C;AAC1C,2DAAwD;AACxD,mDAAqC;AACrC,2CAA6B;AAE7B;;GAEG;AACI,KAAK,UAAU,GAAG,CAAC,OAAe,IAAI,EAAE,UAAkB,OAAO,CAAC,GAAG,EAAE;IAC5E,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAEpD,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC;IAEvC,mBAAmB;IACnB,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IACtC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,oBAAoB;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE;QACtC,OAAO,EAAE,2BAA2B;QACpC,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC7C,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;QACrB,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC7C,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC7C,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const compile_1 = require("./compile");
5
+ const dev_1 = require("./dev");
6
+ const serve_1 = require("./serve");
7
+ const command = process.argv[2];
8
+ const port = process.argv[3] ? parseInt(process.argv[3]) : undefined;
9
+ async function main() {
10
+ try {
11
+ switch (command) {
12
+ case "compile":
13
+ await (0, compile_1.compile)();
14
+ break;
15
+ case "dev":
16
+ await (0, dev_1.dev)(port);
17
+ break;
18
+ case "serve":
19
+ await (0, serve_1.serve)(port);
20
+ break;
21
+ case "--version":
22
+ case "-v":
23
+ console.log("kastrick v1.0.0");
24
+ break;
25
+ case "--help":
26
+ case "-h":
27
+ showHelp();
28
+ break;
29
+ default:
30
+ console.log("❌ Unknown command:", command);
31
+ showHelp();
32
+ process.exit(1);
33
+ }
34
+ }
35
+ catch (err) {
36
+ console.error("❌ Error:", err.message);
37
+ process.exit(1);
38
+ }
39
+ }
40
+ function showHelp() {
41
+ console.log(`
42
+ kastrick - API Framework and Compiler
43
+
44
+ USAGE:
45
+ npx kastrick <command> [port]
46
+
47
+ COMMANDS:
48
+ dev <port> Start dev server with hot reload (default: 3000)
49
+ compile Compile API files to /output folder
50
+ serve <port> Run compiled Express server (default: 3000)
51
+ --help, -h Show this help message
52
+ --version, -v Show version
53
+
54
+ EXAMPLES:
55
+ npx kastrick dev # Start dev server on port 3000
56
+ npx kastrick dev 5000 # Start dev server on port 5000
57
+ npx kastrick compile # Compile to /output
58
+ npx kastrick serve # Run compiled app on port 3000
59
+ npx kastrick serve 8080 # Run compiled app on port 8080
60
+ `);
61
+ }
62
+ main();
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAEA,uCAAoC;AACpC,+BAA4B;AAC5B,mCAAgC;AAEhC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAChC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAErE,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,SAAS;gBACZ,MAAM,IAAA,iBAAO,GAAE,CAAC;gBAChB,MAAM;YACR,KAAK,KAAK;gBACR,MAAM,IAAA,SAAG,EAAC,IAAI,CAAC,CAAC;gBAChB,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;gBAClB,MAAM;YACR,KAAK,WAAW,CAAC;YACjB,KAAK,IAAI;gBACP,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;gBAC/B,MAAM;YACR,KAAK,QAAQ,CAAC;YACd,KAAK,IAAI;gBACP,QAAQ,EAAE,CAAC;gBACX,MAAM;YACR;gBACE,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;gBAC3C,QAAQ,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;GAmBX,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Serve command - runs compiled Express app from /output folder
3
+ */
4
+ export declare function serve(port?: number, rootDir?: string): Promise<void>;
5
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/cli/serve.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAsB,KAAK,CAAC,IAAI,GAAE,MAAa,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyE/F"}