import { Utils } from "@slicemachine/core" ; import * as inquirer from "inquirer" ; export type FrameworkResult = { value : Utils . Framework . FrameworkEnum ; manuallyAdded : boolean ; } ; export async function promptForFramework ( ) { const choices = Utils . Framework . SupportedFrameworks . map ( ( framework ) => { return { name : Utils . Framework . fancyName ( framework ) , value : framework , } ; } ) ; return inquirer . prompt < { framework : Utils . Framework . FrameworkEnum ; } > ( [ { name : "framework" , type : "list" , message : "Select a framework to use" , required : true , choices , } , ] ) . then ( ( res ) => { return { value : res . framework , manuallyAdded : true , } ; } ) ; } export async function detectFramework ( cwd ) { const failMessage = `Please run ${ Utils . bold ( "npx slicemachine init" ) } in a Nuxt or Next.js project` ; const spinner = Utils . spinner ( "Detecting framework to install correct dependencies" ) ; spinner . start ( ) ; try { const maybeFramework = Utils . Framework . detectFramework ( cwd ) ; spinner . stop ( ) ; if ( ! maybeFramework || maybeFramework === Utils . Framework . FrameworkEnum . vanillajs ) { Utils . writeError ( "Framework not detected" ) ; return await promptForFramework ( ) ; } const nameToPrint = Utils . Framework . fancyName ( maybeFramework ) ; if ( Utils . Framework . isUnsupported ( maybeFramework ) ) { Utils . writeError ( `${ nameToPrint } is currently not supported` ) ; console . log ( failMessage ) ; process . exit ( 1 ) ; } Utils . writeCheck ( `${ nameToPrint } detected` ) ; return { value : maybeFramework , manuallyAdded : false , } ; } catch ( error ) { spinner . fail ( "package.json not found" ) ; if ( error instanceof Error && error . message ) { Utils . writeError ( error . message ) ; } else { console . log ( failMessage ) ; } process . exit ( 1 ) ; } }