-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
222 lines (189 loc) · 10.6 KB
/
init.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
####################
# create workspace #
####################
if [[ "$OSTYPE" == "darwin"* ]]; then
SED="sed -i '' -e"
else
SED="sed -i -e"
fi
winpty ng.cmd new --create-application=false WORKSPACE_NAME
cd WORKSPACE_NAME
###################################################
# add an Angular application to Angular workspace #
###################################################
winpty ng.cmd g application --inline-style --inline-template --routing --style=scss APP_NAME
###########################################
# Add an Angular lib to Angular workspace #
###########################################
# This lib is generated by `openapitools` from the OpenAPI spec file produced by APP_NAME REST API (with `mvn clean verify -Popenapi`)
winpty ng.cmd g library @c4-soft/API_LIB_NAME
npm i -D @openapitools/openapi-generator-cli
$SED 's/"ng": "ng",/"ng": "ng",\
"postinstall": "npm run API_LIB_NAME:install",\
"API_LIB_NAME:generate": "npx openapi-generator-cli generate -i ..\/API_SPEC_FILE -g typescript-angular --type-mappings AnyType=any --additional-properties=serviceSuffix=Api,npmName=@c4-soft\/API_LIB_NAME,npmVersion=0.0.1,enumPropertyNaming=camelCase,supportsES6=true,withInterfaces=true --remove-operation-id-prefix -o projects\/c4-soft\/API_LIB_NAME",\
"API_LIB_NAME:build": "npm run API_LIB_NAME:generate \&\& npm run ng -- build @c4-soft\/API_LIB_NAME --configuration production",\
"API_LIB_NAME:install": "cd projects\/c4-soft\/API_LIB_NAME \&\& npm i \&\& cd ..\/..\/.. \&\& npm run API_LIB_NAME:build",/' ./package.json
cp ../angular-ionic-workspace-template/openapitools.json ./
$SED 's/"entryFile": "src\/public-api.ts"/"entryFile": "index.ts"/' ./projects/c4-soft/API_LIB_NAME/ng-package.json
cp ../angular-ionic-workspace-template/.openapi-generator-ignore ./projects/c4-soft/API_LIB_NAME/.openapi-generator-ignore
cp ../angular-ionic-workspace-template/.gitignore ./projects/c4-soft/API_LIB_NAME/.gitignore
cp ../angular-ionic-workspace-template/package.json ./projects/c4-soft/API_LIB_NAME/package.json
$SED 's/"$schema": ".\/node_modules\/ng-packagr\/ng-package.schema.json"/"$schema": ".\/node_modules\/ng-packagr\/ng-package.schema.json",\
"dest": "..\/..\/..\/dist\/c4-soft\/API_LIB_NAME"/' ./projects/c4-soft/API_LIB_NAME/ng-package.json
cp ../angular-ionic-workspace-template/tsconfig.lib.json ./projects/c4-soft/API_LIB_NAME/tsconfig.lib.json
cp ../angular-ionic-workspace-template/tsconfig.lib.prod.json ./projects/c4-soft/API_LIB_NAME/tsconfig.lib.prod.json
npm i
#################################################
# Make Angular application an Ionic-Angular app #
#################################################
# dependencies
npm i -D @ionic/angular-toolkit
cd "./projects/APP_NAME/"
npm init --yes
npm i @capacitor/core @capacitor/app @capacitor/haptics @capacitor/keyboard @capacitor/status-bar @ionic/angular ionicons @awesome-cordova-plugins/core @ionic/storage-angular ionic-plugin-deeplinks @awesome-cordova-plugins/deeplinks
npm i -D @capacitor/cli
cd ../..
# add ionicons to app assets
$SED 's/"projects\/APP_NAME\/src\/assets"/"projects\/APP_NAME\/src\/assets",\
{ "glob": "**\/*.svg", "input": "projects\/APP_NAME\/node_modules\/ionicons\/dist\/ionicons\/svg", "output": ".\/svg" }/' ./angular.json
# add Ionic theme style sheet
cp ../angular-ionic-workspace-template/styles.scss "./projects/APP_NAME/src/styles.scss"
# replace index.html
cp ../angular-ionic-workspace-template/index.html ./projects/APP_NAME/src/index.html
# add Ionic imports & providers in app module
echo -e "import { IonicModule, IonicRouteStrategy } from '@ionic/angular';\n\
import { IonicStorageModule } from '@ionic/storage-angular';\n\
import { Deeplinks } from '@awesome-cordova-plugins/deeplinks/ngx';\n\
import { RouteReuseStrategy } from '@angular/router';\n\
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';\n\
$(cat ./projects/APP_NAME/src/app/app.module.ts)" > ./projects/APP_NAME/src/app/app.module.ts
$SED 's/BrowserModule,/BrowserModule,\
HttpClientModule,\
IonicModule.forRoot(),\
IonicStorageModule.forRoot(),/' "./projects/APP_NAME/src/app/app.module.ts"
$SED 's/providers: \[\]/providers: \[\
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },\
Deeplinks,\
]/' ./projects/APP_NAME/src/app/app.module.ts
winpty ng.cmd build APP_NAME
# init Ionic and Capacitor tooling
ionic init --multi-app
cd ./projects/APP_NAME/
winpty npx.cmd cap init APP_NAME CAPACITOR_ID --web-dir ../../dist/APP_NAME
ionic init --type=angular APP_NAME --default --project=APP_NAME
ionic capacitor add android
cd ../..
rm ./capacitor.config.ts
# add useful npm targets
$SED 's/"test": "echo \\"Error: no test specified\\" \&\& exit 1"/"test": "ionic test",\
"build": "ionic build",\
"serve": "ionic serve",\
"android": "ionic capacitor run android -l"/' ./projects/APP_NAME/package.json
$SED 's/"start": "ng serve"/"APP_NAME:serve": "cd projects\/APP_NAME \&\& npm run serve",\
"APP_NAME:android": "cd projects\/APP_NAME \&\& npm run android"/' ./package.json
$SED 's/"build": "ng build"/"APP_NAME:build": "cd projects\/APP_NAME \&\& npm run build"/' ./package.json
$SED 's/"test": "ng test"/"APP_NAME:test": "cd projects\/APP_NAME \&\& npm run test"/' ./package.json
$SED '/"watch":/d' ./package.json
#####################################
# Add Material for Angular and OIDC #
#####################################
winpty ng.cmd add @angular/material --project=APP_NAME
npm i angular-auth-oidc-client @angular/flex-layout @angular/cdk
# add OIDC conf to environment files
echo -e "import { LogLevel, PassedInitialConfig } from 'angular-auth-oidc-client';\n\
\n\
export const authConfig: PassedInitialConfig = {\n\
config: {\n\
authority: 'https://dev-ch4mpy.eu.auth0.com',\n\
redirectUrl: window.location.origin,\n\
postLogoutRedirectUri: window.location.origin,\n\
clientId: 'lRHwmwQr3bhkKZeezYD8UAaGna3KSnBB',\n\
scope: 'openid profile email offline_access solutions:manage',\n\
responseType: 'code',\n\
silentRenew: true,\n\
useRefreshToken: true,\n\
logLevel: LogLevel.Debug,\n\
}\n\
};\n\
\n\
export const environment = {\n\
production: true,\n\
authConfig,\n\
};" > ./projects/APP_NAME/src/environments/environment.ts
echo -e "import { LogLevel, PassedInitialConfig } from 'angular-auth-oidc-client';\n\
\n\
export const authConfig: PassedInitialConfig = {\n\
config: {\n\
authority: 'https://dev-ch4mpy.eu.auth0.com',\n\
redirectUrl: window.location.origin,\n\
postLogoutRedirectUri: window.location.origin,\n\
clientId: 'lRHwmwQr3bhkKZeezYD8UAaGna3KSnBB',\n\
scope: 'openid profile email offline_access solutions:manage',\n\
responseType: 'code',\n\
silentRenew: true,\n\
useRefreshToken: true,\n\
logLevel: LogLevel.Debug,\n\
}\n\
};\n\
\n\
export const environment = {\n\
production: true,\n\
authConfig,\n\
};" > "./projects/APP_NAME/src/environments/environment.prod.ts"
# import OAuthModule in app module
echo -e "import { AuthModule } from 'angular-auth-oidc-client';\n\
import { MatDialogModule } from '@angular/material/dialog';\n\
import { environment } from '../environments/environment';\n\
$(cat ./projects/APP_NAME/src/app/app.module.ts)" > "./projects/APP_NAME/src/app/app.module.ts"
$SED 's/imports: \[/imports: \[\
AuthModule.forRoot(environment.authConfig),\
MatDialogModule,/' "./projects/APP_NAME/src/app/app.module.ts"
##################################################################################################
# Replace Angular minimal app with an Ionic app composed of a menu in a split-pane and two pages #
##################################################################################################
winpty ng.cmd g c --project=APP_NAME --type=dialog --flat -s -t NetworkError
# handle http errors
ng g c --type=dialog --flat -s -t NetworkError
cp ../../../../../angular-ionic-workspace-template/network-error.dialog.ts "./network-error.dialog.ts"
cp ../../../../../angular-ionic-workspace-template/error-http-interceptor.ts "./error-http-interceptor.ts"
cp ../../../../../angular-ionic-workspace-template/user.service.ts "./user.service.ts"
echo -e "import { ErrorHttpInterceptor } from './error-http-interceptor';\n\
$(cat ./app.module.ts)" > "./app.module.ts"
$SED 's/providers: \[/providers: \[\
{\
provide: HTTP_INTERCEPTORS,\
useClass: ErrorHttpInterceptor,\
multi: true,\
},\' "./app.module.ts"
# copy default content
cp ../../../../../angular-ionic-workspace-template/loading.service.ts "./loading.service.ts"
cp ../../../../../angular-ionic-workspace-template/has-role.guard.ts "./has-role.guard.ts"
ng g c --type=screen --flat -s -t home
cp ../../../../../angular-ionic-workspace-template/home.screen.ts "./home.screen.ts"
ng g module --routing user-account
echo -e "import { FormsModule, ReactiveFormsModule } from '@angular/forms';\n\
import { IonicModule } from '@ionic/angular';\n\
$(cat ./user-account/user-account.module.ts)" > "./user-account/user-account.module.ts"
$SED 's/CommonModule,/CommonModule,\
FormsModule,\
ReactiveFormsModule,\
IonicModule,/' ./projects/APP_NAME/src/app/settings/settings.module.ts
winpty ng.cmd g c --project=APP_NAME --type=screen --flat -s -t -m=settings settings/Settings
cp ../angular-ionic-workspace-template/settings.screen.ts ./projects/APP_NAME/src/app/settings/settings.screen.ts
cp ../angular-ionic-workspace-template/settings-routing.module.ts ./projects/APP_NAME/src/app/settings/settings-routing.module.ts
winpty ng.cmd g module --project=APP_NAME --routing user-account
echo -e "import { FormsModule, ReactiveFormsModule } from '@angular/forms';\n\
import { IonicModule } from '@ionic/angular';\n\
$(cat ./projects/APP_NAME/src/app/user-account/user-account.module.ts)" > ./projects/APP_NAME/src/app/user-account/user-account.module.ts
$SED 's/CommonModule,/CommonModule,\
FormsModule,\
ReactiveFormsModule,\
IonicModule,/' ./projects/APP_NAME/src/app/user-account/user-account.module.ts
winpty ng.cmd g c --project=APP_NAME --type=screen --flat -s -t -m=user-account user-account/UserAccount
cp ../angular-ionic-workspace-template/user-account.screen.ts ./projects/APP_NAME/src/app/user-account/user-account.screen.ts
cp ../angular-ionic-workspace-template/user-account-routing.module.ts ./projects/APP_NAME/src/app/user-account/user-account-routing.module.ts
cp ../angular-ionic-workspace-template/app-routing.module.ts ./projects/APP_NAME/src/app/app-routing.module.ts
cp ../angular-ionic-workspace-template/app.component.ts ./projects/APP_NAME/src/app/app.component.ts
cd ../../../../
$SED 's/\/node_modules/**\/node_modules/' ./.gitignore
git add ionic.config.json openapitools.json projects/ .gitignore angular.json package-lock.json package.json tsconfig.json