             groupsByPath[path] = group
         }
         groups.insert(group, at: 0)
-        return (allFilePaths, groups)
+        return (allSourceFiles, groups)
     }
 }

        var buildPhases: [String] = []

        func getBuildFilesForPhase(_ buildPhase: BuildPhase) -> [String] {
            let files = sourceFilePaths.filter { getBuildPhaseForPath($0) == buildPhase }.map(generateSourceFile)
            return files.map { $0.buildFile.reference }
        }


            .filter { $0.extension == "lproj" }
            .sorted { $0.lastComponent < $1.lastComponent }

        var groupChildren: [String] = filePaths.map { getFileReference(path: $0, inPath: path) }
        var allSourceFiles: [SourceFile] = filePaths.map { generateSourceFile(path: $0) }
        var groups: [PBXGroup] = []

        for path in directories {
            let subGroups = try getGroups(path: path, depth: depth + 1)
            allSourceFiles += subGroups.sourceFiles
            groupChildren.append(subGroups.groups.first!.reference)
            groups += subGroups.groups
        }

        // create variant groups of the base localisation first
        var baseLocalisationVariantGroups:[PBXVariantGroup] = []
        if let baseLocalisedDirectory = localisedDirectories.first(where: { $0.lastComponent == "Base.lproj" }) {
            for path in try baseLocalisedDirectory.children() {
                let filePath = "\(baseLocalisedDirectory.lastComponent)/\(path.lastComponent)"

                let variantGroup: PBXVariantGroup
                if let cachedGroup = variantGroupsByPath[path] {
                    variantGroup = cachedGroup
                } else {
                    variantGroup = PBXVariantGroup(reference: generateUUID(PBXVariantGroup.self, filePath),
                                                   children: [],
                                                   name: path.lastComponent,
                                                   sourceTree: .group)
                    variantGroupsByPath[path] = variantGroup
                    
                    addObject(variantGroup)
                    groupChildren.append(variantGroup.reference)
                }

                baseLocalisationVariantGroups.append(variantGroup)

                let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, variantGroup.reference), fileRef: variantGroup.reference, settings: nil)
                allSourceFiles.append(SourceFile(path: path, fileReference: variantGroup.reference, buildFile: buildFile))
            }
        }

        // add references to localised resources into base localisation variant groups
        for localisedDirectory in localisedDirectories {
            let localisationName = localisedDirectory.lastComponentWithoutExtension
            for path in try localisedDirectory.children().sorted { $0.lastComponent < $1.lastComponent } {
                guard fileReferencesByPath[path] == nil else {
                    continue
                }

                let filePath = "\(localisedDirectory.lastComponent)/\(path.lastComponent)"

                // find base localisation variant group
                let name = path.lastComponentWithoutExtension
                let variantGroup = baseLocalisationVariantGroups.first(where: { Path($0.name).lastComponentWithoutExtension == name })

                let reference = PBXFileReference(reference: generateUUID(PBXFileReference.self, path.lastComponent),
                                                 sourceTree: .group,
                                                 name: variantGroup != nil ? localisationName : path.lastComponent,
                                                 path: filePath)
                addObject(reference)
                fileReferencesByPath[path] = reference.reference
                let fileReference = reference.reference

                if let variantGroup = variantGroup {
                    variantGroup.children.append(fileReference)
                } else {
                    // add SourceFile to group if there is no Base.lproj directory
                    let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference),
                                                 fileRef: fileReference,
                                                 settings: nil)
                    allSourceFiles.append(SourceFile(path: path, fileReference: fileReference, buildFile: buildFile))
                    groupChildren.append(fileReference)
                }
            }
        }

