Skip to content

refactor: update documentation & improve error messages #2081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/deploy/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ng add @angular/fire

*Note that the command above assumes you have global Angular CLI installed. To install Angular CLI globally run `npm i -g @angular/cli`.*

The command above will trigger the `@angular/fire` `ng-add` schematics. Once they install `@angular/fire`. If you are not authenticated, the schematics will open a browser which will guide you through the authentication flow. Once you authenticate, you'll see a prompt to select a Firebase hosting project.
The command above will trigger the `@angular/fire` `ng-add` schematics. The schematics will open a web browser and guide you through the Firebase authentication flow (if you're not signed in already). After you authenticate, you'll see a prompt to select a Firebase hosting project.

The schematics will do the following:

Expand Down Expand Up @@ -53,7 +53,7 @@ ng add @angular/fire --project=[PROJECT_NAME]
As the second step, to deploy your project run:

```
ng run [PROJECT_NAME]:deploy
ng run [ANGULAR_PROJECT_NAME]:deploy
```

The command above will trigger:
Expand Down
44 changes: 23 additions & 21 deletions src/schematics/ng-add.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SchematicsException, Tree } from "@angular-devkit/schematics";
import { FirebaseJSON, FirebaseRc } from "./interfaces";
import { experimental, JsonParseMode, parseJson } from "@angular-devkit/core";
import { from } from "rxjs";
import { map, switchMap } from "rxjs/operators";
import { Project } from "./interfaces";
import { listProjects, projectPrompt } from "./utils";
import { SchematicsException, Tree } from '@angular-devkit/schematics';
import { FirebaseJSON, FirebaseRc } from './interfaces';
import { experimental, JsonParseMode, parseJson } from '@angular-devkit/core';
import { from } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Project } from './interfaces';
import { listProjects, projectPrompt } from './utils';

const stringifyFormatted = (obj: any) => JSON.stringify(obj, null, 2);

Expand All @@ -24,11 +24,11 @@ function generateHostingConfig(project: string, dist: string) {
return {
target: project,
public: dist,
ignore: ["firebase.json", "**/.*", "**/node_modules/**"],
ignore: ['firebase.json', '**/.*', '**/node_modules/**'],
rewrites: [
{
source: "**",
destination: "/index.html"
source: '**',
destination: '/index.html'
}
]
};
Expand Down Expand Up @@ -106,7 +106,7 @@ const overwriteIfExists = (tree: Tree, path: string, content: string) => {
function getWorkspace(
host: Tree
): { path: string; workspace: experimental.workspace.WorkspaceSchema } {
const possibleFiles = ["/angular.json", "/.angular.json"];
const possibleFiles = ['/angular.json', '/.angular.json'];
const path = possibleFiles.filter(path => host.exists(path))[0];

const configBuffer = host.read(path);
Expand Down Expand Up @@ -156,19 +156,21 @@ export function ngAdd(tree: Tree, options: NgAddOptions) {
options.project = workspace.defaultProject;
} else {
throw new SchematicsException(
"No project selected and no default project in the workspace"
'No Angular project selected and no default project in the workspace'
);
}
}

const project = workspace.projects[options.project];
if (!project) {
throw new SchematicsException("Project is not defined in this workspace");
throw new SchematicsException(
'The specified Angular project is not defined in this workspace'
);
}

if (project.projectType !== "application") {
if (project.projectType !== 'application') {
throw new SchematicsException(
`Deploy requires a project type of "application" in angular.json`
`Deploy requires an Angular project type of "application" in angular.json`
);
}

Expand All @@ -179,26 +181,26 @@ export function ngAdd(tree: Tree, options: NgAddOptions) {
!project.architect.build.options.outputPath
) {
throw new SchematicsException(
`Cannot read the output path (architect.build.options.outputPath) of project "${
`Cannot read the output path (architect.build.options.outputPath) of the Angular project "${
options.project
}" in angular.json`
);
}

const outputPath = project.architect.build.options.outputPath;

project.architect["deploy"] = {
builder: "@angular/fire:deploy",
project.architect['deploy'] = {
builder: '@angular/fire:deploy',
options: {}
};

tree.overwrite(workspacePath, JSON.stringify(workspace, null, 2));
generateFirebaseJson(tree, "firebase.json", options.project, outputPath);
generateFirebaseJson(tree, 'firebase.json', options.project!, outputPath);
generateFirebaseRc(
tree,
".firebaserc",
'.firebaserc',
options.firebaseProject,
options.project
options.project!
);
return tree;
}