Skip to content

Commit

Permalink
chore(lint): Clean up deploy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
NothingEverHappens committed Apr 28, 2020
1 parent a9eec3d commit 7cf0804
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/firestore/collection/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AngularFirestoreDocument } from '../document/document';
import { AngularFirestore } from '../firestore';

export function validateEventsArray(events?: DocumentChangeType[]) {
if (!events || events!.length === 0) {
if (!events || events.length === 0) {
events = ['added', 'removed', 'modified'];
}
return events;
Expand Down Expand Up @@ -98,6 +98,7 @@ export class AngularFirestoreCollection<T= DocumentData> {
* provided `idField` property name.
*/
valueChanges(): Observable<T[]>;
// tslint:disable-next-line:unified-signatures
valueChanges({}): Observable<T[]>;
valueChanges<K extends string>(options: {idField: K}): Observable<(T & { [T in K]: string })[]>;
valueChanges<K extends string>(options: {idField?: K} = {}): Observable<T[]> {
Expand All @@ -106,7 +107,7 @@ export class AngularFirestoreCollection<T= DocumentData> {
map(actions => actions.payload.docs.map(a => {
if (options.idField) {
return {
...a.data() as Object,
...a.data() as {},
...{ [options.idField]: a.id }
} as T & { [T in K]: string };
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/firestore/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class AngularFirestore {
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string|FirebaseAppConfig|null|undefined,
@Optional() @Inject(ENABLE_PERSISTENCE) shouldEnablePersistence: boolean|null,
@Optional() @Inject(SETTINGS) settings: Settings|null,
// tslint:disable-next-line:ban-types
@Inject(PLATFORM_ID) platformId: Object,
zone: NgZone,
@Optional() @Inject(PERSISTENCE_SETTINGS) persistenceSettings: PersistenceSettings|null,
Expand Down Expand Up @@ -149,8 +150,7 @@ export class AngularFirestore {
* CollectionReference and an optional query function to narrow the result
* set.
*/
collection<T>(path: string, queryFn?: QueryFn): AngularFirestoreCollection<T>;
collection<T>(ref: CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T>;
collection<T>(path: string| CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T>;
collection<T>(pathOrRef: string | CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T> {
let collectionRef: CollectionReference;
if (typeof pathOrRef === 'string') {
Expand Down
20 changes: 10 additions & 10 deletions src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export const DEFAULTS = new InjectionToken<ConfigTemplate>('angularfire2.remoteC

export interface AngularFireRemoteConfig extends ɵPromiseProxy<remoteConfig.RemoteConfig> {
}
// TODO look into the types here, I don't like the anys
const proxyAll = (observable: Observable<Parameter[]>, as: 'numbers' | 'booleans' | 'strings') => new Proxy(
observable.pipe(mapToObject(as as any)), {
get: (self, name: string) => self[name] || observable.pipe(
map(all => all.find(p => p.key === name)),
map(param => param ? param[AS_TO_FN[as]]() : STATIC_VALUES[as]),
distinctUntilChanged()
)
}
) as any;

// TODO export as implements Partial<...> so minor doesn't break us
export class Value implements remoteConfig.Value {
Expand Down Expand Up @@ -266,13 +276,3 @@ export function mapToObject<T extends ConfigTemplate>(to: 'numbers' | 'booleans'
);
}

// TODO look into the types here, I don't like the anys
const proxyAll = (observable: Observable<Parameter[]>, as: 'numbers' | 'booleans' | 'strings') => new Proxy(
observable.pipe(mapToObject(as as any)), {
get: (self, name: string) => self[name] || observable.pipe(
map(all => all.find(p => p.key === name)),
map(param => param ? param[AS_TO_FN[as]]() : STATIC_VALUES[as]),
distinctUntilChanged()
)
}
) as any;
33 changes: 20 additions & 13 deletions src/schematics/deploy/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { experimental } from '@angular-devkit/core';
import { SchematicsException } from '@angular-devkit/schematics';
import { satisfies } from 'semver';

const escapeRegExp = (str: String) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
const escapeRegExp = (str: string) => str.replace(/[\-\[\]\/{}()*+?.\\^$|]/g, '\\$&');

const moveSync = (src: string, dest: string) => {
copySync(src, dest);
Expand All @@ -30,7 +30,7 @@ const deployToHosting = (
execSync(`open http://localhost:${port} || true`);
}, 1500);

return firebaseTools.serve({ port, targets: ['hosting']}).then(() =>
return firebaseTools.serve({ port, targets: ['hosting'] }).then(() =>
require('inquirer').prompt({
type: 'confirm',
name: 'deployProject',
Expand Down Expand Up @@ -78,19 +78,24 @@ const getPackageJson = (context: BuilderContext, workspaceRoot: string) => {
const npmList = execSync('npm ls || true').toString();
Object.keys(dependencies).forEach((dependency: string) => {
const npmLsMatch = npmList.match(` ${escapeRegExp(dependency)}@.+\\w`);
if (npmLsMatch) { dependencies[dependency] = npmLsMatch[0].split(`${dependency}@`)[1]; }
if (npmLsMatch) {
dependencies[dependency] = npmLsMatch[0].split(`${dependency}@`)[1];
}
});
Object.keys(devDependencies).forEach((devDependency: string) => {
const npmLsMatch = npmList.match(` ${escapeRegExp(devDependency)}@.+\\w`);
if (npmLsMatch) { devDependencies[devDependency] = npmLsMatch[0].split(`${devDependency}@`)[1]; }
if (npmLsMatch) {
devDependencies[devDependency] = npmLsMatch[0].split(`${devDependency}@`)[1];
}
});
if (existsSync(join(workspaceRoot, 'angular.json'))) {
const angularJson = JSON.parse(readFileSync(join(workspaceRoot, 'angular.json')).toString());
// tslint:disable-next-line:no-non-null-assertion
const server = angularJson.projects[context.target!.project].architect.server;
const serverOptions = server && server.options;
const externalDependencies = serverOptions && serverOptions.externalDependencies || [];
const bundleDependencies = serverOptions && serverOptions.bundleDependencies;
if (bundleDependencies == false) {
if (bundleDependencies !== true) {
if (existsSync(join(workspaceRoot, 'package.json'))) {
const packageJson = JSON.parse(readFileSync(join(workspaceRoot, 'package.json')).toString());
Object.keys(packageJson.dependencies).forEach((dependency: string) => {
Expand All @@ -100,7 +105,9 @@ const getPackageJson = (context: BuilderContext, workspaceRoot: string) => {
} else {
externalDependencies.forEach(externalDependency => {
const npmLsMatch = npmList.match(` ${escapeRegExp(externalDependency)}@.+\\w`);
if (npmLsMatch) { dependencies[externalDependency] = npmLsMatch[0].split(`${externalDependency}@`)[1]; }
if (npmLsMatch) {
dependencies[externalDependency] = npmLsMatch[0].split(`${externalDependency}@`)[1];
}
});
}
} // TODO should we throw?
Expand Down Expand Up @@ -177,7 +184,7 @@ export const deployToFunction = async (
execSync(`open http://localhost:${port} || true`);
}, 1500);

return firebaseTools.serve({ port, targets: ['hosting', 'functions']}).then(() =>
return firebaseTools.serve({ port, targets: ['hosting', 'functions'] }).then(() =>
require('inquirer').prompt({
type: 'confirm',
name: 'deployProject',
Expand All @@ -186,6 +193,7 @@ export const deployToFunction = async (
).then(({ deployProject }: { deployProject: boolean }) => {
if (deployProject) {
return firebaseTools.deploy({
// tslint:disable-next-line:no-non-null-assertion
only: `hosting:${context.target!.project},functions:ssr`,
cwd: workspaceRoot
});
Expand All @@ -195,6 +203,7 @@ export const deployToFunction = async (
});
} else {
return firebaseTools.deploy({
// tslint:disable-next-line:no-non-null-assertion
only: `hosting:${context.target!.project},functions:ssr`,
cwd: workspaceRoot
});
Expand Down Expand Up @@ -233,8 +242,6 @@ export default async function deploy(
}

try {
let success: { hosting: string };

const winston = require('winston');
const tripleBeam = require('triple-beam');

Expand All @@ -243,22 +250,22 @@ export default async function deploy(
level: 'info',
format: winston.format.printf((info) =>
[info.message, ...(info[tripleBeam.SPLAT] || [])]
.filter((chunk) => typeof chunk == 'string')
.filter((chunk) => typeof chunk === 'string')
.join(' ')
),
)
})
);

if (ssr) {
success = await deployToFunction(
await deployToFunction(
firebaseTools,
context,
context.workspaceRoot,
projectTargets,
preview
);
} else {
success = await deployToHosting(
await deployToHosting(
firebaseTools,
context,
context.workspaceRoot,
Expand Down

0 comments on commit 7cf0804

Please sign in to comment.