import * as path from "node:path";
import { pathExists, readJsonOrNull } from "../../utils/index.js";
/**
 * Check if any key in an object starts with a prefix
 * @param obj Object to check
 * @param prefix Prefix to search for
 * @returns True if any key starts with prefix
 */
function hasKeyStartingWith(obj, prefix) {
    if (!obj) {
        return false;
    }
    return Object.keys(obj).some(key => key.startsWith(prefix));
}
/**
 * Detector for AWS CDK projects
 * Detects by presence of cdk.json or aws-cdk* dependencies
 */
export class CDKDetector {
    type = "cdk";
    /**
     * Detect if the project uses AWS CDK
     * @param destDir - Project directory to check
     * @returns True if AWS CDK is detected
     */
    async detect(destDir) {
        // Check for cdk.json
        const cdkJsonPath = path.join(destDir, "cdk.json");
        if (await pathExists(cdkJsonPath)) {
            return true;
        }
        // Check for aws-cdk* in package.json
        const packageJsonPath = path.join(destDir, "package.json");
        const packageJson = await readJsonOrNull(packageJsonPath);
        if (!packageJson) {
            return false;
        }
        return (hasKeyStartingWith(packageJson.dependencies, "aws-cdk") ||
            hasKeyStartingWith(packageJson.devDependencies, "aws-cdk"));
    }
}
//# sourceMappingURL=cdk.js.map