first pass
This commit is contained in:
126
cli/detectors/index.js
Normal file
126
cli/detectors/index.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import { detectNodeJS, getNodeJSInfo } from './nodejs.js';
|
||||
import { detectPython, getPythonInfo } from './python.js';
|
||||
import { detectDotNet, getDotNetInfo } from './dotnet.js';
|
||||
import { detectStatic, getStaticInfo } from './static.js';
|
||||
import { basename } from 'path';
|
||||
|
||||
/**
|
||||
* Detect project type by running all detectors
|
||||
* Returns the first successful detection
|
||||
*/
|
||||
export async function detectProject(projectPath) {
|
||||
const projectName = basename(projectPath);
|
||||
|
||||
// Run detectors in order of priority
|
||||
// Node.js first (most common), then Python, .NET, and finally static
|
||||
|
||||
// 1. Node.js detection
|
||||
const nodeResult = detectNodeJS(projectPath);
|
||||
if (nodeResult) {
|
||||
return {
|
||||
...nodeResult,
|
||||
projectName,
|
||||
projectPath
|
||||
};
|
||||
}
|
||||
|
||||
// 2. Python detection
|
||||
const pythonResult = detectPython(projectPath);
|
||||
if (pythonResult) {
|
||||
return {
|
||||
...pythonResult,
|
||||
projectName,
|
||||
projectPath
|
||||
};
|
||||
}
|
||||
|
||||
// 3. .NET detection
|
||||
const dotnetResult = await detectDotNet(projectPath);
|
||||
if (dotnetResult) {
|
||||
return {
|
||||
...dotnetResult,
|
||||
projectName,
|
||||
projectPath
|
||||
};
|
||||
}
|
||||
|
||||
// 4. Static site detection
|
||||
const staticResult = await detectStatic(projectPath);
|
||||
if (staticResult) {
|
||||
return {
|
||||
...staticResult,
|
||||
projectName,
|
||||
projectPath
|
||||
};
|
||||
}
|
||||
|
||||
// No detection
|
||||
return {
|
||||
type: 'unknown',
|
||||
dockerizable: false,
|
||||
reason: 'Could not determine project type. No package.json, requirements.txt, .csproj, or index.html found.',
|
||||
projectName,
|
||||
projectPath,
|
||||
template: null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed info about a project
|
||||
*/
|
||||
export async function getProjectInfo(projectPath, type) {
|
||||
switch (true) {
|
||||
case type.startsWith('nodejs'):
|
||||
return getNodeJSInfo(projectPath);
|
||||
case type.startsWith('python'):
|
||||
return getPythonInfo(projectPath);
|
||||
case type.startsWith('dotnet'):
|
||||
return await getDotNetInfo(projectPath);
|
||||
case type.startsWith('static') || type.startsWith('flutter'):
|
||||
return await getStaticInfo(projectPath);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a path is a valid project directory
|
||||
*/
|
||||
export function isValidProject(projectPath) {
|
||||
// Exclude common non-project directories
|
||||
const excludePatterns = [
|
||||
'node_modules',
|
||||
'.git',
|
||||
'.vscode',
|
||||
'.idea',
|
||||
'dist',
|
||||
'build',
|
||||
'coverage',
|
||||
'__pycache__',
|
||||
'venv',
|
||||
'.venv'
|
||||
];
|
||||
|
||||
const name = basename(projectPath);
|
||||
return !excludePatterns.includes(name) && !name.startsWith('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all project types supported
|
||||
*/
|
||||
export function getSupportedTypes() {
|
||||
return [
|
||||
{ type: 'nodejs-express', description: 'Express.js server', template: 'nodejs/express' },
|
||||
{ type: 'nodejs-vite-react', description: 'Vite + React SPA', template: 'nodejs/vite-react' },
|
||||
{ type: 'nodejs-vite-react-ssr', description: 'Vite + React with Express SSR', template: 'nodejs/vite-react-ssr' },
|
||||
{ type: 'nodejs-generic', description: 'Generic Node.js application', template: 'nodejs/express' },
|
||||
{ type: 'python-standard', description: 'Standard Python application', template: 'python/standard' },
|
||||
{ type: 'python-ml-pytorch', description: 'Python ML/AI with PyTorch', template: 'python/ml-pytorch' },
|
||||
{ type: 'dotnet-blazor', description: '.NET Blazor web application', template: 'dotnet/blazor' },
|
||||
{ type: 'dotnet-webapi', description: '.NET Web API', template: 'dotnet/webapi' },
|
||||
{ type: 'static-nginx', description: 'Static website with Nginx', template: 'static/nginx' },
|
||||
{ type: 'flutter-web', description: 'Flutter web application', template: 'static/nginx' }
|
||||
];
|
||||
}
|
||||
|
||||
export { detectNodeJS, detectPython, detectDotNet, detectStatic };
|
||||
Reference in New Issue
Block a user