Skip to content

Commit 9e4222e

Browse files
committed
fix(core): split disablePrivateOrInternalSupport
fix #241 #271
1 parent 8e09808 commit 9e4222e

File tree

11 files changed

+290
-74
lines changed

11 files changed

+290
-74
lines changed

src/app/compiler/dependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class Dependencies {
232232
let file = srcFile.fileName.replace(cleaner, '');
233233

234234
ts.forEachChild(srcFile, (node: ts.Node) => {
235-
if (this.jsDocHelper.hasJSDocInternalTag(file, srcFile, node) && this.configuration.mainData.disablePrivateOrInternalSupport) {
235+
if (this.jsDocHelper.hasJSDocInternalTag(file, srcFile, node) && this.configuration.mainData.disableInternal) {
236236
return;
237237
}
238238

src/app/compiler/deps/component-dep.factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class ComponentDepFactory {
4949
sourceCode: srcFile.getText(),
5050
exampleUrls: this.helper.getComponentExampleUrls(srcFile.getText())
5151
};
52-
if (this.configuration.mainData.disablePrivateOrInternalSupport) {
52+
if (this.configuration.mainData.disableLifeCycleHooks) {
5353
componentDep.methodsClass = cleanLifecycleHooksFromMethods(componentDep.methodsClass);
5454
}
5555
if (IO.jsdoctags && IO.jsdoctags.length > 0) {

src/app/compiler/deps/helpers/class-helper.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -448,28 +448,38 @@ export class ClassHelper {
448448
hostListeners.push(this.visitHostListener(member, hostListener, sourceFile));
449449
} else if (!this.isHiddenMember(member)) {
450450

451-
if (!((this.isPrivate(member) || this.isInternal(member)) &&
452-
this.configuration.mainData.disablePrivateOrInternalSupport)) {
453-
if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
454-
methods.push(this.visitMethodDeclaration(member, sourceFile));
455-
} else if (ts.isPropertyDeclaration(member) ||
456-
ts.isPropertySignature(member)) {
457-
properties.push(this.visitProperty(member, sourceFile));
458-
} else if (ts.isCallSignatureDeclaration(member)) {
459-
properties.push(this.visitCallDeclaration(member, sourceFile));
460-
} else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
461-
this.addAccessor(accessors, members[i], sourceFile);
462-
} else if (ts.isIndexSignatureDeclaration(member)) {
463-
indexSignatures.push(this.visitIndexDeclaration(member, sourceFile));
464-
} else if (ts.isConstructorDeclaration(member)) {
465-
let _constructorProperties = this.visitConstructorProperties(member, sourceFile);
466-
let j = 0;
467-
let len = _constructorProperties.length;
468-
for (j; j < len; j++) {
469-
properties.push(_constructorProperties[j]);
451+
if (!(this.isPrivate(member) && this.configuration.mainData.disablePrivate)) {
452+
453+
if (!(this.isInternal(member) && this.configuration.mainData.disableInternal)) {
454+
455+
if (!(this.isProtected(member) && this.configuration.mainData.disableProtected)) {
456+
457+
458+
if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
459+
methods.push(this.visitMethodDeclaration(member, sourceFile));
460+
} else if (ts.isPropertyDeclaration(member) ||
461+
ts.isPropertySignature(member)) {
462+
properties.push(this.visitProperty(member, sourceFile));
463+
} else if (ts.isCallSignatureDeclaration(member)) {
464+
properties.push(this.visitCallDeclaration(member, sourceFile));
465+
} else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
466+
this.addAccessor(accessors, members[i], sourceFile);
467+
} else if (ts.isIndexSignatureDeclaration(member)) {
468+
indexSignatures.push(this.visitIndexDeclaration(member, sourceFile));
469+
} else if (ts.isConstructorDeclaration(member)) {
470+
let _constructorProperties = this.visitConstructorProperties(member, sourceFile);
471+
let j = 0;
472+
let len = _constructorProperties.length;
473+
for (j; j < len; j++) {
474+
properties.push(_constructorProperties[j]);
475+
}
476+
constructor = this.visitConstructorDeclaration(member, sourceFile);
477+
}
478+
470479
}
471-
constructor = this.visitConstructorDeclaration(member, sourceFile);
480+
472481
}
482+
473483
}
474484
}
475485
}
@@ -541,6 +551,16 @@ export class ClassHelper {
541551
return this.isHiddenMember(member);
542552
}
543553

554+
private isProtected(member): boolean {
555+
if (member.modifiers) {
556+
const isProtected: boolean = member.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ProtectedKeyword);
557+
if (isProtected) {
558+
return true;
559+
}
560+
}
561+
return this.isHiddenMember(member);
562+
}
563+
544564
private isInternal(member): boolean {
545565
/**
546566
* Copyright https://github.com/ng-bootstrap/ng-bootstrap

src/app/configuration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export class Configuration implements ConfigurationInterface {
4343
disableGraph: COMPODOC_DEFAULTS.disableGraph,
4444
disableMainGraph: COMPODOC_DEFAULTS.disableMainGraph,
4545
disableCoverage: COMPODOC_DEFAULTS.disableCoverage,
46-
disablePrivateOrInternalSupport: COMPODOC_DEFAULTS.disablePrivateOrInternalSupport,
46+
disablePrivate: COMPODOC_DEFAULTS.disablePrivate,
47+
disableInternal: COMPODOC_DEFAULTS.disableInternal,
48+
disableProtected: COMPODOC_DEFAULTS.disableProtected,
49+
disableLifeCycleHooks: COMPODOC_DEFAULTS.disableLifeCycleHooks,
4750
watch: false,
4851
mainGraph: '',
4952
coverageTest: false,

src/app/interfaces/main-data.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export interface MainDataInterface {
3535
disableGraph: boolean;
3636
disableMainGraph: boolean;
3737
disableCoverage: boolean;
38-
disablePrivateOrInternalSupport: boolean;
38+
disablePrivate: boolean;
39+
disableProtected: boolean;
40+
disableInternal: boolean;
41+
disableLifeCycleHooks: boolean;
3942
watch: boolean;
4043
mainGraph: string;
4144
coverageTest: boolean;

src/index-cli.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export class CliApplication extends Application {
5454
.option('--disableSourceCode', 'Do not add source code tab and links to source code', false)
5555
.option('--disableGraph', 'Do not add the dependency graph', false)
5656
.option('--disableCoverage', 'Do not add the documentation coverage report', false)
57-
.option('--disablePrivateOrInternalSupport', 'Do not show private, @internal or Angular lifecycle hooks in generated documentation', false)
57+
.option('--disablePrivate', 'Do not show private in generated documentation', false)
58+
.option('--disableProtected', 'Do not show protected in generated documentation', false)
59+
.option('--disableInternal', 'Do not show @internal in generated documentation', false)
60+
.option('--disableLifeCycleHooks', 'Do not show Angular lifecycle hooks in generated documentation', false)
5861
.option('--customFavicon [path]', 'Use a custom favicon')
5962
.parse(process.argv);
6063

@@ -153,8 +156,20 @@ export class CliApplication extends Application {
153156
this.configuration.mainData.disableCoverage = program.disableCoverage;
154157
}
155158

156-
if (program.disablePrivateOrInternalSupport) {
157-
this.configuration.mainData.disablePrivateOrInternalSupport = program.disablePrivateOrInternalSupport;
159+
if (program.disablePrivate) {
160+
this.configuration.mainData.disablePrivate = program.disablePrivate;
161+
}
162+
163+
if (program.disableProtected) {
164+
this.configuration.mainData.disableProtected = program.disableProtected;
165+
}
166+
167+
if (program.disableInternal) {
168+
this.configuration.mainData.disableInternal = program.disableInternal;
169+
}
170+
171+
if (program.disableLifeCycleHooks) {
172+
this.configuration.mainData.disableLifeCycleHooks = program.disableLifeCycleHooks;
158173
}
159174

160175
if (program.customFavicon) {

src/utils/defaults.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export const COMPODOC_DEFAULTS = {
1515
disableGraph: false,
1616
disableMainGraph: false,
1717
disableCoverage: false,
18-
disablePrivateOrInternalSupport: false,
18+
disablePrivate: false,
19+
disableProtected: false,
20+
disableInternal: false,
21+
disableLifeCycleHooks: false,
1922
PAGE_TYPES: {
2023
ROOT: 'root',
2124
INTERNAL: 'internal'
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import * as chai from 'chai';
2+
import {temporaryDir, shell, pkg, exists, exec, read, shellAsync} from '../helpers';
3+
const expect = chai.expect,
4+
tmp = temporaryDir(),
5+
tsconfigPath = require.resolve('../../../tsconfig.json'),
6+
env = Object.freeze({TS_NODE_PROJECT: tsconfigPath, MODE:'TESTING'});
7+
8+
describe('CLI disable flags', () => {
9+
10+
describe('disabling excluding methods with --disablePrivate', () => {
11+
12+
let componentFile;
13+
before(function (done) {
14+
tmp.create();
15+
let ls = shell('node', [
16+
'../bin/index-cli.js',
17+
'-p', '../test/src/sample-files/tsconfig.simple.json',
18+
'--disablePrivate',
19+
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});
20+
21+
if (ls.stderr.toString() !== '') {
22+
console.error(`shell error: ${ls.stderr.toString()}`);
23+
done('error');
24+
}
25+
componentFile = read(`${tmp.name}/components/BarComponent.html`);
26+
done();
27+
});
28+
after(() => tmp.clean());
29+
30+
it('should exclude methods marked as private', () => {
31+
expect(componentFile).not.to.contain('<code>privateMethod');
32+
});
33+
34+
it('should include methods marked as internal', () => {
35+
expect(componentFile).to.contain('<code>internalMethod');
36+
});
37+
38+
it('should include stuff marked as protected', () => {
39+
expect(componentFile).to.contain('<code>varprotected');
40+
});
41+
42+
it('should display lifecyle hooks', () => {
43+
expect(componentFile).to.contain('<code>ngOnInit');
44+
});
45+
});
46+
47+
describe('disabling excluding methods with --disableProtected', () => {
48+
49+
let componentFile;
50+
before(function (done) {
51+
tmp.create();
52+
let ls = shell('node', [
53+
'../bin/index-cli.js',
54+
'-p', '../test/src/sample-files/tsconfig.simple.json',
55+
'--disableProtected',
56+
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});
57+
58+
if (ls.stderr.toString() !== '') {
59+
console.error(`shell error: ${ls.stderr.toString()}`);
60+
done('error');
61+
}
62+
componentFile = read(`${tmp.name}/components/BarComponent.html`);
63+
done();
64+
});
65+
after(() => tmp.clean());
66+
67+
it('should exclude methods marked as protected', () => {
68+
expect(componentFile).not.to.contain('<code>varprotected');
69+
});
70+
71+
it('should include methods marked as private', () => {
72+
expect(componentFile).to.contain('<code>privateMethod');
73+
});
74+
75+
it('should include methods marked as internal', () => {
76+
expect(componentFile).to.contain('<code>internalMethod');
77+
});
78+
79+
it('should display lifecyle hooks', () => {
80+
expect(componentFile).to.contain('<code>ngOnInit');
81+
});
82+
});
83+
84+
describe('disabling excluding methods with --disableInternal', () => {
85+
86+
let componentFile;
87+
before(function (done) {
88+
tmp.create();
89+
let ls = shell('node', [
90+
'../bin/index-cli.js',
91+
'-p', '../test/src/sample-files/tsconfig.simple.json',
92+
'--disableInternal',
93+
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});
94+
95+
if (ls.stderr.toString() !== '') {
96+
console.error(`shell error: ${ls.stderr.toString()}`);
97+
done('error');
98+
}
99+
componentFile = read(`${tmp.name}/components/BarComponent.html`);
100+
done();
101+
});
102+
after(() => tmp.clean());
103+
104+
it('should exclude methods marked as @internal', () => {
105+
expect(componentFile).not.to.contain('<code>internalMethod');
106+
});
107+
108+
it('should include methods marked as private', () => {
109+
expect(componentFile).to.contain('<code>privateMethod');
110+
});
111+
112+
it('should include stuff marked as protected', () => {
113+
expect(componentFile).to.contain('<code>varprotected');
114+
});
115+
116+
it('should display lifecyle hooks', () => {
117+
expect(componentFile).to.contain('<code>ngOnInit');
118+
});
119+
});
120+
121+
describe('disabling excluding methods with --disableLifeCycleHooks', () => {
122+
123+
let componentFile;
124+
before(function (done) {
125+
tmp.create();
126+
let ls = shell('node', [
127+
'../bin/index-cli.js',
128+
'-p', '../test/src/sample-files/tsconfig.simple.json',
129+
'--disableLifeCycleHooks',
130+
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});
131+
132+
if (ls.stderr.toString() !== '') {
133+
console.error(`shell error: ${ls.stderr.toString()}`);
134+
done('error');
135+
}
136+
componentFile = read(`${tmp.name}/components/BarComponent.html`);
137+
done();
138+
});
139+
after(() => tmp.clean());
140+
141+
it('should exclude lifecyle hooks', () => {
142+
expect(componentFile).not.to.contain('<code>ngOnInit');
143+
});
144+
145+
it('should include methods marked as private', () => {
146+
expect(componentFile).to.contain('<code>privateMethod');
147+
});
148+
149+
it('should include stuff marked as protected', () => {
150+
expect(componentFile).to.contain('<code>varprotected');
151+
});
152+
153+
it('should include methods marked as internal', () => {
154+
expect(componentFile).to.contain('<code>internalMethod');
155+
});
156+
});
157+
158+
describe('disabling excluding methods with --disableLifeCycleHooks --disableInternal --disableProtected --disablePrivate', () => {
159+
160+
let componentFile;
161+
before(function (done) {
162+
tmp.create();
163+
let ls = shell('node', [
164+
'../bin/index-cli.js',
165+
'-p', '../test/src/sample-files/tsconfig.simple.json',
166+
'--disablePrivate',
167+
'--disableProtected',
168+
'--disableInternal',
169+
'--disableLifeCycleHooks',
170+
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env});
171+
172+
if (ls.stderr.toString() !== '') {
173+
console.error(`shell error: ${ls.stderr.toString()}`);
174+
done('error');
175+
}
176+
componentFile = read(`${tmp.name}/components/BarComponent.html`);
177+
done();
178+
});
179+
after(() => tmp.clean());
180+
181+
it('should exclude lifecyle hooks', () => {
182+
expect(componentFile).not.to.contain('<code>ngOnInit');
183+
});
184+
185+
it('should exclude methods marked as private', () => {
186+
expect(componentFile).not.to.contain('<code>privateMethod');
187+
});
188+
189+
it('should exclude stuff marked as protected', () => {
190+
expect(componentFile).not.to.contain('<code>varprotected');
191+
});
192+
193+
it('should exclude methods marked as internal', () => {
194+
expect(componentFile).not.to.contain('<code>internalMethod');
195+
});
196+
});
197+
});

test/src/cli/cli-options.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,24 @@ describe('CLI Options', () => {
117117
expect(runHelp.stdout.toString()).to.contain('Do not add the documentation coverage report');
118118
});
119119

120-
it(`--disablePrivateOrInternalSupport`, () => {
121-
expect(runHelp.stdout.toString()).to.contain('--disablePrivateOrInternalSupport');
122-
expect(runHelp.stdout.toString()).to.contain('Do not show private, @internal or Angular lifecycle hooks in generated documentation');
120+
it(`--disablePrivate`, () => {
121+
expect(runHelp.stdout.toString()).to.contain('--disablePrivate');
122+
expect(runHelp.stdout.toString()).to.contain('Do not show private in generated documentation');
123+
});
124+
125+
it(`--disableProtected`, () => {
126+
expect(runHelp.stdout.toString()).to.contain('--disableProtected');
127+
expect(runHelp.stdout.toString()).to.contain('Do not show protected in generated documentation');
128+
});
129+
130+
it(`--disableInternal`, () => {
131+
expect(runHelp.stdout.toString()).to.contain('--disableInternal');
132+
expect(runHelp.stdout.toString()).to.contain('Do not show @internal in generated documentation');
133+
});
134+
135+
it(`--disableLifeCycleHooks`, () => {
136+
expect(runHelp.stdout.toString()).to.contain('--disableLifeCycleHooks');
137+
expect(runHelp.stdout.toString()).to.contain('Do not show Angular lifecycle hooks in generated documentation');
123138
});
124139

125140
it(`--customFavicon`, () => {

0 commit comments

Comments
 (0)