UNPKG

@stacksjs/launchpad

Version:
23 lines (21 loc) 5.23 kB
// @bun import{ab as M}from"./chunk-b9hx8gsj.js";import"./chunk-8pxdwzvm.js";import D from"fs";import B from"path";import O from"process";class Q{projectRoot;constructor(q=O.cwd()){this.projectRoot=q}async analyzeProject(){let q={framework:null,databases:[],hasApi:!1,hasWebInterface:!1,hasImageProcessing:!1,hasEnterpriseFeatures:!1,recommendedConfig:"laravel-mysql",reasoning:[]};if(q.framework=this.detectFramework(),q.framework)q.reasoning.push(`Detected ${q.framework} framework`);if(q.databases=this.detectDatabases(),q.databases.length>0)q.reasoning.push(`Detected databases: ${q.databases.join(", ")}`);return q.hasApi=this.detectAPI(),q.hasWebInterface=this.detectWebInterface(),q.hasImageProcessing=this.detectImageProcessing(),q.hasEnterpriseFeatures=this.detectEnterpriseFeatures(),q.recommendedConfig=this.determineOptimalConfig(q),q}detectFramework(){if(D.existsSync(B.join(this.projectRoot,"artisan"))&&D.existsSync(B.join(this.projectRoot,"composer.json")))try{let q=JSON.parse(D.readFileSync(B.join(this.projectRoot,"composer.json"),"utf-8"));if(q.require?.["laravel/framework"])return"laravel";if(q.require?.["laravel/lumen-framework"])return"laravel"}catch{}if(D.existsSync(B.join(this.projectRoot,"wp-config.php"))||D.existsSync(B.join(this.projectRoot,"wp-config-sample.php")))return"wordpress";if(D.existsSync(B.join(this.projectRoot,"symfony.lock"))||D.existsSync(B.join(this.projectRoot,"config","bundles.php")))return"symfony";return null}detectDatabases(){let q=[],H=B.join(this.projectRoot,".env");if(D.existsSync(H))try{let z=D.readFileSync(H,"utf-8");if(z.includes("DB_CONNECTION=mysql")||z.includes("DB_CONNECTION=pgsql")||z.includes("DB_CONNECTION=sqlite")){if(z.includes("DB_CONNECTION=mysql"))q.push("mysql");if(z.includes("DB_CONNECTION=pgsql")||z.includes("DB_CONNECTION=postgres"))q.push("postgres");if(z.includes("DB_CONNECTION=sqlite"))q.push("sqlite")}}catch{}if(D.existsSync(B.join(this.projectRoot,"database.sqlite"))||D.existsSync(B.join(this.projectRoot,"database","database.sqlite"))){if(!q.includes("sqlite"))q.push("sqlite")}let K=B.join(this.projectRoot,"wp-config.php");if(D.existsSync(K))try{let z=D.readFileSync(K,"utf-8");if(z.includes("DB_HOST")&&z.includes("DB_NAME")){if(!q.includes("mysql"))q.push("mysql")}}catch{}if(q.length===0)q.push("sqlite");return q}detectAPI(){return[B.join(this.projectRoot,"routes","api.php"),B.join(this.projectRoot,"app","Http","Controllers","Api"),B.join(this.projectRoot,"api")].some((H)=>D.existsSync(H))}detectWebInterface(){return[B.join(this.projectRoot,"routes","web.php"),B.join(this.projectRoot,"resources","views"),B.join(this.projectRoot,"templates"),B.join(this.projectRoot,"public","index.php")].some((H)=>D.existsSync(H))}detectImageProcessing(){return[B.join(this.projectRoot,"storage","app","public","images"),B.join(this.projectRoot,"public","images"),B.join(this.projectRoot,"resources","images"),B.join(this.projectRoot,"uploads")].some((H)=>D.existsSync(H))}detectEnterpriseFeatures(){return[B.join(this.projectRoot,"app","Services"),B.join(this.projectRoot,"app","Jobs"),B.join(this.projectRoot,"app","Events"),B.join(this.projectRoot,"app","Listeners"),B.join(this.projectRoot,"config","queue.php"),B.join(this.projectRoot,"config","cache.php")].some((H)=>D.existsSync(H))}determineOptimalConfig(q){let{framework:H,databases:K,hasApi:z,hasWebInterface:L,hasEnterpriseFeatures:N}=q;if(H==="wordpress")return"wordpress";if(H==="laravel"){if(K.includes("postgres")&&!K.includes("mysql"))return"laravel-postgres";if(K.includes("sqlite")&&K.length===1)return"laravel-sqlite";return"laravel-mysql"}if(z&&!L)return"api-only";if(N||K.length>1)return"enterprise";if(M.services?.php?.autoDetect?.includeAllDatabases)return"full-stack";if(M.services?.php?.autoDetect?.includeEnterprise)return"enterprise";if(K.includes("postgres"))return"laravel-postgres";if(K.includes("sqlite"))return"laravel-sqlite";return"laravel-mysql"}getConfigurationExplanation(q){let{recommendedConfig:H,reasoning:K}=q,z=`\uD83C\uDFAF Recommended PHP Configuration: ${H} `;switch(z+=`\uD83D\uDCCB Analysis: `,K.forEach((L)=>{z+=` \u2022 ${L} `}),z+=` \uD83D\uDD27 Configuration Details: `,H){case"laravel-mysql":z+=` \u2022 Optimized for Laravel with MySQL/MariaDB `,z+=` \u2022 Includes: CLI, FPM, MySQL drivers, web extensions `;break;case"laravel-postgres":z+=` \u2022 Optimized for Laravel with PostgreSQL `,z+=` \u2022 Includes: CLI, FPM, PostgreSQL drivers, web extensions `;break;case"laravel-sqlite":z+=` \u2022 Optimized for Laravel with SQLite (development) `,z+=` \u2022 Includes: CLI, FPM, SQLite drivers, web extensions `;break;case"api-only":z+=` \u2022 Minimal configuration for API-only applications `,z+=` \u2022 Includes: CLI, FPM, basic web extensions `;break;case"enterprise":z+=` \u2022 Full-featured configuration for enterprise applications `,z+=` \u2022 Includes: All major extensions and database drivers `;break;case"wordpress":z+=` \u2022 Optimized for WordPress applications `,z+=` \u2022 Includes: WordPress-specific extensions `;break;case"full-stack":z+=` \u2022 Complete PHP with all database drivers `,z+=` \u2022 Includes: All extensions for maximum flexibility `;break}return z}}export{Q as PHPAutoDetector};