forked from microsoft/fluentui-system-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 2561: Update unused asset script
* More docs * Test cases * Argment parser so it's clear what each parameter is required ``` USAGE: run [--library-name <library-name>] [--asset-catalog-name <asset-catalog-name>] --path-to-source-code <path-to-source-code> --path-to-fluent-icon-source <path-to-fluent-icon-source> [--path-to-list-of-icons-to-keep <path-to-list-of-icons-to-keep>] OPTIONS: --library-name <library-name> Name of the icon library. (default: FluentIcons) --asset-catalog-name <asset-catalog-name> Name of the asset catalog. (default: IconAssets) --path-to-source-code <path-to-source-code> Path to your app's source code. --path-to-fluent-icon-source <path-to-fluent-icon-source> Path to the fluent icon library's source code --path-to-list-of-icons-to-keep <path-to-list-of-icons-to-keep> Path to a custom list of icons in use (for React Native, Optional). -h, --help Show help information. ```
- Loading branch information
Nick Romano
committed
Apr 29, 2020
1 parent
b69ea1d
commit 2013b68
Showing
19 changed files
with
378 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--indent 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
### Cocoapods | ||
|
||
```ruby | ||
use_frameworks! | ||
pod "FluentIcons", git: "https://[email protected]/microsoftdesign/Design%20System/_git/fluent-mobile-icons", tag: "1.0.215" | ||
``` | ||
|
||
|
@@ -42,25 +43,32 @@ No more risky stringly typed `UIImage(named: "")!` | |
At build/release time you can run the following script to ensure all unused assets are stripped from the app: | ||
|
||
Cocoapods | ||
|
||
``` | ||
ICON_SOURCE_PATH="Pods/FluentIcons" | ||
ICON_SOURCE_PATH="./Pods/FluentIcons" | ||
swift $ICON_SOURCE_PATH/ios/FluentIcons/remove_unused_fluent_icons.swift \ | ||
MyProjectCode \ | ||
$ICON_SOURCE_PATH | ||
$ICON_SOURCE_PATH/ios/remove-unused-fluent-icons/run \ | ||
--path-to-source-code "." \ | ||
--path-to-fluent-icon-source $ICON_SOURCE_PATH | ||
``` | ||
|
||
Carthage | ||
|
||
``` | ||
ICON_SOURCE_PATH="Carthage/Checkouts/fluent-mobile-icons" | ||
ICON_SOURCE_PATH="./Carthage/Checkouts/fluent-mobile-icons" | ||
swift $ICON_SOURCE_PATH/ios/FluentIcons/remove_unused_fluent_icons.swift \ | ||
MyProjectCode \ | ||
$ICON_SOURCE_PATH | ||
$ICON_SOURCE_PATH/ios/remove-unused-fluent-icons/run \ | ||
--path-to-source-code "." \ | ||
--path-to-fluent-icon-source $ICON_SOURCE_PATH | ||
carthage build --platform iOS fluent-mobile-icons | ||
``` | ||
|
||
Optionally if you are using React Native or are referencing icons outside of your codebase, you can pass an icon list to prevent these icons from being removed. | ||
``` | ||
--path-to-list-of-icons-to-keep OutlookReactNativeKit/ReactResources/FluentIcons.txt | ||
``` | ||
|
||
#### 3. Consistent asset rendering | ||
|
||
All non-color icons are rendered as template images so you can easily apply a `tintColor` to your `UIImageView` or `UIButton`. You no longer need to specify `.withRenderingMode(.alwaysTemplate)` in case you're unsure the asset was misconfigured. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ |
7 changes: 7 additions & 0 deletions
7
ios/remove-unused-fluent-icons/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "swift-argument-parser", | ||
"repositoryURL": "https://github.com/apple/swift-argument-parser", | ||
"state": { | ||
"branch": null, | ||
"revision": "9f04d1ff1afbccd02279338a2c91e5f27c45e93a", | ||
"version": "0.0.5" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// swift-tools-version:5.2 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "remove-unused-fluent-icons", | ||
platforms: [ | ||
.macOS(.v10_13), | ||
], | ||
products: [ | ||
.executable(name: "remove-unused-fluent-icons", targets: ["remove-unused-fluent-icons"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.0.5"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "RemoveUnusedIcons", | ||
dependencies: [] | ||
), | ||
.testTarget( | ||
name: "RemoveUnusedIconsTests", | ||
dependencies: ["RemoveUnusedIcons"] | ||
), | ||
.target( | ||
name: "remove-unused-fluent-icons", | ||
dependencies: [ | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
"RemoveUnusedIcons", | ||
] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Remove Unused Fluent Icons | ||
|
||
Source code for the script that removes any unused assets in a project. | ||
|
||
## Contributing | ||
|
||
### Generate a project | ||
|
||
``` | ||
swift package generate-xcodeproj | ||
``` | ||
|
||
### Releasing a new version | ||
|
||
Build the binary and commit it to the repo | ||
|
||
``` | ||
swift build -c release | ||
yes | cp .build/release/remove-unused-fluent-icons run | ||
``` |
56 changes: 56 additions & 0 deletions
56
ios/remove-unused-fluent-icons/Sources/RemoveUnusedIcons/Grep.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
private func shell(_ command: String) -> String { | ||
let task = Process() | ||
task.launchPath = "/bin/bash" | ||
task.arguments = ["-c", command] | ||
|
||
let pipe = Pipe() | ||
task.standardOutput = pipe | ||
task.launch() | ||
|
||
let data = pipe.fileHandleForReading.readDataToEndOfFile() | ||
return String(data: data, encoding: .utf8)! | ||
} | ||
|
||
extension String { | ||
func mapToLines() -> [String] { | ||
trimmingCharacters(in: .whitespacesAndNewlines) | ||
.split(separator: "\n") | ||
.map { String($0) } | ||
} | ||
} | ||
|
||
enum Language { | ||
case swift | ||
case objc | ||
} | ||
|
||
func searchForCodeReferences(in path: String, language: Language, weights: Set<String>, excludingFileName: String) -> [String] { | ||
let include: String | ||
let regex: String | ||
switch language { | ||
case .swift: | ||
include = "--include=\"*.swift\"" | ||
regex = "\\.[a-zA-Z0-9]+[0-9]{2}(\(weights.map { $0.capitalized }.joined(separator: "|")))" | ||
case .objc: | ||
include = "--include=\"*.m\" --include=\"*.h\"" | ||
regex = "\(excludingFileName)[a-zA-Z0-9]+[0-9]{2}(\(weights.map { $0.uppercased() }.joined(separator: "|")))" | ||
} | ||
let command = """ | ||
grep --recursive \ | ||
--ignore-case \ | ||
--no-filename \ | ||
--exclude=\"\(excludingFileName).swift\" \ | ||
--extended-regexp \ | ||
\(include) \ | ||
\"\(regex)\" \(path) | ||
""" | ||
print(command) | ||
|
||
return shell(command).mapToLines() | ||
} |
Oops, something went wrong.