Skip to content

Commit

Permalink
Couple small things
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Dec 7, 2023
1 parent 4f7932c commit d72d844
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 244 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ by conforming to Angular conventions.

<strong><pre>ng add @angular/fire</pre></strong>

_Note: If you want to ng add AngularFire and will be using Hosting/Cloud Functions, you need to configure the
Firebase CLI first so that you are logged in for the schematics that are run as part of `ng add @angular/fire`.
Follow [this guide](docs/install-firebase-tools.md) to have the Firebase CLI walk you through the setup._

- **Dependency injection** - Provide and Inject Firebase services in your components
- **Zone.js wrappers** - Stable zones allow proper functionality of service workers, forms, SSR, and pre-rendering
- **Observable based** - Utilize RxJS rather than callbacks for realtime streams
Expand Down
603 changes: 425 additions & 178 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
},
"homepage": "https://github.com/angular/angularfire#readme",
"dependencies": {
"@angular-devkit/architect": "~0.1700.0-next.0",
"@angular-devkit/core": "^17.0.0-next.0",
"@angular-devkit/schematics": "^17.0.0-next.0",
"@angular/common": "^17.0.0-next.0",
"@angular/compiler": "^17.0.0-next.0",
"@angular/core": "^17.0.0-next.0",
"@angular/platform-browser": "^17.0.0-next.0",
"@angular/platform-browser-dynamic": "^17.0.0-next.0",
"@angular/router": "^17.0.0-next.0",
"@schematics/angular": "^17.0.0-next.0",
"@angular-devkit/architect": "~0.1700.0",
"@angular-devkit/core": "^17.0.0",
"@angular-devkit/schematics": "^17.0.0",
"@angular/common": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"@schematics/angular": "^17.0.0",
"firebase": "^10.0.0",
"firebase-admin": "^9.11.1",
"firebase-functions": "^3.6.0",
Expand All @@ -75,11 +75,11 @@
"zone.js": "~0.14.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.0-next.0",
"@angular/animations": "^17.0.0-next.0",
"@angular/cli": "^17.0.0-next.0",
"@angular/compiler-cli": "^17.0.0-next.0",
"@angular/platform-server": "^17.0.0-next.0",
"@angular-devkit/build-angular": "^17.0.0",
"@angular/animations": "^17.0.0",
"@angular/cli": "^17.0.0",
"@angular/compiler-cli": "^17.0.0",
"@angular/platform-server": "^17.0.0",
"@types/fs-extra": "^7.0.0",
"@types/gzip-size": "^5.1.1",
"@types/inquirer": "^0.0.44",
Expand Down Expand Up @@ -107,7 +107,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"karma-safarinative-launcher": "^1.1.0",
"ng-packagr": "^17.0.0-next.0",
"ng-packagr": "^17.0.0",
"reflect-metadata": "^0.1.2",
"replace-in-file": "^5.0.2",
"rimraf": "^2.5.4",
Expand Down
12 changes: 6 additions & 6 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"author": "angular,firebase",
"license": "MIT",
"peerDependencies": {
"@angular/common": "^17.0.0-next.0",
"@angular/core": "^17.0.0-next.0",
"@angular/platform-browser": "^17.0.0-next.0",
"@angular/platform-browser-dynamic": "^17.0.0-next.0",
"@angular/common": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"rxjs": "~7.8.0",
"firebase-tools": "^12.0.0"
},
Expand All @@ -36,8 +36,8 @@
"dependencies": {
"firebase": "^10.5.0",
"rxfire": "^6.0.5",
"@angular-devkit/schematics": "^17.0.0-next.0",
"@schematics/angular": "^17.0.0-next.0",
"@angular-devkit/schematics": "^17.0.0",
"@schematics/angular": "^17.0.0",
"tslib": "^2.3.0",
"fuzzy": "^0.1.3",
"inquirer-autocomplete-prompt": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/schematics/firebaseTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const getFirebaseTools = () => globalThis.firebaseTools ?
globalThis.firebaseTools = firebaseTools;
const version = firebaseTools.cli.version();
console.log(`Using firebase-tools version ${version}`);
if (semver.compare(version, '9.9.0') === -1) {
console.error('firebase-tools version 9.9+ is required, please upgrade and run again');
if (semver.compare(version, '13.0.0') === -1) {
console.error('firebase-tools version 13.0.0+ is required, please upgrade and run again');
return Promise.reject();
}
return firebaseTools;
Expand Down
7 changes: 2 additions & 5 deletions src/schematics/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export interface NgAddNormalizedOptions {
firebaseApp: FirebaseApp|undefined;
firebaseHostingSite: FirebaseHostingSite|undefined;
sdkConfig: Record<string, string>|undefined;
prerender: boolean|undefined;
browserTarget: string|undefined;
serverTarget: string|undefined;
prerenderTarget: string|undefined;
buildTarget: string|undefined;
ssrRegion: string|undefined;
}

Expand Down Expand Up @@ -122,7 +119,7 @@ export interface FirebaseTools {
};

login: {
list(): Promise<{user: Record<string, any>}[]>;
list(): Promise<{user: Record<string, any>}[] | { users: undefined }>;
add(): Promise<Record<string, any>>;
use(email: string, options?: unknown): Promise<string>;
} & ((options?: unknown) => Promise<Record<string, any>>);
Expand Down
30 changes: 14 additions & 16 deletions src/schematics/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { getFirebaseTools } from '../firebaseTools';
import {
DeployOptions, FEATURES, FirebaseApp, FirebaseHostingSite, FirebaseProject,
NgAddNormalizedOptions, PROJECT_TYPE
NgAddNormalizedOptions
} from '../interfaces';
import { FirebaseJSON, Workspace, WorkspaceProject } from '../interfaces';
import {
Expand All @@ -27,14 +27,9 @@ export interface SetupConfig extends DeployOptions {
firebaseApp?: FirebaseApp,
firebaseHostingSite?: FirebaseHostingSite,
sdkConfig?: Record<string, string>,
nodeVersion?: string,
browserTarget?: string,
serverTarget?: string,
prerenderTarget?: string,
buildTarget?: string,
project?: string,
ssrRegion?: string,
projectType?: PROJECT_TYPE,
prerender?: boolean,
}

export const setupProject =
Expand All @@ -55,10 +50,7 @@ export const setupProject =
firebaseApp: config.firebaseApp,
firebaseHostingSite: config.firebaseHostingSite,
sdkConfig: config.sdkConfig,
prerender: undefined,
browserTarget: config.browserTarget,
serverTarget: config.serverTarget,
prerenderTarget: config.prerenderTarget,
buildTarget: config.buildTarget,
ssrRegion: config.ssrRegion,
},
tree,
Expand Down Expand Up @@ -97,7 +89,10 @@ export const ngAddSetupProject = (
if (!host.exists('/firebase.json')) { writeFileSync(join(projectRoot, 'firebase.json'), '{}'); }

const user = await userPrompt({ projectRoot });
await firebaseTools.login.use(user.email, { projectRoot });
const defaultUser = await firebaseTools.login(options);
if (user.email !== defaultUser?.email) {
await firebaseTools.login.use(user.email, { projectRoot });
}

const { project: ngProject, projectName: ngProjectName } = getProject(options, host);

Expand Down Expand Up @@ -187,10 +182,13 @@ export const setupFirebase = (config: {
builder: '@angular/fire:deploy',
options: {
version: 2,
browserTarget: options.browserTarget,
...(options.serverTarget ? {serverTarget: options.serverTarget} : {}),
...(options.prerenderTarget ? {prerenderTarget: options.prerenderTarget} : {})
}
},
configurations: {
production: {
buildTarget: options.buildTarget,
},
},
defaultConfiguration: 'production',
};

tree.overwrite(workspacePath, JSON.stringify(workspace, null, 2));
Expand Down
28 changes: 11 additions & 17 deletions src/schematics/setup/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as inquirer from 'inquirer';
import { shortSiteName } from '../common';
import { getFirebaseTools } from '../firebaseTools';
import { FEATURES, FirebaseApp, FirebaseHostingSite, FirebaseProject, PROJECT_TYPE, WorkspaceProject, featureOptions } from '../interfaces';
import { hasPrerenderOption, isUniversalApp, shortAppId } from '../utils';
import { isUniversalApp, shortAppId } from '../utils';
import { spawnSync } from 'child_process';

// eslint-disable-next-line @typescript-eslint/no-var-requires
inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
Expand Down Expand Up @@ -122,16 +123,15 @@ export const featuresPrompt = async (): Promise<FEATURES[]> => {
return features;
};

export const userPrompt = async (options: unknown): Promise<Record<string, any>> => {
export const userPrompt = async (options: { projectRoot: string }): Promise<Record<string, any>> => {
const firebaseTools = await getFirebaseTools();
const users = await firebaseTools.login.list();
if (!users || users.length === 0) {
await firebaseTools.login(); // first login isn't returning anything of value
const user = await firebaseTools.login(options);
return user;
const loginList = await firebaseTools.login.list();
if (!Array.isArray(loginList) || loginList.length === 0) {
spawnSync('firebase login', { shell: true, cwd: options.projectRoot, stdio: 'inherit' });
return await firebaseTools.login(options);
} else {
const defaultUser = await firebaseTools.login(options);
const choices = users.map(({user}) => ({ name: user.email, value: user }));
const choices = loginList.map(({user}) => ({ name: user.email, value: user }));
const newChoice = { name: '[Login in with another account]', value: NEW_OPTION };
const { user } = await inquirer.prompt({
type: 'list',
Expand Down Expand Up @@ -242,22 +242,16 @@ const ALLOWED_SSR_REGIONS = [
];

export const projectTypePrompt = async (project: WorkspaceProject, name: string) => {
let serverTarget: string|undefined;
let browserTarget = `${name}:build:${project.architect?.build?.defaultConfiguration || 'production'}`;
let prerenderTarget: string|undefined;
const buildTarget = `${name}:build:${project.architect?.build?.defaultConfiguration || 'production'}`;
if (isUniversalApp(project)) {
serverTarget = `${name}:server:${project.architect?.server?.defaultConfiguration || 'production'}`;
browserTarget = `${name}:build:${project.architect?.build?.defaultConfiguration || 'production'}`;
const prerender = hasPrerenderOption(project);
prerenderTarget = prerender && `${name}:prerender:${prerender.defaultConfiguration || 'production'}`;
const { ssrRegion } = await inquirer.prompt({
type: 'list',
name: 'ssrRegion',
choices: ALLOWED_SSR_REGIONS,
message: 'In which region would you like to host server-side content?',
default: DEFAULT_REGION,
}) as { ssrRegion: string };
return { prerender, projectType: PROJECT_TYPE.WebFrameworks, ssrRegion, browserTarget, serverTarget, prerenderTarget };
return { projectType: PROJECT_TYPE.WebFrameworks, ssrRegion, buildTarget };
}
return { projectType: PROJECT_TYPE.WebFrameworks, browserTarget, serverTarget, prerenderTarget };
return { projectType: PROJECT_TYPE.WebFrameworks, buildTarget };
};

0 comments on commit d72d844

Please sign in to comment.