diff --git a/.gitignore b/.gitignore index 4032ec6..bd0b92f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.git/ \ No newline at end of file +.git/ +/.idea diff --git a/bin/compile b/bin/compile index b929fef..d2a7dc0 100644 --- a/bin/compile +++ b/bin/compile @@ -25,7 +25,6 @@ function export_env_dir() { function indent() { sed -u 's/^/ /' } - BUILD_DIR=${1:-} CACHE_DIR=${2:-} @@ -33,38 +32,25 @@ export_env_dir "$3" # Create the cache directory if not exist. mkdir -p $CACHE_DIR +if [ -n "$FLUTTER_BUILD_DIR" ]; then + APP_DIR=$BUILD_DIR/$FLUTTER_BUILD_DIR +else + APP_DIR=$BUILD_DIR +fi +cd "$APP_DIR" -cd $BUILD_DIR - -if [ -d $CACHE_DIR/flutter ]; then +if [ -d "$CACHE_DIR/flutter" ]; then print "Restoring Flutter SDK from CACHE" - cp -R $CACHE_DIR/flutter $BUILD_DIR + cp -R $CACHE_DIR/flutter $APP_DIR else print "Installing SDK from Github repository." - git clone https://github.com/flutter/flutter.git --quiet + git clone https://github.com/flutter/flutter.git --branch $FLUTTER_VERSION --quiet --single-branch | indent fi -# Check if FLUTTER_VERSION variables is set. -if [ -n "$FLUTTER_VERSION" ]; then - # Load bash variables from flutter --machine --version and read it like $FLUTTER_VERSION variable. - flutter/bin/flutter --machine --version >flutter.json - FLUTTER_INSTALLED_VERSION=$(grep -o '"frameworkVersion": *"[^"]*' flutter.json | grep -o '[^"]*$') - - # Check if the FLUTTER_VERSION is the same with the installed one. - if [ "$FLUTTER_VERSION" != "$FLUTTER_INSTALLED_VERSION" ]; then - print "Installing Flutter SDK version : $FLUTTER_VERSION" - flutter/bin/flutter version $FLUTTER_VERSION --quiet | indent - fi - rm flutter.json - -else - - print "Running flutter upgrade command" - if [ $channel != "beta" ]; then - flutter/bin/flutter channel beta | indent - fi - - flutter/bin/flutter upgrade --quiet | indent +if [ -n "$FLUTTER_ENV_FILE" ]; then + print "Generate .env file" + touch .env + echo $FLUTTER_ENV_FILE | base64 --decode > .env fi print "Enabling Web support" @@ -74,7 +60,7 @@ print "Running flutter clean command." flutter/bin/flutter clean --quiet | indent print "Getting packages from Flutter project" -flutter/bin/flutter pub get --quiet | indent +flutter/bin/flutter pub get | indent PATH="$PATH":"$(pwd)/flutter/bin/" @@ -92,9 +78,9 @@ mkdir -p $PUB_CACHE if [ -x flutter/bin/flutter ]; then print "Saving Flutter SDK in Cache" rm -rf $CACHE_DIR/flutter - cp -R $BUILD_DIR/flutter $CACHE_DIR/flutter - mv $BUILD_DIR/flutter/bin/cache/dart-sdk/ $BUILD_DIR - rm -rf $BUILD_DIR/flutter + cp -R $APP_DIR/flutter $CACHE_DIR/flutter + mv $APP_DIR/flutter/bin/cache/dart-sdk/ $APP_DIR + rm -rf $APP_DIR/flutter fi # To read hidden directories and use move with exclusion. @@ -103,11 +89,11 @@ shopt -s extglob # Check FLUTTER_CLEANUP var to delete all files or keep it. if [ "$FLUTTER_CLEANUP" != false ]; then - mkdir -p $BUILD_DIR/TO_DELETE + mkdir -p $APP_DIR/TO_DELETE mv !("TO_DELETE") TO_DELETE - mv TO_DELETE/build/web/* $BUILD_DIR - mv TO_DELETE/dart-sdk $BUILD_DIR + mv TO_DELETE/build/web/* $APP_DIR + mv TO_DELETE/dart-sdk $APP_DIR rm -rf TO_DELETE fi @@ -116,21 +102,27 @@ fi # Is taken from my Github repo because some variables need to be changed every run # like PORT from environment. -if [ -d "$CACHE_DIR/.pub-cache/" ]; then - print "dhttpd Found in cache. Restoring." - cp -R $CACHE_DIR/.pub-cache/* $PUB_CACHE -else +#if [ -d "$CACHE_DIR/.pub-cache/" ]; then +# print "dhttpd Found in cache. Restoring." +# cp -R $CACHE_DIR/.pub-cache/* $PUB_CACHE +#else print "Getting dhttpd to run web service." - $BUILD_DIR/dart-sdk/bin/dart pub global activate -sgit https://github.com/diezep/dhttpd.git | indent + $APP_DIR/dart-sdk/bin/dart pub global activate dhttpd | indent print "Getting dhtppd to run web service." mkdir -p $CACHE_DIR/.pub-cache/ cp -R $PUB_CACHE/* $CACHE_DIR/.pub-cache/ -fi +#fi # Moving to the build, after running the compile. All will be deleted and removed to app directory. # Copying the result, the files will be kept in storage. -cp -R $PUB_CACHE $BUILD_DIR +cp -R $PUB_CACHE $APP_DIR + +if [ -n "$FLUTTER_DEPLOY_DIR" ]; then + cp -r "$APP_DIR" "$BUILD_DIR/$FLUTTER_DEPLOY_DIR" +fi + +du -h -d 2 | sort -n -export PATH="$PATH":"/app/dart-sdk/bin/" -export PATH="$PATH":"/app/.pub-cache/bin" +export PATH="$PATH":"/$APP_DIR/dart-sdk/bin/" +export PATH="$PATH":"/$APP_DIR/.pub-cache/bin" diff --git a/bin/release b/bin/release index 4caa207..0dc9b76 100644 --- a/bin/release +++ b/bin/release @@ -1,16 +1,21 @@ #!/bin/sh BUILD_DIR=${1:-} -# If the FLUTTER_CLEANUP is in false, or in true. -if [ -d $BUILD_DIR/build/web ]; then - DEPLOY_DIR="/app/build/web/" +if [ -n "$FLUTTER_DEPLOY_DIR" ]; then + DEPLOY_DIR="$FLUTTER_DEPLOY_DIR" else - DEPLOY_DIR="/app/" + + # If the FLUTTER_CLEANUP is in false, or in true. + if [ -d $BUILD_DIR/build/web ]; then + DEPLOY_DIR="/app/build/web/" + else + DEPLOY_DIR="/app/" + fi fi cat <