-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrepo-node-bootstrap
executable file
·118 lines (101 loc) · 3.15 KB
/
repo-node-bootstrap
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
set -euo pipefail
YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh
#- repo-node-bootstrap 1.0
## Usage: repo-node-boostrap [OPTION]
## Bootstrap a repo as a node repo.
##
## --diff Bootstrap a temporary folder for comparing
## current status with current bootstrap template
##
## -h, --help Display this help and exit
## -v, --version Output version information and exit
DIFF=false
if { getopt --test >/dev/null 2>&1 && false; } || [[ "$?" = "4" ]] || false; then
ARGS=$(getopt -o hv -l help,version,diff -n $(basename ${BASH_SOURCE[0]}) -- "$@") || sh_script_usage
eval set -- "${ARGS}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--diff)
DIFF=true
shift
;;
-h|--help)
sh_script_usage
;;
-v|--version)
sh_script_version
;;
--)
shift
break
;;
-*)
sh_script_usage
;;
*)
break
;;
esac
done
[[ $# -eq 0 ]] || sh_script_usage
cd ${YP_DIR}/..
git rev-parse --show-toplevel >/dev/null || {
echo_err "yplatform is not in a git repository"
exit 1
}
[[ "$(cd $(git rev-parse --show-toplevel) >/dev/null && pwd -P)" = "$(pwd -P)" ]] || {
echo_err "yplatform is not in the root of a git repository"
exit 1
}
YP_DIR_REL="$(${YP_DIR}/bin/relpath "${YP_DIR}" "$(pwd)")"
ARTIFACTS=
if ${DIFF}; then
echo_info "Creating a temporary vanilla bootstrapped folder for comparison"
TMP_VANILLA_DIR=$(mktemp -d -t yplatform.XXXXXXXXXX)
echo_info "${TMP_VANILLA_DIR}"
echo_info "e.g. opendiff . ${TMP_VANILLA_DIR}"
echo_info "e.g. ksdiff . ${TMP_VANILLA_DIR}"
echo
ln -s ${YP_DIR} ${TMP_VANILLA_DIR}/yplatform
cd ${TMP_VANILLA_DIR}
git init >/dev/null
fi
# NOTE duplicate code on purpose
ARTIFACT=.gitignore
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/dot.gitignore.node ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=.eslintrc.js
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/dot.eslintrc.js ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=.npmrc
[[ -e ${ARTIFACT} ]] || {
ln -s ${YP_DIR_REL}/repo/dot.npmrc ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Symlinked ${ARTIFACT}."
}
ARTIFACT=Makefile
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/Makefile.node ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=jest.config.js
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/jest.config.js ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
${YP_DIR_REL}/bin/repo-generic-bootstrap
echo -e "${ARTIFACTS}" | sort -u