GithubHelp home page GithubHelp logo

onevcat / fengniao Goto Github PK

View Code? Open in Web Editor NEW
3.3K 54.0 234.0 462 KB

A command line tool for cleaning unused resources in Xcode.

License: MIT License

Swift 82.11% Objective-C 17.68% Objective-C++ 0.21%
command-line-tool resources slim xcode images cleanup swift

fengniao's Introduction

FengNiao

What

FengNiao is a simple command-line util to delete unused image resource files from your Xcode project.

How

Install

Mint

Mint is a tool that installs and runs Swift command line tool packages. Make sure you have Xcode installed, then:

> brew install mint
> mint install onevcat/fengniao

Compile from source

> git clone https://github.com/onevcat/FengNiao.git
> cd FengNiao
> swift build -c release

# Then copy the executable to your PATH, such as `/usr/local/bin`
> sudo cp .build/release/FengNiao /usr/local/bin/fengniao

FengNiao should be compiled, tested and installed into the /usr/local/bin.

Usage

Just navigate to your project folder, then:

> fengniao

It will scan current folder and all its subfolders to find unused images, then ask you whether you want to delete them. Please make sure you have a backup or a version control system before you deleting the images; it will be an un-restorable operation.

FengNiao supports some arguments. You can find it by:

> fengniao --help

  -p, --project:
      Root path of your Xcode project. Default is current folder.
  --force:
      Delete the found unused files without asking.
  -e, --exclude:
      Exclude paths from search.
  -r, --resource-extensions:
      Resource file extensions need to be searched. Default is 'imageset jpg png gif pdf'
  -f, --file-extensions:
      In which types of files we should search for resource usage. Default is 'm mm swift xib storyboard'
  --skip-proj-reference:
      Skip the Project file (.pbxproj) reference cleaning.
      By skipping it, the project file will be left untouched. 
      You may want to skip ths step if you are trying to build multiple projects with dependency and keep .pbxproj unchanged while compiling.
  --version:
      Print version.
  -h, --help:
      Print this help message.

A more daily-work usage under a project could be:

> fengniao --project . --exclude Carthage Pods

This will search in current folder, but skip the Carthage and Pods folder, in which there might be some third party resources you do not want to touch.

Use with Xcode build phase

It is easy to integrate FengNiao into your Xcode build process. By doing so, you could ensure your project being cleaned every time you build your project.

Add a "Run Script" phase in the Build Phases tab:

Then drag it above of "Copy Bundle Resources", editing its content to something like this:

fengniao --exclude Carthage --force

It is recommended to exclude vendor's folders like Pods or Carthage. Since you do not have a chance to confirm the result, you also need to add --force option.

App Version

An GUI app version of FengNiao is also available. You can find it under the App folder. We do not provide a pre-built binary for it. If needed, please build it by yourself. Thank you for @ldakhoa's contribution!

How it works

  1. Extract resource file names (default file type: ["imageset", "jpg", "png", "gif", "pdf"]) in these folders ["imageset", "launchimage", "appiconset", "bundle”].
  2. Use regular expression to search all string names in files (default files type: ["m", "mm", "swift", "xib", "storyboard", "plist"]).
  3. Exclude all used string names from resources files, we get all unused resources files.

License and Information

FengNiao is open-sourced as MIT license. The name of this project comes from the Chinese word 蜂鸟 (hummingbird), which is the smallest bird in the world.

Submit an issue if you find something wrong. Pull requests are warmly welcome, but I suggest to discuss first.

You can also follow and contact me on Twitter or Sina Weibo.

Learning to Create

I streamed the way I created this tool as a live-coding session in a live platform in China. You can learn how to create a project with Swift Package Manager, how to apply Protocol-Oriented Programming (POP) in the project, and how to develop in a BDD way as well as write good tests there.

It is a paid series lesson in Chinese. If you are interested in it, please check and watch the links below:

现场编程 - 用 Swift 创建命令行工具 fengniao-cli

fengniao's People

Contributors

ainopara avatar anuj-rajput avatar atuooo avatar filograno avatar ldakhoa avatar onevcat avatar phlippieb avatar raomengyun avatar remlostime avatar shuguenot avatar tzxdtc avatar voidless avatar yanamura avatar yyy153 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fengniao's Issues

xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

environment:macOS Catalina 10.15,Xcode 11.1 (11A1027)

error: terminated(72): xcrun --sdk macosx --find xctest output:
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

error: terminated(72): xcrun --sdk macosx --find xctest output:
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

error: terminated(72): xcrun --sdk macosx --find xctest output:
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

cp: .build/release/FengNiao: No such file or directory

libswiftCore.dylib errro

I have installed FengNiao. When I try to run the command I am getting the following error
my OSX version is 10.15.1 (19B88)

This copy of libswiftCore.dylib requires an OS version prior to 10.14.4.
zsh: abort      fengniao

Permission issue

Hi,

I don't have access to install this in /usr/local/bin, is there any other solution to perform with this tool FengNiao

Swift 5.0 suport

image

喵神您好,我打开项目源码,发现无法编译通过,原因是:
CommandLineKit、CommandLinePackageDescription、PathKit
这三个库使用的时 Swift 3
image
导致此插件无法通过编译,希望您能帮助我解决这个问题,谢谢。
对了,我的Xcode版本yi以及macOS系统版本如下
image
image

error: product dependency 'CommandLineKit' not found

执行./install.sh保存
localhost:FengNiao test01$ ./install.sh
error: product dependency 'CommandLineKit' not found
error: product dependency 'CommandLineKit' not found
cp: .build/release/FengNiao: No such file or directory
不知道要怎么解决

Build failure on Xcode 13 + Mint

PathKit + Spectre should be upgraded to allow compilation on Xcode 13

https://github.com/kylef/PathKit/releases/tag/1.0.1
https://github.com/kylef/Spectre/releases/tag/0.10.1

🌱 Cloning FengNiao fc447de
🌱 Resolving package
🌱 Building package
remark: Incremental compilation has been disabled: it is not compatible with whole module optimizationremark: Incremental compilation has been disabled: it is not compatible with whole module optimizationremark: Incremental compilation has been disabled: it is not compatible with whole module optimization[1/4] Compiling PathKit PathKit.swift
/private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao/.build/checkouts/PathKit/Sources/PathKit.swift:98:14: warning: 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'Path' to 'Hashable' by implementing 'hash(into:)' instead
  public var hashValue: Int {
             ^
/private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao/.build/checkouts/PathKit/Sources/PathKit.swift:591:12: error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
      free(cPattern)
           ^
/private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao/.build/checkouts/PathKit/Sources/PathKit.swift:591:12: note: coalesce using '??' to provide a default when the optional value contains 'nil'
      free(cPattern)
           ^
                    ?? <#default value#>
/private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao/.build/checkouts/PathKit/Sources/PathKit.swift:591:12: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
      free(cPattern)
           ^
                   !
'FengNiao' /private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao: warning: Invalid Exclude '/private/var/folders/7n/psqvtrtd46l4h9m92tb85mrc0000gp/T/mint/github.com_FengNiao/Tests/FengNiaoKitTests/Tests/Fixtures': File not found.
🌱 Encountered error during "swift build -c release -Xswiftc -target -Xswiftc x86_64-apple-macosx11.6". Use --verbose to see full output
🌱  Failed to build FengNiao fc447de with SPM

Error: no such module 'PackageDescription' M1 Pro

Hey guys, I'm getting this error installing FengNiao in a MacBook Pro 2021 with M1 Pro.

With HomeBrew and Mint

error: no such module 'PackageDescription'
import PackageDescription
       ^

Compiled Manually with Verbose

error: 'fengniao': Invalid manifest
<unknown>:0: remark: did not find a prebuilt standard library for target 'arm64-apple-macos' compatible with this Swift compiler; building it may take a few minutes, but it should only happen once for this combination of compiler and target
/Users/carlos.lopez/Development/FengNiao/[email protected]:3:8: error: no such module 'PackageDescription'
import PackageDescription
       ^

Any help?

Doesn't work no macOS 10.15

In terminal I have the message "This copy of libswiftCore.dylib requires an OS version prior to 10.14.4."

会发生@2x文件误报情况

您好!不知道是不是我的使用方法或者我这边设备环境配置的问题,我在工程中执行 fengniao 命令时会发生 @2x 文件误报情况。

Found a dulplicated file key: sc_accessory_arrow. Conflicting name: '.../sc_accessory_arrow.png' | '.../[email protected]'. Consider to rename one of them or exclude one.

Doesn't delete files from Copy Bundle Resources

I have plenty PNG-files just as files included in Bundle. Tool successfully deleted unused ones, but records in target's Copy Bundle Resources stayed untouched. I had to delete them manually to make the project built.

can't find image name surround with quote in json or strings files

for example, there is a image named cat_cn.png, and a localization strings file:

"cat" = "cat_cn"

then I read the image through the code bellow:

[UIImage imageNamed:NSLocalizedString(@"cat", nil)]

FengNiao can't work well in such a scenario

Adding "\"(.*?)\"" to PlainImageSearchRule solves the problem.

struct PlainImageSearchRule: RegPatternSearchRule {
    let extensions: [String]
    var patterns: [String] {
        if extensions.isEmpty {
            return ["\"(.*?)\""]
        }
        
        let joinedExt = extensions.joined(separator: "|")
        return ["\"(.+?)\\.(\(joinedExt))\"", "\"(.*?)\""]
    }
}

The README bottom video links can't play

Hi, I was clicked the bottom video links, and then I payed the money in the Wechat to see the playback. But after payed, I still can't played the video(The error info can see the screenshot image),mobile is same. So I don't konw how to do can make see the videos. Can you help me? Thanks !

Part1

7969f8c3-9578-4621-aac1-1c3acf2e11b4

MacOS App

Hey, this looks great.

I'm using this within my company app, but some images will used within API responses.
What I see now is FengNiao has three options list, delete, and ignore. I need to delete individual files within this tool but cannot, I have to find the file in xcassets and then compare it is right file and delete it manually, this seems hard because the app uses a lot of image resources (more than 30 MB).
So, I want to make a macOS app to visualize unused images and the ability to delete individual files. What do you think? I can PR to your repo.

Add .fengniaoignore file to auto-exclude files upon running

Currently, you have to supply exclude paths via inline arguments fengniao --exclude Pods. However, in situations when your app displays assets based on image names returned by API you will want to exclude a lot of files/paths.

It will be handy to have an .ignore like file similar to .gitignore so that each time I run fengniao I won't need to remember which files I need to exclude.

This file could be called .fengniaoignore and be structured similarly to .gitignore.

Let me know what you think about it and I can make a PR for it.

Thanks for the handy utility!

dyld: Symbol not found

When trying to find unused resources using FengNiao I get this output in console
dyld: Symbol not found: __T0s11CommandLineO9argumentsSaySSGvZ Referenced from: /usr/local/bin/fengniao Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib in /usr/local/bin/fengniao Abort trap: 6
I think it has something to do with Swift 4.1 and Xcode 9.3.

xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation

xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path
cp: .build/release/FengNiao: No such file or directory

search for images

How can I search for images by name and ignore formats
Ex.

- (UIImage *)getImage { return [UIImage getImageNamed:@"imageNamed"]; }

Deleting files with used pngs too

it shows me that how many unused files are there in my project, but it also contains files which are used. And once I run the command , all the respective unused image becomes red files. Maybe its only removing its reference.
Plz help.

sudo ./install.sh之后总是提示错误

error: terminated(72): /usr/bin/xcrun --sdk macosx --find xctest output:
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

cp: .build/release/FengNiao: No such file or directory

command not found: fengniao

  1. brew install mint
  2. mint install onevcat/fengniao
  3. navigate to project folder
  4. fengniao

zsh: command not found: fengniao

Does I miss something?

Swift 5 support issue

The targets “PathKit” and “CommandLineKit” contains source code developed with Swift 3.x. This version of Xcode does not support building or migrating Swift 3.x targets.

Use Xcode 10.1 to migrate the code to Swift 4.
我的Xcode 版本是 10.2.1 (10E1001), 希望有时间能兼容最新的Swift版本,非常感谢!

Xcode10.2升级后不能用了

.build/checkouts/CommandLine.git-5495157118528934026' is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead

Unable to lookup item 'PlatformPath' from command line tools installation

I'm using Xcode 15, with Mint installed via Brew.
Any ideas how can this be resolved?

joseines@Jose-MacBook-2023 desktop % mint install onevcat/fengniao --verbose
🌱 Finding latest version of fengniao
🌱 Cloning fengniao 0.8.1
Cloning into 'github.com_onevcat_fengniao'...
remote: Enumerating objects: 128, done.
remote: Counting objects: 100% (128/128), done.
remote: Compressing objects: 100% (88/88), done.
remote: Total 128 (delta 20), reused 108 (delta 17), pack-reused 0
Receiving objects: 100% (128/128), 132.50 KiB | 1.46 MiB/s, done.
Resolving deltas: 100% (20/20), done.
Note: switching to '7fd538bed2ec6f3da4172ae1ba5285f2e7a35fdf'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

🌱 Resolving package
error: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
    xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
    xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
    
🌱 Encountered error during "swift package resolve"
🌱  Failed to resolve fengniao 0.8.1 with SPM
joseines@Jose-MacBook-2023 desktop % 

Add verbose argument

When using FengNiao via command line mode, I would have a --verbose argument in order to see what file/resource is currently scanning.

工具能否直接输出结果?

现在执行 : fengniao --project . --exclude Carthage Pods
后会提示下一步操作,能否直接list结果,然后结束。

主要想在集成环境下,输出一些warnning作为警告。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.