( firebaseTools: FirebaseTools, context: BuilderContext, workspaceRoot: string, staticBuildTarget: BuildTarget, serverBuildTarget: BuildTarget, options: DeployBuilderOptions, firebaseToken?: string, fsHost: FSHost = defaultFsHost )
| 155 | }; |
| 156 | |
| 157 | export const deployToFunction = async ( |
| 158 | firebaseTools: FirebaseTools, |
| 159 | context: BuilderContext, |
| 160 | workspaceRoot: string, |
| 161 | staticBuildTarget: BuildTarget, |
| 162 | serverBuildTarget: BuildTarget, |
| 163 | options: DeployBuilderOptions, |
| 164 | firebaseToken?: string, |
| 165 | fsHost: FSHost = defaultFsHost |
| 166 | ) => { |
| 167 | |
| 168 | const staticBuildOptions = await context.getTargetOptions(targetFromTargetString(staticBuildTarget.name)); |
| 169 | if (!staticBuildOptions.outputPath || typeof staticBuildOptions.outputPath !== 'string') { |
| 170 | throw new Error( |
| 171 | `Cannot read the output path option of the Angular project '${staticBuildTarget.name}' in angular.json` |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | const serverBuildOptions = await context.getTargetOptions(targetFromTargetString(serverBuildTarget.name)); |
| 176 | if (!serverBuildOptions.outputPath || typeof serverBuildOptions.outputPath !== 'string') { |
| 177 | throw new Error( |
| 178 | `Cannot read the output path option of the Angular project '${serverBuildTarget.name}' in angular.json` |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | const staticOut = join(workspaceRoot, staticBuildOptions.outputPath); |
| 183 | const serverOut = join(workspaceRoot, serverBuildOptions.outputPath); |
| 184 | |
| 185 | const functionsOut = options.outputPath ? join(workspaceRoot, options.outputPath) : dirname(serverOut); |
| 186 | const functionName = options.functionName || DEFAULT_FUNCTION_NAME; |
| 187 | |
| 188 | const newStaticOut = join(functionsOut, staticBuildOptions.outputPath); |
| 189 | const newServerOut = join(functionsOut, serverBuildOptions.outputPath); |
| 190 | |
| 191 | // New behavior vs. old |
| 192 | if (options.outputPath) { |
| 193 | fsHost.removeSync(functionsOut); |
| 194 | fsHost.copySync(staticOut, newStaticOut); |
| 195 | fsHost.copySync(serverOut, newServerOut); |
| 196 | } else { |
| 197 | fsHost.moveSync(staticOut, newStaticOut); |
| 198 | fsHost.moveSync(serverOut, newServerOut); |
| 199 | } |
| 200 | |
| 201 | const packageJson = getPackageJson(context, workspaceRoot, options); |
| 202 | const nodeVersion = packageJson.engines.node; |
| 203 | |
| 204 | if (!satisfies(process.versions.node, nodeVersion.toString())) { |
| 205 | context.logger.warn( |
| 206 | `⚠️ Your Node.js version (${process.versions.node}) does not match the Firebase Functions runtime (${nodeVersion}).` |
| 207 | ); |
| 208 | } |
| 209 | |
| 210 | const functionsPackageJsonPath = join(functionsOut, 'package.json'); |
| 211 | fsHost.writeFileSync( |
| 212 | functionsPackageJsonPath, |
| 213 | JSON.stringify(packageJson, null, 2) |
| 214 | ); |
no test coverage detected