import { existsSync } from "fs" ; import { resolve } from "path" ; import { FrameworkDetectors } from "../constants/FrameworkDetectors" ; import { Extension } from "./Extension" ; export class FrameworkDetector { public static get ( folder ) { return this . check ( folder ) ; } public static getAll ( ) { return FrameworkDetectors . map ( ( detector ) => detector . framework ) ; } private static check ( folder ) { const { dependencies , devDependencies } = Extension . getInstance ( ) . packageJson ; for ( const detector of FrameworkDetectors ) { if ( detector && folder ) { for ( const dependency of detector . requiredDependencies ?? [ ] ) { const inDependencies = dependencies && dependencies [ dependency ] ; const inDevDependencies = devDependencies && devDependencies [ dependency ] ; if ( inDependencies || inDevDependencies ) { return detector . framework ; } } for ( const filename of detector . requiredFiles ?? [ ] ) { const fileExists = existsSync ( resolve ( folder , filename ) ) ; if ( fileExists ) { return detector . framework ; } } } } return undefined ; } }