-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·177 lines (156 loc) · 7.25 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
if [ -z $1 ]
then
lowerEnv="dev"
else
lowerEnv=`echo $1 | tr '[A-Z]' '[a-z]'`
fi
upperEnv=`echo $lowerEnv | tr '[a-z]' '[A-Z]'`
now=`date +%Y-%m-%d-%H%M`
##########################################################################
## Provide Application/Project Specific Configuration Values Here
##########################################################################
#**Flag that determines if the script attempts an android build
buildAndroid=false
#**The absolute root output path for the .ipa/.mdx file(s)
archivePath="${HOME}/Path/To/The/outputDirectory"
#**The prefix value for the output files
packagePrefix="RENAME_ME_IN_BUILD_SCRIPT-${lowerEnv}"
#**Uncomment the line below to override the default android build tools
#** version used by cordova.
#androidBuildToolVersion=22.0.1
##########################################################################
## Provide Signing Configuraiton Values Here
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# To Find these values if you aren't sure of them you can run the
# following command on your target provisioning profile:
#
# security cms -D -i "/path/to/your/TargetProfile.mobileprovision"
#
# in the output look for the Name and TeamIdentifier Keys
# <key>Name</key>
# <string>NAME OF YOUR PROVISIONING PROFILE IS HERE</string>
#
# <key>TeamIdentifier</key>
# <array>
# <string>DEVELOPMENT TEAM ID IS HERE</string>
# </array>
##########################################################################
#**The Name of your provisioning profile
provisioningProfileSpecifier="<PROVISIONING_PROFILE_NAME>"
#**The Development Team ID
devTeamId="<DEV_TEAM_ID>"
#**The path to the export-ipa.plist template file
exportIpaPlisTemplateLocation="export-ipa.plist"
#**The path to the build.json template file
buildJsonTemplateLocation="build.json"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~
#~~Do any Custom Config or JS Build Work Here
#~~ EXAMPLES:
#~~ - replacing config.xml with an ENV specific config
#~~ - running the npm build task for the target ENV
#~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# envConfigXmlRoot="."
# echo "------Setting up Configuration for ${upperENV} Copying ENV Config.xml------"
# cp ${envConfigXmlRoot}/config.xml.${lowerEnv} config.xml
# echo "------PRE-BUILDING Application------"
# npm run build:${lowerEnv}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~END CUSTOM WORK SETUP
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## Start Generic Script
##
## DO NOT MODIFY BELOW UNLESS ABSOLUTELY NECESSARY
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rawVersion=`cat "config.xml" | grep -e "<widget" | grep -o -e "version=\".*\" xmlns=" | grep -o -e "[0-9\.]"`
version=`echo $rawVersion | sed -e 's/ //g'`
bundleId=`cat config.xml | grep -e "<widget" | grep -o -E "id=\"(.*)\" ver" | sed -e 's/\" ver//g' | sed -e 's/id=\"//g'`
appName=`cat config.xml | grep -e "<name>" | sed -e 's/<name>//g; s/<\/name>//g; s/^\s//g; s/^ *//;s/ *$//;'`
cordovaIosVersion=`cat config.xml | grep -e "<engine name=\"ios\"" | grep -o -E "spec=\"(.*)\"" | sed -e 's/spec=\"//g; s/\"$//g;'`
cat ${buildJsonTemplateLocation} | sed -e "s/~~PROVISIONING_PROFILE_NAME~~/${provisioningProfileSpecifier}/g; s/~~TEAM_ID~~/${devTeamId}/g" \
> build-complete.json
cat ${exportIpaPlisTemplateLocation} | sed -e "s/~~BUNDLE_ID~~/${bundleId}/g; s/~~PROVISIONING_PROFILE_NAME~~/${provisioningProfileSpecifier}/g; s/~~TEAM_ID~~/${devTeamId}/g" \
> export-ipa-build.plist
echo "------CONFIG------"
echo "version: ${version}"
echo "bundle id: ${bundleId}"
echo "archivePath: ${archivePath}"
echo "appName: ${appName}"
echo "packagePrefix: ${packagePrefix}"
echo "appName: ${appName}"
echo "cordova-ios version: ${cordovaIosVersion}"
echo "androidBuildToolVersion: ${androidBuildToolVersion}"
archiveLocation="${archivePath}/${now}_${appName}.xcarchive"
exportedIpaRoot="${archivePath}/${upperEnv}"
outputIpaLocation="${archivePath}/${upperEnv}/${packagePrefix}-v${version}.ipa"
ipaLocation="${archivePath}/${appName}.ipa"
xcodeProjectLocation="platforms/ios/${appName}.xcodeproj"
exportPlistLocation="export-ipa-build.plist";
buildJsonLocation="build-complete.json"
#############################################################################################################
## CORDOVA PREPARE SECTION
#############################################################################################################
echo "------RE-ADD iOS PLATFORM------"
cordova platform remove ios
if [ -z "${cordovaIosVersion}" ]
then
cordova platform add ios
else
cordova platform add ios@${cordovaIosVersion}
fi
echo "------PRE-BUILDING iOS------"
cordova build --release --buildConfig ${buildJsonLocation}
echo "------Clean Up Cordova Build------"
rm ${buildJsonLocation}
#############################################################################################################
## IOS BUILD SECTION
#############################################################################################################
echo "------Beginning xcodebuild------"
xcodebuild \
-sdk iphoneos \
-project "${xcodeProjectLocation}" \
-scheme "${appName}" \
-configuration Release build \
-archivePath "${archiveLocation}" \
archive \
DEVELOPMENT_TEAM="${devTeamId}" \
PROVISIONING_PROFILE_SPECIFIER="${provisioningProfileSpecifier}"
echo "------Export Archive Props------"
echo "Archive Loction: ${archiveLocation}"
echo "Export PLIST File: ${exportPlistLocation}"
echo "Export Path: ${exportedIpaRoot}"
xcodebuild \
-exportArchive \
-archivePath "${archiveLocation}" \
-exportPath "${exportedIpaRoot}" \
-exportOptionsPlist "${exportPlistLocation}" \
echo "-------Renaming Exported IPA------"
mv "${exportedIpaRoot}/${appName}.ipa" ${outputIpaLocation}
echo "-------Cleaning Up Export Config------"
rm ${exportPlistLocation}
#############################################################################################################
## ANDROID BUILD SECTION
#############################################################################################################
if [ "$buildAndroid" = true ]
then
echo "------RE-ADDING ANDROID PLATFORM------"
cordova platform remove android
cordova platform add android
echo "------BUILDING ANDROID------"
if [ -z "$androidBuildToolVersion" ]
then
echo "---------No Android Build Tool Version set. Default to Cordova's Default"
cordova build android
else
echo "---------Android Build Tool Version set. Using ${androidBuildToolVersion}"
cordova build android -- --gradleArg=-PcdvBuildToolsVersion=${androidBuildToolVersion}
fi
cp ./platforms/android/build/outputs/apk/android-debug.apk "${archivePath}/${packagePrefix}-v${version}.apk"
fi
echo "------Archives Built-------"
open ${archivePath}