node-apis
Version:
🚀 Advanced TypeScript API generator with clean architecture, comprehensive testing, and automatic formatting. Generate production-ready Node.js APIs with complete integration test suites.
97 lines • 4.03 kB
JavaScript
;
/**
* Module detection service
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExistingModules = exports.detectExistingModule = void 0;
const path = __importStar(require("path"));
const config_service_1 = require("./config.service");
const path_utils_1 = require("../filesystem/path.utils");
const directory_operations_1 = require("../filesystem/directory.operations");
const file_operations_1 = require("../filesystem/file.operations");
/**
* Detects if a module already exists and returns information about it
*/
const detectExistingModule = async ({ moduleName, baseDir = process.cwd(), framework, }) => {
// Get effective framework if not provided
const effectiveFramework = framework || await (0, config_service_1.getEffectiveFramework)();
const modulePath = await (0, path_utils_1.getModulePath)({ moduleName, baseDir, framework: effectiveFramework });
const exists = await (0, directory_operations_1.directoryExists)({ dirPath: modulePath });
if (!exists) {
return null;
}
const typesDir = path.join(modulePath, 'types');
const hasTypes = await (0, directory_operations_1.directoryExists)({ dirPath: typesDir });
let existingFiles = [];
if (hasTypes) {
existingFiles = await (0, file_operations_1.getFilesWithExtension)({
dirPath: typesDir,
extension: '.ts',
});
}
return {
moduleName,
modulePath,
existingFiles,
hasTypes,
};
};
exports.detectExistingModule = detectExistingModule;
/**
* Gets a list of existing modules in the project
*/
const getExistingModules = async ({ baseDir = process.cwd(), framework, } = {}) => {
// Get effective framework if not provided
const effectiveFramework = framework || await (0, config_service_1.getEffectiveFramework)();
// Use detected source path instead of hardcoded 'src'
const { detectSourcePath } = await Promise.resolve().then(() => __importStar(require('../filesystem/path.utils')));
const srcPath = await detectSourcePath(baseDir);
// Determine the correct directory based on framework
let apisDir;
if (effectiveFramework === 't3') {
apisDir = path.join(baseDir, srcPath, 'server', 'api');
}
else {
apisDir = path.join(baseDir, srcPath, 'apis');
}
const exists = await (0, directory_operations_1.directoryExists)({ dirPath: apisDir });
if (!exists) {
return [];
}
return await (0, directory_operations_1.getDirectories)({ dirPath: apisDir });
};
exports.getExistingModules = getExistingModules;
//# sourceMappingURL=module-detection.service.js.map