Files
sample-node-api/.pax/prepare-workspace.sh
Nakul Manchanda 72b5457afb generate tar gz package
Signed-off-by: Nakul Manchanda <nakul.manchanda@ibm.com>
2021-01-26 11:28:06 -05:00

105 lines
3.5 KiB
Bash
Executable File

#!/bin/bash -e
################################################################################
# This program and the accompanying materials are made available under the terms of the
# Eclipse Public License v2.0 which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-v20.html
#
# SPDX-License-Identifier: EPL-2.0
#
# Copyright IBM Corporation 2018, 2020
################################################################################
################################################################################
# Build script
#
# - build client
#################################################################################
# contants
SCRIPT_NAME=$(basename "$0")
BASEDIR=$(dirname "$0")
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(cd "$SCRIPT_DIR" && cd .. && pwd)
PAX_WORKSPACE_DIR=.pax
cd "${ROOT_DIR}"
PACKAGE_NAME=$(node -e "console.log(require('./package.json').name)")
PACKAGE_VERSION=$(node -e "console.log(require('./package.json').version)")
PACKAGE_DESC=$(node -e "console.log(require('./package.json').description)")
ZOWE_PLUGIN_ID="com.ibm.${PACKAGE_NAME}"
# prepare pax workspace
echo "[${SCRIPT_NAME}] cleaning PAX workspace ..."
rm -fr "${PAX_WORKSPACE_DIR}/content"
mkdir -p "${PAX_WORKSPACE_DIR}/content"
cp manifest.yaml "${PAX_WORKSPACE_DIR}/content"
cp README.md "${PAX_WORKSPACE_DIR}/content"
cp LICENSE "${PAX_WORKSPACE_DIR}/content"
# build client
echo "[${SCRIPT_NAME}] building client ..."
# build client
if [ ! -d "dist" ] || [ -z "$(ls -1 dist/src/index.js)" ]; then
echo "[${SCRIPT_NAME}] building client ..."
if [ ! -d "node_modules" ]; then
npm install
fi
echo "[${SCRIPT_NAME}] run build ..."
npm run build
fi
cd "dist"
npm install --only=prod
cd "${ROOT_DIR}"
# copy sample-node-api to target folder
# copy start script to target folder - included in dist
echo "[${SCRIPT_NAME}] copying sample node api backend ..."
mkdir -p "${PAX_WORKSPACE_DIR}/content"
cp -r dist/. "${PAX_WORKSPACE_DIR}/content"
# move content to another folder
rm -fr "${PAX_WORKSPACE_DIR}/ascii"
mkdir -p "${PAX_WORKSPACE_DIR}/ascii"
# update build information
# BRANCH_NAME and BUILD_NUMBER is Jenkins environment variable
commit_hash=$(git rev-parse --verify HEAD)
current_timestamp=$(date +%s%3N)
sed -e "s|{{build\.branch}}|${BRANCH_NAME}|g" \
-e "s|{{build\.number}}|${BUILD_NUMBER}|g" \
-e "s|{{build\.commitHash}}|${commit_hash}|g" \
-e "s|{{build\.timestamp}}|${current_timestamp}|g" \
"${PAX_WORKSPACE_DIR}/content/manifest.yaml" > "${PAX_WORKSPACE_DIR}/content/manifest.yaml.tmp"
mv "${PAX_WORKSPACE_DIR}/content/manifest.yaml.tmp" "${PAX_WORKSPACE_DIR}/content/manifest.yaml"
echo "[${SCRIPT_NAME}] manifest:"
cat "${PAX_WORKSPACE_DIR}/content/manifest.yaml"
echo
rsync -rv \
--include '*.json' --include '*.html' --include '*.jcl' --include '*.template' \
--exclude '*.zip' --exclude '*.png' --exclude '*.tgz' --exclude '*.tar.gz' --exclude '*.pax' \
--prune-empty-dirs --remove-source-files \
"${PAX_WORKSPACE_DIR}/content/" \
"${PAX_WORKSPACE_DIR}/ascii"
echo "[${SCRIPT_NAME}] ${PAX_WORKSPACE_DIR} folder is prepared."
echo "[${SCRIPT_NAME}] ${PAX_WORKSPACE_DIR} prepare local-build and *.tar.gz"
cd "${PAX_WORKSPACE_DIR}"
# remove folder for local build & tar
rm -fr "sample-node-api"
rm -f "sample-node-api.tar.gz"
# copy ascii to sample-node-api
cp -r "ascii" "sample-node-api"
# tar sample-node-api
tar -zcvf "sample-node-api.tar.gz" "sample-node-api"
echo "[${SCRIPT_NAME}] ${PAX_WORKSPACE_DIR} local-build and *.tar.gz is generated"
exit 0