ts-quick-docs
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,2 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
@@ -2,0 +3,0 @@ var ts = require("typescript"); |
{ | ||
"name": "ts-quick-docs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "quick TypeScript documentation extractor", | ||
@@ -8,3 +8,3 @@ "bin": "index.js", | ||
"dependencies": { | ||
"typescript": ">=1.8.10" | ||
"typescript": ">=2.0.0" | ||
}, | ||
@@ -16,7 +16,7 @@ "devDependencies": { | ||
"scripts": { | ||
"all": "npm run clean && npm run compile && npm run mocha", | ||
"clean": "rm -rf {.,src,test}/*.{js,d.ts}", | ||
"compile": "tsc --project .", | ||
"mocha": "mocha --slow 400", | ||
"all": "npm run clean && npm run compile && npm run mocha", | ||
"prepublish": "npm run clean && npm run compile" | ||
"prepublish": "npm run clean && npm run compile", | ||
"test": "mocha" | ||
}, | ||
@@ -23,0 +23,0 @@ "author": "", |
@@ -1,2 +0,2 @@ | ||
# ts-quick-docs | ||
# ts-quick-docs ![NPM](https://img.shields.io/npm/v/ts-quick-docs.svg) ![Circle CI](https://img.shields.io/circleci/project/giladgray/ts-quick-docs.svg) | ||
@@ -53,3 +53,3 @@ > quick TypeScript documentation extractor | ||
Array of patterns that will be matched against each file's path. Matching files will not be parsed and entities in those files will not appear in the output. | ||
Array of patterns that will be matched against each file's path. Matching files _will be_ parsed but entities in those files _will not_ appear in the output. | ||
@@ -56,0 +56,0 @@ #### ignoreDefinitions: `boolean = false` |
@@ -12,3 +12,3 @@ import * as ts from "typescript"; | ||
private options; | ||
private checker; | ||
private readonly checker; | ||
static fromProgram(program: ts.Program, options?: IDocumentationOptions): IInterfaceEntry[]; | ||
@@ -20,8 +20,9 @@ static fromFiles(files: string[], compilerOptions?: ts.CompilerOptions, options?: IDocumentationOptions): IInterfaceEntry[]; | ||
private getTypeOfSymbol(symbol); | ||
private serializeSymbol(symbol); | ||
private getTypeString(symbol); | ||
private serializeSymbol(symbol, fileName); | ||
private serializeDeclaration; | ||
private serializeInterface(symbol, fileName); | ||
private serializeVariable(symbol, fileName); | ||
private serializeDeclaration; | ||
private filterEntryName; | ||
private shouldSkipFile(fileName); | ||
private filterValueDeclaration; | ||
private filterEntry; | ||
} |
@@ -9,10 +9,11 @@ "use strict"; | ||
if (options === void 0) { options = {}; } | ||
this.serializeDeclaration = function (symbol) { | ||
var details = _this.serializeSymbol(symbol); | ||
this.serializeDeclaration = function (symbol, fileName) { | ||
var details = _this.serializeSymbol(symbol, fileName); | ||
details.optional = (symbol.flags & ts.SymbolFlags.Optional) !== 0; | ||
return flags_1.resolveFlags(details); | ||
}; | ||
this.filterEntryName = function (entry) { | ||
var _a = _this.options.excludeNames, excludeNames = _a === void 0 ? [] : _a; | ||
return excludeNames.every(function (pattern) { return entry.name.match(pattern) == null; }); | ||
this.filterValueDeclaration = function (sym) { return sym.valueDeclaration != null; }; | ||
this.filterEntry = function (entry) { | ||
var _a = _this.options, excludeNames = _a.excludeNames, excludePaths = _a.excludePaths; | ||
return testNoMatches(entry.name, excludeNames) && testNoMatches(entry.fileName, excludePaths); | ||
}; | ||
@@ -54,3 +55,3 @@ this.program = program; | ||
var sourceFile = _a[_i]; | ||
if (this.shouldSkipFile(sourceFile.fileName)) { | ||
if (this.options.ignoreDefinitions && /\.d\.ts$/.test(sourceFile.fileName)) { | ||
continue; | ||
@@ -60,3 +61,3 @@ } | ||
} | ||
return output.filter(this.filterEntryName); | ||
return output.filter(this.filterEntry); | ||
}; | ||
@@ -69,10 +70,15 @@ Documentation.prototype.getFileName = function (node) { | ||
}; | ||
Documentation.prototype.serializeSymbol = function (symbol) { | ||
Documentation.prototype.getTypeString = function (symbol) { | ||
return this.checker.typeToString(this.getTypeOfSymbol(symbol), null, ts.TypeFormatFlags.UseFullyQualifiedType); | ||
}; | ||
Documentation.prototype.serializeSymbol = function (symbol, fileName) { | ||
return { | ||
documentation: ts.displayPartsToString(symbol.getDocumentationComment()), | ||
fileName: fileName, | ||
name: symbol.getName(), | ||
type: this.checker.typeToString(this.getTypeOfSymbol(symbol)), | ||
type: this.getTypeString(symbol), | ||
}; | ||
}; | ||
Documentation.prototype.serializeInterface = function (symbol, fileName) { | ||
var _this = this; | ||
var details = { | ||
@@ -89,5 +95,5 @@ documentation: ts.displayPartsToString(symbol.getDocumentationComment()), | ||
details.properties = Object.keys(symbol.members).sort().map(function (name) { return symbol.members[name]; }) | ||
.filter(function (sym) { return sym.valueDeclaration != null; }) | ||
.map(this.serializeDeclaration) | ||
.filter(this.filterEntryName); | ||
.filter(this.filterValueDeclaration) | ||
.map(function (sym) { return _this.serializeDeclaration(sym, fileName); }) | ||
.filter(this.filterEntry); | ||
return details; | ||
@@ -97,6 +103,8 @@ }; | ||
var _this = this; | ||
var details = this.serializeSymbol(symbol); | ||
var details = this.serializeSymbol(symbol, fileName); | ||
details.fileName = fileName; | ||
if (this.options.includeBasicTypeProperties || !/^(boolean|number|string)(\[\])?$/.test(details.type)) { | ||
details.properties = this.getTypeOfSymbol(symbol).getProperties().map(function (s) { return _this.serializeSymbol(s); }); | ||
details.properties = this.getTypeOfSymbol(symbol).getProperties() | ||
.filter(this.filterValueDeclaration) | ||
.map(function (s) { return _this.serializeSymbol(s, fileName); }); | ||
} | ||
@@ -108,7 +116,2 @@ else { | ||
}; | ||
Documentation.prototype.shouldSkipFile = function (fileName) { | ||
var _a = this.options, excludePaths = _a.excludePaths, ignoreDefinitions = _a.ignoreDefinitions; | ||
return (ignoreDefinitions && /\.d\.ts$/.test(fileName)) | ||
|| (excludePaths != null && excludePaths.some(function (pattern) { return fileName.match(pattern) != null; })); | ||
}; | ||
return Documentation; | ||
@@ -118,1 +121,5 @@ }()); | ||
exports.default = Documentation; | ||
function testNoMatches(value, patterns) { | ||
if (patterns === void 0) { patterns = []; } | ||
return patterns.every(function (pattern) { return value.match(pattern) == null; }); | ||
} |
export interface IDocEntry { | ||
documentation?: string; | ||
fileName?: string; | ||
inheritedFrom?: string; | ||
@@ -9,3 +10,3 @@ name?: string; | ||
default?: string; | ||
deprecated?: boolean; | ||
deprecated?: string; | ||
internal?: boolean; | ||
@@ -17,3 +18,2 @@ optional?: boolean; | ||
properties?: IPropertyEntry[]; | ||
fileName?: string; | ||
} |
@@ -7,4 +7,5 @@ { | ||
"mocha": "registry:dt/mocha#2.2.5+20160317120654", | ||
"node": "registry:dt/node#4.0.0+20160330064709" | ||
"node": "registry:dt/node#4.0.0+20160330064709", | ||
"react": "registry:dt/react#0.14.0+20160817201227" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14795
337
Updatedtypescript@>=2.0.0