Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from inthepocket/feature/upload-to-cloud
Browse files Browse the repository at this point in the history
Add support to upload output to cloud storage/providers
  • Loading branch information
thibmaek authored Oct 25, 2018
2 parents f1e05aa + a831452 commit ff2d0cb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions services/upload/gcloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -e

# Pretty log output
function log() {
printf "\\n\\033[1m\\033[34m%s\\033[0m\\n\\n" "[sketchxport-scripts] ${1}"
}

# @param $1 asset output dir
# @param $2 config output dir
# @param $3 bucket name
function upload_to_gcloud() {
if ! command -v gsutil > /dev/null; then
log "The required gsutil CLI was not found."
fi

if [ -z "$1" ]; then
log "-> Google Cloud upload error: Parameter 1 was not supplied."
log "You should supply the asset output dir as parameter 1"
exit 1
fi
if [ -z "$2" ]; then
log "-> Google Cloud upload error: Parameter 2 was not supplied."
log "You should supply the config output dir as parameter 2"
exit 1
fi
if [ -z "$3" ]; then
log "-> Google Cloud upload error: Parameter 3 was not supplied."
log "You should supply the Google Cloud bucket name as parameter 3 without the gs:// prefix"
exit 1
fi

log "⛅️ Uploading to Google Cloud (using bucket: gs://$3)"

# Upload asset output dir recursively to the provided bucket (in parallell)
gsutil -m cp -r "$1" "gs://$3" && \
# Upload config output to the provided bucket.
gsutil cp "$2/sketchxport.json" "gs://$3"
}
14 changes: 14 additions & 0 deletions sketchxport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ function generate_assets() {
bash ./sketchtool.sh "$SKETCHFILE" "$ASSETS_OUTPUT_DIR"
}

function upload_to_cloud() {
# You can enable custom cloud providers here to upload generated output to that provider
# upload_to_gcloud "$ASSETS_OUTPUT_DIR" "$CONFIG_OUTPUT_DIR" "$1"
exit 0
}

function main() {
# Check if we got a sketchfile, otherwise exit 1
if [ -z "$1" ]; then
Expand All @@ -37,11 +43,19 @@ function main() {
if [ -z "$2" ]; then CONFIG_OUTPUT_DIR="$PWD"; else CONFIG_OUTPUT_DIR=$2; fi
if [ -z "$3" ]; then ASSETS_OUTPUT_DIR="$PWD/assets/images"; else ASSETS_OUTPUT_DIR=$3; fi

# Source cloud providers
for file in ./services/upload/*; do
# shellcheck disable=SC1090,SC1091
[ -r "$file" ] && [ -f "$file" ] && source "$file"
done

log "Sketchfile is $SKETCHFILE"
log "Config output dir is $CONFIG_OUTPUT_DIR"
log "Asset output dir is $ASSETS_OUTPUT_DIR"

generate_config "$@"
generate_assets "$@"

upload_to_cloud "sketchxport-output-dir"
}
main "$@"

0 comments on commit ff2d0cb

Please sign in to comment.