diff --git a/src/generator/generator.ts b/src/generator/generator.ts index e62720b8d47..f88f0101f0c 100644 --- a/src/generator/generator.ts +++ b/src/generator/generator.ts @@ -296,6 +296,11 @@ export class Generator { const tsPath = path.join(apisPath, file, 'tsconfig.json'); const tsResult = this.env.render('tsconfig.json.njk'); await writeFile(tsPath, tsResult); + // generate the webpack.config.js + const wpPath = path.join(apisPath, file, 'webpack.config.js'); + const wpResult = + this.env.render('webpack.config.js.njk', {name: file}); + await writeFile(wpPath, wpResult); } } } diff --git a/src/generator/templates/README.md.njk b/src/generator/templates/README.md.njk index d79017a4413..bd54e3ba8bb 100644 --- a/src/generator/templates/README.md.njk +++ b/src/generator/templates/README.md.njk @@ -11,17 +11,37 @@ $ npm install @google/{{name}} ``` ## Usage -All documentation and usage information can be found on [GitHub](https://github.com/google/google-api-nodejs-client). +All documentation and usage information can be found on [GitHub](https://github.com/googleapis/google-api-nodejs-client). + +## Building a browser bundle + +This library can be used in a browser. To prepare a single file bundle, clone the +[repository](https://github.com/googleapis/google-api-nodejs-client) and run + +```sh +$ cd src/apis/{{name}} +$ npm install +$ npm run webpack +``` + +The generated bundle will be written to `dist/{{name}}.min.js`. Use it from your HTML file: + +```html + + +``` ## License -This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/google/google-api-nodejs-client/blob/master/LICENSE). +This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/googleapis/google-api-nodejs-client/blob/master/LICENSE). ## Contributing We love contributions! Before submitting a Pull Request, it's always good to start with a new issue first. To learn more, see [CONTRIBUTING](https://github.com/google/google-api-nodejs-client/blob/master/.github/CONTRIBUTING.md). ## Questions/problems? * Ask your development related questions on [StackOverflow](http://stackoverflow.com/questions/tagged/google-api-nodejs-client). -* If you've found an bug/issue, please [file it on GitHub](https://github.com/google/google-api-nodejs-client/issues). +* If you've found an bug/issue, please [file it on GitHub](https://github.com/googleapis/google-api-nodejs-client/issues). *Crafted with ❤️ by the Google Node.js team* diff --git a/src/generator/templates/api-endpoint.njk b/src/generator/templates/api-endpoint.njk index cd76098a20c..1ef7bc190ed 100644 --- a/src/generator/templates/api-endpoint.njk +++ b/src/generator/templates/api-endpoint.njk @@ -3,7 +3,7 @@ {% set lb = "{" %} {% set rb = "}" %} /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/generator/templates/api-index.njk b/src/generator/templates/api-index.njk index 879f0cc7dc7..1ba6a506360 100644 --- a/src/generator/templates/api-index.njk +++ b/src/generator/templates/api-index.njk @@ -1,4 +1,4 @@ -// Copyright 2018, Google, LLC. +// Copyright 2019 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -13,7 +13,7 @@ /*! THIS FILE IS AUTO-GENERATED */ -import {getAPI, GoogleConfigurable} from 'googleapis-common'; +import {AuthPlus, getAPI, GoogleConfigurable} from 'googleapis-common'; {% for versionName, version in api %} import { {{ name }}_{{ version|replace('.','_') }} } from './{{ version }}'; {% endfor %} @@ -32,3 +32,6 @@ export const VERSIONS = { export function {{ name }}(this: GoogleConfigurable, versionOrOptions: {% for versionName, version in api %}'{{ version|replace('.','_') }}'|{{ name }}_{{ version|replace('.','_') }}.Options{% if not loop.last %}|{% endif %}{% endfor %}) { return getAPI('{{ name }}', versionOrOptions, VERSIONS, this); } + +const auth = new AuthPlus(); +export {auth}; diff --git a/src/generator/templates/index.njk b/src/generator/templates/index.njk index 69fd8c97842..6236b1320c0 100644 --- a/src/generator/templates/index.njk +++ b/src/generator/templates/index.njk @@ -1,4 +1,4 @@ -// Copyright 2012-2016, Google, Inc. +// Copyright 2019 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/generator/templates/package.json.njk b/src/generator/templates/package.json.njk index 07cb438e8dd..219f2d744c9 100644 --- a/src/generator/templates/package.json.njk +++ b/src/generator/templates/package.json.njk @@ -4,16 +4,18 @@ "description": "{{name}}", "main": "build/index.js", "types": "build/index.d.ts", - "keywords": ["google"], + "keywords": [ + "google" + ], "author": "Google LLC", "license": "Apache-2.0", - "homepage": "https://github.com/google/google-api-nodejs-client", + "homepage": "https://github.com/googleapis/google-api-nodejs-client", "bugs": { - "url" : "https://github.com/google/google-api-nodejs-client/issues" + "url": "https://github.com/googleapis/google-api-nodejs-client/issues" }, "repository": { "type": "git", - "url" : "https://github.com/google/google-api-nodejs-client.git" + "url": "https://github.com/googleapis/google-api-nodejs-client.git" }, "engines": { "node": ">=6.0.0" @@ -23,14 +25,19 @@ "lint": "gts check", "compile": "tsc -p .", "prepare": "npm run compile", - "docs": "typedoc --out docs/" + "docs": "typedoc --out docs/", + "webpack": "webpack" }, "dependencies": { - "googleapis-common": "^0.4.0" + "googleapis-common": "^0.6.0" }, "devDependencies": { "gts": "^0.9.0", + "null-loader": "^0.1.1", + "ts-loader": "^5.3.3", + "typedoc": "^0.14.0", "typescript": "~3.2.0", - "typedoc": "^0.14.0" + "webpack": "^4.28.4", + "webpack-cli": "^3.2.1" } } diff --git a/src/generator/templates/root-index.njk b/src/generator/templates/root-index.njk index 9e237cc08a6..a08378c27bf 100644 --- a/src/generator/templates/root-index.njk +++ b/src/generator/templates/root-index.njk @@ -1,5 +1,5 @@ /** - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/generator/templates/webpack.config.js.njk b/src/generator/templates/webpack.config.js.njk new file mode 100644 index 00000000000..218902d248a --- /dev/null +++ b/src/generator/templates/webpack.config.js.njk @@ -0,0 +1,71 @@ +/** + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Use `npm run webpack` to produce Webpack bundle for this library. + +const path = require('path'); + +module.exports = { + entry: './index.ts', + resolve: { + extensions: ['.ts', '.js', '.json'], + }, + output: { + library: '{{ name|capitalize }}', + filename: '{{ name }}.min.js', + path: path.resolve(__dirname, 'dist'), + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + module: { + rules: [ + { + test: /node_modules\/google-auth-library\/src\/crypto\/node\/crypto/, + use: 'null-loader', + }, + { + test: /node_modules\/https-proxy-agent\//, + use: 'null-loader', + }, + { + test: /node_modules\/gcp-metadata\//, + use: 'null-loader', + }, + { + test: /node_modules\/gtoken\//, + use: 'null-loader', + }, + { + test: /node_modules\/pkginfo\//, + use: 'null-loader', + }, + { + test: /node_modules\/semver\//, + use: 'null-loader', + }, + { + test: /\.ts$/, + use: 'ts-loader', + exclude: /node_modules/, + }, + ], + }, + mode: 'production', + plugins: [], +};