diff --git a/ern-container-gen-android/src/AndroidGenerator.ts b/ern-container-gen-android/src/AndroidGenerator.ts index 4e0ff9994..a1a81002f 100644 --- a/ern-container-gen-android/src/AndroidGenerator.ts +++ b/ern-container-gen-android/src/AndroidGenerator.ts @@ -23,6 +23,7 @@ import { import _ from 'lodash' import path from 'path' +import fs from 'fs' import readDir from 'fs-readdir-recursive' const PATH_TO_TEMPLATES_DIR = path.join(__dirname, 'templates') @@ -106,6 +107,7 @@ export default class AndroidGenerator implements ContainerGenerator { const injectPluginsTaskMsg = 'Injecting Native Dependencies' const injectPluginsKaxTask = kax.task(injectPluginsTaskMsg) + const replacements: Array<() => void> = [] const dependencies: AndroidDependencies = { annotationProcessor: [], files: [], @@ -183,6 +185,24 @@ export default class AndroidGenerator implements ContainerGenerator { ) } + const { replaceInFile } = pluginConfig.android + if (replaceInFile && Array.isArray(replaceInFile)) { + for (const r of replaceInFile) { + replacements.push(() => { + 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', + }) + }) + } + } + if (pluginConfig.android.dependencies) { const transitivePrefix = 'transitive:' const filesPrefix = 'files' @@ -286,6 +306,10 @@ export default class AndroidGenerator implements ContainerGenerator { pathToOutputActivityFile ) } + + for (const perform of replacements) { + perform() + } } public buildImplementationStatements(