Skip to content

Commit 0dc0012

Browse files
fix: add firebase to creation menu
1 parent 1c7af05 commit 0dc0012

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

src/commands/create.ts

+57-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ interface AnswersDictionary {
7171
interface WorkingAnswersDictionary {
7272
readonly [key: string]: any
7373
readonly fullname?: string
74+
readonly ide?: string
75+
readonly firebase?: boolean
76+
readonly firebaseModules?: ReadonlyArray<string>
7477
}
7578

7679
interface QuestionWrapper {
@@ -124,6 +127,56 @@ const Q_IDE = {
124127
default: 'Visual Studio Code',
125128
choices: ['Visual Studio Code', 'Other']
126129
},
130+
answerHandler: (
131+
response: QustionResponse,
132+
current: WorkingAnswersDictionary,
133+
stream: Subject<any>
134+
) => {
135+
stream.next(Q_INCLUDE_FIREBASE.question)
136+
}
137+
}
138+
139+
const Q_INCLUDE_FIREBASE = {
140+
question: {
141+
type: 'confirm',
142+
name: 'useFirebase',
143+
message: 'Are you using Firebase?',
144+
default: false
145+
},
146+
answerHandler: (
147+
response: QustionResponse,
148+
current: WorkingAnswersDictionary,
149+
stream: Subject<any>
150+
) => {
151+
current.useFirebase
152+
? stream.next(Q_FIREBASE_CHOICES.question)
153+
: stream.complete()
154+
}
155+
}
156+
157+
const Q_FIREBASE_CHOICES = {
158+
question: {
159+
type: 'checkbox',
160+
name: 'firebaseConfig',
161+
message: 'Which modules of Firebase to include?',
162+
choices: [
163+
{
164+
name: 'Reat Time Database (RTDB)',
165+
value: 'rtdb',
166+
checked: true
167+
},
168+
{
169+
name: 'Firestore',
170+
value: 'firestore',
171+
checked: true
172+
},
173+
{
174+
name: 'Auth',
175+
value: 'auth',
176+
checked: false
177+
}
178+
]
179+
},
127180
answerHandler: (
128181
response: QustionResponse,
129182
current: WorkingAnswersDictionary,
@@ -168,7 +221,9 @@ const QUESTION_DICT = [
168221
Q_FULL_NAME,
169222
Q_SHORT_NAME,
170223
Q_TEST_RUNNERS,
171-
Q_IDE
224+
Q_IDE,
225+
Q_INCLUDE_FIREBASE,
226+
Q_FIREBASE_CHOICES
172227
// Q_APP_TYPE
173228
].reduce(
174229
(acc, curr) => {
@@ -305,6 +360,7 @@ function create(overwriteExisting = false) {
305360
}, {})
306361
}
307362
collector.next(merged)
363+
// TODO: haneld edge case of task not existing in dict
308364
QUESTION_DICT[response.name].answerHandler(response, merged, source)
309365
},
310366
logError,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { NgModule } from '@angular/core'
2+
import { FirebaseNameOrConfigToken, FirebaseOptionsToken, AngularFireModule } from 'angularfire2'
3+
import { FIREBASE_USER_AUTH_TOKEN } from '../firebase/common/server'
4+
5+
export function firebaseAuthFactory() {
6+
return undefined
7+
}
8+
9+
export function firebaseEnvironmentFactory() {
10+
return {
11+
apiKey: "TODO: FNG_FIREBASE_API_KEY",
12+
authDomain: "TODO: FNG_FIREBASE_AUTH_DOMAIN",
13+
databaseURL: "TODO: FNG_FIREBASE_DATABASE_URL",
14+
projectId: "TODO: FNG_FIREBASE_PROJECT_ID",
15+
storageBucket: "TODO: FNG_FIREBASE_STORAGE_BUCKET",
16+
messagingSenderId: "TODO: FNG_FIREBASE_MESSAGING_SENDER_ID"
17+
}
18+
}
19+
20+
@NgModule({
21+
imports: [
22+
AngularFireModule
23+
],
24+
providers: [
25+
{ provide: FIREBASE_USER_AUTH_TOKEN, useFactory: firebaseAuthFactory },
26+
{
27+
provide: FirebaseNameOrConfigToken,
28+
useValue: 'universal-webapp'
29+
},
30+
{
31+
provide: FirebaseOptionsToken,
32+
useFactory: firebaseEnvironmentFactory
33+
}
34+
]
35+
})
36+
export class FirebaseModule { }

src/templates/core/server/server.app.ts.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import { resolve } from 'path'
44
import { ngExpressEngine } from '@nguniversal/express-engine'
55
import { AppServerModule } from './server.angular.module'
66
import { stat, createReadStream } from 'fs'
7+
import { LRU_CACHE } from 'fusing-angular-cli/.build/modules/src/modules'
8+
import * as lru from 'lru-cache'
79

810
const environment = JSON.parse(process.env.FUSING_ANGULAR || '{}')
911
const isLocalDevelopmentServer = environment.ENV === 'dev'
12+
const LRU = new lru({
13+
max: 500,
14+
maxAge: 1000 * 30
15+
})
1016

1117
// const xhr2 = require('xhr2')
12-
1318
// tslint:disable-next-line:no-object-mutation
1419
// xhr2.prototype._restrictedHeaders.cookie = false
1520

@@ -27,7 +32,14 @@ expressApp.set('etag', false)
2732
expressApp.set('view engine', 'html')
2833
expressApp.set('views', publicDir)
2934

30-
expressApp.engine('html', ngExpressEngine({ bootstrap: AppServerModule }))
35+
expressApp.engine('html', ngExpressEngine({
36+
bootstrap: AppServerModule,
37+
providers: [
38+
{
39+
provide: LRU_CACHE, useValue: LRU
40+
}
41+
]
42+
}))
3143

3244
expressApp.use('/favicon.ico', (req, res) => res.sendStatus(204)) // TODO: FAVICONS
3345

0 commit comments

Comments
 (0)