Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generating webpackable packages #1547

Merged
merged 7 commits into from Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/generator/generator.ts
Expand Up @@ -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);
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/generator/templates/README.md.njk
Expand Up @@ -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
<script src="/path/to/{{name}}.min.js"></script>
<script>
const { {{name}}, auth } = {{name|capitalize}};
</script>
```

## 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*
2 changes: 1 addition & 1 deletion src/generator/templates/api-endpoint.njk
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions 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
Expand All @@ -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 %}
Expand All @@ -32,3 +32,6 @@ export const VERSIONS = {
export function {{ name }}<T = {% for versionName, version in api %}{{ name }}_{{ version|replace('.','_') }}.{{name|capitalize}}{% if not loop.last %}|{% endif %}{% endfor %}>(this: GoogleConfigurable, versionOrOptions: {% for versionName, version in api %}'{{ version|replace('.','_') }}'|{{ name }}_{{ version|replace('.','_') }}.Options{% if not loop.last %}|{% endif %}{% endfor %}) {
return getAPI<T>('{{ name }}', versionOrOptions, VERSIONS, this);
}

const auth = new AuthPlus();
export {auth};
2 changes: 1 addition & 1 deletion 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
Expand Down
21 changes: 14 additions & 7 deletions src/generator/templates/package.json.njk
Expand Up @@ -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"
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion 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.
Expand Down
71 changes: 71 additions & 0 deletions 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: [],
};