Skip to content

Commit

Permalink
[#491] Add swift function of replace all in
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Aug 4, 2023
1 parent d4ef290 commit ac197e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_upload_build_to_firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit

- name: Start Setup Script for Template App Firebase Upload
run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Bash.swift Scripts/Swift/Helpers/SafeShell.swift | swift -
run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift -
env:
MATCH_REPO: ${{ secrets.MATCH_REPO }}
STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }}
Expand Down
8 changes: 0 additions & 8 deletions Scripts/Swift/Extensions/FileManager+Bash.swift

This file was deleted.

32 changes: 32 additions & 0 deletions Scripts/Swift/Extensions/FileManager+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,36 @@ extension FileManager {
print("Error \(error)")
}
}

func replaceAllOccurrences(of original: String, to replacing: String) throws {
let files = try allFiles(in: currentDirectoryPath)
for file in files {
do {
let text = try String(contentsOf: file, encoding: .utf8)
print(file)
let modifiedText = text.replacingOccurrences(of: original, with: replacing)
try modifiedText.write(to: file, atomically: true, encoding: .utf8)
}
catch {
print(error)
}
}
}

private func allFiles(in directory: String) throws -> [URL] {
let url = URL(fileURLWithPath: directory)
var files = [URL]()
if let enumerator = enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
for case let fileURL as URL in enumerator {
do {
let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey])
guard fileAttributes.isRegularFile ?? false,
fileURL.pathExtension.count > 0
else { continue }
files.append(fileURL)
}
}
}
return files
}
}

0 comments on commit ac197e0

Please sign in to comment.