import chalk from 'chalk' ; import figlet from 'figlet' ; import { platform } from 'os' ; import { commands } from './constants' ; import { run , getFileExtensions } from './utils' ; import { name , messages , features } from './messages' ; import { notify , handleSetup , checkUpdate , mappedAnswers , writeFolderStructure , generateScaffoldConfig , } from './scripts' ; const { version } = require ( '../package.json' ) ; const init = async ( ) => { const { thanks , welcome , complete , raiseIssue , walkThrough , } = messages ; const winPlatform = platform ( ) === 'win32' ; const asciiArt = figlet . textSync ( name , { font : 'ANSI Shadow' } ) ; console . log ( `\n${ chalk . cyan ( asciiArt ) }` ) ; console . log ( chalk . green ( `(v${ version })\n` ) ) ; await checkUpdate ( ) ; console . log ( `${ welcome }\n` ) ; features . forEach ( value => console . log ( `${ chalk . green ( winPlatform ? '√' : '✔' ) } ${ value }` ) ) ; console . log ( `\n${ chalk . cyan ( walkThrough ) }\n` ) ; try { const inputs = await handleSetup ( ) ; const { tsUsed , routes , appName , folders , scssUsed , sagaUsed , useLogger , namedExport , dependencies , stateManagement , devDependencies , storesOrReducers , } = mappedAnswers ( inputs ) ; const directory = `${ process . cwd ( ) }/${ appName }` ; const fileExtensions = getFileExtensions ( tsUsed , scssUsed ) ; const scaffoldConfig = generateScaffoldConfig ( tsUsed , routes , folders , sagaUsed , useLogger , namedExport , fileExtensions , stateManagement ? { type : stateManagement , storesOrReducers } : undefined ) ; console . log ( `\nSetting up a new React app in ${ chalk . green ( directory ) }\n` ) ; const { installReact , installDependencies , installDevDependencies , } = commands ; await run ( installReact , [ appName , ... tsUsed ? [ '--template typescript' ] : [ ] ] ) ; await writeFolderStructure ( appName , scaffoldConfig , fileExtensions , ! ! routes . length , namedExport , stateManagement ) ; await run ( installDependencies , dependencies , appName ) ; await run ( installDevDependencies , devDependencies , appName ) ; console . log ( `\n${ complete } ${ chalk . green ( directory ) }\n` ) ; console . log ( thanks ) ; console . log ( `${ raiseIssue }\n` ) ; await notify ( winPlatform ) ; } catch ( error ) { console . error ( error . message ) ; } } ; init ( ) ;