Skip to content

Commit

Permalink
perform file replacements after mustache template render
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgovea committed Jun 4, 2019
1 parent 5462ef3 commit ad71b0f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions ern-container-gen-android/src/AndroidGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default class AndroidGenerator implements ContainerGenerator {
const injectPluginsTaskMsg = 'Injecting Native Dependencies'
const injectPluginsKaxTask = kax.task(injectPluginsTaskMsg)

const replacements: Array<() => Promise<void>> = []
const dependencies: AndroidDependencies = {
annotationProcessor: [],
files: [],
Expand Down Expand Up @@ -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',
})
})
}
}
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit ad71b0f

Please sign in to comment.