Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Commit 05224e1

Browse files
authored
Merge pull request #237 from NativeScript/lini/update-publish-code
refactor: update publish code
2 parents 6998baa + 3c2e23d commit 05224e1

File tree

6 files changed

+156
-18
lines changed

6 files changed

+156
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ publish/src
2424
publish/package
2525
demo/report/report.html
2626
demo/report/stats.json
27+
src/platforms/android/sync

native-src/android/gradlew

100644100755
File mode changed.

publish/build-android.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
set -e
2+
set -o pipefail
3+
4+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
SOURCE_NAME="app"
7+
ANDROID_SOURCE_DIR="$CURRENT_DIR/../native-src/android"
8+
9+
PROJECT_NAME="$SOURCE_NAME"
10+
11+
BUILD_OUTPUT_DIR="$ANDROID_SOURCE_DIR/$PROJECT_NAME/build/outputs/aar/"
12+
13+
PLUGIN_TARGET_DIR="$CURRENT_DIR/../src/platforms"
14+
PLUGIN_TARGET_SUBDIR="$PLUGIN_TARGET_DIR/android"
15+
16+
cd $ANDROID_SOURCE_DIR
17+
18+
./gradlew clean assembleRelease
19+
20+
echo "$PROJECT_NAME-release.aar was built in $BUILD_OUTPUT_DIR"
21+
22+
if [ ! -d $PLUGIN_TARGET_DIR ]; then
23+
mkdir $PLUGIN_TARGET_DIR
24+
fi
25+
26+
if [ ! -d $PLUGIN_TARGET_SUBDIR ]; then
27+
mkdir $PLUGIN_TARGET_SUBDIR
28+
fi
29+
30+
cp -R "$BUILD_OUTPUT_DIR/$PROJECT_NAME-release.aar" $PLUGIN_TARGET_SUBDIR/pushplugin.aar
31+
32+
echo "force livesync" > "$PLUGIN_TARGET_SUBDIR/sync"
33+
34+
echo "Android library was copied to $PLUGIN_TARGET_SUBDIR"
35+
36+
cd $CURRENT_DIR

publish/build-ios.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
set -e
2+
set -o pipefail
3+
4+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
SOURCE_NAME="PushPlugin"
7+
IOS_SOURCE_DIR="$CURRENT_DIR/../native-src/ios"
8+
9+
PROJECT_NAME="$SOURCE_NAME.xcodeproj"
10+
TARGET_NAME="$SOURCE_NAME"
11+
FRAMEWORK_NAME="$SOURCE_NAME"
12+
13+
BUILD_DIR="$IOS_SOURCE_DIR/build/intermediates/${FRAMEWORK_NAME}"
14+
BUILD_FOR_DEVICE_DIR="$BUILD_DIR/Release-iphoneos"
15+
BUILD_FOR_SIMULATOR_DIR="$BUILD_DIR/Release-iphonesimulator"
16+
BUILD_OUTPUT_DIR="$IOS_SOURCE_DIR/build/outputs"
17+
18+
PLUGIN_TARGET_DIR="$CURRENT_DIR/../src/platforms"
19+
PLUGIN_TARGET_SUBDIR="$PLUGIN_TARGET_DIR/ios"
20+
21+
cd $IOS_SOURCE_DIR
22+
23+
if [ -d "$BUILD_DIR" ]; then
24+
rm -rf "$BUILD_DIR"
25+
fi
26+
27+
echo "Build for iphonesimulator"
28+
xcodebuild -project $PROJECT_NAME -scheme $TARGET_NAME \
29+
-configuration Release \
30+
-sdk iphonesimulator \
31+
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS ' \
32+
CONFIGURATION_BUILD_DIR=$BUILD_FOR_SIMULATOR_DIR \
33+
clean build -quiet
34+
35+
echo "Build for iphoneos"
36+
xcodebuild -project $PROJECT_NAME -scheme $TARGET_NAME \
37+
-configuration Release \
38+
-sdk iphoneos \
39+
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS ' \
40+
CONFIGURATION_BUILD_DIR=$BUILD_FOR_DEVICE_DIR \
41+
clean build archive -quiet
42+
43+
if [ -d "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework" ]; then
44+
rm -rf "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework"
45+
fi
46+
47+
mkdir -p "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework"
48+
49+
cp -fr "$BUILD_FOR_DEVICE_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME.framework" "$BUILD_OUTPUT_DIR"
50+
51+
echo "Build fat framework"
52+
xcrun -sdk iphoneos lipo -create \
53+
$BUILD_FOR_SIMULATOR_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME \
54+
$BUILD_FOR_DEVICE_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME \
55+
-o "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME"
56+
57+
rm -rf $BUILD_DIR
58+
59+
echo "$FRAMEWORK_NAME.framework was built in $BUILD_OUTPUT_DIR"
60+
61+
if [ ! -d $PLUGIN_TARGET_DIR ]; then
62+
mkdir $PLUGIN_TARGET_DIR
63+
fi
64+
65+
if [ ! -d $PLUGIN_TARGET_SUBDIR ]; then
66+
mkdir $PLUGIN_TARGET_SUBDIR
67+
fi
68+
69+
cp -R "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework" $PLUGIN_TARGET_SUBDIR
70+
71+
echo "iOS Framework was copied to $PLUGIN_TARGET_SUBDIR"
72+
73+
cd $CURRENT_DIR

publish/pack.sh

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,63 @@
11
#!/bin/bash
2+
set -e
3+
set -o pipefail
24

3-
SOURCE_DIR=../src;
4-
TO_SOURCE_DIR=src;
5-
PACK_DIR=package;
6-
ROOT_DIR=..;
5+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
SOURCE_DIR="$CURRENT_DIR/../src"
7+
TO_SOURCE_DIR="$CURRENT_DIR/src"
8+
PACK_DIR="$CURRENT_DIR/package"
9+
ROOT_DIR="$CURRENT_DIR/.."
710
PUBLISH=--publish
811

12+
# pass native android or ios as arguments to skip native building
13+
ARGS={$1""}
14+
915
install(){
16+
cd $CURRENT_DIR
1017
npm i
1118
}
1219

1320
pack() {
14-
echo 'Building plugin package...'
15-
echo '--------------------------'
16-
echo 'NOTE: This plugin contains native libraries for Android and iOS, which should be built separately if you have made changes to them!'
17-
echo 'If you have updated the ./native-src/android/ or ./native-src/ios/ projects and the binaries, you must run this pack script again.'
18-
echo '--------------------------'
19-
20-
echo 'Clearing "'$TO_SOURCE_DIR'" and "'$PACK_DIR'"...'
21+
echo 'Clearing /src and /package...'
2122
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
2223
node_modules/.bin/rimraf "$PACK_DIR"
2324

25+
cd $SOURCE_DIR
26+
npm i
27+
cd $CURRENT_DIR
28+
29+
if [[ $ARGS != *"native"* ]]; then
30+
31+
if [ $ARGS != *"android"* ]; then
32+
# compile native android
33+
echo 'Building native android...'
34+
./build-android.sh
35+
else
36+
echo 'Building native android was skipped...'
37+
fi
38+
39+
if [ $ARGS != *"ios"* ]; then
40+
# compile native ios
41+
echo 'Building native ios...'
42+
./build-ios.sh
43+
else
44+
echo 'Building native ios was skipped...'
45+
fi
46+
else
47+
echo "Native build was skipped, using existing native binaries..."
48+
fi
49+
2450
# copy src
25-
echo 'Copying "'$SOURCE_DIR'" to "'$TO_SOURCE_DIR'"...'
51+
echo 'Copying src...'
2652
node_modules/.bin/ncp "$SOURCE_DIR" "$TO_SOURCE_DIR"
2753

28-
# copy README & LICENSE to src
29-
echo 'Copying README and LICENSE to "'$TO_SOURCE_DIR'"...'
54+
# copy LICENSE to src
55+
echo 'Copying README & LICENSE to /src...'
3056
node_modules/.bin/ncp "$ROOT_DIR"/LICENSE "$TO_SOURCE_DIR"/LICENSE
3157
node_modules/.bin/ncp "$ROOT_DIR"/README.md "$TO_SOURCE_DIR"/README.md
3258

3359
# compile package and copy files required by npm
34-
echo 'Building "'$TO_SOURCE_DIR'"...'
60+
echo 'Building /src...'
3561
cd "$TO_SOURCE_DIR"
3662
node_modules/.bin/tsc
3763
cd ..
@@ -42,11 +68,12 @@ pack() {
4268

4369
# create the package
4470
cd "$PACK_DIR"
45-
npm pack ../"$TO_SOURCE_DIR"
71+
npm pack "$TO_SOURCE_DIR"
72+
echo "Package created in $PACK_DIR"
4673

4774
# delete source directory used to create the package
4875
cd ..
4976
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
5077
}
5178

52-
install && pack
79+
install && pack

publish/publish.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

3-
PACK_DIR=package;
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
PACK_DIR="$CURRENT_DIR/package"
45

56
publish() {
67
cd $PACK_DIR

0 commit comments

Comments
 (0)