-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·110 lines (86 loc) · 2.84 KB
/
setup.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
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
#!/bin/bash
set -e
if [ $# -gt 0 ]; then
project=$1
else
echo "Error: No project name given."
exit 1
fi
command -v envsubst >/dev/null 2>&1 || { echo >&2 "Error: envsubst is not available."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is not available."; exit 1; }
export API_ENDPOINT=${API_ENDPOINT:=api}
if [[ -L "${BASH_SOURCE[0]}" ]];
then
sourcedir=$( dirname $(readlink ${BASH_SOURCE[0]}) )
else
sourcedir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
fi
echo "Creating project $project..."
mkdir -p "$project"
pushd "$project" >/dev/null
echo "Initalizing project..."
git init
npm init -f
echo "Creating README and .gitignore files..."
echo "# ${project}" | cat - "$sourcedir/readme.tmpl.md" > ./README.md
cp "$sourcedir/.gitignore.tmpl" ./.gitignore
echo "Initalizing Webpack and Babel..."
npm install --save-dev \
webpack \
webpack-dev-server \
webpack-cli \
html-webpack-plugin \
@babel/cli \
@babel/core \
@babel/preset-env \
@babel/preset-react \
@babel/plugin-transform-runtime \
babel-loader \
mini-css-extract-plugin \
css-loader
npm install --save @babel/polyfill @babel/runtime
envsubst '$API_ENDPOINT' < "$sourcedir/webpack.config.tmpl.js" > ./webpack.config.js
cp "$sourcedir/.babelrc.tmpl" ./.babelrc
tmp=$(mktemp)
jq '.scripts += {
"build:client": "webpack --mode production",
"start:client": "webpack-dev-server --mode development" }' \
package.json > "$tmp" && mv "$tmp" package.json
echo "Initalizing ESLint and Prettier..."
npm install --save-dev \
eslint \
eslint-plugin-import \
eslint-plugin-react \
eslint-plugin-prettier \
eslint-config-prettier \
babel-eslint \
eslint-plugin-babel \
prettier
cp "$sourcedir/.eslintrc.yml.tmpl" ./.eslintrc.yml
cp "$sourcedir/.prettierrc.yml.tmpl" ./.prettierrc.yml
echo "Initializing Flow typing..."
npm install --save-dev \
flow-bin \
@babel/preset-flow \
eslint-plugin-flowtype \
eslint-plugin-flowtype-errors
npx flow init
echo "Initializing React client entry..."
npm install --save react react-dom
cp -R "$sourcedir/client" .
envsubst '$API_ENDPOINT' < "$sourcedir/client/src/app.jsx" > ./client/src/app.jsx
echo "Initalizing Express backend..."
npm install --save express
npm install --save-dev nodemon @babel/node
mkdir -p server/src
envsubst '$API_ENDPOINT' < "$sourcedir/app.tmpl.js" > ./server/src/app.js
tmp=$(mktemp)
jq '.scripts += {
"build:server": "babel ./server/src --out-dir ./server/dist --delete-dir-on-start",
"start:server": "nodemon --exec babel-node server/src/app.js",
start: "node server/dist/app.js" }' \
package.json > "$tmp" && mv "$tmp" package.json
echo "Adding additional build scripts..."
tmp=$(mktemp)
jq '.scripts += { build: "npm run build:client && npm run build:server" }' \
package.json > "$tmp" && mv "$tmp" package.json