diff --git a/.env.example b/.env.example index 40535db..32bd02b 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,10 @@ #SOURCE_DIR=~/source -SOURCE_DIR=/home/user/cslant.com/home +SOURCE_DIR=/home/user/cslant.com/blog GIT_SSH_URL=git@github.com:cslant # The name of the runner -WORKER_NAME="CSlant Home" +WORKER_NAME="CSlant Blog" # add the env to choose "npm" or "yarn" as the installer INSTALLER=yarn diff --git a/README.md b/README.md index ce20a2f..a95558d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# CSlant Home Runner +# CSlant Blog Runner ```text -██╗ ██╗ ██████╗ ███╗ ███╗███████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ -██║ ██║██╔═══██╗████╗ ████║██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ -███████║██║ ██║██╔████╔██║█████╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ -██╔══██║██║ ██║██║╚██╔╝██║██╔══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ -██║ ██║╚██████╔╝██║ ╚═╝ ██║███████╗ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ -╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ +██████╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ +██╔══██╗██║ ██╔═══██╗██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║ ██║██║ ███╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║ ██║██║ ██║ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ +██████╔╝███████╗╚██████╔╝╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ +╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ``` -This repo is to set up the runner for updating the homepage at https://cslant.com +This repo is to set up the runner for updating the homepage at https://cslant.com/blog -We can use this runner to update the Home automatically with CI/CD pipelines. +We can use this runner to update the Blog automatically with CI/CD pipelines. ## Installation @@ -27,12 +27,12 @@ In the `.env` file, update the values to match your environment. # .env #SOURCE_DIR=~/source -SOURCE_DIR=/home/user/cslant.com/home +SOURCE_DIR=/home/user/cslant.com/blog GIT_SSH_URL=git@github.com:cslant # The name of the runner -WORKER_NAME="CSlant Home" +WORKER_NAME="CSlant Blog" # add the env to choose "npm" or "yarn" as the installer INSTALLER=yarn @@ -63,6 +63,6 @@ The runner has the following commands: | Command | Description | |----------------|------------------------------| | `help`, `tips` | Shows the help message | -| `build`, `b` | Builds the Home | +| `build`, `b` | Builds the Blog | | `worker`, `w` | Create or restart the worker | | `all`, `a` | Runs all the commands | diff --git a/runner.sh b/runner.sh index 57ce865..0b8bd86 100755 --- a/runner.sh +++ b/runner.sh @@ -21,11 +21,11 @@ case "$1" in usage ;; - home_sync) - home_sync "$2" + blog_sync) + blog_sync "$2" ;; - build | build_home | b) + build | build_blog | b) build_fe "${2:-install}" ;; @@ -34,10 +34,10 @@ case "$1" in ;; all | a) - home_sync all - build_fe install + blog_sync all +# build_fe install build_api install - worker +# worker ;; *) diff --git a/setup/functions.sh b/setup/functions.sh index ea98b92..1a12497 100644 --- a/setup/functions.sh +++ b/setup/functions.sh @@ -5,18 +5,18 @@ build_fe() { BUILD_TYPE="$1" - cd "$HOME_FE_DIR" || exit + cd "$BLOG_FE_DIR" || exit - if [ ! -f "$HOME_FE_DIR/.env" ]; then + if [ ! -f "$BLOG_FE_DIR/.env" ]; then echo ' ∟ .env file missing, copying from .env.example...' - cp "$HOME_FE_DIR/.env.example" "$HOME_FE_DIR/.env" + cp "$BLOG_FE_DIR/.env.example" "$BLOG_FE_DIR/.env" fi - home_resource_env + blog_resource_env if ! command -v nvm &> /dev/null; then # shellcheck disable=SC2155 - export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + export NVM_DIR="$([ -z "${XDG_CONFIG_BLOG-}" ] && printf %s "${BLOG}/.nvm" || printf %s "${XDG_CONFIG_BLOG}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" fi nvm use "$NODE_VERSION" @@ -26,7 +26,7 @@ build_fe() { npm install -g yarn fi - if [ ! -d "$HOME_FE_DIR/node_modules" ] || [ "$BUILD_TYPE" = "install" ]; then + if [ ! -d "$BLOG_FE_DIR/node_modules" ] || [ "$BUILD_TYPE" = "install" ]; then echo ' ∟ Installing dependencies...' if [ "$INSTALLER" = "yarn" ]; then yarn install @@ -54,7 +54,7 @@ build_fe() { worker() { echo '📽 Starting worker...' - cd "$HOME_FE_DIR" || exit + cd "$BLOG_FE_DIR" || exit if pm2 show "$WORKER_NAME" > /dev/null; then echo " ∟ Restarting $WORKER_NAME..." @@ -71,7 +71,7 @@ worker() { node_runner() { echo '🏃‍♂️ Running node...' - cd "$HOME_FE_DIR" || exit + cd "$BLOG_FE_DIR" || exit if [ "$INSTALLER" = "yarn" ]; then yarn "$@" @@ -92,11 +92,11 @@ build_api() { COMPOSER_COMMAND="update" fi - cd "$HOME_API_DIR" || exit + cd "$BLOG_ADMIN_DIR" || exit - if [ ! -f "$HOME_API_DIR/.env" ]; then + if [ ! -f "$BLOG_ADMIN_DIR/.env" ]; then echo ' ∟ .env file missing, copying from .env.example...' - cp "$HOME_API_DIR/.env.example" "$HOME_API_DIR/.env" + cp "$BLOG_ADMIN_DIR/.env.example" "$BLOG_ADMIN_DIR/.env" composer $COMPOSER_COMMAND php artisan key:generate else @@ -106,17 +106,17 @@ build_api() { echo '' } -home_resource_env() { +blog_resource_env() { echo '🔧 Setting up home resource environment...' - cd "$HOME_FE_DIR" || exit + cd "$BLOG_FE_DIR" || exit - HOME_RESOURCE_DIR="$HOME_DIR/home-resource" + BLOG_RESOURCE_DIR="$BLOG_DIR/blog-resource" - # check and replace "PUBLIC_DIR=/Users/tanhongit/Data/CSlant/home-resource/public" to "PUBLIC_DIR=$HOME_RESOURCE_DIR/public" - if [ -f "$HOME_FE_DIR/.env" ] && ! grep -q "PUBLIC_DIR=$HOME_RESOURCE_DIR/public" "$HOME_FE_DIR/.env"; then + # check and replace "PUBLIC_DIR=/Users/tanhongit/Data/CSlant/blog-resource/public" to "PUBLIC_DIR=$BLOG_RESOURCE_DIR/public" + if [ -f "$BLOG_FE_DIR/.env" ] && ! grep -q "PUBLIC_DIR=$BLOG_RESOURCE_DIR/public" "$BLOG_FE_DIR/.env"; then echo ' ∟ Setting up PUBLIC_DIR...' - awk -v HOME_RESOURCE_DIR="$HOME_RESOURCE_DIR" '/PUBLIC_DIR=/{gsub(/PUBLIC_DIR=.*/, "PUBLIC_DIR="HOME_RESOURCE_DIR"/public")}1' "$HOME_FE_DIR/.env" >"$HOME_FE_DIR/.env.tmp" && mv "$HOME_FE_DIR/.env.tmp" "$HOME_FE_DIR/.env" + awk -v BLOG_RESOURCE_DIR="$BLOG_RESOURCE_DIR" '/PUBLIC_DIR=/{gsub(/PUBLIC_DIR=.*/, "PUBLIC_DIR="BLOG_RESOURCE_DIR"/public")}1' "$BLOG_FE_DIR/.env" >"$BLOG_FE_DIR/.env.tmp" && mv "$BLOG_FE_DIR/.env.tmp" "$BLOG_FE_DIR/.env" else echo ' ∟ PUBLIC_DIR already set up...' fi diff --git a/setup/tips.sh b/setup/tips.sh index fc23cd4..2e6efe1 100644 --- a/setup/tips.sh +++ b/setup/tips.sh @@ -2,13 +2,13 @@ welcome() { echo ' -██╗ ██╗ ██████╗ ███╗ ███╗███████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ -██║ ██║██╔═══██╗████╗ ████║██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ -███████║██║ ██║██╔████╔██║█████╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ -██╔══██║██║ ██║██║╚██╔╝██║██╔══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ -██║ ██║╚██████╔╝██║ ╚═╝ ██║███████╗ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ -╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ - ' +██████╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ +██╔══██╗██║ ██╔═══██╗██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║ ██║██║ ███╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║ ██║██║ ██║ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ +██████╔╝███████╗╚██████╔╝╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ +╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ +' echo '' echo '⚡ Welcome to the blog runner!' echo '' @@ -31,9 +31,13 @@ usage() { echo ' all Sync git and blog repository, build blog' echo '' echo 'Args for blog_sync:' - echo ' fe Sync frontend blog repository' - echo ' api Sync backend API blog repository' - echo ' all Sync all blog repository' + echo ' resources Sync resources blog repository' + echo ' fe Sync frontend blog repository' + echo ' admin Sync backend admin blog repository' + echo ' private_modules Sync private modules blog repository' + echo ' core_package Sync core package blog repository' + echo ' api_package Sync api package blog repository' + echo ' all Sync all blog repository' echo '' echo 'Args for build:' echo ' install Install dependencies and build (default, if not set)'