@forinda/kickjs 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- #!/usr/bin/env node
3
2
  "use strict";
4
3
  var __create = Object.create;
5
4
  var __defProp = Object.defineProperty;
@@ -31,7 +30,7 @@ var import_commander = require("commander");
31
30
  // package.json
32
31
  var package_default = {
33
32
  name: "@forinda/kickjs",
34
- version: "0.1.3",
33
+ version: "0.1.6",
35
34
  description: "Express + TypeScript + Inversify starter with reactive state, request telemetry, and Spring Boot-style decorators.",
36
35
  main: "dist/index.js",
37
36
  types: "dist/index.d.ts",
@@ -42,21 +41,30 @@ var package_default = {
42
41
  }
43
42
  },
44
43
  files: [
45
- "dist"
44
+ "dist",
45
+ "LICENSE",
46
+ "README.md"
46
47
  ],
47
48
  bin: {
48
49
  kick: "dist/cli.js"
49
50
  },
50
51
  scripts: {
51
52
  clean: "rm -rf dist",
52
- dev: "ts-node-dev --respawn --transpile-only src/main.ts",
53
+ dev: "tsup --watch src/index.ts",
53
54
  check: "tsc --noEmit",
54
55
  build: "tsup",
55
56
  start: "node dist/index.js",
56
57
  prepublishOnly: "npm run build && npm run check && npm test",
57
58
  test: "vitest run",
58
59
  "test:watch": "vitest",
59
- prepare: "husky"
60
+ prepare: "husky",
61
+ prerelease: "npm run clean && npm run build && npm run check && npm test",
62
+ "release:patch": "node scripts/release.js patch",
63
+ "release:minor": "node scripts/release.js minor",
64
+ "release:major": "node scripts/release.js major",
65
+ "release:prerelease": "node scripts/release.js prerelease",
66
+ "release:dry": "node scripts/release.js patch --dry-run",
67
+ version: `git add package.json && git commit -m "chore: bump version to $(node -p "require('./package.json').version")"`
60
68
  },
61
69
  keywords: [
62
70
  "express",
@@ -68,13 +76,15 @@ var package_default = {
68
76
  author: "",
69
77
  license: "MIT",
70
78
  engines: {
71
- node: ">=18.17"
79
+ node: ">=20.0"
72
80
  },
73
81
  publishConfig: {
74
82
  access: "public"
75
83
  },
76
84
  dependencies: {
77
- commander: "^11.1.0",
85
+ commander: "^11.1.0"
86
+ },
87
+ peerDependencies: {
78
88
  express: "^5.1.0",
79
89
  inversify: "^7.10.0",
80
90
  "reflect-metadata": "^0.2.2"
@@ -83,13 +93,19 @@ var package_default = {
83
93
  "@swc/core": "^1.7.28",
84
94
  "@types/express": "^5.0.3",
85
95
  "@types/node": "^24.5.2",
96
+ "@types/supertest": "^6.0.3",
86
97
  "@vitest/coverage-v8": "^3.2.4",
98
+ express: "^5.1.0",
87
99
  husky: "^9.1.7",
100
+ inversify: "^7.10.0",
88
101
  joi: "^18.0.1",
89
102
  "node-mocks-http": "^1.17.2",
103
+ "reflect-metadata": "^0.2.2",
104
+ supertest: "^7.1.4",
90
105
  "ts-node": "^10.9.2",
91
106
  "ts-node-dev": "^2.0.0",
92
107
  tsup: "^8.5.0",
108
+ tsx: "^4.20.6",
93
109
  typescript: "^5.9.2",
94
110
  vitest: "^3.2.4",
95
111
  zod: "^4.1.9"
@@ -573,9 +589,10 @@ function computeDefaultControllerRoot(defaults, name) {
573
589
  }
574
590
  __name(computeDefaultControllerRoot, "computeDefaultControllerRoot");
575
591
 
576
- // src/cli/config.ts
577
- var import_node_fs2 = require("fs");
578
- var import_node_path5 = __toESM(require("path"));
592
+ // src/cli/commands/run.ts
593
+ var import_node_child_process = require("child_process");
594
+ var import_node_fs3 = require("fs");
595
+ var import_node_path6 = __toESM(require("path"));
579
596
 
580
597
  // src/utils/errors.ts
581
598
  var AppError = class extends Error {
@@ -601,7 +618,261 @@ function createError(code, message, options = {}) {
601
618
  }
602
619
  __name(createError, "createError");
603
620
 
621
+ // src/cli/utils/config-loader.ts
622
+ var import_node_fs2 = require("fs");
623
+ var import_node_path5 = __toESM(require("path"));
624
+ var CONFIG_FILE_NAMES = [
625
+ "kick.config.ts",
626
+ "kick.config.js",
627
+ "kick.config.mjs",
628
+ "kickjs.config.ts",
629
+ "kickjs.config.js",
630
+ "kickjs.config.mjs"
631
+ ];
632
+ async function loadKickConfig(cwd) {
633
+ const workingDir = cwd || process.cwd();
634
+ for (const configFileName of CONFIG_FILE_NAMES) {
635
+ const configPath = import_node_path5.default.resolve(workingDir, configFileName);
636
+ if ((0, import_node_fs2.existsSync)(configPath)) {
637
+ try {
638
+ const configModule = await import(configPath);
639
+ const config = configModule.default || configModule;
640
+ return {
641
+ ...config,
642
+ configPath
643
+ };
644
+ } catch (error) {
645
+ console.warn(`\u26A0\uFE0F Failed to load config from ${configPath}:`, error);
646
+ }
647
+ }
648
+ }
649
+ return getDefaultConfig();
650
+ }
651
+ __name(loadKickConfig, "loadKickConfig");
652
+ function getDefaultConfig() {
653
+ return {
654
+ app: {
655
+ name: "KickJS App",
656
+ port: 3e3,
657
+ host: "localhost",
658
+ prefix: "",
659
+ env: "development"
660
+ },
661
+ dev: {
662
+ port: 3e3,
663
+ host: "localhost",
664
+ entry: "src/index.ts",
665
+ watch: true,
666
+ env: {
667
+ NODE_ENV: "development"
668
+ }
669
+ },
670
+ start: {
671
+ port: 3e3,
672
+ host: "0.0.0.0",
673
+ entry: "dist/index.js",
674
+ env: {
675
+ NODE_ENV: "production"
676
+ }
677
+ },
678
+ structure: {
679
+ domainRoot: "src/domains",
680
+ domainFolders: [
681
+ "controllers",
682
+ "services",
683
+ "domain"
684
+ ],
685
+ defaultDomain: "app"
686
+ },
687
+ generators: {
688
+ controllerRoot: "src/domains/app/controllers"
689
+ }
690
+ };
691
+ }
692
+ __name(getDefaultConfig, "getDefaultConfig");
693
+ function mergeConfigWithOptions(config, cliOptions, command) {
694
+ const baseConfig = command === "dev" ? config.dev : config.start;
695
+ return {
696
+ ...baseConfig,
697
+ port: cliOptions.port ? parseInt(cliOptions.port) : baseConfig?.port,
698
+ host: cliOptions.host || baseConfig?.host,
699
+ entry: cliOptions.entry || baseConfig?.entry,
700
+ env: {
701
+ ...baseConfig?.env,
702
+ ...cliOptions.env
703
+ }
704
+ };
705
+ }
706
+ __name(mergeConfigWithOptions, "mergeConfigWithOptions");
707
+
708
+ // src/cli/commands/run.ts
709
+ function registerRunCommands(program) {
710
+ 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) => {
711
+ await runDev(options);
712
+ });
713
+ 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) => {
714
+ await runStart(options);
715
+ });
716
+ }
717
+ __name(registerRunCommands, "registerRunCommands");
718
+ async function runDev(options) {
719
+ const kickConfig = await loadKickConfig();
720
+ const config = mergeConfigWithOptions(kickConfig, options, "dev");
721
+ const entryFile = config.entry;
722
+ const cwd = process.cwd();
723
+ const entryPath = import_node_path6.default.resolve(cwd, entryFile);
724
+ if (!(0, import_node_fs3.existsSync)(entryPath)) {
725
+ throw createError("ENTRY_FILE_NOT_FOUND", `Entry file not found: ${entryPath}`);
726
+ }
727
+ console.log(`\u{1F680} Starting development server...`);
728
+ if (kickConfig.configPath) {
729
+ console.log(`\u2699\uFE0F Config: ${import_node_path6.default.relative(cwd, kickConfig.configPath)}`);
730
+ }
731
+ console.log(`\u{1F4C1} Entry: ${entryFile}`);
732
+ console.log(`\u{1F310} Port: ${config.port}`);
733
+ console.log(`\u{1F3E0} Host: ${config.host}`);
734
+ const runners = [
735
+ {
736
+ cmd: "tsx",
737
+ args: [
738
+ "watch",
739
+ entryFile
740
+ ]
741
+ },
742
+ {
743
+ cmd: "ts-node-dev",
744
+ args: [
745
+ "--respawn",
746
+ "--transpile-only",
747
+ entryFile
748
+ ]
749
+ },
750
+ {
751
+ cmd: "ts-node",
752
+ args: [
753
+ entryFile
754
+ ]
755
+ }
756
+ ];
757
+ let runner = null;
758
+ for (const r of runners) {
759
+ if (await commandExists(r.cmd)) {
760
+ runner = r;
761
+ break;
762
+ }
763
+ }
764
+ if (!runner) {
765
+ 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");
766
+ }
767
+ const env = {
768
+ ...process.env,
769
+ ...config.env,
770
+ PORT: config.port?.toString(),
771
+ HOST: config.host
772
+ };
773
+ console.log(`\u{1F527} Using runner: ${runner.cmd}`);
774
+ const localBinPath = import_node_path6.default.resolve(cwd, "node_modules", ".bin", runner.cmd);
775
+ const commandToRun = (0, import_node_fs3.existsSync)(localBinPath) ? localBinPath : runner.cmd;
776
+ const child = (0, import_node_child_process.spawn)(commandToRun, runner.args, {
777
+ stdio: "inherit",
778
+ env,
779
+ cwd
780
+ });
781
+ child.on("error", (error) => {
782
+ console.error(`\u274C Failed to start development server: ${error.message}`);
783
+ process.exit(1);
784
+ });
785
+ child.on("exit", (code) => {
786
+ if (code !== 0) {
787
+ console.error(`\u274C Development server exited with code ${code}`);
788
+ process.exit(code || 1);
789
+ }
790
+ });
791
+ process.on("SIGINT", () => {
792
+ console.log("\n\u{1F6D1} Shutting down development server...");
793
+ child.kill("SIGINT");
794
+ });
795
+ process.on("SIGTERM", () => {
796
+ console.log("\n\u{1F6D1} Shutting down development server...");
797
+ child.kill("SIGTERM");
798
+ });
799
+ }
800
+ __name(runDev, "runDev");
801
+ async function runStart(options) {
802
+ const kickConfig = await loadKickConfig();
803
+ const config = mergeConfigWithOptions(kickConfig, options, "start");
804
+ const entryFile = config.entry;
805
+ const cwd = process.cwd();
806
+ const entryPath = import_node_path6.default.resolve(cwd, entryFile);
807
+ if (!(0, import_node_fs3.existsSync)(entryPath)) {
808
+ throw createError("ENTRY_FILE_NOT_FOUND", `Entry file not found: ${entryPath}
809
+ Make sure to build your application first with: npm run build`);
810
+ }
811
+ console.log(`\u{1F680} Starting production server...`);
812
+ if (kickConfig.configPath) {
813
+ console.log(`\u2699\uFE0F Config: ${import_node_path6.default.relative(cwd, kickConfig.configPath)}`);
814
+ }
815
+ console.log(`\u{1F4C1} Entry: ${entryFile}`);
816
+ console.log(`\u{1F310} Port: ${config.port}`);
817
+ console.log(`\u{1F3E0} Host: ${config.host}`);
818
+ const env = {
819
+ ...process.env,
820
+ ...config.env,
821
+ PORT: config.port?.toString(),
822
+ HOST: config.host
823
+ };
824
+ const child = (0, import_node_child_process.spawn)("node", [
825
+ entryFile
826
+ ], {
827
+ stdio: "inherit",
828
+ env,
829
+ cwd
830
+ });
831
+ child.on("error", (error) => {
832
+ console.error(`\u274C Failed to start production server: ${error.message}`);
833
+ process.exit(1);
834
+ });
835
+ child.on("exit", (code) => {
836
+ if (code !== 0) {
837
+ console.error(`\u274C Production server exited with code ${code}`);
838
+ process.exit(code || 1);
839
+ }
840
+ });
841
+ process.on("SIGINT", () => {
842
+ console.log("\n\u{1F6D1} Shutting down production server...");
843
+ child.kill("SIGINT");
844
+ });
845
+ process.on("SIGTERM", () => {
846
+ console.log("\n\u{1F6D1} Shutting down production server...");
847
+ child.kill("SIGTERM");
848
+ });
849
+ }
850
+ __name(runStart, "runStart");
851
+ async function commandExists(command) {
852
+ return new Promise((resolve) => {
853
+ const localBinPath = import_node_path6.default.resolve(process.cwd(), "node_modules", ".bin", command);
854
+ if ((0, import_node_fs3.existsSync)(localBinPath)) {
855
+ resolve(true);
856
+ return;
857
+ }
858
+ const child = (0, import_node_child_process.spawn)("which", [
859
+ command
860
+ ], {
861
+ stdio: "ignore"
862
+ });
863
+ child.on("close", (code) => {
864
+ resolve(code === 0);
865
+ });
866
+ child.on("error", () => {
867
+ resolve(false);
868
+ });
869
+ });
870
+ }
871
+ __name(commandExists, "commandExists");
872
+
604
873
  // src/cli/config.ts
874
+ var import_node_fs4 = require("fs");
875
+ var import_node_path7 = __toESM(require("path"));
605
876
  var CONFIG_FILE_CANDIDATES = [
606
877
  "kick.config.ts",
607
878
  "kick.config.js",
@@ -610,14 +881,14 @@ var CONFIG_FILE_CANDIDATES = [
610
881
  "kick.config.json"
611
882
  ];
612
883
  var tsNodeRegistered = false;
613
- async function loadKickConfig(cwd = process.cwd()) {
884
+ async function loadKickConfig2(cwd = process.cwd()) {
614
885
  for (const file of CONFIG_FILE_CANDIDATES) {
615
- const absolute = import_node_path5.default.join(cwd, file);
616
- if (!(0, import_node_fs2.existsSync)(absolute)) {
886
+ const absolute = import_node_path7.default.join(cwd, file);
887
+ if (!(0, import_node_fs4.existsSync)(absolute)) {
617
888
  continue;
618
889
  }
619
890
  if (file.endsWith(".json")) {
620
- const raw = await import_node_fs2.promises.readFile(absolute, "utf8");
891
+ const raw = await import_node_fs4.promises.readFile(absolute, "utf8");
621
892
  return normalizeConfig(JSON.parse(raw));
622
893
  }
623
894
  if (file.endsWith(".ts")) {
@@ -629,7 +900,7 @@ async function loadKickConfig(cwd = process.cwd()) {
629
900
  }
630
901
  return void 0;
631
902
  }
632
- __name(loadKickConfig, "loadKickConfig");
903
+ __name(loadKickConfig2, "loadKickConfig");
633
904
  function ensureTsNode() {
634
905
  if (tsNodeRegistered) {
635
906
  return;
@@ -694,10 +965,10 @@ function normalizeStructureConfig(raw) {
694
965
  __name(normalizeStructureConfig, "normalizeStructureConfig");
695
966
 
696
967
  // src/cli/utils/shell.ts
697
- var import_node_child_process = require("child_process");
968
+ var import_node_child_process2 = require("child_process");
698
969
  function runShellCommand(command, options = {}) {
699
970
  return new Promise((resolve, reject) => {
700
- const child = (0, import_node_child_process.spawn)(command, {
971
+ const child = (0, import_node_child_process2.spawn)(command, {
701
972
  cwd: options.cwd,
702
973
  stdio: "inherit",
703
974
  shell: true
@@ -740,7 +1011,7 @@ __name(registerCustomCommands, "registerCustomCommands");
740
1011
  async function main() {
741
1012
  const program = new import_commander.Command();
742
1013
  program.name("kick").description("Kick project CLI").version(package_default.version ?? "0.0.0");
743
- const config = await loadKickConfig(process.cwd());
1014
+ const config = await loadKickConfig2(process.cwd());
744
1015
  registerInitCommand(program, {
745
1016
  structure: config?.structure
746
1017
  });
@@ -748,6 +1019,7 @@ async function main() {
748
1019
  controllerRoot: config?.generators?.controllerRoot,
749
1020
  structure: config?.structure
750
1021
  });
1022
+ registerRunCommands(program);
751
1023
  registerCustomCommands(program, config);
752
1024
  program.showHelpAfterError();
753
1025
  try {