import { ExpoConfig } from '@expo/config-types' ; import { ConfigPlugin } from '../Plugin.types' ; import { createStringsXmlPlugin , withSettingsGradle } from '../plugins/android-plugins' ; import { addWarningAndroid } from '../utils/warnings' ; import { buildResourceItem , ResourceXML } from './Resources' ; import { removeStringItem , setStringItem } from './Strings' ; param name export function sanitizeNameForGradle ( name ) { name = name . replace ( /[\n\r\t]/g , '' ) ; return name . replace ( /(\/|\\|:|<|>|"|\?|\*|\|)/g , '' ) ; } export const withName = createStringsXmlPlugin ( applyNameFromConfig , 'withName' ) ; export const withNameSettingsGradle = config => { return withSettingsGradle ( config , config => { if ( config . modResults . language === 'groovy' ) { config . modResults . contents = applyNameSettingsGradle ( config , config . modResults . contents ) ; } else { addWarningAndroid ( 'name' , `Cannot automatically configure settings.gradle if it's not groovy` ) ; } return config ; } ) ; } ; export function getName ( config ) { return typeof config . name === 'string' ? config . name : null ; } function applyNameFromConfig ( config , stringsJSON ) { const name = getName ( config ) ; if ( name ) { return setStringItem ( [ buildResourceItem ( { name : 'app_name' , value : name } ) ] , stringsJSON ) ; } return removeStringItem ( 'app_name' , stringsJSON ) ; } param config param settingsGradle export function applyNameSettingsGradle ( config , settingsGradle ) { const name = sanitizeNameForGradle ( getName ( config ) ?? '' ) ; return settingsGradle . replace ( /rootProject.name\s?=\s?(["'])(?:(?=(\\?))\2.)*?\1/g , `rootProject.name = '${ name . replace ( /'/g , "\\'" ) }'` ) ; }