servcraft 0.1.5 → 0.1.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "servcraft",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "A modular, production-ready Node.js backend framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,7 +51,7 @@
51
51
  "@fastify/cookie": "^9.3.1",
52
52
  "@fastify/cors": "^9.0.1",
53
53
  "@fastify/helmet": "^11.1.1",
54
- "@fastify/jwt": "^10.0.0",
54
+ "@fastify/jwt": "^7.2.4",
55
55
  "@fastify/multipart": "^8.3.0",
56
56
  "@fastify/rate-limit": "^9.1.0",
57
57
  "@fastify/swagger": "^8.15.0",
@@ -621,19 +621,63 @@ export interface ${name.charAt(0).toUpperCase() + name.slice(1)}Data {
621
621
  }
622
622
 
623
623
  /**
624
- * Helper: Generate module files - copies from existing src/modules if available
624
+ * Helper: Find servcraft modules source directory
625
+ */
626
+ async function findServercraftModules(): Promise<string | null> {
627
+ // Get the directory where the CLI script is located
628
+ const scriptDir = path.dirname(new URL(import.meta.url).pathname);
629
+
630
+ const possiblePaths = [
631
+ // Local node_modules (when servcraft is a dependency)
632
+ path.join(process.cwd(), 'node_modules', 'servcraft', 'src', 'modules'),
633
+ // From dist/cli/index.js -> src/modules (npx or global install)
634
+ path.resolve(scriptDir, '..', '..', 'src', 'modules'),
635
+ // From src/cli/commands/add-module.ts -> src/modules (development)
636
+ path.resolve(scriptDir, '..', '..', 'modules'),
637
+ ];
638
+
639
+ for (const p of possiblePaths) {
640
+ try {
641
+ const stats = await fs.stat(p);
642
+ if (stats.isDirectory()) {
643
+ return p;
644
+ }
645
+ } catch {
646
+ // Path doesn't exist, try next
647
+ }
648
+ }
649
+ return null;
650
+ }
651
+
652
+ /**
653
+ * Helper: Generate module files - copies from servcraft package modules
625
654
  */
626
655
  async function generateModuleFiles(moduleName: string, moduleDir: string): Promise<void> {
627
- // Check if module exists in src/modules (our new modules)
628
- const sourceModuleDir = path.join(process.cwd(), 'src', 'modules', moduleName);
656
+ // Map module names to their directory names in servcraft
657
+ const moduleNameMap: Record<string, string> = {
658
+ users: 'user',
659
+ 'rate-limit': 'rate-limit',
660
+ 'feature-flag': 'feature-flag',
661
+ 'api-versioning': 'api-versioning',
662
+ 'media-processing': 'media-processing',
663
+ };
629
664
 
630
- if (await fileExists(sourceModuleDir)) {
631
- // Copy from existing module
632
- await copyModuleFromSource(sourceModuleDir, moduleDir);
633
- return;
665
+ const sourceDirName = moduleNameMap[moduleName] || moduleName;
666
+
667
+ // Find servcraft modules directory
668
+ const servercraftModulesDir = await findServercraftModules();
669
+
670
+ if (servercraftModulesDir) {
671
+ const sourceModuleDir = path.join(servercraftModulesDir, sourceDirName);
672
+
673
+ if (await fileExists(sourceModuleDir)) {
674
+ // Copy from servcraft package
675
+ await copyModuleFromSource(sourceModuleDir, moduleDir);
676
+ return;
677
+ }
634
678
  }
635
679
 
636
- // Fallback to old generation methods for basic modules
680
+ // Fallback to inline templates for basic modules
637
681
  switch (moduleName) {
638
682
  case 'auth':
639
683
  await generateAuthModule(moduleDir);