Skip to content

Commit f7c45b2

Browse files
devversionkara
authored andcommitted
build: move functions folder into tools/ (#4127)
1 parent 11b97aa commit f7c45b2

File tree

12 files changed

+48
-34
lines changed

12 files changed

+48
-34
lines changed

firebase.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"functions": {
3+
"source": "tools/screenshot-test/functions"
4+
},
25
"hosting": {
36
"public": "dist",
47
"rewrites": [

functions/package.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@
6262
"dgeni": "^0.4.7",
6363
"dgeni-packages": "^0.16.5",
6464
"firebase": "^3.7.2",
65-
"firebase-admin": "^4.1.2",
66-
"firebase-functions": "^0.5.2",
67-
"firebase-tools": "^2.2.1",
65+
"firebase-admin": "~4.1.2",
66+
"firebase-tools": "^3.6.1",
6867
"fs-extra": "^2.0.0",
6968
"glob": "^7.1.1",
7069
"google-closure-compiler": "^20170218.0.0",

tools/gulp/util/firebase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const firebaseAdmin = require('firebase-admin');
22
const firebase = require('firebase');
33
const cloudStorage = require('@google-cloud/storage');
44

5-
const config = require('../../../functions/config.json');
5+
// Firebase configuration for the Screenshot project. Use the config from the screenshot functions.
6+
const screenshotFirebaseConfig = require('../../screenshot-test/functions/config.json');
67

78
/** Opens a connection to the firebase realtime database. */
89
export function openFirebaseDashboardDatabase() {
@@ -51,6 +52,6 @@ export function decode(str: string): string {
5152
* This connection is client side connection with no credentials
5253
*/
5354
export function connectFirebaseScreenshots() {
54-
return firebase.initializeApp(config.firebase);
55+
return firebase.initializeApp(screenshotFirebaseConfig.firebase);
5556
}
5657

File renamed without changes.

tools/screenshot-test/functions/github.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ export function updateGithubStatus(event: firebaseFunctions.Event<any>) {
1818
return;
1919
}
2020
let result = event.data.val() == true;
21-
let prNumber = event.params.prNumber;
22-
return setGithubStatus(event.params.sha,
23-
{
21+
let {prNumber, sha} = event.params;
22+
return setGithubStatus(sha, {
2423
result: result,
2524
name: toolName,
2625
description: `${toolName} ${result ? 'passed' : 'failed'}`,
2726
url: `http://${authDomain}/${prNumber}`
28-
},
29-
repoSlug,
30-
token);
27+
}, repoSlug, token);
3128
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Entry point for the Firebase functions of the Screenshot tool. Firebase functions only support
3+
* JavaScript files and therefore the TypeScript files needs to be transpiled. Using ts-node
4+
* seems to be more elegant for now, because Firebase requires the `node_modules` to be copied
5+
* to the output directory and when using TSC the `node_modules` won't be copied to the destination.
6+
*/
7+
8+
'use strict';
9+
10+
const path = require('path');
11+
12+
// Enable TypeScript compilation at runtime using ts-node.
13+
require('ts-node').register({
14+
project: path.join(__dirname, 'tsconfig.json')
15+
});
16+
17+
require('./screenshot-functions');

tools/screenshot-test/functions/jwt-util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const secret = firebaseFunctions.config().secret.key;
1313
* Replace '/' with '.' to get the token.
1414
*/
1515
function getSecureToken(event: firebaseFunctions.Event<any>) {
16-
return `${event.params.jwtHeader}.${event.params.jwtPayload}.${event.params.jwtSignature}`;
16+
let {jwtHeader, jwtPayload, jwtSignature} = event.params;
17+
return `${jwtHeader}.${jwtPayload}.${jwtSignature}`;
1718
}
1819

1920
/**
@@ -22,7 +23,7 @@ function getSecureToken(event: firebaseFunctions.Event<any>) {
2223
*/
2324
export function verifySecureToken(event: firebaseFunctions.Event<any>) {
2425
return new Promise((resolve, reject) => {
25-
const prNumber = event.params.prNumber;
26+
const prNumber = event.params['prNumber'];
2627
const secureToken = getSecureToken(event);
2728

2829
return verifyJWT(secureToken, prNumber, secret, repoSlug).then(() => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "material2-screenshot-functions",
3+
"description": "Angular Material screenshot firebase functions",
4+
"dependencies": {
5+
"@google-cloud/storage": "^0.8.0",
6+
"firebase-admin": "~4.1.3",
7+
"firebase-functions": "^0.5.2",
8+
"jsonwebtoken": "^7.3.0",
9+
"request": "^2.81.0",
10+
"typescript": "^2.2.2",
11+
"ts-node": "^3.0.2"
12+
}
13+
}

tools/screenshot-test/functions/index.ts renamed to tools/screenshot-test/functions/screenshot-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {updateGithubStatus} from './github';
4646
* The JWT has 3 parts: header, payload and signature. These three parts are joint by '/' in path.
4747
*/
4848

49-
// Initailize the admin app
49+
// Initialize the admin app
5050
firebaseAdmin.initializeApp(firebaseFunctions.config().firebase);
5151

5252
/** The valid data types database accepts */

0 commit comments

Comments
 (0)