Skip to content

Commit

Permalink
doc: update README with info on events (#18)
Browse files Browse the repository at this point in the history
* doc: update README with info on events

Also document `setDefaultHandlers()`.
  • Loading branch information
jinwoo authored Jan 9, 2018
1 parent 7a1b1d2 commit 34e9a5e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ gulp.task('check_licenses', function() {

### Methods

* `LicenseChecker#setDefaultHandler()`

```typescript
setDefaultHandlers(): void;
```

Sets the default event handlers that are used by the CLI. For events
emitted by `LicenseChecker`, see the [*Events*](#hd-events) subsection.

* `LicenseChecker#checkLocalDirectory()`

```typescript
Expand Down Expand Up @@ -244,9 +253,9 @@ gulp.task('check_licenses', function() {
This method reads in the configuration from the `js-green-licenses.json`
file in the repository, if it exists.

`GitHubRepository` is a helper class for interacting with the GitHub API. You
can create its instance by calling
`LicenseChecker#prPathToGitHubRepoAndId()`.
`GitHubRepository` is a helper class for interacting with the GitHub API.
You can create its instance by calling
`LicenseChecker#prPathToGitHubRepoAndId()`.

* `LicenseChecker#prPathToGitHubRepoAndId()`

Expand All @@ -261,6 +270,42 @@ can create its instance by calling
will return the `GitHubRepository` instance and the PR id for the
`prPath`.

### <a name="hd-events"></a>Events

A `LicenseChecker` object emits following events during its processing.

* `non-green-license`
Emitted when a package with a non-green license is detected. The argument is
```typescript
interface NonGreenLicense {
packageName: string;
version: string;
licenseName: string|null;
parentPackages: string[];
}
```

* `package.json`
Emitted for each `package.json` file being checked. This is emitted only
when checking local repositories or GitHub repositories, but not when
checking remote packages.

The argument is a file path string of the corresponding `package.json` file.

* `end`
Emitted when the processing is done. No argument is given.

* `error`
Emitted when an error occurrs while processing. The argument is
```typescript
interface CheckError {
err: Error;
packageName: string;
versionSpec: string;
parentPackages: string[];
}
```

[circle-image]: https://circleci.com/gh/google/js-green-licenses.svg?style=svg
[circle-url]: https://circleci.com/gh/google/js-green-licenses
[codecov-image]: https://codecov.io/gh/google/js-green-licenses/branch/master/graph/badge.svg
Expand Down
2 changes: 1 addition & 1 deletion ts/src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class LicenseChecker extends EventEmitter {
}

/** set default event handlers for CLI output. */
setDefaultHandlers() {
setDefaultHandlers(): void {
let nonGreenCount = 0;
let errorCount = 0;
this.on('non-green-license',
Expand Down

0 comments on commit 34e9a5e

Please sign in to comment.