servcraft 0.1.5 → 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/index.cjs +40 -4
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +36 -4
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/add-module.ts +80 -8
package/package.json
CHANGED
|
@@ -621,19 +621,91 @@ export interface ${name.charAt(0).toUpperCase() + name.slice(1)}Data {
|
|
|
621
621
|
}
|
|
622
622
|
|
|
623
623
|
/**
|
|
624
|
-
* Helper:
|
|
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
|
-
//
|
|
628
|
-
const
|
|
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
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
|
708
|
+
// Fallback to inline templates for basic modules
|
|
637
709
|
switch (moduleName) {
|
|
638
710
|
case 'auth':
|
|
639
711
|
await generateAuthModule(moduleDir);
|