-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathbuilder.ts
72 lines (63 loc) · 2.66 KB
/
builder.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { getFirebaseTools } from '../firebaseTools';
import { BuildTarget } from '../interfaces';
import { getFirebaseProjectNameFromFs } from '../utils';
import deploy, { DeployBuilderOptions } from './actions';
// 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 [defaultFirebaseProject, defulatFirebaseHostingSite] = getFirebaseProjectNameFromFs(
context.workspaceRoot,
context.target.project
);
const firebaseProject = options.firebaseProject || defaultFirebaseProject;
if (!firebaseProject) {
throw new Error('Cannot determine the Firebase Project from your angular.json or .firebaserc');
}
if (firebaseProject !== defaultFirebaseProject) {
throw new Error('The Firebase Project specified by your angular.json or .firebaserc is in conflict');
}
const firebaseHostingSite = options.firebaseHostingSite || defulatFirebaseHostingSite;
if (!firebaseHostingSite) {
throw new Error(`Cannot determine the Firebase Hosting Site from your angular.json or .firebaserc`);
}
if (firebaseHostingSite !== defulatFirebaseHostingSite) {
throw new Error('The Firebase Hosting Site specified by your angular.json or .firebaserc is in conflict');
}
const staticBuildTarget = { name: options.browserTarget || options.buildTarget || `${context.target.project}:build:production` };
let prerenderBuildTarget: BuildTarget | undefined;
if (options.prerender) {
prerenderBuildTarget = {
name: options.prerenderTarget || `${context.target.project}:prerender:production`
};
}
let serverBuildTarget: BuildTarget | undefined;
if (options.ssr) {
serverBuildTarget = {
name: options.serverTarget || options.universalBuildTarget || `${context.target.project}:server:production`
};
}
try {
process.env.FIREBASE_DEPLOY_AGENT = 'angularfire';
await deploy(
(await getFirebaseTools()),
context,
staticBuildTarget,
serverBuildTarget,
prerenderBuildTarget,
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 };
}
);