-
Notifications
You must be signed in to change notification settings - Fork 39
/
new-version.sh
executable file
·86 lines (62 loc) · 2.62 KB
/
new-version.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
#!/bin/bash
newVersion=$2
# Get the last branch
lastGitBranch=$1
# Checkout it
git checkout $lastGitBranch
# Get the version of React (and strip the version qualifier)
reactVersion=`npm view react-native@$newVersion peerDependencies.react | sed -e 's/[\~\^]//'`
cd RnDiffApp
# Save package.json for later use (for not being taken into account when computing stats)
cp package.json ../package.json.temp
# Replace versions in package.json (WARNING: the -E option is specific to BSD, replace with -r if you don't use MacOS)
sed -E -i "" "s/\"react\": \"[0-9]*\.[0-9]*\.[0-9]*(-[^\"]*)?\",/\"react\": \"${reactVersion}\",/" ./package.json
sed -E -i "" "s/\"react-native\": \"[0-9]*\.[0-9]*\.[0-9]*(-[^\"]*)?\"/\"react-native\": \"${newVersion}\"/" ./package.json
# Install dependencies
npm install
# Remove lock file, it is irrelevant for computing the diff
rm package-lock.json
# Launch RN upgrade and automatically overwrite all files
react-native upgrade
cd ..
# Create the new branch
git branch rn-$newVersion
# Checkout it
git checkout rn-$newVersion
# Add modified files to commit
git add RnDiffApp
# Commit
git commit -m "Output version ${newVersion}"
# Compute diff stats pour README.md
## Restore the old package.json (we don't want to take it into account for stats)
cp package.json.temp RnDiffApp/package.json
## Save the stats
diffStat=`git --no-pager diff HEAD~1 --shortstat`
## Clean old package.json
rm package.json.temp
## Restore the new package.json
git checkout -- RnDiffApp/package.json
# Print diff
git --no-pager diff HEAD~1
# Print all branches (inspired from the oh-my-zsh shortcut: "glola")
git --no-pager log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all
# Ask for confirmation before pushing
echo -e "\nIs that OK ? (Yn)"
read confirmation
if [ -z $confirmation ] || [ $confirmation = "y" ] || [ $confirmation = "Y" ]
then
echo -e "Push branch..."
# Push the branch
git push origin rn-$newVersion
fi
# Come back to master branch
git checkout master
# Update README.md
diffUrl="[${lastGitBranch}...rn-${newVersion}](https://github.com/ncuillery/rn-diff/compare/${lastGitBranch}...rn-${newVersion})"
patchUrl="[${lastGitBranch}...rn-${newVersion}](https://github.com/ncuillery/rn-diff/compare/${lastGitBranch}...rn-${newVersion}.diff)"
# Insert a row in the version table
## Insert a new line (a bit tricky but compatible with either OSX sed and GNU sed)
sed -i '' 's/----|----|----|----/----|----|----|----\
NEWLINE/g' README.md
## Edit the new line with the version info
sed -i "" "s@NEWLINE@${newVersion}|${diffUrl}|${patchUrl}|${diffStat}@" README.md