FengNiao

repository·master·Indexed 25 days ago

https://github.com/onevcat/fengniao

A command-line utility for Xcode projects that identifies and deletes unused image resource files to reduce project size. It scans for resource files and verifies their usage within source code files, offering options to exclude specific directories, customize file extensions, and integrate into Xcode Build Phases.

Tokens
1.1K
Snippets
5
Records
8
Agent score
36%

What's inside FengNiao

  1. Use FengNiao CLI

    master

    Navigate to your Xcode project folder and run fengniao to scan for unused image resources. The tool will identify unused files and prompt you for deletion.

    Warning: Deletion is an un-restorable operation. Ensure you have a backup or are using version control before proceeding.

    fengniao
  2. Integrate FengNiao into Xcode Build Phases

    master

    To automatically clean unused resources every time you build your project:

    1. Open your project in Xcode.
    2. Go to the Build Phases tab.
    3. Add a new Run Script phase.
    4. Drag the new phase to be positioned above the "Copy Bundle Resources" phase.
    5. Add a script to delete unused files automatically. Since this happens during build, you must use the --force flag and it is highly recommended to --exclude vendor folders (like Pods or Carthage).

    Example script content:

    fengniao --exclude Carthage --force
  3. Install FengNiao

    master

    You can install FengNiao using Mint or by compiling it from source.

    Using Mint

    If you have Mint installed, run:

    mint install onevcat/fengniao

    Compiling from source

    Clone the repository, build the release version, and move the executable to your PATH (e.g., /usr/local/bin):

    git clone https://github.com/onevcat/FengNiao.git
    cd FengNiao
    swift build -c release
    sudo cp .build/release/FengNiao /usr/local/bin/fengniao
    mint install onevcat/fengniao
  4. Use the fengniao CLI to find and delete unused resources

    master
    fengniao is a command-line tool designed to find and delete unused resources in Xcode projects. It searches for resource files (like images) and checks if they are referenced in your source code files (like .swift or .m files). By default, it will prompt you before deleting files.
  5. Example: Exclude specific directories

    master

    To scan the current directory while skipping third-party dependency folders like Carthage or Pods, use the --exclude flag:

    fengniao --project . --exclude Carthage Pods
    > fengniao --project . --exclude Carthage Pods
  6. Reference: FengNiao CLI arguments

    master

    Available command-line arguments for fengniao:

    ArgumentDescription
    -p, --projectRoot path of your Xcode project. Default is current folder.
    --forceDelete the found unused files without asking.
    -e, --excludeExclude paths from search.
    -r, --resource-extensionsResource file extensions to search. Default: imageset jpg png gif pdf
    -f, --file-extensionsFile types to search for resource usage. Default: m mm swift xib storyboard
    --skip-proj-referenceSkip the Project file (.pbxproj) reference cleaning. Keeps the project file untouched.
    --xcode-warningsPrint results as Xcode warnings and return a non-zero exit code if any are found.
    --list-onlyList unused files and exit without prompting.
    --versionPrint version.
    -h, --helpPrint this help message.
    fengniao --help
  7. Reference the fengniao CLI options and flags

    master

    The following options and flags are available for the fengniao command:

    Options

    • --project <String> (or -p): Root path of your Xcode project. Default is the current folder (.).
    • --exclude <[String]> (or -e): Exclude specific paths from the search.
    • --resource-extensions <[String]> (or -r): Resource file extensions to search for. Default: imageset jpg png gif pdf.
    • --file-extensions <[String]> (or -f): File types to search for resource usage. Default: h m mm swift xib storyboard plist.

    Flags

    • --force: Delete the found unused files without asking for confirmation.
    • --skip-proj-reference: Skip the .pbxproj reference cleaning. This leaves the project file untouched, which is useful if you are building multiple projects with dependencies and want to keep .pbxproj unchanged.
    • --xcode-warnings: Print results as Xcode warnings and return a non-zero exit code if any unused resources are found.
    • --list-only: List unused files and exit without prompting for action.
  8. Understand fengniao exit codes

    master

    The fengniao CLI uses specific exit codes to communicate the result of the operation:

    • 0: Success (no unused resources found or operation completed successfully).
    • 1: Unused resources were found (when using --xcode-warnings).
    • 64: Usage error (e.g., invalid arguments or missing required extensions).