Skip to content

Commit

Permalink
Add replaceInFile for android modules
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgovea authored and belemaire committed Jun 5, 2019
1 parent 29df99b commit 8782f11
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 8782f11

Please sign in to comment.