servcraft 0.1.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "servcraft",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "A modular, production-ready Node.js backend framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -621,19 +621,91 @@ 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: Get the servcraft package directory (works for both npm installed and local dev)
625
+ */
626
+ function getServercraftModulesDir(): string {
627
+ // Try node_modules first (when installed as dependency)
628
+ const nodeModulesPath = path.join(process.cwd(), 'node_modules', 'servcraft', 'src', 'modules');
629
+
630
+ // Try global npm path
631
+ const globalPath = path.join(
632
+ process.env.npm_config_prefix || '/usr/local',
633
+ 'lib',
634
+ 'node_modules',
635
+ 'servcraft',
636
+ 'src',
637
+ 'modules'
638
+ );
639
+
640
+ // For CLI execution, use import.meta.url to find package location
641
+ const cliPath = path.resolve(
642
+ path.dirname(new URL(import.meta.url).pathname),
643
+ '..',
644
+ '..',
645
+ 'modules'
646
+ );
647
+
648
+ return nodeModulesPath; // Primary path - will check existence in generateModuleFiles
649
+ }
650
+
651
+ /**
652
+ * Helper: Find servcraft modules source directory
653
+ */
654
+ async function findServercraftModules(): Promise<string | null> {
655
+ // Get the directory where the CLI script is located
656
+ const scriptDir = path.dirname(new URL(import.meta.url).pathname);
657
+
658
+ const possiblePaths = [
659
+ // Local node_modules (when servcraft is a dependency)
660
+ path.join(process.cwd(), 'node_modules', 'servcraft', 'src', 'modules'),
661
+ // From dist/cli/index.js -> src/modules (npx or global install)
662
+ path.resolve(scriptDir, '..', '..', 'src', 'modules'),
663
+ // From src/cli/commands/add-module.ts -> src/modules (development)
664
+ path.resolve(scriptDir, '..', '..', 'modules'),
665
+ ];
666
+
667
+ for (const p of possiblePaths) {
668
+ try {
669
+ const stats = await fs.stat(p);
670
+ if (stats.isDirectory()) {
671
+ return p;
672
+ }
673
+ } catch {
674
+ // Path doesn't exist, try next
675
+ }
676
+ }
677
+ return null;
678
+ }
679
+
680
+ /**
681
+ * Helper: Generate module files - copies from servcraft package modules
625
682
  */
626
683
  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);
684
+ // Map module names to their directory names in servcraft
685
+ const moduleNameMap: Record<string, string> = {
686
+ 'users': 'user',
687
+ 'rate-limit': 'rate-limit',
688
+ 'feature-flag': 'feature-flag',
689
+ 'api-versioning': 'api-versioning',
690
+ 'media-processing': 'media-processing',
691
+ };
629
692
 
630
- if (await fileExists(sourceModuleDir)) {
631
- // Copy from existing module
632
- await copyModuleFromSource(sourceModuleDir, moduleDir);
633
- return;
693
+ const sourceDirName = moduleNameMap[moduleName] || moduleName;
694
+
695
+ // Find servcraft modules directory
696
+ const servercraftModulesDir = await findServercraftModules();
697
+
698
+ if (servercraftModulesDir) {
699
+ const sourceModuleDir = path.join(servercraftModulesDir, sourceDirName);
700
+
701
+ if (await fileExists(sourceModuleDir)) {
702
+ // Copy from servcraft package
703
+ await copyModuleFromSource(sourceModuleDir, moduleDir);
704
+ return;
705
+ }
634
706
  }
635
707
 
636
- // Fallback to old generation methods for basic modules
708
+ // Fallback to inline templates for basic modules
637
709
  switch (moduleName) {
638
710
  case 'auth':
639
711
  await generateAuthModule(moduleDir);
@@ -620,7 +620,7 @@ model User {
620
620
  function generateEntryFile(options: InitOptions): string {
621
621
  const isTS = options.language === 'typescript';
622
622
 
623
- return `${isTS ? "import { createServer } from './core/server.js';\nimport { logger } from './core/logger.js';" : "const { createServer } = require('./core/server.js');\nconst { logger } = require('./core/logger.js');"}
623
+ return `${isTS ? "import 'dotenv/config';\nimport { createServer } from './core/server.js';\nimport { logger } from './core/logger.js';" : "require('dotenv').config();\nconst { createServer } = require('./core/server.js');\nconst { logger } = require('./core/logger.js');"}
624
624
 
625
625
  async function main()${isTS ? ': Promise<void>' : ''} {
626
626
  const server = createServer();
@@ -1,30 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(git add:*)",
5
- "Bash(git commit -m \"$\\(cat <<''EOF''\nfeat: Add advanced rate limiting module\n\n- Implemented three algorithms: fixed-window, sliding-window, token-bucket\n- Support for Memory and Redis stores\n- Flexible key generation \\(IP, User, API Key, custom\\)\n- Whitelist/Blacklist functionality\n- Custom limits per endpoint and user role\n- Pre-configured rate limiters \\(strict, standard, relaxed, auth\\)\n- Admin routes for rate limit management\n- Standard X-RateLimit-* headers\n- Updated documentation with usage examples\n\nAlso includes previous modules:\n- Cache module\n- MFA/TOTP module\n- Notification module\n- OAuth providers \\(Google, GitHub, Facebook, Twitter, Apple\\)\n- Payment providers \\(Stripe, PayPal, Mobile Money\\)\n- File upload module\n\nšŸ¤– Generated with [Claude Code]\\(https://claude.com/claude-code\\)\n\nCo-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>\nEOF\n\\)\")",
6
- "Bash(npx eslint:*)",
7
- "Bash(git commit:*)",
8
- "Bash(git push:*)",
9
- "Bash(find:*)",
10
- "Bash(done)",
11
- "Bash(wc:*)",
12
- "Bash(npm install:*)",
13
- "Bash(npm run typecheck:*)",
14
- "Bash(npm run lint:*)",
15
- "Bash(npm test:*)",
16
- "Bash(npm run db:generate:*)",
17
- "Bash(npx prettier:*)",
18
- "Bash(grep:*)",
19
- "Bash(cat:*)",
20
- "Bash(DATABASE_URL=\"postgresql://postgres:Lesourcier@localhost:5432/servcraft_test?schema=public\" npx prisma db push:*)",
21
- "Bash(ls:*)",
22
- "Bash(npm run build:*)",
23
- "Bash(npm whoami:*)",
24
- "Bash(npm login)",
25
- "Bash(npm publish:*)",
26
- "Bash(npm version:*)",
27
- "Bash(servcraft:*)"
28
- ]
29
- }
30
- }
File without changes