|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Usage: ./removePublicDeclarations.sh Sources/StreamNuke |
| 4 | +# |
| 5 | +# This script would iterate over the files on a particular directory, and perform basic replacement operations. |
| 6 | +# It heavily relies on 'sed': |
| 7 | +# sed -i '<backup-file-extension>' -e 's/<original-string>/<replacement>/g' <file> |
| 8 | +# ^ |
| 9 | +# Passing empty string prevents the creation of backup files |
| 10 | + |
| 11 | +args=("$@") |
| 12 | +directory=$1 |
| 13 | + |
| 14 | +replaceDeclaration() { |
| 15 | + original=$1 |
| 16 | + replacement=$2 |
| 17 | + file=$3 |
| 18 | + `sed -i '' -e "s/$original/$replacement/g" $file` |
| 19 | +} |
| 20 | + |
| 21 | +files=`find $directory -name "*.swift"` |
| 22 | +for f in $files |
| 23 | +do |
| 24 | + replaceDeclaration 'public internal(set) ' '' $f |
| 25 | + replaceDeclaration 'open ' '' $f |
| 26 | + replaceDeclaration 'public ' '' $f |
| 27 | + |
| 28 | + # Nuke |
| 29 | + if [[ $directory == *"Nuke"* ]]; then |
| 30 | + replaceDeclaration 'var log' 'var nukeLog' $f |
| 31 | + replaceDeclaration 'log =' 'nukeLog =' $f |
| 32 | + replaceDeclaration 'log: log' 'log: nukeLog' $f |
| 33 | + replaceDeclaration 'signpost(log' 'signpost(nukeLog' $f |
| 34 | + replaceDeclaration ' Cache(' ' NukeCache(' $f |
| 35 | + replaceDeclaration ' Cache<' ' NukeCache<' $f |
| 36 | + replaceDeclaration ' Image?' ' NukeImage?' $f |
| 37 | + replaceDeclaration ' Image(' ' NukeImage(' $f |
| 38 | + replaceDeclaration 'struct Image:' 'struct NukeImage:' $f |
| 39 | + replaceDeclaration 'extension Image {' 'extension NukeImage {' $f |
| 40 | + replaceDeclaration 'Content == Image' 'Content == NukeImage' $f |
| 41 | + replaceDeclaration ' VideoPlayerView' ' NukeVideoPlayerView' $f |
| 42 | + replaceDeclaration 'typealias Color' 'typealias NukeColor' $f |
| 43 | + replaceDeclaration 'extension Color' 'extension NukeColor' $f |
| 44 | + replaceDeclaration 'AssetType' 'NukeAssetType' $f |
| 45 | + replaceDeclaration 'typealias ImageRequest = Nuke.ImageRequest' '' $f |
| 46 | + replaceDeclaration 'typealias ImageResponse = Nuke.ImageResponse' '' $f |
| 47 | + replaceDeclaration 'typealias ImagePipeline = Nuke.ImagePipeline' '' $f |
| 48 | + replaceDeclaration 'typealias ImageContainer = Nuke.ImageContainer' '' $f |
| 49 | + replaceDeclaration 'open class ' '' $f |
| 50 | + replaceDeclaration 'import Nuke' '' $f |
| 51 | + |
| 52 | + # Remove Cancellable interface duplicate |
| 53 | + if [[ $f == *"DataLoader"* && `head -10 $f` == *"protocol Cancellable"* ]]; then |
| 54 | + `sed -i '' -e '7,11d' $f` |
| 55 | + fi |
| 56 | + |
| 57 | + # Rename files |
| 58 | + if [[ $f == *"Caching/Cache.swift" ]]; then |
| 59 | + new_f="${f/Cache.swift/NukeCache.swift}" |
| 60 | + mv "$f" "$new_f" |
| 61 | + elif [[ $f == *"NukeUI/VideoPlayerView.swift" ]]; then |
| 62 | + new_f="${f/VideoPlayerView.swift/NukeVideoPlayerView.swift}" |
| 63 | + mv "$f" "$new_f" |
| 64 | + fi |
| 65 | + fi |
| 66 | +done |
0 commit comments