Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android replaceInFile #1197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions ern-container-gen-android/src/AndroidGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -286,6 +306,10 @@ export default class AndroidGenerator implements ContainerGenerator {
pathToOutputActivityFile
)
}

for (const perform of replacements) {
perform()
}
}

public buildImplementationStatements(
Expand Down