Skip to content

Adding custom external @types .d.ts files, ExternalApiHelper to create json files on external .d.ts - #52

Merged
Dan Gaeta (dgaeta) merged 19 commits into
masterfrom
dagaeta/external-api-helper
Jan 24, 2017
Merged

Dan Gaeta (dgaeta) merged 19 commits into
masterfrom
dagaeta/external-api-helper

Conversation

@dgaeta

Copy link
Copy Markdown
Contributor

No description provided.

Dan Gaeta (dgaeta) and others added 12 commits January 18, 2017 14:42
# Conflicts:
#	common/npm-shrinkwrap.json
#	common/temp_modules/rush-api-extractor/package.json
#	common/temp_modules/rush-gulp-core-build-karma/package.json
#	common/temp_modules/rush-gulp-core-build-mocha/package.json
#	common/temp_modules/rush-gulp-core-build-sass/package.json
#	common/temp_modules/rush-gulp-core-build-serve/package.json
#	common/temp_modules/rush-gulp-core-build-typescript/package.json
#	common/temp_modules/rush-gulp-core-build-webpack/package.json
#	common/temp_modules/rush-gulp-core-build/package.json
#	common/temp_modules/rush-node-library-build/package.json
#	common/temp_modules/rush-package-deps-hash/package.json
#	common/temp_modules/rush-web-library-build/package.json
Comment thread gulp-core-build-typescript/gulpfile.js Outdated
// We need to wrap this class in a getter because it hasn't been compiled by the time this file is executed
const taskWrapper = {};
Object.defineProperty(taskWrapper, "default", {
get: () => require('./lib/RunApiExtractorOnExternalApiTypes.js').default

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ian Clanton-Thuon (@iclanton) nickpape-msft The idea of ExternalApiHelper.generateApiJson() was to push all the complicated logic down into a TypeScript function that could be compiled as part of api-extractor, so that the gulpfile would just be a few simple lines that invoke it. This would eliminate the need for a weird wrapper that uses the gulpfile to compile part of its own code.

The one wrinkle is that api-extractor should not have a dependency on GulpTask, so you would need to solve that somehow. Is that doable?

public executeTask(gulp: gulp.Gulp, completeCallback?: (result?: Object) => void): void {
let outputPath: string = path.join(this.buildConfig.rootPath, this.buildConfig.distFolder);
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the last step of the build, surely the "dist" folder would already exist, right?

import { GulpTask } from '@microsoft/gulp-core-build';
import { ExternalApiHelper } from '@microsoft/api-extractor';

const files: string[] = ['external-api-types/es6-collections/index.d.ts',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top-level folders for our NPM packages are always standard roles such as "src", "temp", "typings", etc.

To solve this problem, maybe we coudl define a "resources" folder that would contain other build inputs that are not source code. So the path name would be something like:

./resources/external-types/es6-collections

@@ -0,0 +1,111 @@
// Type definitions for fetch API

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the top of this file, we should have a note like this:

"Typings based on DefinitelyTyped definitions from whatwg-fetch@1.2.3"

But delete all other source code comments, since we will be authoring our own original content.

@octogonz Pete Gonzalez (octogonz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

import Analyzer from './Analyzer';
import ApiJsonGenerator from './generators/ApiJsonGenerator';

export default class ExternalApiHelper {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some JSDoc explaining what this thing is, how it is used, etc.


export default class ExternalApiHelper {

public static generateApiJson(rootDir: string, libFolder: string, externalPackageFilePath: string): void {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document these parameters. Mainly it would be helpful to have an example string for each parameter (e.g. is it a relative or absolute path, etc)


// Typings based on DefinitelyTyped definitions from es6-collections@0.5.1

/* tslint:disable: interface-name */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't running tslint, so we don't need these directives

@octogonz Pete Gonzalez (octogonz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments

@dgaeta
Dan Gaeta (dgaeta) merged commit be36a34 into master Jan 24, 2017
Pete Gonzalez (octogonz) pushed a commit that referenced this pull request Feb 13, 2017
Adding custom external @types .d.ts files, ExternalApiHelper to create json files on external .d.ts
Christian Gonzalez (christiango) pushed a commit to christiango/web-build-tools that referenced this pull request Aug 22, 2017
…elper

Adding custom external @types .d.ts files, ExternalApiHelper to create json files on external .d.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants