Skip to content

Commit b091e19

Browse files
committed
feat(app): display project properties from package.json file
fix #1198
1 parent ce6e2a6 commit b091e19

File tree

18 files changed

+164
-6
lines changed

18 files changed

+164
-6
lines changed

src/app/application.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,35 @@ export class Application {
233233
}
234234
}
235235

236+
if (!Configuration.mainData.disableProperties) {
237+
const propertiesToCheck = [
238+
'version',
239+
'description',
240+
'keywords',
241+
'homepage',
242+
'bugs',
243+
'license',
244+
'repository',
245+
'author'
246+
];
247+
let hasOneOfCheckedProperties = false;
248+
propertiesToCheck.forEach(prop => {
249+
if (prop in parsedData) {
250+
hasOneOfCheckedProperties = true;
251+
Configuration.mainData.packageProperties[prop] = parsedData[prop];
252+
}
253+
});
254+
if (hasOneOfCheckedProperties) {
255+
Configuration.addPage({
256+
name: 'properties',
257+
id: 'packageProperties',
258+
context: 'package-properties',
259+
depth: 0,
260+
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
261+
});
262+
}
263+
}
264+
236265
this.processMarkdowns().then(
237266
() => {
238267
this.getDependenciesData();

src/app/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class Configuration implements ConfigurationInterface {
6666
disableRoutesGraph: COMPODOC_DEFAULTS.disableRoutesGraph,
6767
disableSearch: false,
6868
disableDependencies: COMPODOC_DEFAULTS.disableDependencies,
69+
disableProperties: COMPODOC_DEFAULTS.disableProperties,
6970
watch: false,
7071
mainGraph: '',
7172
coverageTest: false,
@@ -84,6 +85,7 @@ export class Configuration implements ConfigurationInterface {
8485
customLogo: '',
8586
packageDependencies: [],
8687
packagePeerDependencies: [],
88+
packageProperties: {},
8789
gaID: '',
8890
gaSite: '',
8991
angularProject: false,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { IHtmlEngineHelper } from './html-engine-helper.interface';
2+
import * as Handlebars from 'handlebars';
3+
4+
export class CapitalizeHelper implements IHtmlEngineHelper {
5+
public helperFunc(context: any, text: string) {
6+
return text.charAt(0).toUpperCase() + text.slice(1);
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { IHtmlEngineHelper } from './html-engine-helper.interface';
2+
import * as Handlebars from 'handlebars';
3+
4+
export class ParsePropertyHelper implements IHtmlEngineHelper {
5+
public helperFunc(context: any, text: string) {
6+
if (text.indexOf('https') !== -1) {
7+
return `<a href="${text}" target="_blank">${text}</a>`;
8+
} else {
9+
return text;
10+
}
11+
}
12+
}

src/app/engines/html.engine.helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as _ from 'lodash';
33

44
import { BreakCommaHelper } from './html-engine-helpers/break-comma.helper';
55
import { BreakLinesHelper } from './html-engine-helpers/break-lines.helper';
6+
import { CapitalizeHelper } from './html-engine-helpers/capitalize.helper';
67
import { CleanParagraphHelper } from './html-engine-helpers/clean-paragraph.helper';
78
import { CompareHelper } from './html-engine-helpers/compare.helper';
89
import { DebugHelper } from './html-engine-helpers/debug.helper';
@@ -33,6 +34,7 @@ import { OneParameterHasHelper } from './html-engine-helpers/one-parameter-has.h
3334
import { OrLengthHelper } from './html-engine-helpers/or-length.helper';
3435
import { OrHelper } from './html-engine-helpers/or.helper';
3536
import { ParseDescriptionHelper } from './html-engine-helpers/parse-description.helper';
37+
import { ParsePropertyHelper } from './html-engine-helpers/parse-property.helper';
3638
import { RelativeURLHelper } from './html-engine-helpers/relative-url.helper';
3739
import { ShortURLHelper } from './html-engine-helpers/short-url.helper';
3840
import { StripURLHelper } from './html-engine-helpers/strip-url.helper';
@@ -73,10 +75,12 @@ export class HtmlEngineHelpers {
7375
this.registerHelper(bars, 'short-url', new ShortURLHelper());
7476
this.registerHelper(bars, 'strip-url', new StripURLHelper());
7577
this.registerHelper(bars, 't', new I18nHelper());
78+
this.registerHelper(bars, 'capitalize', new CapitalizeHelper());
79+
this.registerHelper(bars, 'parse-property', new ParsePropertyHelper());
7680
}
7781

7882
private registerHelper(bars, key: string, helper: IHtmlEngineHelper) {
79-
Handlebars.registerHelper(key, function() {
83+
Handlebars.registerHelper(key, function () {
8084
// tslint:disable-next-line:no-invalid-this
8185
return helper.helperFunc.apply(helper, [this, ..._.slice(arguments as any)]);
8286
});

src/app/engines/html.engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class HtmlEngine {
6363
'miscellaneous-typealiases',
6464
'miscellaneous-enumerations',
6565
'additional-page',
66-
'package-dependencies'
66+
'package-dependencies',
67+
'package-properties'
6768
];
6869
if (templatePath) {
6970
if (

src/app/interfaces/configuration-file.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface ConfigurationFileInterface {
3737
disableRoutesGraph: boolean;
3838
disableSearch: boolean;
3939
disableDependencies: boolean;
40+
disableProperties: boolean;
4041
minimal: boolean;
4142
customFavicon: string;
4243
customLogo: string;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface MainDataInterface {
5757
disableRoutesGraph: boolean;
5858
disableSearch: boolean;
5959
disableDependencies: boolean;
60+
disableProperties: boolean;
6061
watch: boolean;
6162
mainGraph: string;
6263
coverageTest: boolean;
@@ -75,6 +76,7 @@ export interface MainDataInterface {
7576
customLogo: string;
7677
packageDependencies: Object[];
7778
packagePeerDependencies: Object[];
79+
packageProperties: any;
7880
gaID: string;
7981
gaSite: string;
8082
angularProject: boolean;

src/config/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@
284284
"default": false,
285285
"examples": [false]
286286
},
287+
"disableProperties": {
288+
"$id": "/properties/disableProperties",
289+
"type": "boolean",
290+
"title": "Do not add the properties list",
291+
"default": false,
292+
"examples": [false]
293+
},
287294
"minimal": {
288295
"$id": "/properties/minimal",
289296
"type": "boolean",

src/index-cli.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
174174
'Do not add the dependencies list',
175175
COMPODOC_DEFAULTS.disableDependencies
176176
)
177+
.option(
178+
'--disableProperties',
179+
'Do not add the properties list',
180+
COMPODOC_DEFAULTS.disableProperties
181+
)
177182
.option(
178183
'--minimal',
179184
'Minimal mode with only documentation. No search, no graph, no coverage.',
@@ -520,6 +525,13 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
520525
Configuration.mainData.disableDependencies = programOptions.disableDependencies;
521526
}
522527

528+
if (configFile.disableProperties) {
529+
Configuration.mainData.disableProperties = configFile.disableProperties;
530+
}
531+
if (programOptions.disableProperties) {
532+
Configuration.mainData.disableProperties = programOptions.disableProperties;
533+
}
534+
523535
if (configFile.minimal) {
524536
Configuration.mainData.disableSearch = true;
525537
Configuration.mainData.disableRoutesGraph = true;

0 commit comments

Comments
 (0)