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/dist/cli/index.js
CHANGED
|
@@ -3532,11 +3532,43 @@ export interface ${name.charAt(0).toUpperCase() + name.slice(1)}Data {
|
|
|
3532
3532
|
await writeFile(path6.join(dir, fileName), content);
|
|
3533
3533
|
}
|
|
3534
3534
|
}
|
|
3535
|
+
async function findServercraftModules() {
|
|
3536
|
+
const scriptDir = path6.dirname(new URL(import.meta.url).pathname);
|
|
3537
|
+
const possiblePaths = [
|
|
3538
|
+
// Local node_modules (when servcraft is a dependency)
|
|
3539
|
+
path6.join(process.cwd(), "node_modules", "servcraft", "src", "modules"),
|
|
3540
|
+
// From dist/cli/index.js -> src/modules (npx or global install)
|
|
3541
|
+
path6.resolve(scriptDir, "..", "..", "src", "modules"),
|
|
3542
|
+
// From src/cli/commands/add-module.ts -> src/modules (development)
|
|
3543
|
+
path6.resolve(scriptDir, "..", "..", "modules")
|
|
3544
|
+
];
|
|
3545
|
+
for (const p of possiblePaths) {
|
|
3546
|
+
try {
|
|
3547
|
+
const stats = await fs5.stat(p);
|
|
3548
|
+
if (stats.isDirectory()) {
|
|
3549
|
+
return p;
|
|
3550
|
+
}
|
|
3551
|
+
} catch {
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
return null;
|
|
3555
|
+
}
|
|
3535
3556
|
async function generateModuleFiles(moduleName, moduleDir) {
|
|
3536
|
-
const
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3557
|
+
const moduleNameMap = {
|
|
3558
|
+
"users": "user",
|
|
3559
|
+
"rate-limit": "rate-limit",
|
|
3560
|
+
"feature-flag": "feature-flag",
|
|
3561
|
+
"api-versioning": "api-versioning",
|
|
3562
|
+
"media-processing": "media-processing"
|
|
3563
|
+
};
|
|
3564
|
+
const sourceDirName = moduleNameMap[moduleName] || moduleName;
|
|
3565
|
+
const servercraftModulesDir = await findServercraftModules();
|
|
3566
|
+
if (servercraftModulesDir) {
|
|
3567
|
+
const sourceModuleDir = path6.join(servercraftModulesDir, sourceDirName);
|
|
3568
|
+
if (await fileExists(sourceModuleDir)) {
|
|
3569
|
+
await copyModuleFromSource(sourceModuleDir, moduleDir);
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3540
3572
|
}
|
|
3541
3573
|
switch (moduleName) {
|
|
3542
3574
|
case "auth":
|