Skip to content

Commit

Permalink
Feature: Logging (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martynas Žilinskas authored Feb 1, 2018
1 parent 58a9651 commit abd21be
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 80 deletions.
38 changes: 19 additions & 19 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions packages/ts-docs-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ ts-docs-gen --config ./docs-gen.json
## Configuration
JSON config properties and CLI flags.

| Property | CLI Flag | Required | Type | Default | Description |
| ------------------- | --------------------- | ---------- | -------- | ----------- | ------------------------------------------------------------------------------------- |
| | `--config` | _optional_ | string | | Relative path to config json file. |
| `entryFile` | `--entryFile` | _required_ | string[] | | TypeScript project entry files. |
| `project` | `--project`, `-p` | _optional_ | string | cwd | Full path to TypeScript project directory. |
| `output` | `--output`, `-o` | _optional_ | string | ./docs/api/ | Documentation output directory. |
| `plugin` | `--plugin` | _optional_ | string[] | | Package name or path to plugin. |
| `exclude` | `--exclude` | _optional_ | string[] | | File locations that should not be included generated documentation. |
| `externalPackage` | `--externalPackage` | _optional_ | string[] | | External package names to include in extracted data. |
| `excludePrivateApi` | `--excludePrivateApi` | _optional_ | boolean | `true` | Excludes api items that has access modifier set to "private" or JSDoc tag "@private". |
| Property | CLI Flag | Required | Type | Default | Description |
| ------------------- | --------------------- | ---------- | ----------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------ |
| | `--config` | _optional_ | string | | Relative path to config json file. |
| `entryFile` | `--entryFile` | _required_ | string[] | | TypeScript project entry files. |
| `project` | `--project`, `-p` | _optional_ | string | cwd | Full path to TypeScript project directory. |
| `output` | `--output`, `-o` | _optional_ | string | ./docs/api/ | Documentation output directory. |
| `plugin` | `--plugin` | _optional_ | string[] | | Package name or path to plugin. |
| `exclude` | `--exclude` | _optional_ | string[] | | File locations that should not be included generated documentation. |
| `externalPackage` | `--externalPackage` | _optional_ | string[] | | External package names to include in extracted data. |
| `excludePrivateApi` | `--excludePrivateApi` | _optional_ | boolean | `true` | Excludes api items that has access modifier set to "private" or JSDoc tag "@private". |
| `verbosity` | `--verbosity` | _optional_ | "None", "Critical", "Error", "Warning", "Information", "Debug", "Trace" | "Information" | Verbosity of output. |
| `dryRun` | `--dryRun` | _optional_ | boolean | | Generates markdown files but not writes them. Outputs generated data in `Debug` log level. |
4 changes: 2 additions & 2 deletions packages/ts-docs-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@types/yargs": "^10.0.1",
"fs-extra": "^5.0.0",
"simplr-logger": "^1.0.1",
"ts-extractor": "^4.0.0-rc.2",
"typescript": "^2.6.2",
"ts-extractor": "^4.0.0-rc.4",
"typescript": "^2.7.1",
"yargs": "^11.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-docs-gen/src/api-items/api-callable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ReferenceRenderHandler } from "../contracts/serialized-api-item";
* Base class for callable api items.
*/
export abstract class ApiCallable<TKind extends Contracts.ApiCallableBaseDefinition> extends ApiDefinitionBase<TKind> {
private parameters: ApiParameter[];
private parameters: ApiParameter[] | undefined;

public get Parameters(): ApiParameter[] {
if (this.parameters == null) {
Expand All @@ -23,7 +23,7 @@ export abstract class ApiCallable<TKind extends Contracts.ApiCallableBaseDefinit
return this.parameters;
}

private typeParameters: ApiTypeParameter[];
private typeParameters: ApiTypeParameter[] | undefined;

public get TypeParameters(): ApiTypeParameter[] {
if (this.typeParameters == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ApiBaseItemContainerDto = Contracts.ApiBaseDefinition & { Members: C
export abstract class ApiDefinitionContainer<TKind extends ApiBaseItemContainerDto = ApiBaseItemContainerDto>
extends ApiDefinitionBase<TKind> {

private members: ApiDefinitions[];
private members: ApiDefinitions[] | undefined;

public get Members(): ApiDefinitions[] {
if (this.members == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ApiBaseItemWithTypeDto = Contracts.ApiBaseDefinition & { Type: Contr
export abstract class ApiDefinitionWithType<TKind extends ApiBaseItemWithTypeDto = ApiBaseItemWithTypeDto>
extends ApiDefinitionBase<TKind> {

private type: ApiTypes;
private type: ApiTypes | undefined;

public get Type(): ApiTypes {
if (this.type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GeneratorHelpers } from "../generator-helpers";
import { ApiTypes } from "./api-type-list";

export abstract class ApiTypeMembersBase<TKind extends Contracts.ApiMembersBaseType> extends ApiTypeBase<TKind> {
private members: ApiTypes[];
private members: ApiTypes[] | undefined;

public get Members(): ApiTypes[] {
if (this.members == null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-docs-gen/src/api-items/definitions/api-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ApiTypeParameter } from "./api-type-parameter";
import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";

export class ApiClass extends ApiDefinitionContainer<Contracts.ApiClassDto> {
private typeParameters: ApiTypeParameter[];
private typeParameters: ApiTypeParameter[] | undefined;

public get TypeParameters(): ApiTypeParameter[] {
if (this.typeParameters == null) {
Expand All @@ -23,7 +23,7 @@ export class ApiClass extends ApiDefinitionContainer<Contracts.ApiClassDto> {
return this.extends;
}

private implements: ApiTypes[];
private implements: ApiTypes[] | undefined;

public get Implements(): ApiTypes[] {
if (this.implements == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-docs-gen/src/api-items/definitions/api-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ApiItemReference } from "../../contracts/api-item-reference";
import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";

export class ApiEnum extends ApiDefinitionBase<Contracts.ApiEnumDto> {
private enumMembers: ApiEnumMember[];
private enumMembers: ApiEnumMember[] | undefined;

public get EnumMembers(): ApiEnumMember[] {
if (this.enumMembers == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiDefinitionWithType } from "../api-definition-with-type";
import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";

export class ApiIndex extends ApiDefinitionWithType<Contracts.ApiIndexDto> {
private parameter: ApiParameter;
private parameter: ApiParameter | undefined;

public get Parameter(): ApiParameter {
if (this.parameter == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ApiTypeParameter } from "./api-type-parameter";
import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";

export class ApiInterface extends ApiDefinitionContainer<Contracts.ApiInterfaceDto> {
private typeParameters: ApiTypeParameter[];
private typeParameters: ApiTypeParameter[] | undefined;

public get TypeParameters(): ApiTypeParameter[] {
if (this.typeParameters == null) {
Expand All @@ -17,7 +17,7 @@ export class ApiInterface extends ApiDefinitionContainer<Contracts.ApiInterfaceD
return this.typeParameters;
}

private extends: ApiTypes[];
private extends: ApiTypes[] | undefined;

public get Extends(): ApiTypes[] {
if (this.extends == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GeneratorHelpers } from "../../generator-helpers";
import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";

export class ApiTypeAlias extends ApiDefinitionWithType<Contracts.ApiTypeAliasDto> {
private typeParameters: ApiTypeParameter[];
private typeParameters: ApiTypeParameter[] | undefined;

public get TypeParameters(): ApiTypeParameter[] {
if (this.typeParameters == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-docs-gen/src/api-items/types/api-type-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";
* Example: `Foo[]`
*/
export class ApiTypeArray extends ApiTypeBase<Contracts.ArrayTypeDto> {
private type: ApiTypes;
private type: ApiTypes | undefined;

public get Type(): ApiTypes {
if (this.type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SerializedApiType, ReferenceRenderHandler } from "../../contracts/seria
* Example: `Foo[T]`
*/
export class ApiIndexedAccess extends ApiTypeBase<Contracts.IndexedAccessTypeDto> {
private objectType: SerializedApiType;
private objectType: SerializedApiType | undefined;

public get ObjectType(): SerializedApiType {
if (this.objectType == null) {
Expand All @@ -16,7 +16,7 @@ export class ApiIndexedAccess extends ApiTypeBase<Contracts.IndexedAccessTypeDto
return this.objectType;
}

private indexType: SerializedApiType;
private indexType: SerializedApiType | undefined;

public get IndexType(): SerializedApiType {
if (this.indexType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";
* Example: `keyof Foo`
*/
export class ApiTypeOperator extends ApiTypeBase<Contracts.TypeOperatorTypeDto> {
private type: ApiTypes;
private type: ApiTypes | undefined;

public get Type(): ApiTypes {
if (this.type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";
* Example: `(string | number)`
*/
export class ApiTypeParenthesized extends ApiTypeBase<Contracts.ParenthesizedTypeDto> {
private type: ApiTypes;
private type: ApiTypes | undefined;

public get Type(): ApiTypes {
if (this.type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReferenceRenderHandler } from "../../contracts/serialized-api-item";
* Example: `arg is string`
*/
export class ApiTypePredicate extends ApiTypeBase<Contracts.TypePredicateTypeDto> {
private type: ApiTypes;
private type: ApiTypes | undefined;

public get Type(): ApiTypes {
if (this.type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Plugin } from "../contracts/plugin";
import { PluginRegistry } from "../registries/plugin-registry";
import { DefaultPlugins } from "../default-plugins";
import { GeneratorHelpers } from "../generator-helpers";
import { LoggerHelpers } from "../utils/logger";

export class GeneratorConfigurationBuilder {
constructor(private projectDirectory: string) {
Expand All @@ -18,7 +19,7 @@ export class GeneratorConfigurationBuilder {
private configuration: Partial<WorkingGeneratorConfiguration> = {
excludePrivateApi: true
};
private compilerOptions: Partial<ts.CompilerOptions>;
private compilerOptions: Partial<ts.CompilerOptions> | undefined;
private tsConfigLocation: string | undefined;

private resolveProjectDirectory(): string {
Expand Down Expand Up @@ -95,6 +96,10 @@ export class GeneratorConfigurationBuilder {
}

public async Build(entryFiles: string[]): Promise<GeneratorConfiguration> {
// Verbosity level.
if (this.configuration.verbosity != null) {
LoggerHelpers.SetLogLevel(this.configuration.verbosity);
}

// Register all plugins.
const pluginManager = new PluginRegistry();
Expand Down Expand Up @@ -124,7 +129,8 @@ export class GeneratorConfigurationBuilder {
Exclude: this.configuration.exclude,
OutputPathSeparator: this.configuration.outputPathSeparator,
ExternalPackages: this.configuration.externalPackage,
FilterApiItems: this.extractorFilterApiItem
FilterApiItems: this.extractorFilterApiItem,
Verbosity: this.configuration.verbosity
});

// Output directory
Expand Down
14 changes: 14 additions & 0 deletions packages/ts-docs-gen/src/cli/arguments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as yargs from "yargs";
import { LogLevel } from "simplr-logger";
import { LoggerHelpers } from "../utils/logger";

export interface CliFlags {
project: string;
Expand All @@ -8,6 +10,8 @@ export interface CliFlags {
exclude?: string[];
externalPackage?: string[];
excludePrivateApi?: boolean;
verbosity?: string;
dryRun?: boolean;
}

export type CliArguments = CliFlags & yargs.Arguments;
Expand Down Expand Up @@ -59,4 +63,14 @@ export const ArgsHandler = yargs
describe: "Package name or path to plugin.",
type: "array"
})
.option(flagName("verbosity"), {
describe: "Verbosity of output.",
type: "string",
choices: LoggerHelpers.GetLogLevelKeys(),
default: LogLevel[LogLevel.Information]
})
.option(flagName("dryRun"), {
describe: "Generates markdown files but not writes them.",
type: "boolean"
})
.argv as CliArguments;
Loading

0 comments on commit abd21be

Please sign in to comment.