Skip to content

Commit 0413d9a

Browse files
committed
chore(build): authentication build
1 parent a431037 commit 0413d9a

File tree

11 files changed

+130
-52
lines changed

11 files changed

+130
-52
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ typings/
66
npm-debug.log
77
.idea/
88
.vscode/settings.json
9-
angularfire2-*.tgz
9+
angularfire2-*.tgz
10+
*.ngfactory.ts
11+
*.ngsummary.json

src/auth/auth.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule, NgZone } from '@angular/core';
22
import * as firebase from 'firebase/app';
33
import 'firebase/auth';
4-
import { FirebaseApp, AngularFireModule } from '../core';
4+
import { FirebaseApp, AngularFireModule } from 'angularfire2';
55
import { AngularFireAuth } from './auth';
66

77
export function _getAngularFireAuth(app: FirebaseApp) {

src/auth/auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as firebase from 'firebase/app';
2-
import * as utils from '../utils';
32
import 'firebase/auth';
43
import { Injectable, NgZone } from '@angular/core';
5-
import { Auth } from '../interfaces';
64
import { Observable } from 'rxjs/Observable';
75
import { Observer } from 'rxjs/Observer';
86
import { observeOn } from 'rxjs/operator/observeOn';
9-
import { FirebaseApp } from '../core';
7+
import { FirebaseApp, ZoneScheduler } from 'angularfire2';
8+
9+
export type Auth = firebase.auth.Auth;
1010

1111
@Injectable()
1212
export class AngularFireAuth {
@@ -47,7 +47,7 @@ export function FirebaseAuthStateObservable(app: FirebaseApp): Observable<fireba
4747
() => observer.complete()
4848
);
4949
});
50-
return observeOn.call(authState, new utils.ZoneScheduler(Zone.current));
50+
return observeOn.call(authState, new ZoneScheduler(Zone.current));
5151
}
5252

5353
/**
@@ -63,5 +63,5 @@ export function FirebaseIdTokenObservable(app: FirebaseApp): Observable<firebase
6363
() => observer.complete()
6464
)
6565
});
66-
return observeOn.call(idToken, new utils.ZoneScheduler(Zone.current));
66+
return observeOn.call(idToken, new ZoneScheduler(Zone.current));
6767
}

src/auth/package.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
{ "main": "../bundles/angularfire2.umd.js" }
1+
{
2+
"name": "angularfire2/auth",
3+
"version": "ANGULARFIRE2_VERSION",
4+
"description": "The auth module",
5+
"main": "../bundles/auth.umd.js",
6+
"module": "index.js",
7+
"es2015": "./es2015/index.js",
8+
"keywords": [
9+
"angular",
10+
"firebase",
11+
"rxjs"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/angular/angularfire2.git"
16+
},
17+
"author": "angular,firebase",
18+
"license": "MIT",
19+
"peerDependencies": {
20+
"angularfire2": "ANGULARFIRE2_VERSION",
21+
"@angular/common": "ANGULAR_VERSION",
22+
"@angular/core": "ANGULAR_VERSION",
23+
"@angular/platform-browser": "ANGULAR_VERSION",
24+
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
25+
"firebase": "FIREBASE_VERSION",
26+
"rxjs": "RXJS_VERSION",
27+
"zone.js": "ZONEJS_VERSION"
28+
},
29+
"typings": "index.d.ts"
30+
}

src/auth/tsconfig-build.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
{
22
"compilerOptions": {
3+
"baseUrl": ".",
34
"experimentalDecorators": true,
45
"emitDecoratorMetadata": true,
56
"module": "es2015",
67
"target": "es2015",
78
"noImplicitAny": false,
8-
"outDir": "../../dist/packages/auth",
9+
"outDir": "../../dist/packages-dist/auth/es2015",
910
"rootDir": ".",
1011
"sourceMap": true,
1112
"inlineSources": true,
12-
"declaration": true,
13+
"declaration": false,
1314
"removeComments": true,
1415
"strictNullChecks": true,
1516
"lib": [
1617
"es2015",
1718
"dom"
1819
],
1920
"skipLibCheck": true,
20-
"moduleResolution": "node"
21+
"moduleResolution": "node",
22+
"paths": {
23+
"angularfire2": ["../../dist/packages-dist"]
24+
}
2125
},
2226
"files": [
2327
"index.ts",
2428
"../../node_modules/zone.js/dist/zone.js.d.ts"
2529
],
2630
"angularCompilerOptions": {
2731
"skipTemplateCodegen": true,
28-
"strictMetadataEmit": true
32+
"strictMetadataEmit": true,
33+
"enableSummariesForJit": false
2934
}
3035
}
36+

src/auth/tsconfig-esm.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"extends": "tsconfig-build.json",
2+
"extends": "./tsconfig-build.json",
33
"compilerOptions": {
44
"target": "es5",
5-
"outDir": "../../dist/packages-dist/auth"
5+
"outDir": "../../dist/packages-dist/auth",
6+
"declaration": true
67
}
78
}

src/core/angularfire2.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ export class AngularFireModule {
3434
}
3535
}
3636

37+
import { Subscription } from 'rxjs/Subscription';
38+
import { Scheduler } from 'rxjs/Scheduler';
39+
import { queue } from 'rxjs/scheduler/queue';
40+
41+
/**
42+
* TODO: remove this scheduler once Rx has a more robust story for working
43+
* with zones.
44+
*/
45+
export class ZoneScheduler {
46+
constructor(public zone: Zone) {}
47+
48+
schedule(...args): Subscription {
49+
return <Subscription>this.zone.run(() => queue.schedule.apply(queue, args));
50+
}
51+
}
52+
3753
export { FirebaseApp, FirebaseAppName, FirebaseAppConfigToken };

src/core/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2",
3-
"version": "4.0.0-rc.1",
3+
"version": "ANGULARFIRE2_VERSION",
44
"description": "The core module",
55
"main": "./bundles/core.umd.js",
66
"module": "index.js",
@@ -17,13 +17,13 @@
1717
"author": "angular,firebase",
1818
"license": "MIT",
1919
"peerDependencies": {
20-
"@angular/common": "^4.0.0",
21-
"@angular/core": "^4.0.0",
22-
"@angular/platform-browser": "^4.0.0",
23-
"@angular/platform-browser-dynamic": "^4.0.0",
24-
"firebase": "^4.0.0",
25-
"rxjs": "^5.0.1",
26-
"zone.js": "^0.8.0"
20+
"@angular/common": "ANGULAR_VERSION",
21+
"@angular/core": "ANGULAR_VERSION",
22+
"@angular/platform-browser": "ANGULAR_VERSION",
23+
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
24+
"firebase": "FIREBASE_VERSION",
25+
"rxjs": "RXJS_VERSION",
26+
"zone.js": "ZONEJS_VERSION"
2727
},
2828
"typings": "index.d.ts"
2929
}

src/interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ export type DatabaseReference = firebase.database.Reference;
8686
export type DatabaseQuery = firebase.database.Query;
8787
export type QueryReference = DatabaseReference | DatabaseQuery;
8888
export type PathReference = QueryReference | string;
89-
export type Auth = firebase.auth.Auth;

src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,3 @@ export function getRef(app: FirebaseApp, pathRef: PathReference): DatabaseRefere
122122
}
123123
return app.database().ref(path);
124124
}
125-
126-
/**
127-
* TODO: remove this scheduler once Rx has a more robust story for working
128-
* with zones.
129-
*/
130-
export class ZoneScheduler {
131-
constructor(public zone: Zone) {}
132-
133-
schedule(...args): Subscription {
134-
return <Subscription>this.zone.run(() => queue.schedule.apply(queue, args));
135-
}
136-
}

tools/build.js

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
const { rollup } = require('rollup');
22
const { spawn } = require('child_process');
33
const { Observable } = require('rxjs');
4-
const { copy, rename, readdirSync } = require('fs-extra');
4+
const { copy } = require('fs-extra');
55

6+
// Rollup globals
7+
const GLOBALS = {
8+
'rxjs/Observable': 'Rx',
9+
'rxjs/Subject': 'Rx',
10+
'rxjs/Observer': 'Rx',
11+
'rxjs/Subscription': 'Rx',
12+
'rxjs/observable/merge': 'Rx.Observable',
13+
'rxjs/operator/share': 'Rx.Observable.prototype',
14+
'rxjs/operator/observeOn': 'Rx.Observable.prototype',
15+
'rxjs/operator': 'Rx.Observable.prototype',
16+
'@angular/core': 'ng.core',
17+
'@angular/compiler': 'ng.compiler',
18+
'@angular/platform-browser': 'ng.platformBrowser',
19+
'firebase/auth': 'firebase',
20+
'firebase/app': 'firebase',
21+
'firebase/database': 'firebase',
22+
'rxjs/scheduler/queue': 'Rx.Scheduler',
23+
'@angular/core/testing': 'ng.core.testing',
24+
'angularfire2': 'angularfire2'
25+
};
26+
27+
// constants for running typescript commands
28+
const TSC = 'node_modules/.bin/tsc';
29+
const NGC = 'node_modules/.bin/ngc';
30+
const TSC_ARGS = (name, config = 'build') => [`-p`, `${process.cwd()}/src/${name}/tsconfig-${config}.json`];
31+
32+
/**
33+
* Create an Observable of a spawned child process.
34+
* @param {string} command
35+
* @param {string[]} args
36+
*/
637
function spawnObservable(command, args) {
738
return Observable.create(observer => {
839
const cmd = spawn(command, args);
@@ -13,7 +44,7 @@ function spawnObservable(command, args) {
1344
});
1445
}
1546

16-
function createUmd(name) {
47+
function createUmd(name, globals) {
1748
// core module is angularfire2 the rest are angularfire2.feature
1849
const moduleName = name === 'core' ? 'angularfire2' : `angularfire2.${name}`;
1950
// core is at the root and the rest are in their own folders
@@ -23,11 +54,15 @@ function createUmd(name) {
2354
.then(bundle => {
2455
const result = bundle.generate({
2556
format: 'umd',
57+
external: Object.keys(globals),
58+
globals,
2659
moduleName
2760
});
2861
return bundle.write({
2962
format: 'umd',
30-
dest: `${process.cwd()}/dist/bundles/${name}.umd.js`,
63+
dest: `${process.cwd()}/dist/packages-dist/bundles/${name}.umd.js`,
64+
external: Object.keys(globals),
65+
globals,
3166
moduleName
3267
});
3368
});
@@ -55,23 +90,25 @@ function copyPackage(moduleName) {
5590
return copy(getSrcPackageFile(moduleName), getDestPackageFile(moduleName));
5691
}
5792

58-
// constants for running typescript commands
59-
const TSC = 'node_modules/.bin/tsc';
60-
const NGC = 'node_modules/.bin/ngc';
61-
const TSC_ARGS = (name, config = 'build') => [`-p`, `${process.cwd()}/src/${name}/tsconfig-${config}.json`];
62-
63-
function buildModule(name) {
64-
// Run tsc on module (TS -> ES2015)
65-
const es2015$ = spawnObservable(TSC, TSC_ARGS(name));
66-
const esm$ = spawnObservable(TSC, TSC_ARGS(name, 'esm'));
93+
function buildModule(name, globals) {
94+
const es2015$ = spawnObservable(NGC, TSC_ARGS(name));
95+
const esm$ = spawnObservable(NGC, TSC_ARGS(name, 'esm'));
6796
return Observable
6897
.forkJoin(es2015$, esm$)
69-
.mergeMap(() => Observable.from(createUmd(name)))
70-
.mergeMap(() => Observable.from(copyPackage(name)));
98+
.switchMap(() => Observable.from(createUmd(name, globals)))
99+
.switchMap(() => Observable.from(copyPackage(name)));
100+
}
101+
102+
function buildLibrary(globals) {
103+
const core$ = buildModule('core', globals);
104+
const auth$ = buildModule('auth', globals);
105+
return Observable
106+
.forkJoin(core$)
107+
.switchMapTo(auth$);
71108
}
72109

73-
buildModule('core').subscribe(
74-
data => { console.log(data) },
75-
err => { console.log(err) },
110+
const $lib = buildLibrary(GLOBALS).subscribe(
111+
data => { console.log('data', data) },
112+
err => { console.log('err', err) },
76113
() => { console.log('complete') }
77114
);

0 commit comments

Comments
 (0)