Repository navigation
Expand file tree
/
Copy pathbuilder.ts
More file actions
51 lines (43 loc) · 1.57 KB
/
Copy pathbuilder.ts
File metadata and controls
51 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import deploy, { DeployBuilderOptions } from './actions';
import { BuildTarget } from '../interfaces';
import { getFirebaseProjectName } from '../utils';
// Call the createBuilder() function to create a builder. This mirrors
// createJobHandler() but add typings specific to Architect Builders.
export default createBuilder(
async (options: DeployBuilderOptions, context: BuilderContext): Promise<BuilderOutput> => {
if (!context.target) {
throw new Error('Cannot deploy the application without a target');
}
const firebaseProject = options.firebaseProject || getFirebaseProjectName(
context.workspaceRoot,
context.target.project
);
if (!firebaseProject) {
throw new Error('Cannot find firebase project for your app in .firebaserc');
}
const staticBuildTarget = { name: options.buildTarget || `${context.target.project}:build:production` };
let serverBuildTarget: BuildTarget | undefined;
if (options.ssr) {
serverBuildTarget = {
name: options.universalBuildTarget || `${context.target.project}:server:production`
};
}
try {
await deploy(
require('firebase-tools'),
context,
staticBuildTarget,
serverBuildTarget,
firebaseProject,
options,
process.env.FIREBASE_TOKEN,
);
} catch (e) {
console.error('Error when trying to deploy: ');
console.error(e.message);
return { success: false };
}
return { success: true };
}
);