Skip to content

Commit

Permalink
fix(core): split disablePrivateOrInternalSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Nov 4, 2017
1 parent 8e09808 commit 9e4222e
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/app/compiler/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class Dependencies {
let file = srcFile.fileName.replace(cleaner, '');

ts.forEachChild(srcFile, (node: ts.Node) => {
if (this.jsDocHelper.hasJSDocInternalTag(file, srcFile, node) && this.configuration.mainData.disablePrivateOrInternalSupport) {
if (this.jsDocHelper.hasJSDocInternalTag(file, srcFile, node) && this.configuration.mainData.disableInternal) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/deps/component-dep.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ComponentDepFactory {
sourceCode: srcFile.getText(),
exampleUrls: this.helper.getComponentExampleUrls(srcFile.getText())
};
if (this.configuration.mainData.disablePrivateOrInternalSupport) {
if (this.configuration.mainData.disableLifeCycleHooks) {
componentDep.methodsClass = cleanLifecycleHooksFromMethods(componentDep.methodsClass);
}
if (IO.jsdoctags && IO.jsdoctags.length > 0) {
Expand Down
60 changes: 40 additions & 20 deletions src/app/compiler/deps/helpers/class-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,28 +448,38 @@ export class ClassHelper {
hostListeners.push(this.visitHostListener(member, hostListener, sourceFile));
} else if (!this.isHiddenMember(member)) {

if (!((this.isPrivate(member) || this.isInternal(member)) &&
this.configuration.mainData.disablePrivateOrInternalSupport)) {
if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
methods.push(this.visitMethodDeclaration(member, sourceFile));
} else if (ts.isPropertyDeclaration(member) ||
ts.isPropertySignature(member)) {
properties.push(this.visitProperty(member, sourceFile));
} else if (ts.isCallSignatureDeclaration(member)) {
properties.push(this.visitCallDeclaration(member, sourceFile));
} else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
this.addAccessor(accessors, members[i], sourceFile);
} else if (ts.isIndexSignatureDeclaration(member)) {
indexSignatures.push(this.visitIndexDeclaration(member, sourceFile));
} else if (ts.isConstructorDeclaration(member)) {
let _constructorProperties = this.visitConstructorProperties(member, sourceFile);
let j = 0;
let len = _constructorProperties.length;
for (j; j < len; j++) {
properties.push(_constructorProperties[j]);
if (!(this.isPrivate(member) && this.configuration.mainData.disablePrivate)) {

if (!(this.isInternal(member) && this.configuration.mainData.disableInternal)) {

if (!(this.isProtected(member) && this.configuration.mainData.disableProtected)) {


if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
methods.push(this.visitMethodDeclaration(member, sourceFile));
} else if (ts.isPropertyDeclaration(member) ||
ts.isPropertySignature(member)) {
properties.push(this.visitProperty(member, sourceFile));
} else if (ts.isCallSignatureDeclaration(member)) {
properties.push(this.visitCallDeclaration(member, sourceFile));
} else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
this.addAccessor(accessors, members[i], sourceFile);
} else if (ts.isIndexSignatureDeclaration(member)) {
indexSignatures.push(this.visitIndexDeclaration(member, sourceFile));
} else if (ts.isConstructorDeclaration(member)) {
let _constructorProperties = this.visitConstructorProperties(member, sourceFile);
let j = 0;
let len = _constructorProperties.length;
for (j; j < len; j++) {
properties.push(_constructorProperties[j]);
}
constructor = this.visitConstructorDeclaration(member, sourceFile);
}

}
constructor = this.visitConstructorDeclaration(member, sourceFile);

}

}
}
}
Expand Down Expand Up @@ -541,6 +551,16 @@ export class ClassHelper {
return this.isHiddenMember(member);
}

private isProtected(member): boolean {
if (member.modifiers) {
const isProtected: boolean = member.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ProtectedKeyword);
if (isProtected) {
return true;
}
}
return this.isHiddenMember(member);
}

private isInternal(member): boolean {
/**
* Copyright https://github.com/ng-bootstrap/ng-bootstrap
Expand Down
5 changes: 4 additions & 1 deletion src/app/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export class Configuration implements ConfigurationInterface {
disableGraph: COMPODOC_DEFAULTS.disableGraph,
disableMainGraph: COMPODOC_DEFAULTS.disableMainGraph,
disableCoverage: COMPODOC_DEFAULTS.disableCoverage,
disablePrivateOrInternalSupport: COMPODOC_DEFAULTS.disablePrivateOrInternalSupport,
disablePrivate: COMPODOC_DEFAULTS.disablePrivate,
disableInternal: COMPODOC_DEFAULTS.disableInternal,
disableProtected: COMPODOC_DEFAULTS.disableProtected,
disableLifeCycleHooks: COMPODOC_DEFAULTS.disableLifeCycleHooks,
watch: false,
mainGraph: '',
coverageTest: false,
Expand Down
5 changes: 4 additions & 1 deletion src/app/interfaces/main-data.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export interface MainDataInterface {
disableGraph: boolean;
disableMainGraph: boolean;
disableCoverage: boolean;
disablePrivateOrInternalSupport: boolean;
disablePrivate: boolean;
disableProtected: boolean;
disableInternal: boolean;
disableLifeCycleHooks: boolean;
watch: boolean;
mainGraph: string;
coverageTest: boolean;
Expand Down
21 changes: 18 additions & 3 deletions src/index-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export class CliApplication extends Application {
.option('--disableSourceCode', 'Do not add source code tab and links to source code', false)
.option('--disableGraph', 'Do not add the dependency graph', false)
.option('--disableCoverage', 'Do not add the documentation coverage report', false)
.option('--disablePrivateOrInternalSupport', 'Do not show private, @internal or Angular lifecycle hooks in generated documentation', false)
.option('--disablePrivate', 'Do not show private in generated documentation', false)
.option('--disableProtected', 'Do not show protected in generated documentation', false)
.option('--disableInternal', 'Do not show @internal in generated documentation', false)
.option('--disableLifeCycleHooks', 'Do not show Angular lifecycle hooks in generated documentation', false)
.option('--customFavicon [path]', 'Use a custom favicon')
.parse(process.argv);

Expand Down Expand Up @@ -153,8 +156,20 @@ export class CliApplication extends Application {
this.configuration.mainData.disableCoverage = program.disableCoverage;
}

if (program.disablePrivateOrInternalSupport) {
this.configuration.mainData.disablePrivateOrInternalSupport = program.disablePrivateOrInternalSupport;
if (program.disablePrivate) {
this.configuration.mainData.disablePrivate = program.disablePrivate;
}

if (program.disableProtected) {
this.configuration.mainData.disableProtected = program.disableProtected;
}

if (program.disableInternal) {
this.configuration.mainData.disableInternal = program.disableInternal;
}

if (program.disableLifeCycleHooks) {
this.configuration.mainData.disableLifeCycleHooks = program.disableLifeCycleHooks;
}

if (program.customFavicon) {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const COMPODOC_DEFAULTS = {
disableGraph: false,
disableMainGraph: false,
disableCoverage: false,
disablePrivateOrInternalSupport: false,
disablePrivate: false,
disableProtected: false,
disableInternal: false,
disableLifeCycleHooks: false,
PAGE_TYPES: {
ROOT: 'root',
INTERNAL: 'internal'
Expand Down
197 changes: 197 additions & 0 deletions test/src/cli/cli-disable-options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import * as chai from 'chai';
import {temporaryDir, shell, pkg, exists, exec, read, shellAsync} from '../helpers';
const expect = chai.expect,
tmp = temporaryDir(),
tsconfigPath = require.resolve('../../../tsconfig.json'),
env = Object.freeze({TS_NODE_PROJECT: tsconfigPath, MODE:'TESTING'});

describe('CLI disable flags', () => {

describe('disabling excluding methods with --disablePrivate', () => {

let componentFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'--disablePrivate',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
componentFile = read(`${tmp.name}/components/BarComponent.html`);
done();
});
after(() => tmp.clean());

it('should exclude methods marked as private', () => {
expect(componentFile).not.to.contain('<code>privateMethod');
});

it('should include methods marked as internal', () => {
expect(componentFile).to.contain('<code>internalMethod');
});

it('should include stuff marked as protected', () => {
expect(componentFile).to.contain('<code>varprotected');
});

it('should display lifecyle hooks', () => {
expect(componentFile).to.contain('<code>ngOnInit');
});
});

describe('disabling excluding methods with --disableProtected', () => {

let componentFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'--disableProtected',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
componentFile = read(`${tmp.name}/components/BarComponent.html`);
done();
});
after(() => tmp.clean());

it('should exclude methods marked as protected', () => {
expect(componentFile).not.to.contain('<code>varprotected');
});

it('should include methods marked as private', () => {
expect(componentFile).to.contain('<code>privateMethod');
});

it('should include methods marked as internal', () => {
expect(componentFile).to.contain('<code>internalMethod');
});

it('should display lifecyle hooks', () => {
expect(componentFile).to.contain('<code>ngOnInit');
});
});

describe('disabling excluding methods with --disableInternal', () => {

let componentFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'--disableInternal',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
componentFile = read(`${tmp.name}/components/BarComponent.html`);
done();
});
after(() => tmp.clean());

it('should exclude methods marked as @internal', () => {
expect(componentFile).not.to.contain('<code>internalMethod');
});

it('should include methods marked as private', () => {
expect(componentFile).to.contain('<code>privateMethod');
});

it('should include stuff marked as protected', () => {
expect(componentFile).to.contain('<code>varprotected');
});

it('should display lifecyle hooks', () => {
expect(componentFile).to.contain('<code>ngOnInit');
});
});

describe('disabling excluding methods with --disableLifeCycleHooks', () => {

let componentFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'--disableLifeCycleHooks',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
componentFile = read(`${tmp.name}/components/BarComponent.html`);
done();
});
after(() => tmp.clean());

it('should exclude lifecyle hooks', () => {
expect(componentFile).not.to.contain('<code>ngOnInit');
});

it('should include methods marked as private', () => {
expect(componentFile).to.contain('<code>privateMethod');
});

it('should include stuff marked as protected', () => {
expect(componentFile).to.contain('<code>varprotected');
});

it('should include methods marked as internal', () => {
expect(componentFile).to.contain('<code>internalMethod');
});
});

describe('disabling excluding methods with --disableLifeCycleHooks --disableInternal --disableProtected --disablePrivate', () => {

let componentFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'--disablePrivate',
'--disableProtected',
'--disableInternal',
'--disableLifeCycleHooks',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
componentFile = read(`${tmp.name}/components/BarComponent.html`);
done();
});
after(() => tmp.clean());

it('should exclude lifecyle hooks', () => {
expect(componentFile).not.to.contain('<code>ngOnInit');
});

it('should exclude methods marked as private', () => {
expect(componentFile).not.to.contain('<code>privateMethod');
});

it('should exclude stuff marked as protected', () => {
expect(componentFile).not.to.contain('<code>varprotected');
});

it('should exclude methods marked as internal', () => {
expect(componentFile).not.to.contain('<code>internalMethod');
});
});
});
21 changes: 18 additions & 3 deletions test/src/cli/cli-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,24 @@ describe('CLI Options', () => {
expect(runHelp.stdout.toString()).to.contain('Do not add the documentation coverage report');
});

it(`--disablePrivateOrInternalSupport`, () => {
expect(runHelp.stdout.toString()).to.contain('--disablePrivateOrInternalSupport');
expect(runHelp.stdout.toString()).to.contain('Do not show private, @internal or Angular lifecycle hooks in generated documentation');
it(`--disablePrivate`, () => {
expect(runHelp.stdout.toString()).to.contain('--disablePrivate');
expect(runHelp.stdout.toString()).to.contain('Do not show private in generated documentation');
});

it(`--disableProtected`, () => {
expect(runHelp.stdout.toString()).to.contain('--disableProtected');
expect(runHelp.stdout.toString()).to.contain('Do not show protected in generated documentation');
});

it(`--disableInternal`, () => {
expect(runHelp.stdout.toString()).to.contain('--disableInternal');
expect(runHelp.stdout.toString()).to.contain('Do not show @internal in generated documentation');
});

it(`--disableLifeCycleHooks`, () => {
expect(runHelp.stdout.toString()).to.contain('--disableLifeCycleHooks');
expect(runHelp.stdout.toString()).to.contain('Do not show Angular lifecycle hooks in generated documentation');
});

it(`--customFavicon`, () => {
Expand Down
Loading

0 comments on commit 9e4222e

Please sign in to comment.