-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
74 lines (59 loc) · 1.66 KB
/
build.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
#!/bin/bash
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
mkdir -p dist
dist_dir=$(pwd)/dist/
MANIFEST_FILE=manifest.json
# build project
echo -e "\n$YELLOW"
read -p 'Do you really want to build project? (Yes | No)
> ' build_project
echo -e "\n$ENDCOLOR"
if [[ "$build_project" == "yes" ]]; then
npm run build
# copy all static files
cp -R static/. $dist_dir
cp manifest.json $dist_dir
# copy all rulesets files
cp -R rulesets/. $dist_dir
fi
# browserType: chrome | firefox
echo -e "\n$YELLOW"
read -p 'Enter browser type: (chrome | firefox)
> ' browserType
echo -e "\n$ENDCOLOR"
# generating manifest file
touch $dist_dir/$MANIFEST_FILE
if [[ "$browserType" == "firefox" ]]; then
cp manifest-firefox.json $dist_dir/manifest.json
find $dist_dir -type f -name "*.js" -exec sh -c '
for file do
# Replace "chrome." with "browser."
echo $file
sed -i "s/chrome\.action/browser\.browserAction/g" "$file"
sed -i "s/chrome\./browser\./g" "$file"
done
' sh {} +
fi
# create zip file for dist
echo -e "\n$YELLOW"
read -p 'Do you really want to create zip file? (Yes | No)
> ' create_zip
echo -e "\n$ENDCOLOR"
if [[ "$create_zip" == "yes" ]]; then
(cd $dist_dir; zip -r ../"$browserType".zip .)
fi
# Push changes
echo -e "\n$YELLOW"
read -p "Do you really want to push changes to Github? (Yes | No)
> " push_changes
echo -e "\n$ENDCOLOR"
if [[ "$push_changes" == "yes" ]]; then
# extract version
line_number=$(grep -n "\"version\"" $dist_dir/$MANIFEST_FILE)
# using sed: version=$(echo "$line" | sed 's/"version": "\(.*\)"/\1/')
version=$(echo "$line_number" | grep -oP '(?<=version": ")[^"]*')
git add .
git commit -m "$version"
git push
fi