(config: Config, cordovaPlugins: Plugin[], platform: string)
| 171 | } |
| 172 | |
| 173 | export async function autoGenerateConfig(config: Config, cordovaPlugins: Plugin[], platform: string): Promise<void> { |
| 174 | let xmlDir = join(config.android.resDirAbs, 'xml'); |
| 175 | const fileName = 'config.xml'; |
| 176 | if (platform === 'ios') { |
| 177 | xmlDir = config.ios.nativeTargetDirAbs; |
| 178 | } |
| 179 | await ensureDir(xmlDir); |
| 180 | const cordovaConfigXMLFile = join(xmlDir, fileName); |
| 181 | await remove(cordovaConfigXMLFile); |
| 182 | const pluginEntries: any[] = []; |
| 183 | cordovaPlugins.map((p) => { |
| 184 | const currentPlatform = getPluginPlatform(p, platform); |
| 185 | if (currentPlatform) { |
| 186 | const configFiles = currentPlatform['config-file']; |
| 187 | if (configFiles) { |
| 188 | const configXMLEntries = configFiles.filter(function (item: any) { |
| 189 | return item.$?.target.includes(fileName); |
| 190 | }); |
| 191 | configXMLEntries.map((entry: any) => { |
| 192 | if (entry.feature) { |
| 193 | const feature = { feature: entry.feature }; |
| 194 | pluginEntries.push(feature); |
| 195 | } |
| 196 | }); |
| 197 | } |
| 198 | } |
| 199 | }); |
| 200 | |
| 201 | let accessOriginString: string[] = []; |
| 202 | if (config.app.extConfig?.cordova?.accessOrigins) { |
| 203 | accessOriginString = await Promise.all( |
| 204 | config.app.extConfig.cordova.accessOrigins.map(async (host): Promise<string> => { |
| 205 | return ` |
| 206 | <access origin="${host}" />`; |
| 207 | }), |
| 208 | ); |
| 209 | } else { |
| 210 | accessOriginString.push(`<access origin="*" />`); |
| 211 | } |
| 212 | const pluginEntriesString: string[] = await Promise.all( |
| 213 | pluginEntries.map(async (item): Promise<string> => { |
| 214 | const xmlString = await writeXML(item); |
| 215 | return xmlString; |
| 216 | }), |
| 217 | ); |
| 218 | let pluginPreferencesString: string[] = []; |
| 219 | if (config.app.extConfig?.cordova?.preferences) { |
| 220 | pluginPreferencesString = await Promise.all( |
| 221 | Object.entries(config.app.extConfig.cordova.preferences).map(async ([key, value]): Promise<string> => { |
| 222 | return ` |
| 223 | <preference name="${key}" value="${value}" />`; |
| 224 | }), |
| 225 | ); |
| 226 | } |
| 227 | const content = `<?xml version='1.0' encoding='utf-8'?> |
| 228 | <widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> |
| 229 | ${accessOriginString.join('')} |
| 230 | ${pluginEntriesString.join('')} |
no test coverage detected