Skip to content

Commit

Permalink
build: zoneless
Browse files Browse the repository at this point in the history
  • Loading branch information
Robby Rabbitman committed Jan 24, 2024
1 parent 12cca35 commit bb3171f
Show file tree
Hide file tree
Showing 21 changed files with 625 additions and 233 deletions.
1 change: 0 additions & 1 deletion apps/web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"outputPath": "dist/apps/web",
"index": "apps/web/src/index.html",
"browser": "apps/web/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/web/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
Expand Down
52 changes: 5 additions & 47 deletions apps/web/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,27 @@
import { provideHttpClient } from '@angular/common/http';
import {
ApplicationConfig,
importProvidersFrom,
makeEnvironmentProviders,
ɵprovideZonelessChangeDetection,
} from '@angular/core';
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { connectAuthEmulator, getAuth, provideAuth } from '@angular/fire/auth';
import {
connectFirestoreEmulator,
getFirestore,
provideFirestore,
} from '@angular/fire/firestore';

import { provideRouter } from '@angular/router';
import { provideAuthData } from '@cv/auth/data';
import { provideCommonData } from '@cv/common/data';
import { provideFirebase } from '@cv/common/util';
import { provideCvData } from '@cv/data';
import { provideI18nData } from '@cv/i18n/data';
import { environment } from '../environments/environment';
import { appRoutes } from './app.routes';

function provideFirebase() {
return makeEnvironmentProviders([
importProvidersFrom([
provideFirebaseApp(() => initializeApp(environment.firebase)),
// auth
provideAuth(() => {
const auth = getAuth();
const emulators = environment.firebase.emulators;

if (emulators?.auth) {
connectAuthEmulator(
auth,
`http://${emulators.auth.host}:${emulators.auth.port}`,
);
}

return auth;
}),
// firestore
provideFirestore(() => {
const firestore = getFirestore();
const emulators = environment.firebase.emulators;

if (emulators?.firestore) {
connectFirestoreEmulator(
firestore,
emulators.firestore.host,
emulators.firestore.port,
);
}

return firestore;
}),
]),
]);
}

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideFirebase(),
provideFirebase(environment.firebase),
provideCommonData(),
provideCvData(),
provideAuthData(),
provideI18nData(),
provideHttpClient(),
ɵprovideZonelessChangeDetection(),
],
};
16 changes: 9 additions & 7 deletions apps/web/src/environments/environment.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Environment } from './type';
export const environment: Environment = {
stage: 'dev',
firebase: {
apiKey: 'AIzaSyBfjIK2S8Y_T7lqswoad2kE-qdV5PdlLrg',
authDomain: 'cv-dev-f08b0.firebaseapp.com',
projectId: 'cv-dev-f08b0',
storageBucket: 'cv-dev-f08b0.appspot.com',
messagingSenderId: '730268236033',
appId: '1:730268236033:web:9213d549c0d61033a94300',
measurementId: 'G-VJN9EZWX4H',
options: {
apiKey: 'AIzaSyBfjIK2S8Y_T7lqswoad2kE-qdV5PdlLrg',
authDomain: 'cv-dev-f08b0.firebaseapp.com',
projectId: 'cv-dev-f08b0',
storageBucket: 'cv-dev-f08b0.appspot.com',
messagingSenderId: '730268236033',
appId: '1:730268236033:web:9213d549c0d61033a94300',
measurementId: 'G-VJN9EZWX4H',
},
},
};
22 changes: 12 additions & 10 deletions apps/web/src/environments/environment.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { Environment } from './type';
export const environment: Environment = {
stage: 'local',
firebase: {
emulators: {
auth: { host: 'localhost', port: 9099 },
firestore: { host: 'localhost', port: 8080 },
features: {
auth: { emulators: { host: 'localhost', port: 9099 } },
firestore: { emulators: { host: 'localhost', port: 8080 } },
},
options: {
apiKey: 'local',
authDomain: 'local',
projectId: 'local',
storageBucket: 'local',
messagingSenderId: 'local',
appId: 'local',
measurementId: 'local',
},
apiKey: 'local',
authDomain: 'local',
projectId: 'local',
storageBucket: 'local',
messagingSenderId: 'local',
appId: 'local',
measurementId: 'local',
},
};
16 changes: 9 additions & 7 deletions apps/web/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Environment } from './type';
export const environment: Environment = {
stage: 'prod',
firebase: {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
measurementId: '',
options: {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
measurementId: '',
},
},
};
12 changes: 2 additions & 10 deletions apps/web/src/environments/type.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { FirebaseOptions } from '@angular/fire/app';
import { FirebaseConfig } from '@cv/common/util';

export interface Environment {
stage: 'prod' | 'dev' | 'local';
firebase: FirebaseOptions & {
emulators?: Record<
'firestore' | 'auth',
{
host: string;
port: number;
}
>;
};
firebase: FirebaseConfig;
}
5 changes: 3 additions & 2 deletions libs/auth/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"dependencies": {
"@ngrx/signals": "17.1.0",
"@angular/core": "17.1.0",
"@angular/fire": "17.0.1",
"rxjs": "7.8.0",
"tslib": "2.3.0"
"tslib": "2.3.0",
"@cv/common/util": "*",
"firebase": "10.7.2"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
19 changes: 10 additions & 9 deletions libs/auth/data/src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Injectable, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { Injectable, signal } from '@angular/core';
import { firebaseAuth } from '@cv/common/util';
import {
Auth as FirebaseAuth,
GoogleAuthProvider,
authState,
getRedirectResult,
onAuthStateChanged,
signInWithRedirect,
} from '@angular/fire/auth';
} from 'firebase/auth';

@Injectable()
export class Auth {
protected auth = inject(FirebaseAuth);
protected auth = firebaseAuth();

constructor() {
onAuthStateChanged(this.auth, (user) => this.user.set(user));
}

/** The user if logged in, else null. */
user = toSignal(authState(this.auth), {
initialValue: this.auth.currentUser,
});
user = signal(this.auth.currentUser);

/** Signs out the current user. */
async signOut() {
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/data/src/lib/user.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const UserStore = signalStore(
signIn: rxMethod<void>(pipe(exhaustMap(() => auth.signIn()))),

/** The user if logged in, else null. */
value: auth.user,
value: auth.user.asReadonly(),
};
}),
);
22 changes: 1 addition & 21 deletions libs/common/smart/src/lib/theme-select.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ThemeSelect } from './theme-select';

describe('ThemeSelect', () => {
let component: ThemeSelect;
let fixture: ComponentFixture<ThemeSelect>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ThemeSelect],
}).compileComponents();

fixture = TestBed.createComponent(ThemeSelect);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
test.todo('ThemeSelect');
3 changes: 2 additions & 1 deletion libs/common/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"uuid": "9.0.1",
"tslib": "2.3.0",
"@angular/common": "17.1.0",
"@cv/common/types": "*"
"@cv/common/types": "*",
"firebase": "10.7.2"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
1 change: 1 addition & 0 deletions libs/common/util/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './lib/document';
export * from './lib/firebase';
export * from './lib/signal';
export * from './lib/theme';
export * from './lib/uuid';
68 changes: 68 additions & 0 deletions libs/common/util/src/lib/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { FirebaseApp, FirebaseOptions, initializeApp } from 'firebase/app';
import { Auth, connectAuthEmulator, getAuth } from 'firebase/auth';
import {
Firestore,
connectFirestoreEmulator,
getFirestore,
} from 'firebase/firestore';
import { createNoopInjectionToken } from 'ngxtension/create-injection-token';

export const [firebaseApp, provideFirebaseApp] =
createNoopInjectionToken<FirebaseApp>('[Firebase] App');

export const [firestore, provideFirestore] =
createNoopInjectionToken<Firestore>('[Firebase] Firestore');

export const [firebaseAuth, provideFirebaseAuth] =
createNoopInjectionToken<Auth>('[Firebase] Auth');

export interface FirebaseConfig {
options: FirebaseOptions;
features?: Partial<{
auth: {
emulators?: { host: string; port: number };
};
firestore: {
emulators?: { host: string; port: number };
};
}>;
}

export function provideFirebase({ options, features }: FirebaseConfig) {
const app = initializeApp(options);
const providers = [provideFirebaseApp(app)];

for (const feature in features) {
switch (feature) {
case 'auth': {
const auth = getAuth(app);
providers.push(provideFirebaseAuth(auth));

const emulators = features[feature]?.emulators;

if (emulators) {
connectAuthEmulator(
auth,
`http://${emulators.host}:${emulators.port}`,
);
}

break;
}
case 'firestore': {
const firestore = getFirestore(app);
providers.push(provideFirestore(firestore));

const emulators = features[feature]?.emulators;

if (emulators) {
connectFirestoreEmulator(firestore, emulators.host, emulators.port);
}

break;
}
}
}

return providers;
}
4 changes: 2 additions & 2 deletions libs/cv/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"@angular/core": "17.1.0",
"rxjs": "7.8.0",
"tslib": "2.3.0",
"@angular/fire": "17.0.1",
"@ngrx/operators": "17.1.0",
"@ngrx/signals": "17.1.0",
"@cv/common/types": "*",
"@cv/common/util": "*",
"@cv/types": "*",
"@cv/util": "*",
"@cv/auth/data": "*",
"ngxtension": "1.12.0"
"ngxtension": "1.12.0",
"firebase": "10.7.2"
},
"sideEffects": false
}
15 changes: 7 additions & 8 deletions libs/cv/data/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Injectable, inject } from '@angular/core';
import { UserStore } from '@cv/auth/data';
import { UUID } from '@cv/common/types';
import { firestore, uuid } from '@cv/common/util';
import { BlockPrototype, Cv, Paragraph, Section, TextField } from '@cv/types';
import { createBlock } from '@cv/util';
import {
CollectionReference,
DocumentData,
Firestore,
collection,
doc,
getDoc,
Expand All @@ -11,12 +15,7 @@ import {
serverTimestamp,
setDoc,
where,
} from '@angular/fire/firestore';
import { UserStore } from '@cv/auth/data';
import { UUID } from '@cv/common/types';
import { uuid } from '@cv/common/util';
import { BlockPrototype, Cv, Paragraph, Section, TextField } from '@cv/types';
import { createBlock } from '@cv/util';
} from 'firebase/firestore';

type InferCollectionModel<C> =
C extends CollectionReference<DocumentData, infer T> ? keyof T : never;
Expand Down Expand Up @@ -90,7 +89,7 @@ export class Api {
protected BLOCK_PROTOTYPES = 'blockPrototypes';
protected CV_BLOCK_PROTOTYPES = 'cvBlockPrototypes';

protected firestore = inject(Firestore);
protected firestore = firestore();
protected user = inject(UserStore);

protected cv = collection(this.firestore, this.CV) as unknown as CvCollection;
Expand Down
3 changes: 2 additions & 1 deletion libs/cv/util/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@cv/util",
"version": "0.0.1",
"dependencies": {
"peerDependencies": {
"@angular/core": "17.1.0",
"tslib": "2.3.0",
"@cv/common/types": "*",
"@cv/types": "*",
Expand Down
Loading

0 comments on commit bb3171f

Please sign in to comment.