diff --git a/ern-container-gen-android/src/AndroidGenerator.ts b/ern-container-gen-android/src/AndroidGenerator.ts index e1951f7d1..0960f4c14 100644 --- a/ern-container-gen-android/src/AndroidGenerator.ts +++ b/ern-container-gen-android/src/AndroidGenerator.ts @@ -107,6 +107,7 @@ export default class AndroidGenerator implements ContainerGenerator { const injectPluginsTaskMsg = 'Injecting Native Dependencies' const injectPluginsKaxTask = kax.task(injectPluginsTaskMsg) + const replacements: Array<() => Promise> = [] const dependencies: AndroidDependencies = { annotationProcessor: [], files: [], @@ -184,18 +185,20 @@ export default class AndroidGenerator implements ContainerGenerator { ) } - if (pluginConfig.android.replaceInFile) { - log.debug('Performing file replacements (before final Mustache render)'); - log.debug('TODO - consider performing this after final render'); - for (const r of pluginConfig.android.replaceInFile) { - const pathToFile = path.join(config.outDir, r.path) - const fileContent = fs.readFileSync(pathToFile, 'utf8') - const patchedFileContent = fileContent.replace( - RegExp(r.string, 'g'), - r.replaceWith - ) - fs.writeFileSync(pathToFile, patchedFileContent, { - encoding: 'utf8', + const { replaceInFile } = pluginConfig.android + if (replaceInFile && Array.isArray(replaceInFile)) { + for (const r of replaceInFile) { + replacements.push(async () => { + log.debug(`Performing string replacement on ${r.path}`) + const pathToFile = path.join(config.outDir, r.path) + const fileContent = fs.readFileSync(pathToFile, 'utf8') + const patchedFileContent = fileContent.replace( + RegExp(r.string, 'g'), + r.replaceWith + ) + fs.writeFileSync(pathToFile, patchedFileContent, { + encoding: 'utf8', + }) }) } } @@ -282,6 +285,10 @@ export default class AndroidGenerator implements ContainerGenerator { ) } + for (const replacement of replacements) { + await replacement() + } + log.debug('Creating miniapp activities') for (const miniApp of config.composite.getMiniApps()) { const activityFileName = `${miniApp.pascalCaseName}Activity.java`