Skip to content

Commit

Permalink
feat(build): updated tslint command
Browse files Browse the repository at this point in the history
* clean some tools files
  • Loading branch information
pimenovoleg committed Aug 5, 2018
1 parent 2456dcb commit 53be9a7
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 162 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"build:docs": "gulp docs",
"changelog": "ts-node --project ./scripts/tsconfig.deploy.json ./scripts/changelog.ts",
"publish": "ts-node --project ./scripts/tsconfig.deploy.json ./scripts/deploy/publish-artifacts.ts",
"linter:lib": "tslint './src/lib'",
"linter:lib": "tslint --config 'tslint.json' --project '.'",
"linter:styles": "stylelint --syntax scss \"./**/*.scss\"",
"server-dev": "webpack-dev-server --config tools/webpack/webpack.lib.dev.js",
"server-dev:button": "npm run server-dev -- --env.component button",
Expand Down
22 changes: 13 additions & 9 deletions tools/dgeni/common/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
import {CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc} from './dgeni-definitions';
import { ClassExportDoc } from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import { MemberDoc } from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
import { PropertyMemberDoc } from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';

import { CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc } from './dgeni-definitions';


/**
* We want to avoid emitting selectors that are deprecated but don't have a way to mark
Expand All @@ -13,7 +15,7 @@ const SELECTOR_BLACKLIST = new Set([
'[portalHost]',
'textarea[mat-autosize]',
'[overlay-origin]',
'[connected-overlay]',
'[connected-overlay]'
]);

export function isMethod(doc: MemberDoc) {
Expand All @@ -24,6 +26,7 @@ export function isGenericTypeParameter(doc: MemberDoc) {
if (doc.containerDoc instanceof ClassExportDoc) {
return doc.containerDoc.typeParams && `<${doc.name}>` === doc.containerDoc.typeParams;
}

return false;
}

Expand All @@ -35,6 +38,7 @@ export function isProperty(doc: MemberDoc) {
(!isMethod(doc) && (doc.isGetAccessor || doc.isSetAccessor))) {
return !isGenericTypeParameter(doc);
}

return false;
}

Expand Down Expand Up @@ -64,22 +68,22 @@ export function getDirectiveSelectors(classDoc: CategorizedClassDoc) {
if (directiveSelectors) {
// Filter blacklisted selectors and remove line-breaks in resolved selectors.
return directiveSelectors.replace(/[\r\n]/g, '').split(/\s*,\s*/)
.filter(s => s !== '' && !s.includes('md') && !SELECTOR_BLACKLIST.has(s));
.filter((s) => s !== '' && !s.includes('md') && !SELECTOR_BLACKLIST.has(s));
}
}

export function hasMemberDecorator(doc: MemberDoc, decoratorName: string) {
return doc.docType == 'member' && hasDecorator(doc, decoratorName);
return doc.docType === 'member' && hasDecorator(doc, decoratorName);
}

export function hasClassDecorator(doc: ClassExportDoc, decoratorName: string) {
return doc.docType == 'class' && hasDecorator(doc, decoratorName);
return doc.docType === 'class' && hasDecorator(doc, decoratorName);
}

export function hasDecorator(doc: HasDecoratorsDoc, decoratorName: string) {
return !!doc.decorators &&
doc.decorators.length > 0 &&
doc.decorators.some(d => d.name == decoratorName);
doc.decorators.some((d) => d.name === decoratorName);
}

export function getDeletionTarget(doc: any): string | null {
Expand Down
13 changes: 7 additions & 6 deletions tools/dgeni/common/dgeni-definitions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
import {NormalizedMethodMemberDoc} from './normalize-method-parameters';
import { ApiDoc } from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
import { ClassExportDoc } from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import { ClassLikeExportDoc } from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import { PropertyMemberDoc } from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import { ParsedDecorator } from 'dgeni-packages/typescript/services/TsParser/getDecorators';

import { NormalizedMethodMemberDoc } from './normalize-method-parameters';


/** Interface that describes categorized docs that can be deprecated. */
Expand Down
10 changes: 6 additions & 4 deletions tools/dgeni/common/directive-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {CategorizedClassDoc} from './dgeni-definitions';
import {
ArrayLiteralExpression,
CallExpression,
Expand All @@ -7,6 +6,9 @@ import {
StringLiteral, SyntaxKind
} from 'typescript';

import { CategorizedClassDoc } from './dgeni-definitions';


/**
* Determines the component or directive metadata from the specified Dgeni class doc. The resolved
* directive metadata will be stored in a Map.
Expand All @@ -30,9 +32,9 @@ export function getDirectiveMetadata(classDoc: CategorizedClassDoc): Map<string,
}

const directiveDecorator = declaration.decorators
.filter(decorator => decorator.expression)
.filter(decorator => (decorator.expression.kind as any) === SyntaxKind.CallExpression)
.find(decorator => (decorator.expression as any).expression.getText() === 'Component' ||
.filter((decorator) => decorator.expression)
.filter((decorator) => (decorator.expression.kind as any) === SyntaxKind.CallExpression)
.find((decorator) => (decorator.expression as any).expression.getText() === 'Component' ||
(decorator.expression as any).expression.getText() === 'Directive');

if (!directiveDecorator) {
Expand Down
9 changes: 5 additions & 4 deletions tools/dgeni/common/normalize-method-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
import { MethodMemberDoc } from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';


export class NormalizedMethodMemberDoc extends MethodMemberDoc {
Expand All @@ -23,7 +23,7 @@ export interface MethodParameterInfo {
*/
export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
if (method.parameters) {
method.parameters.forEach(parameter => {
method.parameters.forEach((parameter) => {
let [parameterName, parameterType] = parameter.split(':');

// If the parameter is optional, the name here will contain a '?'. We store whether the
Expand All @@ -41,16 +41,17 @@ export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
if (!parameterType) {
console.warn(`Missing parameter type information (${parameterName}) in ` +
`${method.fileInfo.relativePath}:${method.startingLine}`);

return;
}

const existingParameterInfo = method.params.find(p => p.name == parameterName);
const existingParameterInfo = method.params.find((p) => p.name === parameterName);

if (!existingParameterInfo) {
method.params.push({
name: parameterName,
type: parameterType.trim(),
isOptional: isOptional
isOptional
});
} else {
existingParameterInfo.type = parameterType.trim();
Expand Down
10 changes: 6 additions & 4 deletions tools/dgeni/common/property-bindings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {hasMemberDecorator} from './decorators';
import { PropertyMemberDoc } from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';

import { hasMemberDecorator } from './decorators';


/* tslint:disable:no-non-null-assertion */
/** Interface that describes an Angular property binding. Can be either an input or output. */
export interface PropertyBinding {
name: string;
Expand Down Expand Up @@ -35,7 +37,7 @@ function getBindingPropertyData(doc: PropertyMemberDoc, metadata: Map<string, an

if (metadata) {
const metadataValues: string[] = metadata.get(propertyName) || [];
const foundValue = metadataValues.find(value => value.split(':')[0] === doc.name);
const foundValue = metadataValues.find((value) => value.split(':')[0] === doc.name);

if (foundValue) {
return {
Expand All @@ -48,7 +50,7 @@ function getBindingPropertyData(doc: PropertyMemberDoc, metadata: Map<string, an
if (hasMemberDecorator(doc, decoratorName)) {
return {
name: doc.name,
alias: doc.decorators!.find(d => d.name == decoratorName)!.arguments![0]
alias: doc.decorators!.find((d) => d.name === decoratorName)!.arguments![0]
};
}
}
2 changes: 1 addition & 1 deletion tools/dgeni/common/sort-members.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CategorizedMethodMemberDoc, CategorizedPropertyMemberDoc} from './dgeni-definitions';
import { CategorizedMethodMemberDoc, CategorizedPropertyMemberDoc } from './dgeni-definitions';


/** Combined type for a categorized method member document. */
Expand Down
22 changes: 12 additions & 10 deletions tools/dgeni/processors/categorizer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DocCollection, Processor} from 'dgeni';
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
import {getDirectiveMetadata} from '../common/directive-metadata';
import { DocCollection, Processor } from 'dgeni';
import { MethodMemberDoc } from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';

import {
decorateDeprecatedDoc, getDirectiveSelectors, isDirective, isMethod, isNgModule, isProperty,
isService
Expand All @@ -9,11 +9,13 @@ import {
CategorizedClassDoc, CategorizedClassLikeDoc, CategorizedMethodMemberDoc,
CategorizedPropertyMemberDoc
} from '../common/dgeni-definitions';
import {normalizeMethodParameters} from '../common/normalize-method-parameters';
import {getInputBindingData, getOutputBindingData} from '../common/property-bindings';
import {sortCategorizedMembers} from '../common/sort-members';
import { getDirectiveMetadata } from '../common/directive-metadata';
import { normalizeMethodParameters } from '../common/normalize-method-parameters';
import { getInputBindingData, getOutputBindingData } from '../common/property-bindings';
import { sortCategorizedMembers } from '../common/sort-members';


/* tslint:disable:no-non-null-assertion */
/**
* Processor to add properties to docs objects.
*
Expand All @@ -28,8 +30,8 @@ export class Categorizer implements Processor {

$process(docs: DocCollection) {
docs
.filter(doc => doc.docType === 'class' || doc.docType === 'interface')
.forEach(doc => this.decorateClassLikeDoc(doc));
.filter((doc) => doc.docType === 'class' || doc.docType === 'interface')
.forEach((doc) => this.decorateClassLikeDoc(doc));
}

/**
Expand All @@ -52,8 +54,8 @@ export class Categorizer implements Processor {
}

// Call decorate hooks that can modify the method and property docs.
classLikeDoc.methods.forEach(doc => this.decorateMethodDoc(doc));
classLikeDoc.properties.forEach(doc => this.decoratePropertyDoc(doc));
classLikeDoc.methods.forEach((doc) => this.decorateMethodDoc(doc));
classLikeDoc.properties.forEach((doc) => this.decoratePropertyDoc(doc));

decorateDeprecatedDoc(classLikeDoc);

Expand Down
19 changes: 10 additions & 9 deletions tools/dgeni/processors/component-grouper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as path from 'path';

import {DocCollection, Document, Processor} from 'dgeni';
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
import { DocCollection, Document, Processor } from 'dgeni';
import { InterfaceExportDoc } from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';

import {CategorizedClassDoc} from '../common/dgeni-definitions';
import { CategorizedClassDoc } from '../common/dgeni-definitions';


/* tslint:disable:no-non-null-assertion */
/** Component group data structure. */
export class ComponentGroup {

Expand Down Expand Up @@ -66,14 +67,14 @@ export class ComponentGrouper implements Processor {
// Map of group name to group instance.
const groups = new Map<string, ComponentGroup>();

docs.forEach(doc => {
docs.forEach((doc) => {
const documentInfo = getDocumentPackageInfo(doc);

const packageName = documentInfo.packageName;
const packageDisplayName = documentInfo.packageName === 'cdk' ? 'CDK' : 'Mosaic';

const moduleImportPath = `@ptsecurity/${packageName}/${documentInfo.entryPointName}`;
const groupName = packageName + '-' + documentInfo.name;
const groupName = `${packageName}-${documentInfo.name}`;

// Get the group for this doc, or, if one does not exist, create it.
let group;
Expand All @@ -96,9 +97,9 @@ export class ComponentGrouper implements Processor {
group.services.push(doc);
} else if (doc.isNgModule) {
group.ngModule = doc;
} else if (doc.docType == 'class') {
} else if (doc.docType === 'class') {
group.additionalClasses.push(doc);
} else if (doc.docType == 'interface') {
} else if (doc.docType === 'interface') {
group.additionalInterfaces.push(doc);
}
});
Expand All @@ -116,11 +117,11 @@ function getDocumentPackageInfo(doc: Document) {
// All of the component documentation is under either `src/lib` or `src/cdk`.
// We group the docs up by the directory immediately under that root.
const pathSegments = path.relative(basePath, filePath).split(path.sep);
let groupName = pathSegments[1];
const groupName = pathSegments[1];

return {
name: groupName,
packageName: pathSegments[0] === 'lib' ? 'mosaic' : pathSegments[0],
entryPointName: pathSegments[1],
entryPointName: pathSegments[1]
};
}
Loading

0 comments on commit 53be9a7

Please sign in to comment.