Skip to content

Commit a960030

Browse files
fix: add google analytics to create script
1 parent 882cd5e commit a960030

File tree

11 files changed

+71
-25
lines changed

11 files changed

+71
-25
lines changed

docs/environment.md

Whitespace-only changes.

docs/firebase.md

Whitespace-only changes.

docs/http-cache-tags.md

Whitespace-only changes.

docs/user-agent.md

Whitespace-only changes.

docs/window.md

Whitespace-only changes.

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"consolidate": "^0.15.1",
8181
"cookie-parser": "^1.4.3",
8282
"core-js": "^2.5.7",
83+
"date-fns": "^1.29.0",
8384
"dotenv": "^6.0.0",
8485
"express": "^4.16.3",
8586
"favicons": "^5.1.1",

src/commands/create-common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface AnswersDictionary {
2222
readonly firebaseStorageBucket?: string
2323
readonly firebaseMesssagingSenderId?: string
2424
readonly firebaseModules?: ReadonlyArray<string>
25+
readonly googleAnalyticsTrackingId?: string
26+
readonly googleSiteVerificationCode?: string
2527
}
2628

2729
export interface WorkingAnswersDictionary extends AnswersDictionary {

src/commands/create.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ command(
6363
const Q_FULL_NAME: QuestionWrapper = {
6464
question: {
6565
name: 'fullname',
66-
message: 'Application Full Name',
66+
message: 'App Full Name:',
6767
default: 'fusing-angular-demo-app'
6868
},
6969
answerHandler: (
@@ -78,9 +78,37 @@ const Q_FULL_NAME: QuestionWrapper = {
7878
const Q_SHORT_NAME = {
7979
question: {
8080
name: 'shortname',
81-
message: 'Application Short Name',
81+
message: 'App Short Name:',
8282
default: 'fusing-ng'
8383
},
84+
answerHandler: (
85+
response: QustionResponse,
86+
current: WorkingAnswersDictionary,
87+
stream: Subject<any>
88+
) => {
89+
stream.next(Q_GOOGLE_ANALYTICS_TRACKING_ID.question)
90+
}
91+
}
92+
93+
const Q_GOOGLE_ANALYTICS_TRACKING_ID = {
94+
question: {
95+
name: 'googleAnalyticsTrackingId',
96+
message: 'Google Analytics Tracking ID (Optional):'
97+
},
98+
answerHandler: (
99+
response: QustionResponse,
100+
current: WorkingAnswersDictionary,
101+
stream: Subject<any>
102+
) => {
103+
stream.next(Q_GOOGLE_SITE_VERIFICATION_CODE.question)
104+
}
105+
}
106+
107+
const Q_GOOGLE_SITE_VERIFICATION_CODE = {
108+
question: {
109+
name: 'googleSiteVerificationCode',
110+
message: 'Google Site Verification Code (Optional):'
111+
},
84112
answerHandler: (
85113
response: QustionResponse,
86114
current: WorkingAnswersDictionary,
@@ -107,21 +135,6 @@ const Q_IDE = {
107135
}
108136
}
109137

110-
// const Q_APP_TYPE = {
111-
// question: {
112-
// type: 'confirm',
113-
// name: 'isUniversalApp',
114-
// message: 'Server rendered (Angular Universal)?'
115-
// },
116-
// answerHandler: (
117-
// response: QustionResponse,
118-
// current: WorkingAnswersDictionary,
119-
// stream: Subject<any>
120-
// ) => {
121-
// stream.complete()
122-
// }
123-
// }
124-
125138
const Q_TEST_RUNNERS = {
126139
question: {
127140
type: 'list',
@@ -143,8 +156,9 @@ const QUESTION_DICT = [
143156
Q_SHORT_NAME,
144157
Q_TEST_RUNNERS,
145158
Q_IDE,
159+
Q_GOOGLE_ANALYTICS_TRACKING_ID,
160+
Q_GOOGLE_SITE_VERIFICATION_CODE,
146161
...Q_FIREBASE
147-
// Q_APP_TYPE
148162
].reduce(
149163
(acc, curr) => {
150164
return { ...acc, [curr.question.name]: curr }
@@ -319,7 +333,13 @@ function create(overwriteExisting = false) {
319333
generateCoreAngular(im.config.fullname),
320334
generateGitIgnore(path, overwriteExisting),
321335
generateTsLint(path, overwriteExisting),
322-
generateDotEnv(path, overwriteExisting, firebaseConfig),
336+
generateDotEnv(
337+
path,
338+
overwriteExisting,
339+
firebaseConfig,
340+
im.config.googleAnalyticsTrackingId,
341+
im.config.googleSiteVerificationCode
342+
),
323343
generateFngConfig(path, overwriteExisting),
324344
generateTsConfig(path, overwriteExisting),
325345
generateTsDeclartionFile(path, overwriteExisting),

src/generators/env.gen.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,29 @@ FNG_FIREBASE_MESSAGING_SENDER_ID=${config.messagingSenderId}`
1717
export default function generateDotEnv(
1818
dir: string,
1919
overwrite = false,
20-
firebaseConfig?: FirebaseConfig
20+
firebaseConfig?: FirebaseConfig,
21+
googleAnalyticsId?: string,
22+
googleSiteVerificationCode?: string
2123
) {
22-
const final = firebaseConfig
24+
const resolvedFirebase = firebaseConfig
2325
? env.replace('$FIREBASE', firebaseEnvConfigMap(firebaseConfig))
24-
: env
26+
: env.replace('$FIREBASE', '')
27+
28+
const resolvedGoogleAnalytics = googleAnalyticsId
29+
? resolvedFirebase.replace(
30+
'$GOOGLE_ANALYTICS',
31+
`FNG_GOOGLE_ANALYTICS_TRACKING_ID=${googleAnalyticsId}`
32+
)
33+
: resolvedFirebase.replace('$GOOGLE_ANALYTICS', '')
34+
35+
const resolvedGoogleSite = googleSiteVerificationCode
36+
? resolvedGoogleAnalytics.replace(
37+
'$GOOGLE_SITE_VERIFICATION',
38+
`FNG_GOOGLE_SITE_VERIFICATION_CODE=${googleSiteVerificationCode}`
39+
)
40+
: resolvedGoogleAnalytics.replace('$GOOGLE_SITE_VERIFICATION', '')
2541

2642
return overwrite
27-
? writeFile_(resolve(dir, configPath), final)
28-
: writeFileSafely_(resolve(dir, configPath), final)
43+
? writeFile_(resolve(dir, configPath), resolvedGoogleSite)
44+
: writeFileSafely_(resolve(dir, configPath), resolvedGoogleSite)
2945
}

0 commit comments

Comments
 (0)