in experimental/generation/generator/packages/library/src/mergeAssets.ts [219:285]
async function mergeRootLGFile(schemaName: string, oldPath: string, oldFileList: string[], newPath: string, newFileList: string[], mergedPath: string, locale: string, oldPropertySet: Set<string>, newPropertySet: Set<string>, feedback: Feedback): Promise<void> {
const outDir = assetDirectory('.lg')
const oldText = await fs.readFile(ppath.join(oldPath, outDir, locale, `${schemaName}.${locale}${'.lg'}`), 'utf8')
const oldRefs = oldText.split(os.EOL)
const newText = await fs.readFile(ppath.join(newPath, outDir, locale, `${schemaName}.${locale}${'.lg'}`), 'utf8')
const newRefs = newText.split(os.EOL)
const resultRefs: string[] = []
const oldRefSet = new Set<string>()
for (const ref of oldRefs) {
if (ref.match('> Generator:')) {
if (resultRefs.length !== 0 && resultRefs[resultRefs.length - 1] === '') {
resultRefs.pop()
}
break
}
if (!ref.startsWith('[')) {
resultRefs.push(ref)
continue
}
oldRefSet.add(ref)
const file = refFilename(ref, feedback)
const extractedProperty = extractProperty(file, oldPropertySet, schemaName)
if (extractedProperty !== undefined) {
if (newPropertySet.has(extractedProperty)) {
resultRefs.push(ref)
if (file.match(`${extractedProperty}Value`)) {
await changeEntityEnumLG(oldPath, oldFileList, newPath, newFileList, mergedPath, file, feedback)
} else {
if (await !isOldUnchanged(oldFileList, file) && await getHashCodeFromFile(oldFileList, file) !== await getHashCodeFromFile(newFileList, file)) {
cannotMergeMessage(file, oldFileList, newFileList, feedback)
} else {
await copySingleFile(oldPath, mergedPath, file, oldFileList, feedback)
}
}
}
} else {
resultRefs.push(ref)
if (newText.match(file) && !await isOldUnchanged(oldFileList, file) && await getHashCodeFromFile(oldFileList, file) !== await getHashCodeFromFile(newFileList, file)) {
cannotMergeMessage(file, oldFileList, newFileList, feedback)
} else {
await copySingleFile(oldPath, mergedPath, file, oldFileList, feedback)
}
}
}
for (const ref of newRefs) {
if (!ref.startsWith('[')) {
continue
}
if (!oldRefSet.has(ref)) {
resultRefs.push(ref)
const file = refFilename(ref, feedback)
await copySingleFile(newPath, mergedPath, file, newFileList, feedback)
}
}
let val = resultRefs.join(os.EOL)
const patternIndex = oldText.search(GeneratorPattern)
if (patternIndex !== -1) {
val = val + os.EOL + oldText.substring(patternIndex)
}
await writeToFile(oldPath, mergedPath, `${schemaName}.${locale}.lg`, oldFileList, val, feedback)
}