78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
import chalk from 'chalk';
|
|
import { resolve } from 'path';
|
|
import { existsSync } from 'fs';
|
|
import { detectProject, getProjectInfo } from '../detectors/index.js';
|
|
|
|
/**
|
|
* Detect command - identify project type and show deployment recommendations
|
|
*/
|
|
export async function detectCommand(path, options) {
|
|
const projectPath = resolve(path);
|
|
|
|
if (!existsSync(projectPath)) {
|
|
throw new Error(`Path does not exist: ${projectPath}`);
|
|
}
|
|
|
|
console.log(chalk.blue('Scanning project...'), projectPath);
|
|
console.log();
|
|
|
|
const detection = await detectProject(projectPath);
|
|
|
|
if (options.json) {
|
|
console.log(JSON.stringify(detection, null, 2));
|
|
return detection;
|
|
}
|
|
|
|
// Display results
|
|
if (detection.dockerizable) {
|
|
console.log(chalk.green('✓ Detected:'), chalk.bold(detection.description || detection.type));
|
|
console.log();
|
|
console.log(chalk.gray(' Project: '), detection.projectName);
|
|
console.log(chalk.gray(' Type: '), detection.type);
|
|
console.log(chalk.gray(' Template: '), detection.template);
|
|
console.log(chalk.gray(' Port: '), detection.port || 'N/A');
|
|
console.log(chalk.gray(' Entry: '), detection.entryPoint || 'N/A');
|
|
|
|
if (detection.buildCommand) {
|
|
console.log(chalk.gray(' Build: '), detection.buildCommand);
|
|
}
|
|
|
|
if (detection.note) {
|
|
console.log();
|
|
console.log(chalk.yellow(' Note:'), detection.note);
|
|
}
|
|
|
|
console.log();
|
|
console.log(chalk.gray('Dockerizable:'), chalk.green('Yes'));
|
|
|
|
// Get additional info
|
|
const info = await getProjectInfo(projectPath, detection.type);
|
|
if (info) {
|
|
console.log();
|
|
console.log(chalk.gray('Additional Info:'));
|
|
if (info.dependencies) {
|
|
console.log(chalk.gray(' Dependencies:'), info.dependencies.length);
|
|
}
|
|
if (info.scripts) {
|
|
console.log(chalk.gray(' Scripts:'), info.scripts.join(', '));
|
|
}
|
|
if (info.packages) {
|
|
console.log(chalk.gray(' Packages:'), info.packages.length);
|
|
}
|
|
}
|
|
|
|
console.log();
|
|
console.log(chalk.blue('Next step:'), `npm run docker-deploy -- init "${path}"`);
|
|
|
|
} else {
|
|
console.log(chalk.red('✗ Not Dockerizable:'), chalk.bold(detection.type));
|
|
console.log();
|
|
console.log(chalk.gray(' Project:'), detection.projectName);
|
|
console.log(chalk.gray(' Reason: '), detection.reason);
|
|
console.log();
|
|
console.log(chalk.gray('Dockerizable:'), chalk.red('No'));
|
|
}
|
|
|
|
return detection;
|
|
}
|