Skip to content

Commit

Permalink
fix: code complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Apr 20, 2023
1 parent 7c0873f commit bb6e4d8
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/post-processor/flowTranslationProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,39 @@ class FlowTranslationProcessor extends BaseProcessor {
member: getTranslationName(translationPath),
})
if (this.config.generateDelta) {
const translationPathInOutputFolder = join(
this.config.output,
treatPathSep(translationPath)
)
const translationExist = await pathExists(translationPathInOutputFolder)

let jsonTranslation = getDefaultTranslation()
if (translationExist) {
const xmlTranslation = await readFile(translationPathInOutputFolder)
jsonTranslation = xml2Json(xmlTranslation)
}

const flowDefinitions =
jsonTranslation.Translations?.flowDefinitions ?? []
const fullNames = flowDefinitions.map(flowDef => flowDef.fullName)

const flowDefinitionsImpacted = this.translationPaths
.get(translationPath)
.filter(flowDef => !fullNames.includes(flowDef.fullName))
jsonTranslation.Translations.flowDefinitions = flowDefinitions.concat(
flowDefinitionsImpacted
)

const xmlTranslation = convertJsonToXml(jsonTranslation)

await writeFile(translationPath, xmlTranslation, this.config)
this._scrapTranslationFile(translationPath)
}
}
}

async _scrapTranslationFile(translationPath) {
const translationPathInOutputFolder = join(
this.config.output,
treatPathSep(translationPath)
)
const translationExist = await pathExists(translationPathInOutputFolder)

let jsonTranslation = getDefaultTranslation()
if (translationExist) {
const xmlTranslation = await readFile(translationPathInOutputFolder)
jsonTranslation = xml2Json(xmlTranslation)
}

const flowDefinitions = jsonTranslation.Translations?.flowDefinitions ?? []
const fullNames = flowDefinitions.map(flowDef => flowDef.fullName)

const flowDefinitionsImpacted = this.translationPaths
.get(translationPath)
.filter(flowDef => !fullNames.includes(flowDef.fullName))
jsonTranslation.Translations.flowDefinitions = flowDefinitions.concat(
flowDefinitionsImpacted
)

const xmlTranslation = convertJsonToXml(jsonTranslation)

await writeFile(translationPath, xmlTranslation, this.config)
}

async _parseTranslationFile(translationPath) {
const translationJSON = await parseXmlFileToJson(
translationPath,
Expand Down

0 comments on commit bb6e4d8

Please sign in to comment.