forked from ng-alain/delon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffold.sh
82 lines (63 loc) · 1.9 KB
/
scaffold.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -u -e -o pipefail
readonly currentDir=$(cd $(dirname $0); pwd)
cd ${currentDir}
BUILD=false
DEPLOY=false
for ARG in "$@"; do
case "$ARG" in
-d)
DEPLOY=true
;;
-b)
BUILD=true
;;
esac
done
#######################################
# update version references
# Arguments:
# param1 - package.json path
# Returns:
# None
#######################################
updateVersionReferences() {
PACKAGE_DIR="$1"
(
echo "====== VERSION: Updating version references in ${PACKAGE_DIR}"
sed -i "s/\"version\":[ ]*\"[^\"]*\"/\"version\": \"${VERSION}\"/g" ${PACKAGE_DIR}
PACKAGE_NAMES=(abc acl auth cache mock form theme util)
for name in ${PACKAGE_NAMES[@]}
do
sed -i "s/\"@delon\/${name}\":[ ]*\"[^\"]*\"/\"@delon\/${name}\": \"^${VERSION}\"/g" ${PACKAGE_DIR}
done
)
}
VERSION=$(node -p "require('./package.json').version")
echo "Version ${VERSION}, BUILD(-b): ${BUILD}, DEPLOY(-d): ${DEPLOY}"
PWD=`pwd`
SCAFFOLD_DIR=${PWD}/scaffold
ROOT_DIR=${PWD}/dist/scaffold
DIST_DIR=${ROOT_DIR}/dist
if [[ ${BUILD} == true ]]; then
echo '===== copy...'
rm -rf ${ROOT_DIR}
mkdir -p ${ROOT_DIR}
rsync -a --exclude "node_modules" ${SCAFFOLD_DIR}/ ${ROOT_DIR}
cd ${ROOT_DIR}
updateVersionReferences ${ROOT_DIR}/package.json
updateVersionReferences ${SCAFFOLD_DIR}/package.json
echo '===== need mock'
sed -i "s/const MOCKMODULE = !environment.production/const MOCKMODULE = true/g" ${ROOT_DIR}/src/app/delon.module.ts
npm i
echo '===== build...'
$(npm bin)/ng build --prod --build-optimizer --base-href /ng-alain/
fi
if [[ ${DEPLOY} == true ]]; then
echo 'copy index.html > 404.html'
cp -f ${DIST_DIR}/index.html ${DIST_DIR}/404.html
echo 'deploy by gh-pages'
$(npm bin)/gh-pages-clean
$(npm bin)/gh-pages -d dist/scaffold/dist -r https://github.com/cipchk/ng-alain/
fi
echo 'FINISHED!'