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

refactor: update publish code #237

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ publish/src
publish/package
demo/report/report.html
demo/report/stats.json
src/platforms/android/sync
Empty file modified native-src/android/gradlew
100644 → 100755
Empty file.
36 changes: 36 additions & 0 deletions publish/build-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set -e
set -o pipefail

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

SOURCE_NAME="app"
ANDROID_SOURCE_DIR="$CURRENT_DIR/../native-src/android"

PROJECT_NAME="$SOURCE_NAME"

BUILD_OUTPUT_DIR="$ANDROID_SOURCE_DIR/$PROJECT_NAME/build/outputs/aar/"

PLUGIN_TARGET_DIR="$CURRENT_DIR/../src/platforms"
PLUGIN_TARGET_SUBDIR="$PLUGIN_TARGET_DIR/android"

cd $ANDROID_SOURCE_DIR

./gradlew clean assembleRelease

echo "$PROJECT_NAME-release.aar was built in $BUILD_OUTPUT_DIR"

if [ ! -d $PLUGIN_TARGET_DIR ]; then
mkdir $PLUGIN_TARGET_DIR
fi

if [ ! -d $PLUGIN_TARGET_SUBDIR ]; then
mkdir $PLUGIN_TARGET_SUBDIR
fi

cp -R "$BUILD_OUTPUT_DIR/$PROJECT_NAME-release.aar" $PLUGIN_TARGET_SUBDIR/pushplugin.aar

echo "force livesync" > "$PLUGIN_TARGET_SUBDIR/sync"

echo "Android library was copied to $PLUGIN_TARGET_SUBDIR"

cd $CURRENT_DIR
73 changes: 73 additions & 0 deletions publish/build-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
set -e
set -o pipefail

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

SOURCE_NAME="PushPlugin"
IOS_SOURCE_DIR="$CURRENT_DIR/../native-src/ios"

PROJECT_NAME="$SOURCE_NAME.xcodeproj"
TARGET_NAME="$SOURCE_NAME"
FRAMEWORK_NAME="$SOURCE_NAME"

BUILD_DIR="$IOS_SOURCE_DIR/build/intermediates/${FRAMEWORK_NAME}"
BUILD_FOR_DEVICE_DIR="$BUILD_DIR/Release-iphoneos"
BUILD_FOR_SIMULATOR_DIR="$BUILD_DIR/Release-iphonesimulator"
BUILD_OUTPUT_DIR="$IOS_SOURCE_DIR/build/outputs"

PLUGIN_TARGET_DIR="$CURRENT_DIR/../src/platforms"
PLUGIN_TARGET_SUBDIR="$PLUGIN_TARGET_DIR/ios"

cd $IOS_SOURCE_DIR

if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi

echo "Build for iphonesimulator"
xcodebuild -project $PROJECT_NAME -scheme $TARGET_NAME \
-configuration Release \
-sdk iphonesimulator \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS ' \
CONFIGURATION_BUILD_DIR=$BUILD_FOR_SIMULATOR_DIR \
clean build -quiet

echo "Build for iphoneos"
xcodebuild -project $PROJECT_NAME -scheme $TARGET_NAME \
-configuration Release \
-sdk iphoneos \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS ' \
CONFIGURATION_BUILD_DIR=$BUILD_FOR_DEVICE_DIR \
clean build archive -quiet

if [ -d "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework" ]; then
rm -rf "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework"
fi

mkdir -p "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework"

cp -fr "$BUILD_FOR_DEVICE_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME.framework" "$BUILD_OUTPUT_DIR"

echo "Build fat framework"
xcrun -sdk iphoneos lipo -create \
$BUILD_FOR_SIMULATOR_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME \
$BUILD_FOR_DEVICE_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME \
-o "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME"

rm -rf $BUILD_DIR

echo "$FRAMEWORK_NAME.framework was built in $BUILD_OUTPUT_DIR"

if [ ! -d $PLUGIN_TARGET_DIR ]; then
mkdir $PLUGIN_TARGET_DIR
fi

if [ ! -d $PLUGIN_TARGET_SUBDIR ]; then
mkdir $PLUGIN_TARGET_SUBDIR
fi

cp -R "$BUILD_OUTPUT_DIR/$FRAMEWORK_NAME.framework" $PLUGIN_TARGET_SUBDIR

echo "iOS Framework was copied to $PLUGIN_TARGET_SUBDIR"

cd $CURRENT_DIR
61 changes: 44 additions & 17 deletions publish/pack.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
#!/bin/bash
set -e
set -o pipefail

SOURCE_DIR=../src;
TO_SOURCE_DIR=src;
PACK_DIR=package;
ROOT_DIR=..;
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_DIR="$CURRENT_DIR/../src"
TO_SOURCE_DIR="$CURRENT_DIR/src"
PACK_DIR="$CURRENT_DIR/package"
ROOT_DIR="$CURRENT_DIR/.."
PUBLISH=--publish

# pass native android or ios as arguments to skip native building
ARGS={$1""}

install(){
cd $CURRENT_DIR
npm i
}

pack() {
echo 'Building plugin package...'
echo '--------------------------'
echo 'NOTE: This plugin contains native libraries for Android and iOS, which should be built separately if you have made changes to them!'
echo 'If you have updated the ./native-src/android/ or ./native-src/ios/ projects and the binaries, you must run this pack script again.'
echo '--------------------------'

echo 'Clearing "'$TO_SOURCE_DIR'" and "'$PACK_DIR'"...'
echo 'Clearing /src and /package...'
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
node_modules/.bin/rimraf "$PACK_DIR"

cd $SOURCE_DIR
npm i
cd $CURRENT_DIR

if [[ $ARGS != *"native"* ]]; then

if [ $ARGS != *"android"* ]; then
# compile native android
echo 'Building native android...'
./build-android.sh
else
echo 'Building native android was skipped...'
fi

if [ $ARGS != *"ios"* ]; then
# compile native ios
echo 'Building native ios...'
./build-ios.sh
else
echo 'Building native ios was skipped...'
fi
else
echo "Native build was skipped, using existing native binaries..."
fi

# copy src
echo 'Copying "'$SOURCE_DIR'" to "'$TO_SOURCE_DIR'"...'
echo 'Copying src...'
node_modules/.bin/ncp "$SOURCE_DIR" "$TO_SOURCE_DIR"

# copy README & LICENSE to src
echo 'Copying README and LICENSE to "'$TO_SOURCE_DIR'"...'
# copy LICENSE to src
echo 'Copying README & LICENSE to /src...'
node_modules/.bin/ncp "$ROOT_DIR"/LICENSE "$TO_SOURCE_DIR"/LICENSE
node_modules/.bin/ncp "$ROOT_DIR"/README.md "$TO_SOURCE_DIR"/README.md

# compile package and copy files required by npm
echo 'Building "'$TO_SOURCE_DIR'"...'
echo 'Building /src...'
cd "$TO_SOURCE_DIR"
node_modules/.bin/tsc
cd ..
Expand All @@ -42,11 +68,12 @@ pack() {

# create the package
cd "$PACK_DIR"
npm pack ../"$TO_SOURCE_DIR"
npm pack "$TO_SOURCE_DIR"
echo "Package created in $PACK_DIR"

# delete source directory used to create the package
cd ..
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
}

install && pack
install && pack
3 changes: 2 additions & 1 deletion publish/publish.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

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

publish() {
cd $PACK_DIR
Expand Down