Skip to content

Commit

Permalink
Merge pull request #99 from SimplrJS/dev
Browse files Browse the repository at this point in the history
v4.0.0-rc.1
  • Loading branch information
Martynas Žilinskas authored Jan 30, 2018
2 parents bc2670d + 2d9865c commit 10f8508
Show file tree
Hide file tree
Showing 269 changed files with 4,011 additions and 7,687 deletions.
1,751 changes: 1,599 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-extractor",
"version": "4.0.0-beta.8",
"version": "4.0.0-rc.1",
"description": "TypeScript AST extractor to useful JSON structure.",
"keywords": [
"typescript",
Expand All @@ -27,7 +27,7 @@
"test-watch": "start npm run build-tests -- --watchAll && jest --watchAll",
"build": "tsc -p .",
"build-watch": "npm run build -- -w",
"build-tests": "cd tests && ts-node ./build-tests.ts -p ./",
"build-tests": "test-generator-cli",
"prepublishOnly": "npm run build && rimraf dist/debug.*",
"travis-release": "node ./tools/travis-release/release.js"
},
Expand All @@ -46,10 +46,10 @@
"typescript": "^2.6.2"
},
"devDependencies": {
"@simplrjs/test-generator-cli": "^0.1.3",
"@types/globby": "^6.1.0",
"@types/jest": "^21.1.9",
"coveralls": "^3.0.0",
"globby": "^7.1.1",
"jest": "^22.0.3",
"rimraf": "^2.6.2",
"simplr-tslint": "0.0.1",
Expand Down
25 changes: 24 additions & 1 deletion src/api-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ export namespace ApiHelpers {
const declarationSourceFile = declaration.getSourceFile();
const declarationFileName = declarationSourceFile.fileName;

// External library.
if (options.Program.isSourceFileFromExternalLibrary(declarationSourceFile)) {
const match = declarationSourceFile.fileName.match(NODE_MODULES_PACKAGE_REGEX);
const packageName = match != null ? match[1] : undefined;

if (packageName != null) {
// Check if PackageName is in external packages.
return options.ExternalPackages.
findIndex(x => x.toLowerCase() === packageName.toLowerCase()) !== -1;
} else {
Expand All @@ -133,6 +135,19 @@ export namespace ApiHelpers {
} else if (!PathIsInside(declarationFileName, options.ExtractorOptions.ProjectDirectory)) {
// If it's not external package, it should be in project directory.
return false;
} else if (options.ExtractorOptions.Exclude != null) {
// Exclude file name.
const result = options.ExtractorOptions.Exclude
.findIndex(excludeItem => {
const fullPath = path
.resolve(options.ExtractorOptions.ProjectDirectory, excludeItem)
.split(path.sep)
.join(options.ExtractorOptions.OutputPathSeparator);

return fullPath === declarationFileName;
});

return result === -1;
}

return true;
Expand Down Expand Up @@ -198,6 +213,11 @@ export namespace ApiHelpers {
}
}

// If symbol doesn't have resolved api definitions.
if (symbolItems.length === 0) {
return undefined;
}

return {
Alias: symbol.name,
Ids: symbolItems
Expand All @@ -208,7 +228,7 @@ export namespace ApiHelpers {
declarations: ts.NodeArray<ts.Declaration>,
options: ApiItemOptions
): ApiItemReference[] {
const items: ApiItemReference[] = [];
let items: ApiItemReference[] = [];
const typeChecker = options.Program.getTypeChecker();

declarations.forEach(declaration => {
Expand All @@ -234,6 +254,9 @@ export namespace ApiHelpers {
}
});

// If symbol doesn't have resolved api definitions.
items = items.filter(x => x.Ids.length !== 0);

return items;
}

Expand Down
14 changes: 13 additions & 1 deletion src/contracts/extractor-options.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import * as ts from "typescript";

export interface ExtractorOptions {
/**
* TypeScript compiler options.
*/
CompilerOptions: ts.CompilerOptions;
/**
* Full path to TypeScript project directory.
*/
ProjectDirectory: string;
/**
* Not Yet implemented.
* File locations that should not be included in extracted data.
*/
Exclude?: string[];
/**
* Used to standartize paths in extracted data.
*/
OutputPathSeparator?: string;
/**
* Package names to include in extracted data.
*/
ExternalPackages?: string[];
/**
* Include TypeScript specific information in extracted data.
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/api-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ApiExport extends ApiItem<ts.ExportDeclaration, ApiExportDto> {
// Extract members from Source file.
const sourceFileDeclaration = TsHelpers.ResolveSourceFile(this.Declaration, this.Options.Program);

if (sourceFileDeclaration != null) {
if (sourceFileDeclaration != null && ApiHelpers.ShouldVisit(sourceFileDeclaration, this.Options)) {
const sourceFileSymbol = TsHelpers.GetSymbolFromDeclaration(sourceFileDeclaration, this.TypeChecker);

if (sourceFileSymbol != null) {
Expand Down
38 changes: 0 additions & 38 deletions tests/build-tests.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/cases/ExportDeclaration1.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/cases/ExportSpecifier1.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/cases/ExportSpecifier2.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/cases/ExportSpecifier3.ts

This file was deleted.

3 changes: 0 additions & 3 deletions tests/cases/ImportDeclaration1.ts

This file was deleted.

3 changes: 0 additions & 3 deletions tests/cases/ImportSpecifier1.ts

This file was deleted.

Loading

0 comments on commit 10f8508

Please sign in to comment.