Created
June 13, 2019 07:29
-
-
Save mpneuried/e5d2a8c97dd581de334f82b7e4bc0640 to your computer and use it in GitHub Desktop.
Script to generate and "publish/copy" a local doc folder to another folder taht could be synced via dropbox/onedrive/google-drive ... it write keep the latest folder and keep archived versions as zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#colors | |
COFF='\033[0m' | |
CRED='\033[1;31m' | |
CGREEN='\033[1;32m' | |
CYELLOW='\033[0;33m' | |
CCYAN='\033[1;36m' | |
CBLUE='\033[1;34m' | |
ENVFILE="$PWD/deploy.env" | |
if [ -f "$ENVFILE" ]; then | |
eval $(grep -v -e '^#' $ENVFILE | xargs -I {} echo export \'{}\') | |
echo "$CCYAN INFO:$CGREEN use 'deploy.env'$COFF\n" | |
else | |
echo "$CCYAN INFO:$CYELLOW no 'deploy.env' so use defaults$COFF\n" | |
fi | |
# get the version from env or via script | |
VERSION=${VERSION:=$(sh "$PWD/version.sh")} | |
# get the name from env or jq script | |
NAME=${APP_NAME:=$(cat ./package.json | jq -r '.name| split("/")[-1]')} | |
GENDOCS_COMMAND=${GENDOCS_COMMAND:="npm run docs"} | |
DOCS_SOURCE_PATH=${DOCS_SOURCE_PATH:="$PWD/docs/"} | |
DOCS_TARGET_PATH=${DOCS_TARGET_PATH:="$HOME/Default-Path/To/your/docs"} | |
if [ -z "$NAME" ]; then | |
echo "$CRED ERROR: No name defined $COFF" | |
exit 1 | |
fi | |
echo "$CCYAN GENERATE DOCS for '$NAME' version $VERSION $COFF" | |
# check for configuration | |
if [ -d "$DOCS_TARGET_PATH" ]; then | |
echo "$CBLUE generate docs ...\n -------------------------------------------$COFF" | |
set -e | |
eval "$GENDOCS_COMMAND" | |
echo "$CBLUE -------------------------------------------\n docs generated$COFF\n" | |
echo "$CBLUE copy files to target ... $COFF" | |
# create target folder and clear the existing latest folder | |
DOCS_FOLDER="$DOCS_TARGET_PATH/$NAME/latest" | |
rm -rf "$DOCS_FOLDER" | |
mkdir -p "$DOCS_FOLDER" | |
# generate zip to archive current version | |
zip -q -o "$DOCS_TARGET_PATH/$NAME/$VERSION.zip" -r "$DOCS_SOURCE_PATH" | |
# add a txt file containing the current version | |
echo "$VERSION" > "$DOCS_TARGET_PATH/$NAME/currentversion.txt" | |
# copy the current docs to onedrive | |
cp -r "$DOCS_SOURCE_PATH" "$DOCS_FOLDER" | |
echo "\n$CGREEN DONE! $COFF" | |
else | |
echo "$CRED ERROR: The OneDrive docs folder doesn't exists at: '$DOCS_TARGET_PATH'$COFF" | |
echo "$CCYAN Try to define the file '$ENVFILE' and set the value 'DOCS_SOURCE_PATH=/path/to/target/folder'$COFF\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment