const patterns = require ( '../lib/patterns' ) ; module . exports = async function ( context ) { const { parameters , print , strings , ignite , filesystem } = context ; const { pascalCase , isBlank } = strings ; const config = ignite . loadIgniteConfig ( ) ; if ( isBlank ( parameters . first ) ) { print . info ( `${ context . runtime . brand } generate screen <name>\n` ) ; print . info ( 'A name is required.' ) ; return ; } const name = pascalCase ( parameters . first ) ; const screenName = name . endsWith ( 'Screen' ) ? name : `${ name }Screen` ; const props = { name : screenName } ; const jobs = [ { template : `screen.ejs` , target : `App/Containers/${ screenName }/${ screenName }.tsx` } , { template : `screen-style.ejs` , target : `App/Containers/${ screenName }/${ screenName }Style.tsx` } , { template : 'component-index.ejs' , target : `App/Containers/${ screenName }/index.ts` } ] ; await ignite . copyBatch ( context , jobs , props ) ; if ( config . navigation === 'react-navigation' ) { const appNavFilePath = `${ process . cwd ( ) }/App/Navigation/AppNavigation.tsx` ; const importToAdd = `import ${ screenName } from "../Containers/${ screenName }";` ; const routeToAdd = `  ${ screenName }: { screen: ${ screenName } },` ; if ( ! filesystem . exists ( appNavFilePath ) ) { const msg = `No '${ appNavFilePath }' file found.  Can't insert screen.` ; print . error ( msg ) ; process . exit ( 1 ) ; } ignite . patchInFile ( appNavFilePath , { after : patterns [ patterns . constants . PATTERN_IMPORTS ] , insert : importToAdd } ) ; ignite . patchInFile ( appNavFilePath , { after : patterns [ patterns . constants . PATTERN_ROUTES ] , insert : routeToAdd } ) ; } else { print . info ( `Screen ${ screenName } created, manually add it to your navigation` ) ; } } ;