Skip to content

Commit 7a121eb

Browse files
docs(samples): modernize the samples, tests, and README (#244)
1 parent 0dbdbaa commit 7a121eb

12 files changed

+121
-109
lines changed

packages/google-cloud-dns/.cloud-repo-tools.json

-16
This file was deleted.

packages/google-cloud-dns/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ system-test/*key.json
99
*.lock
1010
package-lock.json
1111
build/
12+
__pycache__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "dns",
3+
"name_pretty": "Cloud DNS",
4+
"product_documentation": "https://cloud.google.com/dns",
5+
"client_documentation": "https://cloud.google.com/nodejs/docs/reference/dns/latest/",
6+
"issue_tracker": "https://issuetracker.google.com/savedsearches/559772",
7+
"release_level": "alpha",
8+
"language": "nodejs",
9+
"repo": "googleapis/nodejs-dns",
10+
"distribution_name": "@google-cloud/dns",
11+
"api_id": "dns.googleapis.com",
12+
"requires_billing": true
13+
}

packages/google-cloud-dns/README.md

+43-46
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2+
[//]: # "To regenerate it, use `python -m synthtool`."
13
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
24

3-
# [Google Cloud DNS: Node.js Client](https://github.com/googleapis/nodejs-dns)
5+
# [Cloud DNS: Node.js Client](https://github.com/googleapis/nodejs-dns)
46

5-
[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
7+
[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
68
[![npm version](https://img.shields.io/npm/v/@google-cloud/dns.svg)](https://www.npmjs.org/package/@google-cloud/dns)
79
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-dns/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-dns)
810

9-
> Node.js idiomatic client for [Cloud DNS][product-docs].
1011

11-
[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google&#x27;s infrastructure for production-quality, high-volume DNS services. Google&#x27;s global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world.
12+
13+
14+
Cloud DNS Client Library for Node.js
1215

1316

1417
* [Cloud DNS Node.js Client API Reference][client-docs]
15-
* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns)
1618
* [Cloud DNS Documentation][product-docs]
19+
* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns)
1720

1821
Read more about the client libraries for Cloud APIs, including the older
1922
Google APIs Client Libraries, in [Client Libraries Explained][explained].
@@ -22,6 +25,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
2225

2326
**Table of contents:**
2427

28+
2529
* [Quickstart](#quickstart)
2630
* [Before you begin](#before-you-begin)
2731
* [Installing the client library](#installing-the-client-library)
@@ -35,66 +39,51 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
3539

3640
### Before you begin
3741

38-
1. Select or create a Cloud Platform project.
39-
40-
[Go to the projects page][projects]
41-
42-
1. Enable billing for your project.
43-
44-
[Enable billing][billing]
45-
46-
1. Enable the Google Cloud DNS API.
47-
48-
[Enable the API][enable_api]
49-
42+
1. [Select or create a Cloud Platform project][projects].
43+
1. [Enable billing for your project][billing].
44+
1. [Enable the Cloud DNS API][enable_api].
5045
1. [Set up authentication with a service account][auth] so you can access the
5146
API from your local workstation.
5247

53-
[projects]: https://console.cloud.google.com/project
54-
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
55-
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com
56-
[auth]: https://cloud.google.com/docs/authentication/getting-started
57-
5848
### Installing the client library
5949

60-
npm install --save @google-cloud/dns
50+
```bash
51+
npm install @google-cloud/dns
52+
```
53+
6154

6255
### Using the client library
6356

6457
```javascript
65-
// Imports the Google Cloud client library
66-
const {DNS} = require('@google-cloud/dns');
58+
// Imports the Google Cloud client library
59+
const {DNS} = require('@google-cloud/dns');
6760

68-
// Your Google Cloud Platform project ID
69-
const projectId = 'YOUR_PROJECT_ID';
70-
71-
// Creates a client
72-
const dns = new DNS({
73-
projectId: projectId,
74-
});
75-
76-
// Lists all zones in the current project
77-
dns
78-
.getZones()
79-
.then(results => {
80-
const zones = results[0];
61+
// Creates a client
62+
const dns = new DNS();
8163

64+
async function quickstart() {
65+
// Lists all zones in the current project
66+
const [zones] = await dns.getZones();
8267
console.log('Zones:');
8368
zones.forEach(zone => console.log(zone.name));
84-
})
85-
.catch(err => {
86-
console.error('ERROR:', err);
87-
});
69+
}
70+
quickstart();
71+
8872
```
8973

74+
75+
9076
## Samples
9177

9278
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-dns/tree/master/samples) directory. The samples' `README.md`
9379
has instructions for running the samples.
9480

9581
| Sample | Source Code | Try it |
9682
| --------------------------- | --------------------------------- | ------ |
97-
| Zones | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/zones.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/zones.js,samples/README.md) |
83+
| List Zones | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/listZones.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/listZones.js,samples/README.md) |
84+
| Quickstart | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
85+
86+
9887

9988
The [Cloud DNS Node.js Client API Reference][client-docs] documentation
10089
also contains samples.
@@ -103,10 +92,15 @@ also contains samples.
10392

10493
This library follows [Semantic Versioning](http://semver.org/).
10594

95+
96+
97+
10698
This library is considered to be in **alpha**. This means it is still a
10799
work-in-progress and under active development. Any release is subject to
108100
backwards-incompatible changes at any time.
109101

102+
103+
110104
More Information: [Google Cloud Platform Launch Stages][launch_stages]
111105

112106
[launch_stages]: https://cloud.google.com/terms/launch-stages
@@ -122,6 +116,9 @@ Apache Version 2.0
122116
See [LICENSE](https://github.com/googleapis/nodejs-dns/blob/master/LICENSE)
123117

124118
[client-docs]: https://cloud.google.com/nodejs/docs/reference/dns/latest/
125-
[product-docs]: https://cloud.google.com/dns/docs/
126-
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
127-
119+
[product-docs]: https://cloud.google.com/dns
120+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
121+
[projects]: https://console.cloud.google.com/project
122+
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
123+
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com
124+
[auth]: https://cloud.google.com/docs/authentication/getting-started

packages/google-cloud-dns/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
],
2929
"scripts": {
3030
"docs": "jsdoc -c .jsdoc.js",
31-
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
3231
"lint": "gts check && eslint '**/*.js'",
3332
"test": "nyc mocha build/test",
3433
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
@@ -52,7 +51,6 @@
5251
"string-format-obj": "^1.1.1"
5352
},
5453
"devDependencies": {
55-
"@google-cloud/nodejs-repo-tools": "^3.0.0",
5654
"@types/lodash.groupby": "^4.6.4",
5755
"@types/mocha": "^5.2.5",
5856
"@types/node": "^10.9.4",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
---
22
rules:
33
no-console: off
4-
node/no-missing-require: off
+39-24
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
1+
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2+
[//]: # "To regenerate it, use `python -m synthtool`."
13
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
24

3-
# Google Cloud DNS: Node.js Samples
5+
# [Cloud DNS: Node.js Samples](https://github.com/googleapis/nodejs-dns)
46

57
[![Open in Cloud Shell][shell_img]][shell_link]
68

7-
[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google&#x27;s infrastructure for production-quality, high-volume DNS services. Google&#x27;s global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world.
9+
810

911
## Table of Contents
1012

1113
* [Before you begin](#before-you-begin)
1214
* [Samples](#samples)
13-
* [Zones](#zones)
15+
* [List Zones](#list-zones)
16+
* [Quickstart](#quickstart)
1417

1518
## Before you begin
1619

17-
Before running the samples, make sure you've followed the steps in the
18-
[Before you begin section](../README.md#before-you-begin) of the client
19-
library's README.
20+
Before running the samples, make sure you've followed the steps outlined in
21+
[Using the client library](https://github.com/googleapis/nodejs-dns#using-the-client-library).
2022

2123
## Samples
2224

23-
### Zones
2425

25-
View the [source code][zones_0_code].
2626

27-
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/zones.js,samples/README.md)
27+
### List Zones
28+
29+
Lists all zones in the current project.
30+
31+
View the [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/listZones.js).
32+
33+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/listZones.js,samples/README.md)
34+
35+
__Usage:__
36+
37+
38+
`node listZones`
39+
40+
41+
-----
42+
43+
44+
45+
46+
### Quickstart
47+
48+
Fetches a list of all available zones.
49+
50+
View the [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/quickstart.js).
51+
52+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)
53+
54+
__Usage:__
2855

29-
__Usage:__ `node zones.js --help`
3056

31-
```
32-
zones.js <command>
57+
`node quickstart`
3358

34-
Commands:
35-
zones.js list Lists all zones in the current project.
3659

37-
Options:
38-
--version Show version number [boolean]
39-
--help Show help [boolean]
4060

41-
Examples:
42-
node zones.js list Lists all zones in the current project.
4361

44-
For more information, see https://cloud.google.com/dns/docs
45-
```
4662

47-
[zones_0_docs]: https://cloud.google.com/dns/docs
48-
[zones_0_code]: zones.js
4963

50-
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
64+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
5165
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/README.md
66+
[product-docs]: https://cloud.google.com/dns

packages/google-cloud-dns/samples/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
"*.js"
1212
],
1313
"scripts": {
14-
"test": "mocha system-test --timeout 600000"
14+
"test": "mocha --timeout 600000"
1515
},
1616
"dependencies": {
17-
"@google-cloud/dns": "^0.9.2",
18-
"yargs": "^13.0.0"
17+
"@google-cloud/dns": "^0.9.2"
1918
},
2019
"devDependencies": {
2120
"chai": "^4.2.0",
22-
"execa": "^1.0.0",
2321
"mocha": "^6.0.0",
2422
"uuid": "^3.3.0"
2523
}

packages/google-cloud-dns/samples/quickstart.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@
1515

1616
'use strict';
1717

18-
// [START dns_quickstart]
19-
async function quickstart(
20-
projectId = 'YOUR_PROJECT_ID' // Your GCP project Id
21-
) {
18+
// sample-metadata:
19+
// name: Quickstart
20+
// description: Fetches a list of all available zones.
21+
// usage: node quickstart
22+
23+
async function main() {
24+
// [START dns_quickstart]
2225
// Imports the Google Cloud client library
2326
const {DNS} = require('@google-cloud/dns');
2427

2528
// Creates a client
26-
const dns = new DNS({projectId});
29+
const dns = new DNS();
2730

28-
// Lists all zones in the current project
29-
const [zones] = await dns.getZones();
30-
console.log('Zones:');
31-
zones.forEach(zone => console.log(zone.name));
31+
async function quickstart() {
32+
// Lists all zones in the current project
33+
const [zones] = await dns.getZones();
34+
console.log('Zones:');
35+
zones.forEach(zone => console.log(zone.name));
36+
}
37+
quickstart();
38+
// [END dns_quickstart]
3239
}
33-
// [END dns_quickstart]
3440

35-
const args = process.argv.slice(2);
36-
quickstart(...args).catch(console.error);
41+
main();

packages/google-cloud-dns/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ class DNS extends Service {
314314
callback!(err, null, null, resp);
315315
return;
316316
}
317-
const zones = arrify(resp.managedZones).map(zone => {
317+
// tslint:disable-next-line no-any
318+
const zones = arrify(resp.managedZones).map((zone: any) => {
318319
const zoneInstance = this.zone(zone.name);
319320
zoneInstance.metadata = zone;
320321
return zoneInstance;

packages/google-cloud-dns/src/zone.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,8 @@ import(localPath: string, callback?: CreateChangeCallback): void|Promise<CreateC
10021002
const recordsToCreate: Record[] = [];
10031003
recordTypes.forEach(recordType => {
10041004
const recordTypeSet = arrify(parsedZonefile[recordType]);
1005-
recordTypeSet.forEach(record => {
1005+
// tslint:disable-next-line no-any
1006+
recordTypeSet.forEach((record: any) => {
10061007
record.ttl = record.ttl || defaultTTL;
10071008
recordsToCreate.push(Record.fromZoneRecord_(this, recordType, record));
10081009
});

packages/google-cloud-dns/synth.metadata

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"updateTime": "2019-03-08T00:45:37.531320Z",
2+
"updateTime": "2019-05-01T19:31:02.875460Z",
33
"sources": [
44
{
55
"template": {
66
"name": "node_library",
77
"origin": "synthtool.gcp",
8-
"version": "2019.1.16"
8+
"version": "2019.4.10"
99
}
1010
}
1111
]

0 commit comments

Comments
 (0)