-
Notifications
You must be signed in to change notification settings - Fork 58
/
generate-podspecs.sh
executable file
·154 lines (126 loc) · 6.69 KB
/
generate-podspecs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# Exit if any command fails
set -e
function warn_missing_tag_commit() {
RED="\033[0;31m"
NO_COLOR="\033[0m"
PODSPEC_HAS_TAG_OR_COMMIT=$(jq '.source | has("tag") or has("commit")' "$DEST/$pod.podspec.json")
# If the source points to an HTTP endpoint and SHA, we consider it versioned
PODSPEC_HAS_HTTP_AND_SHA=$(jq '.source | has("http") and (has("sha256") or has("sha1"))' "$DEST/$pod.podspec.json")
if [[ $PODSPEC_HAS_TAG_OR_COMMIT == "false" && $PODSPEC_HAS_HTTP_AND_SHA == "false" ]]; then
printf "${RED}WARNING! $pod.podspec doesn't have a 'tag' or 'commit' field, or doesn't point to a SHA verified file. Either modify this script to add a patch during the podspec generation or modify the original $pod.podspec in the source repo.${NO_COLOR}\n"
exit 1
fi
}
function add_codegen_warning_to_podspec() {
jq '. + {"__WARNING!__": "This file is autogenerated by generate-podspecs.sh script. Do not modify manually. Re-run the script if necessary."}' "$DEST/$pod.podspec.json" > "$TMP_SPEC"
}
# Change to the expected directory.
pushd "$( dirname "$0" )" > /dev/null
popd > /dev/null
WD=$(pwd)
echo "Working directory: $WD"
# Check for CocoaPods and jq
command -v pod > /dev/null || ( echo Cocoapods is required to generate podspecs; exit 1 )
command -v jq > /dev/null || ( echo jq is required to generate podspecs; exit 1 )
read -r -p "If your node_modules folder isn't up-to-date please run 'npm install' first and re-run the script. Is your node_modules folder up-to-date? [y/N] " PROMPT_RESPONSE
if [[ $PROMPT_RESPONSE != "y" ]]; then
echo "Please run npm install first and re-run the script."
exit 1
fi
read -r -p "Enter the commit hash of previous commit. If this is the first-time running this script, enter 0, then commit generated files and re-rerun the script and this time use the previous commit hash: " COMMIT_HASH
if [[ -z "$COMMIT_HASH" ]]; then
echo "Commit hash cannot be empty."
exit 1
fi
DEST="${WD}/third-party-podspecs"
read -r -p "Please delete '$DEST' folder manually before continuing. This script will re-generate it. Did you delete it? [y/N] " PROMPT_RESPONSE_2
if [[ $PROMPT_RESPONSE_2 != "y" ]]; then
echo "Aborting."
exit 1
fi
mkdir "$DEST"
NODE_MODULES_DIR="gutenberg/node_modules"
# Generate the external (non-RN podspecs)
EXTERNAL_PODSPECS=$(find "$NODE_MODULES_DIR/@react-native-community/blur" \
"$NODE_MODULES_DIR/@react-native-masked-view/masked-view" \
"$NODE_MODULES_DIR/@react-native-community/slider" \
"$NODE_MODULES_DIR/@react-native-clipboard/clipboard" \
"$NODE_MODULES_DIR/react-native-gesture-handler" \
"$NODE_MODULES_DIR/react-native-get-random-values" \
"$NODE_MODULES_DIR/react-native-linear-gradient" \
"$NODE_MODULES_DIR/react-native-reanimated" \
"$NODE_MODULES_DIR/react-native-safe-area" \
"$NODE_MODULES_DIR/react-native-safe-area-context" \
"$NODE_MODULES_DIR/react-native-screens" \
"$NODE_MODULES_DIR/react-native-svg" \
"$NODE_MODULES_DIR/react-native-video"\
"$NODE_MODULES_DIR/react-native-webview"\
"$NODE_MODULES_DIR/react-native-fast-image"\
-type f -name "*.podspec" -print)
for podspec in $EXTERNAL_PODSPECS
do
pod=$(basename "$podspec" .podspec)
echo "Generating podspec for $pod"
pod ipc spec "$podspec" > "$DEST/$pod.podspec.json"
# react-native-blur doesn't have a tag field in it's podspec
if [[ "$pod" == "react-native-blur" ]]; then
echo " ==> Patching $pod podspec"
TMP_RNBlurPodspec=$(mktemp)
# The npm version we're using is 3.6.0 because 3.6.1 still isn't on npm https://www.npmjs.com/package/@react-native-community/blur/v/3.6.1
# And there's no v3.6.0 tag in https://github.com/Kureev/react-native-blur so we depend on v3.6.1 in the podspec
jq '.source.tag = "v3.6.1" | .version = "3.6.1"' "$DEST/$pod.podspec.json" > "$TMP_RNBlurPodspec"
mv "$TMP_RNBlurPodspec" "$DEST/$pod.podspec.json"
fi
# Add warning to bottom
TMP_SPEC=$(mktemp)
add_codegen_warning_to_podspec
mv "$TMP_SPEC" "$DEST/$pod.podspec.json"
# As a last step check if podspec has a "tag" or "commit" field in "source"
warn_missing_tag_commit
done
# Generate the React Native podspecs
# Change to the React Native directory to get relative paths for the RN podspecs
pushd "$NODE_MODULES_DIR/react-native" > /dev/null
SCRIPTS_PATH="./scripts/"
CODEGEN_REPO_PATH="../packages/react-native-codegen"
CODEGEN_NPM_PATH="../react-native-codegen"
PACKAGE_JSON_PATH="./package.json"
SRCS_DIR=${SRCS_DIR:-$(cd "./Libraries" && pwd)}
RN_VERSION=$(cat ./package.json | grep -m 1 version | sed 's/[^0-9.]//g')
RN_PODSPECS=$(find * -type f -name "*.podspec" -not -name "React-rncore.podspec" -not -path "third-party-podspecs/*" -not -path "*Fabric*" -print)
TMP_DEST=$(mktemp -d)
for podspec in $RN_PODSPECS
do
pod=$(basename "$podspec" .podspec)
path=$(dirname "$podspec")
# The only one we need is React-jsc, all the others can be skipped.
if [[ $pod != 'React-jsc' ]]; then
echo "Skipping copying React Native $pod podspec..."
continue
fi
echo "Generating podspec for $pod with path $path"
pod ipc spec "$podspec" > "$TMP_DEST/$pod.podspec.json"
# Removes message [Codegen] Found at the beginning of the file
sed -i '' -e '/\[Codegen\] Found/d' "$TMP_DEST/$pod.podspec.json"
cat "$TMP_DEST/$pod.podspec.json" | jq > "$DEST/$pod.podspec.json"
# Add a "prepare_command" entry to each podspec so that 'pod install' will fetch sources from the correct directory
# and retains the existing prepare_command if it exists
prepare_command="TMP_DIR=\$(mktemp -d); mv * \$TMP_DIR; cp -R \"\$TMP_DIR/${path}\"/* ."
cat "$TMP_DEST/$pod.podspec.json" | jq --arg CMD "$prepare_command" '.prepare_command = "\($CMD) && \(.prepare_command // true)"' > "$DEST/$pod.podspec.json"
# Add warning to bottom
TMP_SPEC=$(mktemp)
add_codegen_warning_to_podspec
mv "$TMP_SPEC" "$DEST/$pod.podspec.json"
# As a last step check if podspec has a "tag" or "commit" field in "source"
warn_missing_tag_commit
done
popd > /dev/null
# We are required to run this script twice to capture the correct target.
# 0 is the value set during the first script run to generate the podspecs.
if [[ "$COMMIT_HASH" != "0" ]]; then
echo 'Updating XCFramework Podfile.lock with these changes'
pushd ios-xcframework > /dev/null
bundle exec pod update
popd > /dev/null
fi