Skip to content

Commit f5ae6d3

Browse files
committed
New build and stackdriver snippets
Change-Id: I88e1f2b705f9685a85fbe35728f1fae917aa51d0
1 parent 5f34ecc commit f5ae6d3

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: node_js
22
node_js:
3-
- "7"
3+
- "8"
44
install:
5-
- npm install -g lerna
6-
- npm install -g eslint
7-
- lerna bootstrap
5+
- npm install
86
script:
97
- ./scripts/test.sh

firestore/main/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"@google-cloud/firestore": "^0.16.1",
14-
"firebase-admin": "^6.0.0"
13+
"@google-cloud/firestore": "^0.19.0",
14+
"firebase-admin": "^6.4.0"
1515
},
1616
"devDependencies": {
1717
"mocha": "^3.3.0"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// [START sd_logging_import]
2+
const { Logging } = require('@google-cloud/logging');
3+
// [END sd_logging_import]
4+
const functions = require('firebase-functions');
5+
6+
// [START sd_example_function]
7+
exports.helloError = functions.https.onRequest((request, response) => {
8+
console.log('I am a log entry!');
9+
response.send('Hello World...');
10+
});
11+
// [END sd_example_function]
12+
13+
// [START sd_logging_setup]
14+
// Instantiate the StackDriver Logging SDK. The project ID will
15+
// be automatically inferred from the Cloud Functions environment.
16+
const logging = new Logging();
17+
const log = logging.log('my-custom-log-name');
18+
19+
// This metadata is attached to each log entry. This specifies a fake
20+
// Cloud Function called 'Custom Metrics' in order to make your custom
21+
// log entries appear in the Cloud Functions logs viewer.
22+
const METADATA = {
23+
resource: {
24+
type: 'cloud_function',
25+
labels: {
26+
function_name: 'CustomMetrics',
27+
region: 'us-central1'
28+
}
29+
}
30+
};
31+
// [END sd_logging_setup]
32+
33+
function writeLog() {
34+
// [START sd_write_log]
35+
// Data to write to the log. This can be a JSON object with any properties
36+
// of the event you want to record.
37+
const data = {
38+
event: 'my-event',
39+
value: 'foo-bar-baz',
40+
41+
// Optional 'message' property will show up in the Firebase
42+
// console and other human-readable logging surfaces
43+
message: 'my-event: foo-bar-baz'
44+
};
45+
46+
// Write to the log. The log.write() call returns a Promise if you want to
47+
// make sure that the log was written successfully.
48+
const entry = log.entry(METADATA, data);
49+
log.write(entry);
50+
// [END sd_write_log]
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "functions-stackdriver-logging",
3+
"version": "1.0.0",
4+
"description": "StackDriver logging for Cloud Functions",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"@google-cloud/logging": "^4.2.0",
10+
"firebase-functions": "^2.1.0"
11+
}
12+
}

lerna.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"lerna": "2.8.0",
33
"packages": [
4+
"auth",
45
"firestore/main",
56
"firestore/extend-with-functions",
67
"firestore/full-text-search",
78
"firestore/presence",
8-
"auth"
9+
"functions/stackdriver-logging"
910
],
1011
"version": "1.0.0"
1112
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
"description": "Code snippets used in Node.js documentation on firebase.google.com",
55
"author": "Firebase (https://firebase.google.com/)",
66
"license": "Apache-2.0",
7+
"scripts": {
8+
"lerna-test": "lerna run test",
9+
"lerna-bootstrap": "lerna bootstrap",
10+
"lint": "find . -type f -name \"*.js\" -not -path \"*node_modules*\" | xargs eslint"
11+
},
712
"devDependencies": {
813
"eslint": "^4.17.0",
9-
"eslint-config-google": "^0.9.1"
14+
"eslint-config-google": "^0.9.1",
15+
"lerna": "^2.8.0"
1016
}
1117
}

scripts/test.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
set -e
22

3+
# 0) Bootstrap
4+
echo "Bootstrapping..."
5+
npm run lerna-bootstrap
6+
37
# 1) Pull request
48
if [ -z "$TRAVIS_PULL_REQUEST" ]; then
59
echo "TRAVIS_PULL_REQUEST: unset, setting to false"
@@ -18,8 +22,7 @@ fi
1822

1923
# Run linter
2024
echo "Linting..."
21-
find . -type f -name "*.js" -not -path "*node_modules*" \
22-
| xargs eslint
25+
npm run lint
2326

2427
# Only run test suite when we can decode the service acct
2528
if [ "$TRAVIS_SECURE_ENV_VARS" = false ]; then
@@ -29,5 +32,5 @@ else
2932
openssl aes-256-cbc -K $encrypted_001d217edcb2_key -iv $encrypted_001d217edcb2_iv -in service-account.json.enc -out service-account.json -d
3033

3134
# Run all tests
32-
lerna run test
35+
npm run lerna-test
3336
fi

0 commit comments

Comments
 (0)