Skip to content

Commit

Permalink
Checks for non existing local patched podspecs.
Browse files Browse the repository at this point in the history
Recreating patched podspecs if they are not exists in the .patched.
  • Loading branch information
geekbrother committed Sep 30, 2021
1 parent d410ddf commit 045ed58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ How not forget what and where was patched and patch them on the new versions or

As this tool doesn't require many parameters we are using the **convention over configuration** approach.

By default tool will look into the `native/ios/patches` directory for the `.patch` files. The file name itself tells the tool which Pod and which version you want to patch the Pod's `podspec` and use it in your main Podfile.
By default tool will look into the `native/ios/pod-patch` directory for the `.patch` files. The file name itself tells the tool which Pod and which version you want to patch the Pod's `podspec` and use it in your main Podfile.

The naming convention for the `.patch` files is `[email protected]` where `podName` is the name of the Pod and `version` is the Pod version to use for the patch apply.

For example, `native/ios/patches/[email protected]` will tell that we want to apply patch from this file to the `gRPC-Core` podspec file for the `1.40.0` version.
For example, `native/ios/pod-patch/[email protected]` will tell that we want to apply patch from this file to the `gRPC-Core` podspec file for the `1.40.0` version.

Also, you can use it without a version. When using `native/ios/patches/gRPC-Core.patch` tool will apply the patch from this file to the `gRPC-Core` pod with the version from your Podfile. When using without a version you need to have a record in the Podfile with the pod and version.
Also, you can use it without a version. When using `native/ios/pod-patch/gRPC-Core.patch` tool will apply the patch from this file to the `gRPC-Core` pod with the version from your Podfile. When using without a version you need to have a record in the Podfile with the pod and version.

For example:

Expand All @@ -51,30 +51,32 @@ The tool can be executed as the `npx pod-patch` command in the `native` director
When running the tool will iterate through your `.patch` files checks if anything has changed and made some magic:

- Checks if there is no version conflicts in your `Podfile` and `.patch` file,
- Download a `podspec` file for your Pod from the [cocoapods git repo](https://github.com/CocoaPods/Specs/tree/master/Specs) to the `native/ios/patches/{pod-name}/{pod-version}/` directory,
- Download a `podspec` file for your Pod from the [cocoapods git repo](https://github.com/CocoaPods/Specs/tree/master/Specs) to the `native/ios/pod-patch/.patched/{pod-name}/{pod-version}/` directory,
- Apply the patch from the `.patch` file to it,
- Changes the record for the patched **Pod** in the `Podfile` to point it to the local patched podspec. For example, the record for the `gRPC-Core` will automatically change to:

```ruby
target 'App' do
...
pod 'gRPC-Core', :podspec => './patches/gRPC-Core/1.40.0/gRPC-Core.podspec.json'
pod 'gRPC-Core', :podspec => './pod-patch/.patched/gRPC-Core/1.40.0/gRPC-Core.podspec.json'
```

The tool checks if the Pod is already patched.
If nothing changed from the already applied patches - it will do nothing.

## Using with the `yarn` or `npm i`

A good practice is to use is linked with the running of `yarn` or `npm i` in the `native` directory.
A good practice is to use it linked with the running of `yarn` or `npm i` in the `native` directory in your install script in the `package.json` before the `pod install` execution.

This will updates/install the packages with the transparent checking if all of the Pod patches are up-to-date or need to be applied if something in the `.patch` file changed or `Podspec` has new changes in the pod dependency or version changes.
This will updates/install the packages with the transparent checking if all of the Pod patches are up-to-date or need to be applied if something in the `.patch` file changed or `Podspec` has new changes in the pod dependency or version changes before the `pod install`.

If using this way with the `git` repo you can add `native/ios/pod-patch/.patched` directory to your `.gitignore`. Because when the tool runs it will check the existence of the local patched podspec files and create those that not exists.

# Pod version changing

In case when the Pod version changed but you already have a `.patch` file for the previous version and it is already applied, but you want to upgrade the Pod and patch to the new version there are three simple steps:

**First**, if your `.patch` file in the `native/ios/patches` has a version format i.e. `[email protected]` you need to create a patch file for the new version i.e. `[email protected]`.
**First**, if your `.patch` file in the `native/ios/pod-patch` has a version format i.e. `[email protected]` you need to create a patch file for the new version i.e. `[email protected]`.

If the `.patch` file in the no-version format i.e. `gRPC-Core.patch` you do nothing here as this is an universal patch for all versions.

Expand All @@ -94,7 +96,7 @@ If you have a version-agnostic `.patch` file, actually you only need to do a sec

- `-h`: Output the command usage help.
- `-v`: Output the script version.
- `-p`: Path to the directory where the `.patch` files are if it differs from the default `native/ios/patches`.
- `-p`: Path to the directory where the `.patch` files are if it differs from the default `native/ios/pod-patch`.
- `-d`: Path to the `Podfile` if it differs from the default `native/ios/Podfile`.

# Todo
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pod-patch",
"version": "0.0.6",
"version": "0.0.7",
"description": "Patching the Pod specfiles in ReactNative projects.",
"main": "index.js",
"bin":{
Expand Down
21 changes: 15 additions & 6 deletions patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
# Usage: npx pod-patch [-h Usage] [-v Version] [-d <path/Podfile> Podfile path ] [-p <path> .patch files directory]
# Run it as npx or bash script from the 'native' directory of
# the ReactNative project.
readonly SCRIPT_VERSION='0.0.6'
readonly SCRIPT_VERSION='0.0.7'
set -e

# Default parameters
## Directory relatively to the ReactNative '/native' directory where the .patch files are.
PATCHES_DIR="./ios/patches"
PATCHES_DIR="./ios/pod-patch"
## Cocoapods Podfile path
PODFILE_PATH="./ios/Podfile"
## Where the patched files will be placed
readonly PATCHED_SUBDIR=".patched"

# Parsing CLI arguments
while getopts ":hvp:d:" opt; do
Expand Down Expand Up @@ -88,8 +90,15 @@ function MAKE_PATCH() {
LOG ERROR "Podfile version ${POD_VERSION_PODFILE} not equal to patch version ${POD_VERSION}"
fi
elif [[ $POD_VERSION_PODFILE =~ .*podspec.* ]]; then
LOG SKIP "${POD_NAME} podspec already patched and has a :podspec property in Podfile"
return
# If already patched and have a ':podspec =>' we need to check if the patched podspec file exists
# in case of this is a git copy with the .patched directory in .gitignore
local PODSPEC_PODFILE=$(cat ${PODFILE_PATH} | grep "pod '${POD_NAME}'" | awk '{print $5}' | tr -d "'")
if [[ -f "./ios/${PODSPEC_PODFILE##./}" ]]; then
LOG SKIP "${POD_NAME} podspec already patched and has a local podspec file in a Podfile"
return
else
LOG INFO "Patched podspec file not found, creating a new one"
fi
else
LOG ERROR "Wrong ${POD_NAME} pod version ${POD_VERSION_PODFILE} in the Podfile"
fi
Expand All @@ -101,9 +110,9 @@ function MAKE_PATCH() {
SPEC_PATH=${SPEC_PATH%/*}
local GITHUB_SPEC_URL="https://raw.githubusercontent.com/CocoaPods/Specs/master${SPEC_PATH}/${POD_VERSION}/${POD_NAME}.podspec.json"

local PATCHED_PODSPEC_PATCH="${PATCHES_DIR}/${POD_NAME}/${POD_VERSION}/${POD_NAME}.podspec.json"
local PATCHED_PODSPEC_PATCH="${PATCHES_DIR}/${PATCHED_SUBDIR}/${POD_NAME}/${POD_VERSION}/${POD_NAME}.podspec.json"
rm -f "${PATCHED_PODSPEC_PATCH}"
mkdir -p "${PATCHES_DIR}/${POD_NAME}/${POD_VERSION}"
mkdir -p "${PATCHES_DIR}/${PATCHED_SUBDIR}/${POD_NAME}/${POD_VERSION}"

# Download the podspec file for the pod
local CODE=$(curl -sSL -w '%{http_code}' --output "${PATCHED_PODSPEC_PATCH}" "${GITHUB_SPEC_URL}")
Expand Down

0 comments on commit 045ed58

Please sign in to comment.