@gaman/kame 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +1 -21
  2. package/dist/commands/database/migrate.d.ts +1 -0
  3. package/dist/commands/database/migrate.js +33 -0
  4. package/dist/commands/database/migrate.mjs +35 -0
  5. package/dist/commands/database/seed.d.ts +1 -0
  6. package/dist/commands/database/seed.js +18 -0
  7. package/dist/commands/database/seed.mjs +19 -0
  8. package/dist/commands/gen-controller.js +8 -2
  9. package/dist/commands/gen-controller.mjs +8 -2
  10. package/dist/commands/gen-exception.js +8 -2
  11. package/dist/commands/gen-exception.mjs +8 -2
  12. package/dist/commands/gen-middleware.js +2 -2
  13. package/dist/commands/gen-middleware.mjs +2 -2
  14. package/dist/commands/gen-migration.d.ts +1 -0
  15. package/dist/commands/gen-migration.js +28 -0
  16. package/dist/commands/gen-migration.mjs +30 -0
  17. package/dist/commands/gen-module.js +2 -2
  18. package/dist/commands/gen-module.mjs +2 -2
  19. package/dist/commands/gen-router.js +2 -2
  20. package/dist/commands/gen-router.mjs +2 -2
  21. package/dist/commands/gen-seeder.d.ts +1 -0
  22. package/dist/commands/gen-seeder.js +23 -0
  23. package/dist/commands/gen-seeder.mjs +25 -0
  24. package/dist/commands/gen-service.js +9 -3
  25. package/dist/commands/gen-service.mjs +9 -3
  26. package/dist/commands/registry.d.ts +2 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.js +2 -2
  29. package/dist/index.mjs +2 -2
  30. package/dist/repl.d.ts +11 -1
  31. package/dist/repl.js +3 -3
  32. package/dist/repl.mjs +6 -2
  33. package/dist/templates/database.d.ts +2 -0
  34. package/dist/templates/database.js +87 -0
  35. package/dist/templates/database.mjs +65 -0
  36. package/package.json +1 -1
package/README.md CHANGED
@@ -1,21 +1 @@
1
- # @gaman/static
2
- **Secure, Lightweight & High-Performance Static File Server for GamanJS**. Built for Bun, optimized for speed with non-blocking I/O, built-in compression, and ETag caching.
3
-
4
- ## Installation
5
- ```bash
6
- bun add @gaman/static
7
- ```
8
-
9
- ## Quick Used
10
- By default, this middleware will serve files from the `public/` folder in the root of your project.
11
- ```ts
12
- import { defineBootstrap } from "gaman";
13
- import { StaticServe } from "@gaman/static";
14
-
15
- defineBootstrap((app) => {
16
- // Mount the static server
17
- app.mount(StaticServe());
18
-
19
- app.mountServer(...)
20
- });
21
- ```
1
+ # @gaman/kame
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var import_registry = require('../registry.js'), import_utils = require('gaman/utils'), import_path = require("path"), import_fs = require("fs");
3
+ (0, import_registry.registerCommand)({
4
+ name: "db:migrate",
5
+ description: "Execute database migrations",
6
+ usage: "db:migrate [filename] [--fresh] [--force]",
7
+ aliases: ["migrate"],
8
+ handler: async (args, flags, cfg) => {
9
+ const targetFile = args[0], srcDir = cfg.srcDir || "src", migrationDir = (0, import_path.join)(process.cwd(), srcDir, "database", "migrations");
10
+ try {
11
+ let filesToProcess = [];
12
+ if (targetFile ? filesToProcess = [targetFile] : filesToProcess = (0, import_fs.readdirSync)(migrationDir, { withFileTypes: !0 }).filter(
13
+ (dirent) => dirent.isFile() && (dirent.name.endsWith(".ts") || dirent.name.endsWith(".js"))
14
+ ).map((dirent) => dirent.name).sort((a, b) => a.localeCompare(b)), filesToProcess.length === 0) {
15
+ import_utils.Logger.info("No migrations found to execute.");
16
+ return;
17
+ }
18
+ for (const filename of filesToProcess) {
19
+ const migrationModule = await import((0, import_path.join)(migrationDir, filename)), migration = await (migrationModule.default || migrationModule);
20
+ if (!migration || typeof migration.runUp != "function") {
21
+ import_utils.Logger.error(
22
+ `Invalid migration format in: ${filename}. Make sure to use export default composeMigration(...)`
23
+ );
24
+ continue;
25
+ }
26
+ "fresh" in flags && await migration.runDown(filename, !0), await migration.runUp(filename, "force" in flags);
27
+ }
28
+ import_utils.Logger.info("Migration process completed.");
29
+ } catch (error) {
30
+ import_utils.Logger.error(`Migration failed: ${error.message}`), error.stack && console.error(error.stack);
31
+ }
32
+ }
33
+ });
@@ -0,0 +1,35 @@
1
+ import { registerCommand } from "../registry.mjs";
2
+ import { Logger } from 'gaman/utils';
3
+ import { join } from "path";
4
+ import { readdirSync } from "fs";
5
+ registerCommand({
6
+ name: "db:migrate",
7
+ description: "Execute database migrations",
8
+ usage: "db:migrate [filename] [--fresh] [--force]",
9
+ aliases: ["migrate"],
10
+ handler: async (args, flags, cfg) => {
11
+ const targetFile = args[0], srcDir = cfg.srcDir || "src", migrationDir = join(process.cwd(), srcDir, "database", "migrations");
12
+ try {
13
+ let filesToProcess = [];
14
+ if (targetFile ? filesToProcess = [targetFile] : filesToProcess = readdirSync(migrationDir, { withFileTypes: !0 }).filter(
15
+ (dirent) => dirent.isFile() && (dirent.name.endsWith(".ts") || dirent.name.endsWith(".js"))
16
+ ).map((dirent) => dirent.name).sort((a, b) => a.localeCompare(b)), filesToProcess.length === 0) {
17
+ Logger.info("No migrations found to execute.");
18
+ return;
19
+ }
20
+ for (const filename of filesToProcess) {
21
+ const migrationModule = await import(join(migrationDir, filename)), migration = await (migrationModule.default || migrationModule);
22
+ if (!migration || typeof migration.runUp != "function") {
23
+ Logger.error(
24
+ `Invalid migration format in: ${filename}. Make sure to use export default composeMigration(...)`
25
+ );
26
+ continue;
27
+ }
28
+ "fresh" in flags && await migration.runDown(filename, !0), await migration.runUp(filename, "force" in flags);
29
+ }
30
+ Logger.info("Migration process completed.");
31
+ } catch (error) {
32
+ Logger.error(`Migration failed: ${error.message}`), error.stack && console.error(error.stack);
33
+ }
34
+ }
35
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var import_registry = require('../registry.js'), import_utils = require('gaman/utils'), import_path = require("path");
3
+ (0, import_registry.registerCommand)({
4
+ name: "db:seed",
5
+ description: "Execute migration file",
6
+ usage: "db:seed <filename>",
7
+ aliases: [],
8
+ handler: async (args, flags, cfg) => {
9
+ const filename = args[0];
10
+ if (filename == null) {
11
+ import_utils.Logger.error("Usage: db:seed <filename>");
12
+ return;
13
+ }
14
+ import_utils.Logger.info(`seeder ${filename} is already running...`);
15
+ let seeder = await import((0, import_path.join)(process.cwd(), cfg.srcDir || "src", "database", "seeders", filename));
16
+ seeder.default && (seeder = seeder.default), await seeder(), import_utils.Logger.info(`seeder ${filename} process has been completed`);
17
+ }
18
+ });
@@ -0,0 +1,19 @@
1
+ import { registerCommand } from "../registry.mjs";
2
+ import { Logger } from 'gaman/utils';
3
+ import { join } from "path";
4
+ registerCommand({
5
+ name: "db:seed",
6
+ description: "Execute migration file",
7
+ usage: "db:seed <filename>",
8
+ aliases: [],
9
+ handler: async (args, flags, cfg) => {
10
+ const filename = args[0];
11
+ if (filename == null) {
12
+ Logger.error("Usage: db:seed <filename>");
13
+ return;
14
+ }
15
+ Logger.info(`seeder ${filename} is already running...`);
16
+ let seeder = await import(join(process.cwd(), cfg.srcDir || "src", "database", "seeders", filename));
17
+ seeder.default && (seeder = seeder.default), await seeder(), Logger.info(`seeder ${filename} process has been completed`);
18
+ }
19
+ });
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_module = require('../templates/module.js'), import_utils2 = require('../utils.js');
3
- const handler = async (args) => {
3
+ const handler = async (args, flags, cfg) => {
4
4
  const [name, module2 = "app"] = args;
5
5
  if (!name || !module2) {
6
6
  import_utils.Logger.error("Usage: gen:controller <name> <module: 'app'>");
7
7
  return;
8
8
  }
9
- const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), controllerDir = (0, import_node_path.join)(cwd, "src", "modules", module2, "controllers"), filePath = (0, import_node_path.join)(controllerDir, `${nameCapitalized}Controller.ts`);
9
+ const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), controllerDir = (0, import_node_path.join)(
10
+ cwd,
11
+ cfg.srcDir || "src",
12
+ "modules",
13
+ module2,
14
+ "controllers"
15
+ ), filePath = (0, import_node_path.join)(controllerDir, `${nameCapitalized}Controller.ts`);
10
16
  await Bun.$`mkdir -p ${controllerDir}`.quiet(), await Bun.write(filePath, (0, import_module.controllerTemplate)(name) + `
11
17
  `), import_utils.Logger.info(`created ${(0, import_node_path.relative)(cwd, filePath)}`), import_utils.Logger.info(
12
18
  `Controller "${nameCapitalized}Controller" generated successfully.`
@@ -3,13 +3,19 @@ import { join, relative } from "node:path";
3
3
  import { registerCommand } from "./registry.mjs";
4
4
  import { controllerTemplate } from "../templates/module.mjs";
5
5
  import { capitalize } from "../utils.mjs";
6
- const handler = async (args) => {
6
+ const handler = async (args, flags, cfg) => {
7
7
  const [name, module = "app"] = args;
8
8
  if (!name || !module) {
9
9
  Logger.error("Usage: gen:controller <name> <module: 'app'>");
10
10
  return;
11
11
  }
12
- const nameCapitalized = capitalize(name), cwd = process.cwd(), controllerDir = join(cwd, "src", "modules", module, "controllers"), filePath = join(controllerDir, `${nameCapitalized}Controller.ts`);
12
+ const nameCapitalized = capitalize(name), cwd = process.cwd(), controllerDir = join(
13
+ cwd,
14
+ cfg.srcDir || "src",
15
+ "modules",
16
+ module,
17
+ "controllers"
18
+ ), filePath = join(controllerDir, `${nameCapitalized}Controller.ts`);
13
19
  await Bun.$`mkdir -p ${controllerDir}`.quiet(), await Bun.write(filePath, controllerTemplate(name) + `
14
20
  `), Logger.info(`created ${relative(cwd, filePath)}`), Logger.info(
15
21
  `Controller "${nameCapitalized}Controller" generated successfully.`
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_module = require('../templates/module.js'), import_utils2 = require('../utils.js');
3
- const handler = async (args) => {
3
+ const handler = async (args, flags, cfg) => {
4
4
  const [name, module2 = "app"] = args;
5
5
  if (!name || !module2) {
6
6
  import_utils.Logger.error("Usage: gen:exception <name> <module: 'app'>");
7
7
  return;
8
8
  }
9
- const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), exceptionDir = (0, import_node_path.join)(cwd, "src", "modules", module2, "exceptions"), filePath = (0, import_node_path.join)(exceptionDir, `${nameCapitalized}Exception.ts`);
9
+ const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), exceptionDir = (0, import_node_path.join)(
10
+ cwd,
11
+ cfg.srcDir || "src",
12
+ "modules",
13
+ module2,
14
+ "exceptions"
15
+ ), filePath = (0, import_node_path.join)(exceptionDir, `${nameCapitalized}Exception.ts`);
10
16
  await Bun.$`mkdir -p ${exceptionDir}`.quiet(), await Bun.write(filePath, (0, import_module.exceptionTemplate)() + `
11
17
  `), import_utils.Logger.info(
12
18
  `created ${import_utils.TextFormat.UNDERLINE}${(0, import_node_path.relative)(cwd, filePath)}${import_utils.TextFormat.RESET}`
@@ -3,13 +3,19 @@ import { join, relative } from "node:path";
3
3
  import { registerCommand } from "./registry.mjs";
4
4
  import { exceptionTemplate } from "../templates/module.mjs";
5
5
  import { capitalize } from "../utils.mjs";
6
- const handler = async (args) => {
6
+ const handler = async (args, flags, cfg) => {
7
7
  const [name, module = "app"] = args;
8
8
  if (!name || !module) {
9
9
  Logger.error("Usage: gen:exception <name> <module: 'app'>");
10
10
  return;
11
11
  }
12
- const nameCapitalized = capitalize(name), cwd = process.cwd(), exceptionDir = join(cwd, "src", "modules", module, "exceptions"), filePath = join(exceptionDir, `${nameCapitalized}Exception.ts`);
12
+ const nameCapitalized = capitalize(name), cwd = process.cwd(), exceptionDir = join(
13
+ cwd,
14
+ cfg.srcDir || "src",
15
+ "modules",
16
+ module,
17
+ "exceptions"
18
+ ), filePath = join(exceptionDir, `${nameCapitalized}Exception.ts`);
13
19
  await Bun.$`mkdir -p ${exceptionDir}`.quiet(), await Bun.write(filePath, exceptionTemplate() + `
14
20
  `), Logger.info(
15
21
  `created ${TextFormat.UNDERLINE}${relative(cwd, filePath)}${TextFormat.RESET}`
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_module = require('../templates/module.js'), import_utils2 = require('../utils.js');
3
- const handler = async (args) => {
3
+ const handler = async (args, flags, cfg) => {
4
4
  const [name, module2 = "app"] = args;
5
5
  if (!name || !module2) {
6
6
  import_utils.Logger.error("Usage: gen:middleware <name> <module: 'app'>");
7
7
  return;
8
8
  }
9
- const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), middlewareDir = (0, import_node_path.join)(cwd, "src", "modules", module2, "middlewares"), filePath = (0, import_node_path.join)(middlewareDir, `${nameCapitalized}Middleware.ts`);
9
+ const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), middlewareDir = (0, import_node_path.join)(cwd, cfg.srcDir || "src", "modules", module2, "middlewares"), filePath = (0, import_node_path.join)(middlewareDir, `${nameCapitalized}Middleware.ts`);
10
10
  await Bun.$`mkdir -p ${middlewareDir}`.quiet(), await Bun.write(filePath, (0, import_module.middlewareTemplate)() + `
11
11
  `), import_utils.Logger.info(
12
12
  `created ${import_utils.TextFormat.UNDERLINE}${(0, import_node_path.relative)(cwd, filePath)}${import_utils.TextFormat.RESET}`
@@ -3,13 +3,13 @@ import { join, relative } from "node:path";
3
3
  import { registerCommand } from "./registry.mjs";
4
4
  import { middlewareTemplate } from "../templates/module.mjs";
5
5
  import { capitalize } from "../utils.mjs";
6
- const handler = async (args) => {
6
+ const handler = async (args, flags, cfg) => {
7
7
  const [name, module = "app"] = args;
8
8
  if (!name || !module) {
9
9
  Logger.error("Usage: gen:middleware <name> <module: 'app'>");
10
10
  return;
11
11
  }
12
- const nameCapitalized = capitalize(name), cwd = process.cwd(), middlewareDir = join(cwd, "src", "modules", module, "middlewares"), filePath = join(middlewareDir, `${nameCapitalized}Middleware.ts`);
12
+ const nameCapitalized = capitalize(name), cwd = process.cwd(), middlewareDir = join(cwd, cfg.srcDir || "src", "modules", module, "middlewares"), filePath = join(middlewareDir, `${nameCapitalized}Middleware.ts`);
13
13
  await Bun.$`mkdir -p ${middlewareDir}`.quiet(), await Bun.write(filePath, middlewareTemplate() + `
14
14
  `), Logger.info(
15
15
  `created ${TextFormat.UNDERLINE}${relative(cwd, filePath)}${TextFormat.RESET}`
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_database = require('../templates/database.js');
3
+ const handler = async (args, flags, cfg) => {
4
+ const [name] = args;
5
+ if (!name) {
6
+ import_utils.Logger.error("Usage: gen:migration <name>");
7
+ return;
8
+ }
9
+ const cwd = process.cwd(), now = /* @__PURE__ */ new Date(), timestamp = now.getFullYear().toString() + (now.getMonth() + 1).toString().padStart(2, "0") + now.getDate().toString().padStart(2, "0") + "_" + now.getHours().toString().padStart(2, "0") + now.getMinutes().toString().padStart(2, "0") + now.getSeconds().toString().padStart(2, "0"), migrationDir = (0, import_node_path.join)(
10
+ cwd,
11
+ cfg.srcDir || "src",
12
+ "database",
13
+ "migrations"
14
+ ), fileName = `${timestamp}_${name.toLowerCase().replace(/\s+/g, "_")}.ts`, filePath = (0, import_node_path.join)(migrationDir, fileName);
15
+ try {
16
+ await Bun.$`mkdir -p ${migrationDir}`.quiet(), await Bun.write(filePath, (0, import_database.migrationTemplate)() + `
17
+ `), import_utils.Logger.info(`created ${(0, import_node_path.relative)(cwd, filePath)}`), import_utils.Logger.info(`Migration "${fileName}" generated successfully.`);
18
+ } catch (error) {
19
+ import_utils.Logger.error(`Failed to generate migration: ${error.message}`);
20
+ }
21
+ };
22
+ (0, import_registry.registerCommand)({
23
+ name: "gen:migration",
24
+ description: "Generate a new database migration file with timestamp",
25
+ usage: "gen:migration <name>",
26
+ aliases: ["gen:mi", "make:migration"],
27
+ handler
28
+ });
@@ -0,0 +1,30 @@
1
+ import { Logger } from 'gaman/utils';
2
+ import { join, relative } from "node:path";
3
+ import { registerCommand } from "./registry.mjs";
4
+ import { migrationTemplate } from "../templates/database.mjs";
5
+ const handler = async (args, flags, cfg) => {
6
+ const [name] = args;
7
+ if (!name) {
8
+ Logger.error("Usage: gen:migration <name>");
9
+ return;
10
+ }
11
+ const cwd = process.cwd(), now = /* @__PURE__ */ new Date(), timestamp = now.getFullYear().toString() + (now.getMonth() + 1).toString().padStart(2, "0") + now.getDate().toString().padStart(2, "0") + "_" + now.getHours().toString().padStart(2, "0") + now.getMinutes().toString().padStart(2, "0") + now.getSeconds().toString().padStart(2, "0"), migrationDir = join(
12
+ cwd,
13
+ cfg.srcDir || "src",
14
+ "database",
15
+ "migrations"
16
+ ), fileName = `${timestamp}_${name.toLowerCase().replace(/\s+/g, "_")}.ts`, filePath = join(migrationDir, fileName);
17
+ try {
18
+ await Bun.$`mkdir -p ${migrationDir}`.quiet(), await Bun.write(filePath, migrationTemplate() + `
19
+ `), Logger.info(`created ${relative(cwd, filePath)}`), Logger.info(`Migration "${fileName}" generated successfully.`);
20
+ } catch (error) {
21
+ Logger.error(`Failed to generate migration: ${error.message}`);
22
+ }
23
+ };
24
+ registerCommand({
25
+ name: "gen:migration",
26
+ description: "Generate a new database migration file with timestamp",
27
+ usage: "gen:migration <name>",
28
+ aliases: ["gen:mi", "make:migration"],
29
+ handler
30
+ });
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_module = require('../templates/module.js'), import_utils2 = require('../utils.js');
3
- const handler = async (args) => {
3
+ const handler = async (args, flags, cfg) => {
4
4
  const modulePath = args[0];
5
5
  if (!modulePath) {
6
6
  import_utils.Logger.error("Usage: gen:module <name>");
7
7
  return;
8
8
  }
9
- const name = (0, import_node_path.basename)(modulePath), nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), moduleDir = (0, import_node_path.join)(cwd, "src", "modules", modulePath), files = [
9
+ const name = (0, import_node_path.basename)(modulePath), nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), moduleDir = (0, import_node_path.join)(cwd, cfg.srcDir || "src", "modules", modulePath), files = [
10
10
  {
11
11
  filePath: (0, import_node_path.join)(
12
12
  moduleDir,
@@ -7,13 +7,13 @@ import {
7
7
  serviceTemplate
8
8
  } from "../templates/module.mjs";
9
9
  import { capitalize } from "../utils.mjs";
10
- const handler = async (args) => {
10
+ const handler = async (args, flags, cfg) => {
11
11
  const modulePath = args[0];
12
12
  if (!modulePath) {
13
13
  Logger.error("Usage: gen:module <name>");
14
14
  return;
15
15
  }
16
- const name = basename(modulePath), nameCapitalized = capitalize(name), cwd = process.cwd(), moduleDir = join(cwd, "src", "modules", modulePath), files = [
16
+ const name = basename(modulePath), nameCapitalized = capitalize(name), cwd = process.cwd(), moduleDir = join(cwd, cfg.srcDir || "src", "modules", modulePath), files = [
17
17
  {
18
18
  filePath: join(
19
19
  moduleDir,
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_module = require('../templates/module.js'), import_utils2 = require('../utils.js');
3
- const handler = async (args) => {
3
+ const handler = async (args, flags, cfg) => {
4
4
  const [name, module2 = "app"] = args;
5
5
  if (!name || !module2) {
6
6
  import_utils.Logger.error("Usage: gen:router <name> <module: 'app'>");
7
7
  return;
8
8
  }
9
- const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), routerDir = (0, import_node_path.join)(cwd, "src", "modules", module2), filePath = (0, import_node_path.join)(routerDir, `${nameCapitalized}Router.ts`);
9
+ const nameCapitalized = (0, import_utils2.capitalize)(name), cwd = process.cwd(), routerDir = (0, import_node_path.join)(cwd, cfg.srcDir || "src", "modules", module2), filePath = (0, import_node_path.join)(routerDir, `${nameCapitalized}Router.ts`);
10
10
  await Bun.$`mkdir -p ${routerDir}`.quiet(), await Bun.write(filePath, (0, import_module.routerBlankTemplate)() + `
11
11
  `), import_utils.Logger.info(`created ${(0, import_node_path.relative)(cwd, filePath)}`), import_utils.Logger.info(`Router "${nameCapitalized}Router" generated successfully.`);
12
12
  };
@@ -3,13 +3,13 @@ import { join, relative } from "node:path";
3
3
  import { registerCommand } from "./registry.mjs";
4
4
  import { routerBlankTemplate } from "../templates/module.mjs";
5
5
  import { capitalize } from "../utils.mjs";
6
- const handler = async (args) => {
6
+ const handler = async (args, flags, cfg) => {
7
7
  const [name, module = "app"] = args;
8
8
  if (!name || !module) {
9
9
  Logger.error("Usage: gen:router <name> <module: 'app'>");
10
10
  return;
11
11
  }
12
- const nameCapitalized = capitalize(name), cwd = process.cwd(), routerDir = join(cwd, "src", "modules", module), filePath = join(routerDir, `${nameCapitalized}Router.ts`);
12
+ const nameCapitalized = capitalize(name), cwd = process.cwd(), routerDir = join(cwd, cfg.srcDir || "src", "modules", module), filePath = join(routerDir, `${nameCapitalized}Router.ts`);
13
13
  await Bun.$`mkdir -p ${routerDir}`.quiet(), await Bun.write(filePath, routerBlankTemplate() + `
14
14
  `), Logger.info(`created ${relative(cwd, filePath)}`), Logger.info(`Router "${nameCapitalized}Router" generated successfully.`);
15
15
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var import_utils = require('gaman/utils'), import_node_path = require("node:path"), import_registry = require('./registry.js'), import_database = require('../templates/database.js');
3
+ const handler = async (args, flags, cfg) => {
4
+ const [name] = args;
5
+ if (!name) {
6
+ import_utils.Logger.error("Usage: gen:seeder <name>");
7
+ return;
8
+ }
9
+ const cwd = process.cwd(), seederDir = (0, import_node_path.join)(cwd, cfg.srcDir || "src", "database", "seeders"), fileName = name.includes(".ts") ? name : `${name}.ts`, filePath = (0, import_node_path.join)(seederDir, fileName);
10
+ try {
11
+ await Bun.$`mkdir -p ${seederDir}`.quiet(), await Bun.write(filePath, (0, import_database.seederTemplate)() + `
12
+ `), import_utils.Logger.info(`created ${(0, import_node_path.relative)(cwd, filePath)}`), import_utils.Logger.info(`Seeder "${fileName}" generated successfully.`);
13
+ } catch (error) {
14
+ import_utils.Logger.error(`Failed to generate seeder: ${error.message}`);
15
+ }
16
+ };
17
+ (0, import_registry.registerCommand)({
18
+ name: "gen:seeder",
19
+ description: "Generate a new database seeder file with timestamp",
20
+ usage: "gen:seeder <name>",
21
+ aliases: ["gen:seed", "make:seeder"],
22
+ handler
23
+ });
@@ -0,0 +1,25 @@
1
+ import { Logger } from 'gaman/utils';
2
+ import { join, relative } from "node:path";
3
+ import { registerCommand } from "./registry.mjs";
4
+ import { seederTemplate } from "../templates/database.mjs";
5
+ const handler = async (args, flags, cfg) => {
6
+ const [name] = args;
7
+ if (!name) {
8
+ Logger.error("Usage: gen:seeder <name>");
9
+ return;
10
+ }
11
+ const cwd = process.cwd(), seederDir = join(cwd, cfg.srcDir || "src", "database", "seeders"), fileName = name.includes(".ts") ? name : `${name}.ts`, filePath = join(seederDir, fileName);
12
+ try {
13
+ await Bun.$`mkdir -p ${seederDir}`.quiet(), await Bun.write(filePath, seederTemplate() + `
14
+ `), Logger.info(`created ${relative(cwd, filePath)}`), Logger.info(`Seeder "${fileName}" generated successfully.`);
15
+ } catch (error) {
16
+ Logger.error(`Failed to generate seeder: ${error.message}`);
17
+ }
18
+ };
19
+ registerCommand({
20
+ name: "gen:seeder",
21
+ description: "Generate a new database seeder file with timestamp",
22
+ usage: "gen:seeder <name>",
23
+ aliases: ["gen:seed", "make:seeder"],
24
+ handler
25
+ });
@@ -28,18 +28,24 @@ import `), insertAfter = lastImportIdx !== -1 ? source.indexOf(`
28
28
  );
29
29
  }
30
30
  await Bun.write(routerPath, source);
31
- }, handler = async (args) => {
31
+ }, handler = async (args, flags, cfg) => {
32
32
  const [name, module2 = "app"] = args;
33
33
  if (!name || !module2) {
34
34
  import_utils.Logger.error("Usage: gen:service <name> <module: 'app'>");
35
35
  return;
36
36
  }
37
- const nameCapitalized = (0, import_utils2.capitalize)(name), moduleSegment = (0, import_node_path.basename)(module2), moduleCapitalized = (0, import_utils2.capitalize)(moduleSegment), cwd = process.cwd(), serviceDir = (0, import_node_path.join)(cwd, "src", "modules", module2, "services"), filePath = (0, import_node_path.join)(serviceDir, `${nameCapitalized}Service.ts`);
37
+ const nameCapitalized = (0, import_utils2.capitalize)(name), moduleSegment = (0, import_node_path.basename)(module2), moduleCapitalized = (0, import_utils2.capitalize)(moduleSegment), cwd = process.cwd(), serviceDir = (0, import_node_path.join)(
38
+ cwd,
39
+ cfg.srcDir || "src",
40
+ "modules",
41
+ module2,
42
+ "services"
43
+ ), filePath = (0, import_node_path.join)(serviceDir, `${nameCapitalized}Service.ts`);
38
44
  await Bun.$`mkdir -p ${serviceDir}`.quiet(), await Bun.write(filePath, (0, import_service.standaloneServiceTemplate)(name) + `
39
45
  `), import_utils.Logger.info(`created ${(0, import_node_path.relative)(cwd, filePath)}`);
40
46
  const routerPath = (0, import_node_path.join)(
41
47
  cwd,
42
- "src",
48
+ cfg.srcDir || "src",
43
49
  "modules",
44
50
  module2,
45
51
  `${moduleCapitalized}Router.ts`
@@ -31,18 +31,24 @@ import `), insertAfter = lastImportIdx !== -1 ? source.indexOf(`
31
31
  );
32
32
  }
33
33
  await Bun.write(routerPath, source);
34
- }, handler = async (args) => {
34
+ }, handler = async (args, flags, cfg) => {
35
35
  const [name, module = "app"] = args;
36
36
  if (!name || !module) {
37
37
  Logger.error("Usage: gen:service <name> <module: 'app'>");
38
38
  return;
39
39
  }
40
- const nameCapitalized = capitalize(name), moduleSegment = basename(module), moduleCapitalized = capitalize(moduleSegment), cwd = process.cwd(), serviceDir = join(cwd, "src", "modules", module, "services"), filePath = join(serviceDir, `${nameCapitalized}Service.ts`);
40
+ const nameCapitalized = capitalize(name), moduleSegment = basename(module), moduleCapitalized = capitalize(moduleSegment), cwd = process.cwd(), serviceDir = join(
41
+ cwd,
42
+ cfg.srcDir || "src",
43
+ "modules",
44
+ module,
45
+ "services"
46
+ ), filePath = join(serviceDir, `${nameCapitalized}Service.ts`);
41
47
  await Bun.$`mkdir -p ${serviceDir}`.quiet(), await Bun.write(filePath, standaloneServiceTemplate(name) + `
42
48
  `), Logger.info(`created ${relative(cwd, filePath)}`);
43
49
  const routerPath = join(
44
50
  cwd,
45
- "src",
51
+ cfg.srcDir || "src",
46
52
  "modules",
47
53
  module,
48
54
  `${moduleCapitalized}Router.ts`
@@ -1,4 +1,5 @@
1
- export type CommandHandler = (args: string[], flags: Record<string, string | boolean>) => Promise<void> | void;
1
+ import type { KameConfig } from '../repl';
2
+ export type CommandHandler = (args: string[], flags: Record<string, string | boolean>, appConfig: KameConfig) => Promise<void> | void;
2
3
  export declare class Command {
3
4
  private _name;
4
5
  private _handler;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { startKame } from './repl';
2
2
  import { Gaman } from 'gaman';
3
- export declare function startKameWithGaman(gaman: Gaman): void;
3
+ import { type KameConfig } from './repl';
4
+ export declare function startKameWithGaman(gaman: Gaman, cfg?: KameConfig): void;
package/dist/index.js CHANGED
@@ -20,8 +20,8 @@ __export(index_exports, {
20
20
  });
21
21
  module.exports = __toCommonJS(index_exports);
22
22
  var import_repl = require('./repl.js'), import_gaman = require('gaman'), import_repl2 = require('./repl.js');
23
- function startKameWithGaman(gaman) {
24
- return (0, import_repl2.startKame)();
23
+ function startKameWithGaman(gaman, cfg = { srcDir: "src" }) {
24
+ return (0, import_repl2.startKame)(cfg);
25
25
  }
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { startKame } from "./repl.mjs";
2
2
  import { Gaman } from 'gaman';
3
3
  import { startKame as startKame2 } from "./repl.mjs";
4
- function startKameWithGaman(gaman) {
5
- return startKame2();
4
+ function startKameWithGaman(gaman, cfg = { srcDir: "src" }) {
5
+ return startKame2(cfg);
6
6
  }
7
7
  export {
8
8
  startKame,
package/dist/repl.d.ts CHANGED
@@ -4,6 +4,16 @@ import './commands/gen-controller';
4
4
  import './commands/gen-service';
5
5
  import './commands/gen-middleware';
6
6
  import './commands/gen-exception';
7
+ import './commands/gen-migration';
8
+ import './commands/gen-seeder';
9
+ import './commands/database/migrate';
10
+ import './commands/database/seed';
7
11
  import './commands/buntest-cmd';
8
12
  import './commands/fetch';
9
- export declare function startKame(): void;
13
+ export interface KameConfig {
14
+ /**
15
+ * @default 'src/'
16
+ */
17
+ srcDir?: string;
18
+ }
19
+ export declare function startKame(cfg?: KameConfig): void;
package/dist/repl.js CHANGED
@@ -26,8 +26,8 @@ __export(repl_exports, {
26
26
  startKame: () => startKame
27
27
  });
28
28
  module.exports = __toCommonJS(repl_exports);
29
- var readline = __toESM(require("node:readline")), import_utils = require('gaman/utils'), import_registry = require('./commands/registry.js'), import_input_parser = require('./input-parser.js'), import_gen_module = require('./commands/gen-module.js'), import_gen_router = require('./commands/gen-router.js'), import_gen_controller = require('./commands/gen-controller.js'), import_gen_service = require('./commands/gen-service.js'), import_gen_middleware = require('./commands/gen-middleware.js'), import_gen_exception = require('./commands/gen-exception.js'), import_buntest_cmd = require('./commands/buntest-cmd.js'), import_fetch = require('./commands/fetch.js');
30
- function startKame() {
29
+ var readline = __toESM(require("node:readline")), import_utils = require('gaman/utils'), import_registry = require('./commands/registry.js'), import_input_parser = require('./input-parser.js'), import_gen_module = require('./commands/gen-module.js'), import_gen_router = require('./commands/gen-router.js'), import_gen_controller = require('./commands/gen-controller.js'), import_gen_service = require('./commands/gen-service.js'), import_gen_middleware = require('./commands/gen-middleware.js'), import_gen_exception = require('./commands/gen-exception.js'), import_gen_migration = require('./commands/gen-migration.js'), import_gen_seeder = require('./commands/gen-seeder.js'), import_migrate = require('./commands/database/migrate.js'), import_seed = require('./commands/database/seed.js'), import_buntest_cmd = require('./commands/buntest-cmd.js'), import_fetch = require('./commands/fetch.js');
30
+ function startKame(cfg = { srcDir: "src" }) {
31
31
  if (!process.env.KAME_CLI) return;
32
32
  import_utils.Logger.info(
33
33
  `${import_utils.TextFormat.BG_CYAN} ${import_utils.TextFormat.BOLD}Kame ${import_utils.TextFormat.RESET} System active. Type "help" for commands.`
@@ -52,7 +52,7 @@ function startKame() {
52
52
  return;
53
53
  }
54
54
  const cmd = (0, import_registry.getCommand)(commandName);
55
- cmd ? await cmd.getHandler()(args, flags) : import_utils.Logger.error(
55
+ cmd ? await cmd.getHandler()(args, flags, cfg) : import_utils.Logger.error(
56
56
  `Unknown command: "${commandName}". Run "help" to see available commands.`
57
57
  ), rl.prompt();
58
58
  });
package/dist/repl.mjs CHANGED
@@ -8,9 +8,13 @@ import "./commands/gen-controller";
8
8
  import "./commands/gen-service";
9
9
  import "./commands/gen-middleware";
10
10
  import "./commands/gen-exception";
11
+ import "./commands/gen-migration";
12
+ import "./commands/gen-seeder";
13
+ import "./commands/database/migrate";
14
+ import "./commands/database/seed";
11
15
  import "./commands/buntest-cmd";
12
16
  import "./commands/fetch";
13
- function startKame() {
17
+ function startKame(cfg = { srcDir: "src" }) {
14
18
  if (!process.env.KAME_CLI) return;
15
19
  Logger.info(
16
20
  `${TextFormat.BG_CYAN} ${TextFormat.BOLD}Kame ${TextFormat.RESET} System active. Type "help" for commands.`
@@ -35,7 +39,7 @@ function startKame() {
35
39
  return;
36
40
  }
37
41
  const cmd = getCommand(commandName);
38
- cmd ? await cmd.getHandler()(args, flags) : Logger.error(
42
+ cmd ? await cmd.getHandler()(args, flags, cfg) : Logger.error(
39
43
  `Unknown command: "${commandName}". Run "help" to see available commands.`
40
44
  ), rl.prompt();
41
45
  });
@@ -0,0 +1,2 @@
1
+ export declare const migrationTemplate: () => string;
2
+ export declare const seederTemplate: () => string;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
+ var database_exports = {};
17
+ __export(database_exports, {
18
+ migrationTemplate: () => migrationTemplate,
19
+ seederTemplate: () => seederTemplate
20
+ });
21
+ module.exports = __toCommonJS(database_exports);
22
+ const migrationTemplate = () => `
23
+ import { composeMigration } from "./../packages/db/index.ts"
24
+
25
+ /**
26
+ * This migration file acts as version control for your database schema.
27
+ * Use it to define changes such as creating tables, adding columns, or managing indexes.
28
+ */
29
+ export default composeMigration({
30
+
31
+ /**
32
+ * The 'up' method is executed when you run the 'db:migrate' command.
33
+ * This is where you write the logic to APPLY changes to the database.
34
+ *
35
+ * Example:
36
+ * await m.createTable('users', (table) => {
37
+ * table.int('id').primary().autoIncrement();
38
+ * table.string('username').unique();
39
+ * table.text('bio');
40
+ * });
41
+ */
42
+ async up(m) {
43
+ // Write your 'up' logic here
44
+ },
45
+
46
+ /**
47
+ * The 'down' method is executed when you run the 'db:rollback' or 'db:migrate -fresh' command.
48
+ * This is where you write the logic to REVERSE the changes made in the 'up' method.
49
+ * Warning: Rolling back often results in permanent data loss in the affected tables.
50
+ *
51
+ * Example:
52
+ * await m.dropTable('users');
53
+ */
54
+ async down(m) {
55
+ // Write your 'down' logic here (the inverse of 'up')
56
+ },
57
+ });
58
+ `.trim(), seederTemplate = () => `
59
+ import { composeSeeder } from './../packages/db/index.ts';
60
+
61
+ /**
62
+ * This seeder file is used to populate your database with initial or sample data.
63
+ * Useful for testing, development setup, or inserting default records.
64
+ */
65
+ export default composeSeeder(async () => {
66
+ /**
67
+ * Add your seed data here.
68
+ *
69
+ * Example:
70
+ * await UserModel.create({
71
+ * name: 'Anomali',
72
+ * umur: 12,
73
+ * });
74
+ *
75
+ * You can also insert multiple records:
76
+ *
77
+ * await UserModel.createMany([
78
+ * { name: 'Anomali', umur: 12 },
79
+ * { name: 'Budi', umur: 20 },
80
+ * ]);
81
+ */
82
+ });`.trim();
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ migrationTemplate,
86
+ seederTemplate
87
+ });
@@ -0,0 +1,65 @@
1
+ const migrationTemplate = () => `
2
+ import { composeMigration } from "@gaman/db"
3
+
4
+ /**
5
+ * This migration file acts as version control for your database schema.
6
+ * Use it to define changes such as creating tables, adding columns, or managing indexes.
7
+ */
8
+ export default composeMigration({
9
+
10
+ /**
11
+ * The 'up' method is executed when you run the 'db:migrate' command.
12
+ * This is where you write the logic to APPLY changes to the database.
13
+ *
14
+ * Example:
15
+ * await m.createTable('users', (table) => {
16
+ * table.int('id').primary().autoIncrement();
17
+ * table.string('username').unique();
18
+ * table.text('bio');
19
+ * });
20
+ */
21
+ async up(m) {
22
+ // Write your 'up' logic here
23
+ },
24
+
25
+ /**
26
+ * The 'down' method is executed when you run the 'db:rollback' or 'db:migrate -fresh' command.
27
+ * This is where you write the logic to REVERSE the changes made in the 'up' method.
28
+ * Warning: Rolling back often results in permanent data loss in the affected tables.
29
+ *
30
+ * Example:
31
+ * await m.dropTable('users');
32
+ */
33
+ async down(m) {
34
+ // Write your 'down' logic here (the inverse of 'up')
35
+ },
36
+ });
37
+ `.trim(), seederTemplate = () => `
38
+ import { composeSeeder } from '@gaman/db';
39
+
40
+ /**
41
+ * This seeder file is used to populate your database with initial or sample data.
42
+ * Useful for testing, development setup, or inserting default records.
43
+ */
44
+ export default composeSeeder(async () => {
45
+ /**
46
+ * Add your seed data here.
47
+ *
48
+ * Example:
49
+ * await UserModel.create({
50
+ * name: 'Anomali',
51
+ * umur: 12,
52
+ * });
53
+ *
54
+ * You can also insert multiple records:
55
+ *
56
+ * await UserModel.createMany([
57
+ * { name: 'Anomali', umur: 12 },
58
+ * { name: 'Budi', umur: 20 },
59
+ * ]);
60
+ */
61
+ });`.trim();
62
+ export {
63
+ migrationTemplate,
64
+ seederTemplate
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaman/kame",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "author": "angga7togk",
5
5
  "license": "MIT",
6
6
  "types": "./dist/index.d.ts",