From 7a121eb8517097b605dd628295d421a71d235cdc Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 1 May 2019 19:15:29 -0700 Subject: [PATCH] docs(samples): modernize the samples, tests, and README (#244) --- .../google-cloud-dns/.cloud-repo-tools.json | 16 ---- packages/google-cloud-dns/.gitignore | 1 + packages/google-cloud-dns/.repo-metadata.json | 13 +++ packages/google-cloud-dns/README.md | 89 +++++++++---------- packages/google-cloud-dns/package.json | 2 - .../google-cloud-dns/samples/.eslintrc.yml | 1 - packages/google-cloud-dns/samples/README.md | 63 ++++++++----- .../google-cloud-dns/samples/package.json | 6 +- .../google-cloud-dns/samples/quickstart.js | 29 +++--- packages/google-cloud-dns/src/index.ts | 3 +- packages/google-cloud-dns/src/zone.ts | 3 +- packages/google-cloud-dns/synth.metadata | 4 +- 12 files changed, 121 insertions(+), 109 deletions(-) delete mode 100644 packages/google-cloud-dns/.cloud-repo-tools.json create mode 100644 packages/google-cloud-dns/.repo-metadata.json diff --git a/packages/google-cloud-dns/.cloud-repo-tools.json b/packages/google-cloud-dns/.cloud-repo-tools.json deleted file mode 100644 index 4c3dfedd37f..00000000000 --- a/packages/google-cloud-dns/.cloud-repo-tools.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "requiresKeyFile": true, - "requiresProjectId": true, - "product": "dns", - "client_reference_url": "https://cloud.google.com/nodejs/docs/reference/dns/latest/", - "release_quality": "alpha", - "samples": [ - { - "id": "zones", - "name": "Zones", - "file": "zones.js", - "docs_link": "https://cloud.google.com/dns/docs", - "usage": "node zones.js --help" - } - ] -} diff --git a/packages/google-cloud-dns/.gitignore b/packages/google-cloud-dns/.gitignore index 7af032008f8..fd95430233a 100644 --- a/packages/google-cloud-dns/.gitignore +++ b/packages/google-cloud-dns/.gitignore @@ -9,3 +9,4 @@ system-test/*key.json *.lock package-lock.json build/ +__pycache__ diff --git a/packages/google-cloud-dns/.repo-metadata.json b/packages/google-cloud-dns/.repo-metadata.json new file mode 100644 index 00000000000..9ffc51c29a4 --- /dev/null +++ b/packages/google-cloud-dns/.repo-metadata.json @@ -0,0 +1,13 @@ +{ + "name": "dns", + "name_pretty": "Cloud DNS", + "product_documentation": "https://cloud.google.com/dns", + "client_documentation": "https://cloud.google.com/nodejs/docs/reference/dns/latest/", + "issue_tracker": "https://issuetracker.google.com/savedsearches/559772", + "release_level": "alpha", + "language": "nodejs", + "repo": "googleapis/nodejs-dns", + "distribution_name": "@google-cloud/dns", + "api_id": "dns.googleapis.com", + "requires_billing": true +} diff --git a/packages/google-cloud-dns/README.md b/packages/google-cloud-dns/README.md index 274f20ec5ed..e6aa54fb7f3 100644 --- a/packages/google-cloud-dns/README.md +++ b/packages/google-cloud-dns/README.md @@ -1,19 +1,22 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `python -m synthtool`." Google Cloud Platform logo -# [Google Cloud DNS: Node.js Client](https://github.com/googleapis/nodejs-dns) +# [Cloud DNS: Node.js Client](https://github.com/googleapis/nodejs-dns) -[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style=flat)](https://cloud.google.com/terms/launch-stages) +[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style=flat)](https://cloud.google.com/terms/launch-stages) [![npm version](https://img.shields.io/npm/v/@google-cloud/dns.svg)](https://www.npmjs.org/package/@google-cloud/dns) [![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-dns/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-dns) -> Node.js idiomatic client for [Cloud DNS][product-docs]. -[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google's infrastructure for production-quality, high-volume DNS services. Google's global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world. + + +Cloud DNS Client Library for Node.js * [Cloud DNS Node.js Client API Reference][client-docs] -* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns) * [Cloud DNS Documentation][product-docs] +* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns) Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in [Client Libraries Explained][explained]. @@ -22,6 +25,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. **Table of contents:** + * [Quickstart](#quickstart) * [Before you begin](#before-you-begin) * [Installing the client library](#installing-the-client-library) @@ -35,58 +39,40 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. ### Before you begin -1. Select or create a Cloud Platform project. - - [Go to the projects page][projects] - -1. Enable billing for your project. - - [Enable billing][billing] - -1. Enable the Google Cloud DNS API. - - [Enable the API][enable_api] - +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Cloud DNS API][enable_api]. 1. [Set up authentication with a service account][auth] so you can access the API from your local workstation. -[projects]: https://console.cloud.google.com/project -[billing]: https://support.google.com/cloud/answer/6293499#enable-billing -[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com -[auth]: https://cloud.google.com/docs/authentication/getting-started - ### Installing the client library - npm install --save @google-cloud/dns +```bash +npm install @google-cloud/dns +``` + ### Using the client library ```javascript -// Imports the Google Cloud client library -const {DNS} = require('@google-cloud/dns'); + // Imports the Google Cloud client library + const {DNS} = require('@google-cloud/dns'); -// Your Google Cloud Platform project ID -const projectId = 'YOUR_PROJECT_ID'; - -// Creates a client -const dns = new DNS({ - projectId: projectId, -}); - -// Lists all zones in the current project -dns - .getZones() - .then(results => { - const zones = results[0]; + // Creates a client + const dns = new DNS(); + async function quickstart() { + // Lists all zones in the current project + const [zones] = await dns.getZones(); console.log('Zones:'); zones.forEach(zone => console.log(zone.name)); - }) - .catch(err => { - console.error('ERROR:', err); - }); + } + quickstart(); + ``` + + ## Samples Samples are in the [`samples/`](https://github.com/googleapis/nodejs-dns/tree/master/samples) directory. The samples' `README.md` @@ -94,7 +80,10 @@ has instructions for running the samples. | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | -| 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) | +| 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) | +| 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) | + + The [Cloud DNS Node.js Client API Reference][client-docs] documentation also contains samples. @@ -103,10 +92,15 @@ also contains samples. This library follows [Semantic Versioning](http://semver.org/). + + + This library is considered to be in **alpha**. This means it is still a work-in-progress and under active development. Any release is subject to backwards-incompatible changes at any time. + + More Information: [Google Cloud Platform Launch Stages][launch_stages] [launch_stages]: https://cloud.google.com/terms/launch-stages @@ -122,6 +116,9 @@ Apache Version 2.0 See [LICENSE](https://github.com/googleapis/nodejs-dns/blob/master/LICENSE) [client-docs]: https://cloud.google.com/nodejs/docs/reference/dns/latest/ -[product-docs]: https://cloud.google.com/dns/docs/ -[shell_img]: //gstatic.com/cloudssh/images/open-btn.png - +[product-docs]: https://cloud.google.com/dns +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started \ No newline at end of file diff --git a/packages/google-cloud-dns/package.json b/packages/google-cloud-dns/package.json index 0c5c6f20f87..30dffc4524a 100644 --- a/packages/google-cloud-dns/package.json +++ b/packages/google-cloud-dns/package.json @@ -28,7 +28,6 @@ ], "scripts": { "docs": "jsdoc -c .jsdoc.js", - "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", "lint": "gts check && eslint '**/*.js'", "test": "nyc mocha build/test", "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", @@ -52,7 +51,6 @@ "string-format-obj": "^1.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.0.0", "@types/lodash.groupby": "^4.6.4", "@types/mocha": "^5.2.5", "@types/node": "^10.9.4", diff --git a/packages/google-cloud-dns/samples/.eslintrc.yml b/packages/google-cloud-dns/samples/.eslintrc.yml index 0aa37ac630e..282535f55f6 100644 --- a/packages/google-cloud-dns/samples/.eslintrc.yml +++ b/packages/google-cloud-dns/samples/.eslintrc.yml @@ -1,4 +1,3 @@ --- rules: no-console: off - node/no-missing-require: off diff --git a/packages/google-cloud-dns/samples/README.md b/packages/google-cloud-dns/samples/README.md index 7e7acf210dd..25f555234a4 100644 --- a/packages/google-cloud-dns/samples/README.md +++ b/packages/google-cloud-dns/samples/README.md @@ -1,51 +1,66 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `python -m synthtool`." Google Cloud Platform logo -# Google Cloud DNS: Node.js Samples +# [Cloud DNS: Node.js Samples](https://github.com/googleapis/nodejs-dns) [![Open in Cloud Shell][shell_img]][shell_link] -[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google's infrastructure for production-quality, high-volume DNS services. Google's global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world. + ## Table of Contents * [Before you begin](#before-you-begin) * [Samples](#samples) - * [Zones](#zones) + * [List Zones](#list-zones) + * [Quickstart](#quickstart) ## Before you begin -Before running the samples, make sure you've followed the steps in the -[Before you begin section](../README.md#before-you-begin) of the client -library's README. +Before running the samples, make sure you've followed the steps outlined in +[Using the client library](https://github.com/googleapis/nodejs-dns#using-the-client-library). ## Samples -### Zones -View the [source code][zones_0_code]. -[![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) +### List Zones + +Lists all zones in the current project. + +View the [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) + +__Usage:__ + + +`node listZones` + + +----- + + + + +### Quickstart + +Fetches a list of all available zones. + +View the [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) + +__Usage:__ -__Usage:__ `node zones.js --help` -``` -zones.js +`node quickstart` -Commands: - zones.js list Lists all zones in the current project. -Options: - --version Show version number [boolean] - --help Show help [boolean] -Examples: - node zones.js list Lists all zones in the current project. -For more information, see https://cloud.google.com/dns/docs -``` -[zones_0_docs]: https://cloud.google.com/dns/docs -[zones_0_code]: zones.js -[shell_img]: //gstatic.com/cloudssh/images/open-btn.png +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png [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 +[product-docs]: https://cloud.google.com/dns \ No newline at end of file diff --git a/packages/google-cloud-dns/samples/package.json b/packages/google-cloud-dns/samples/package.json index 0c417b36c3b..2035e911390 100644 --- a/packages/google-cloud-dns/samples/package.json +++ b/packages/google-cloud-dns/samples/package.json @@ -11,15 +11,13 @@ "*.js" ], "scripts": { - "test": "mocha system-test --timeout 600000" + "test": "mocha --timeout 600000" }, "dependencies": { - "@google-cloud/dns": "^0.9.2", - "yargs": "^13.0.0" + "@google-cloud/dns": "^0.9.2" }, "devDependencies": { "chai": "^4.2.0", - "execa": "^1.0.0", "mocha": "^6.0.0", "uuid": "^3.3.0" } diff --git a/packages/google-cloud-dns/samples/quickstart.js b/packages/google-cloud-dns/samples/quickstart.js index 9f3121a5dd4..5c594ea4dc2 100644 --- a/packages/google-cloud-dns/samples/quickstart.js +++ b/packages/google-cloud-dns/samples/quickstart.js @@ -15,22 +15,27 @@ 'use strict'; -// [START dns_quickstart] -async function quickstart( - projectId = 'YOUR_PROJECT_ID' // Your GCP project Id -) { +// sample-metadata: +// name: Quickstart +// description: Fetches a list of all available zones. +// usage: node quickstart + +async function main() { + // [START dns_quickstart] // Imports the Google Cloud client library const {DNS} = require('@google-cloud/dns'); // Creates a client - const dns = new DNS({projectId}); + const dns = new DNS(); - // Lists all zones in the current project - const [zones] = await dns.getZones(); - console.log('Zones:'); - zones.forEach(zone => console.log(zone.name)); + async function quickstart() { + // Lists all zones in the current project + const [zones] = await dns.getZones(); + console.log('Zones:'); + zones.forEach(zone => console.log(zone.name)); + } + quickstart(); + // [END dns_quickstart] } -// [END dns_quickstart] -const args = process.argv.slice(2); -quickstart(...args).catch(console.error); +main(); diff --git a/packages/google-cloud-dns/src/index.ts b/packages/google-cloud-dns/src/index.ts index f9a0c0d4c95..b7c039ef59e 100644 --- a/packages/google-cloud-dns/src/index.ts +++ b/packages/google-cloud-dns/src/index.ts @@ -314,7 +314,8 @@ class DNS extends Service { callback!(err, null, null, resp); return; } - const zones = arrify(resp.managedZones).map(zone => { + // tslint:disable-next-line no-any + const zones = arrify(resp.managedZones).map((zone: any) => { const zoneInstance = this.zone(zone.name); zoneInstance.metadata = zone; return zoneInstance; diff --git a/packages/google-cloud-dns/src/zone.ts b/packages/google-cloud-dns/src/zone.ts index d5e26dae976..1f8345c63c3 100644 --- a/packages/google-cloud-dns/src/zone.ts +++ b/packages/google-cloud-dns/src/zone.ts @@ -1002,7 +1002,8 @@ import(localPath: string, callback?: CreateChangeCallback): void|Promise { const recordTypeSet = arrify(parsedZonefile[recordType]); - recordTypeSet.forEach(record => { + // tslint:disable-next-line no-any + recordTypeSet.forEach((record: any) => { record.ttl = record.ttl || defaultTTL; recordsToCreate.push(Record.fromZoneRecord_(this, recordType, record)); }); diff --git a/packages/google-cloud-dns/synth.metadata b/packages/google-cloud-dns/synth.metadata index b5945ea42d3..4b4d58098b1 100644 --- a/packages/google-cloud-dns/synth.metadata +++ b/packages/google-cloud-dns/synth.metadata @@ -1,11 +1,11 @@ { - "updateTime": "2019-03-08T00:45:37.531320Z", + "updateTime": "2019-05-01T19:31:02.875460Z", "sources": [ { "template": { "name": "node_library", "origin": "synthtool.gcp", - "version": "2019.1.16" + "version": "2019.4.10" } } ]