-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-angular-project.sh
executable file
·98 lines (74 loc) · 3.13 KB
/
init-angular-project.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
#!/usr/bin/env bash
# shellcheck disable=SC2086
# Quick Angular 8 sandbox demo using Github pages:
usage(){
echo
echo "USAGE:"
echo "init-angular-project.sh <your-project-name> <your-github-username>"
echo
}
if [[ -n $1 ]]; then echo "Project Name: $1"; else usage && exit; fi
PROJECTNAME=$1
if [[ -n $2 ]]; then echo "Github Username: $2"; else usage && exit; fi
GITHUBUSERNAME=$2
# for most control, install nvm, use it to install nodejs and npm
# or more simply use brew to install nodejs and npm
echo "Node.js version: $(node --version)"
echo "NPM version: $(npm --version)"
#npm install -g @angular/cli
ng --version
ng new ${PROJECTNAME} --defaults
cd ${PROJECTNAME} || exit
git init
git add .
git commit -m "Initial commit of Angular sandbox, if any issues can rollback to this commit to try again"
cd - || exit
echo
echo "Github Repository creation:"
echo "--------------------------"
#TODO: use Github API for these steps rather than manually performing them
echo "manually: create public repo named ${PROJECTNAME} in Github web UI https://github.com/new"
echo
read -n 1 -s -r -p "Press any key to continue..."
echo
echo
echo "Github Actions automation:"
echo "--------------------------"
#TODO: use Github API for these steps rather than manually performing them
echo "manually: create Personal Access Token with repo access https://github.com/settings/tokens"
echo "manually: add this new secret as GH_TOKEN to the Angular sandbox Github repo https://github.com/${GITHUBUSERNAME}/${PROJECTNAME}/settings/secrets"
echo
read -n 1 -s -r -p "Press any key to continue..."
echo
echo "Creating Github Actions workflow configuration: ${PROJECTNAME}/.github/workflows/main.yml"
mkdir -p ${PROJECTNAME}/.github/workflows && ls -ld ${PROJECTNAME}/.github/workflows
cp github-actions-main.yml ${PROJECTNAME}/.github/workflows/main.yml
ls -l ${PROJECTNAME}/.github/workflows
sed -e "s/PROJECTNAME/${PROJECTNAME}/g" -i '' ${PROJECTNAME}/.github/workflows/main.yml
echo
echo "cat ${PROJECTNAME}/.github/workflows/main.yml"
echo "---------------------------------------------"
echo
cat ${PROJECTNAME}/.github/workflows/main.yml
echo
echo "Next step will fail if Github repo doesn't exist and/or SSH key not configured:"
echo
cd ${PROJECTNAME} || exit
git remote add origin git@github.com:${GITHUBUSERNAME}/${PROJECTNAME}
git push -u origin master
ng add angular-cli-ghpages
# note this creates and pushes git branch "gh-pages"
ng deploy --base-href=/${PROJECTNAME}/
echo "manually: verify settings OK for Github Pages https://github.com/${GITHUBUSERNAME}/${PROJECTNAME}/settings"
git add .
git commit -m "Build and deploy Angular sandbox to Github Pages"
git push origin master
cd - || exit
echo
echo "Check out the results:"
echo "--------------------------"
echo "Check out your Github Actions Workflows, should be running: https://github.com/${GITHUBUSERNAME}/${PROJECTNAME}/actions"
echo "Check out your Github Deployments, should be running: https://github.com/${GITHUBUSERNAME}/${PROJECTNAME}/deployments"
echo "Check out your Github Pages, will be available when Workflow and Deployment steps completed: https://${GITHUBUSERNAME}.github.io/${PROJECTNAME}/"
echo
echo "Done."