|
1 | | -import { SchematicsException, Tree } from '@angular-devkit/schematics'; |
| 1 | +import { SchematicsException, Tree, SchematicContext } from '@angular-devkit/schematics'; |
| 2 | +import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks'; |
2 | 3 | import { FirebaseJSON, FirebaseRc, FirebaseHostingConfig } from './interfaces'; |
3 | 4 | import { experimental, JsonParseMode, parseJson } from '@angular-devkit/core'; |
4 | | -import { from } from 'rxjs'; |
| 5 | +import { from, of } from 'rxjs'; |
5 | 6 | import { map, switchMap } from 'rxjs/operators'; |
6 | 7 | import { Project } from './interfaces'; |
7 | 8 | import { listProjects, projectPrompt } from './utils'; |
| 9 | +import { dependencies as requiredDependencyVersions, devDependencies as requiredDevDependencyVersions } from './versions'; |
8 | 10 |
|
9 | 11 | const stringifyFormatted = (obj: any) => JSON.stringify(obj, null, 2); |
10 | 12 |
|
@@ -155,13 +157,36 @@ interface DeployOptions { |
155 | 157 |
|
156 | 158 | // You don't have to export the function as default. You can also have more than one rule factory |
157 | 159 | // per file. |
158 | | -export const ngDeploy = ({ project }: DeployOptions) => (host: Tree) => |
159 | | - from(listProjects()).pipe( |
| 160 | +export const setupNgDeploy = ({ project }: DeployOptions) => (host: Tree) => { |
| 161 | + return from(listProjects()).pipe( |
160 | 162 | switchMap((projects: Project[]) => projectPrompt(projects)), |
161 | | - map(({ firebaseProject }: any) => ngAdd(host, { firebaseProject, project })) |
| 163 | + map(({ firebaseProject }: any) => setupFirebaseProject(host, { firebaseProject, project })) |
162 | 164 | ); |
| 165 | +} |
| 166 | + |
| 167 | +export const ngAdd = (options: DeployOptions) => (host: Tree, context: SchematicContext) => { |
| 168 | + const packageJson = host.exists('package.json') && safeReadJSON('package.json', host); |
| 169 | + |
| 170 | + if (packageJson === undefined) { |
| 171 | + throw new SchematicsException('Could not locate package.json'); |
| 172 | + } |
| 173 | + |
| 174 | + Object.keys(requiredDependencyVersions).forEach(name => { |
| 175 | + packageJson.dependencies[name] = packageJson.dependencies[name] || requiredDependencyVersions[name]; |
| 176 | + }); |
| 177 | + |
| 178 | + Object.keys(requiredDevDependencyVersions).forEach(name => { |
| 179 | + packageJson.devDependencies[name] = packageJson.devDependencies[name] || requiredDevDependencyVersions[name]; |
| 180 | + }); |
| 181 | + |
| 182 | + overwriteIfExists(host, 'package.json', stringifyFormatted(packageJson)); |
| 183 | + |
| 184 | + const installTaskId = context.addTask(new NodePackageInstallTask()); |
| 185 | + |
| 186 | + context.addTask(new RunSchematicTask('ng-add-setup-firebase-deploy', options), [installTaskId]); |
| 187 | +} |
163 | 188 |
|
164 | | -export function ngAdd(tree: Tree, options: NgAddOptions) { |
| 189 | +export function setupFirebaseProject(tree: Tree, options: NgAddOptions) { |
165 | 190 | const { path: workspacePath, workspace } = getWorkspace(tree); |
166 | 191 |
|
167 | 192 | if (!options.project) { |
|
0 commit comments