Skip to content

Commit

Permalink
feat: export bundled types for TypeScript (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jun 19, 2020
1 parent 9a3150b commit 62f8193
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,7 @@
"clean": "gts clean",
"fix": "gts fix",
"pregenerate": "npm run build-tools",
"generate": "node build/src/generator/generate.js",
"generate": "node build/src/generator/generator.js",
"docs-test": "echo 🙈 this was taking too long and timing out CI",
"presubmit-prs": "npm run compile",
"submit-prs": "node build/src/generator/synth.js",
Expand Down
46 changes: 0 additions & 46 deletions src/generator/generate.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/generator/generator.ts
Expand Up @@ -21,6 +21,9 @@ import {URL} from 'url';
import * as util from 'util';
import Q from 'p-queue';
import * as prettier from 'prettier';
import * as minimist from 'yargs-parser';
import * as rimraf from 'rimraf';
import {DISCOVERY_URL} from './download';
import {downloadDiscoveryDocs, ChangeSet} from './download';
import * as filters from './filters';
import {addFragments} from './samplegen';
Expand Down Expand Up @@ -264,3 +267,30 @@ export class Generator {
await writeFile(outputPath, output, {encoding: 'utf8'});
}
}

async function main() {
const argv = minimist(process.argv.slice(2));
const discoveryUrl = argv['discovery-url'];
const useCache = argv['use-cache'];

console.log(`useCache: ${useCache}`);

const gen = new Generator({debug: true, includePrivate: false});
if (!discoveryUrl && argv._.length > 0) {
argv._.forEach(async url => {
await gen.generateAPI(url);
console.log('Generated API for ' + url);
});
} else {
console.log('Removing old APIs...');
const apiPath = path.join(__dirname, '../../../src/apis');
await util.promisify(rimraf)(apiPath);
console.log('Generating APIs...');
await gen.generateAllAPIs(discoveryUrl || DISCOVERY_URL, useCache);
console.log('Finished generating APIs!');
}
}

if (require.main === module) {
main().catch(console.error);
}
2 changes: 2 additions & 0 deletions src/generator/templates/root-index.njk
Expand Up @@ -4,6 +4,8 @@
import {GoogleApis} from './googleapis';
const google = new GoogleApis();
export {google, GoogleApis};
export * as Common from 'googleapis-common';
export * as Auth from 'google-auth-library';

{% for apiName, api in apis %}
{% for versionName, version in api %}export { {{ apiName }}_{{ version|replace('.','_') }} } from './apis/{{ apiName }}/{{ version }}';
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Expand Up @@ -15,6 +15,8 @@
import {GoogleApis} from './googleapis';
const google = new GoogleApis();
export {google, GoogleApis};
export * as Common from 'googleapis-common';
export * as Auth from 'google-auth-library';

export {abusiveexperiencereport_v1} from './apis/abusiveexperiencereport/v1';
export {acceleratedmobilepageurl_v1} from './apis/acceleratedmobilepageurl/v1';
Expand Down
26 changes: 26 additions & 0 deletions test/test.index.ts
@@ -0,0 +1,26 @@
// Copyright 2020 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.

import {describe, it} from 'mocha';
import {Auth, Common} from '../src';

/* eslint-disable @typescript-eslint/no-unused-vars */

describe(__filename, () => {
it('should export bundled package interfaces', () => {
let p: Auth.OAuth2Client;
let q: Auth.Credentials;
let t: Common.StreamMethodOptions;
let v: Common.SchemaResource;
});
});

0 comments on commit 62f8193

Please sign in to comment.