Skip to content

Commit

Permalink
feat(app): display project properties from package.json file
Browse files Browse the repository at this point in the history
fix #1198
  • Loading branch information
vogloblinsky committed Feb 10, 2022
1 parent ce6e2a6 commit b091e19
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/app/application.ts
Expand Up @@ -233,6 +233,35 @@ export class Application {
}
}

if (!Configuration.mainData.disableProperties) {
const propertiesToCheck = [
'version',
'description',
'keywords',
'homepage',
'bugs',
'license',
'repository',
'author'
];
let hasOneOfCheckedProperties = false;
propertiesToCheck.forEach(prop => {
if (prop in parsedData) {
hasOneOfCheckedProperties = true;
Configuration.mainData.packageProperties[prop] = parsedData[prop];
}
});
if (hasOneOfCheckedProperties) {
Configuration.addPage({
name: 'properties',
id: 'packageProperties',
context: 'package-properties',
depth: 0,
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
});
}
}

this.processMarkdowns().then(
() => {
this.getDependenciesData();
Expand Down
2 changes: 2 additions & 0 deletions src/app/configuration.ts
Expand Up @@ -66,6 +66,7 @@ export class Configuration implements ConfigurationInterface {
disableRoutesGraph: COMPODOC_DEFAULTS.disableRoutesGraph,
disableSearch: false,
disableDependencies: COMPODOC_DEFAULTS.disableDependencies,
disableProperties: COMPODOC_DEFAULTS.disableProperties,
watch: false,
mainGraph: '',
coverageTest: false,
Expand All @@ -84,6 +85,7 @@ export class Configuration implements ConfigurationInterface {
customLogo: '',
packageDependencies: [],
packagePeerDependencies: [],
packageProperties: {},
gaID: '',
gaSite: '',
angularProject: false,
Expand Down
8 changes: 8 additions & 0 deletions src/app/engines/html-engine-helpers/capitalize.helper.ts
@@ -0,0 +1,8 @@
import { IHtmlEngineHelper } from './html-engine-helper.interface';
import * as Handlebars from 'handlebars';

export class CapitalizeHelper implements IHtmlEngineHelper {
public helperFunc(context: any, text: string) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
}
12 changes: 12 additions & 0 deletions src/app/engines/html-engine-helpers/parse-property.helper.ts
@@ -0,0 +1,12 @@
import { IHtmlEngineHelper } from './html-engine-helper.interface';
import * as Handlebars from 'handlebars';

export class ParsePropertyHelper implements IHtmlEngineHelper {
public helperFunc(context: any, text: string) {
if (text.indexOf('https') !== -1) {
return `<a href="${text}" target="_blank">${text}</a>`;
} else {
return text;
}
}
}
6 changes: 5 additions & 1 deletion src/app/engines/html.engine.helpers.ts
Expand Up @@ -3,6 +3,7 @@ import * as _ from 'lodash';

import { BreakCommaHelper } from './html-engine-helpers/break-comma.helper';
import { BreakLinesHelper } from './html-engine-helpers/break-lines.helper';
import { CapitalizeHelper } from './html-engine-helpers/capitalize.helper';
import { CleanParagraphHelper } from './html-engine-helpers/clean-paragraph.helper';
import { CompareHelper } from './html-engine-helpers/compare.helper';
import { DebugHelper } from './html-engine-helpers/debug.helper';
Expand Down Expand Up @@ -33,6 +34,7 @@ import { OneParameterHasHelper } from './html-engine-helpers/one-parameter-has.h
import { OrLengthHelper } from './html-engine-helpers/or-length.helper';
import { OrHelper } from './html-engine-helpers/or.helper';
import { ParseDescriptionHelper } from './html-engine-helpers/parse-description.helper';
import { ParsePropertyHelper } from './html-engine-helpers/parse-property.helper';
import { RelativeURLHelper } from './html-engine-helpers/relative-url.helper';
import { ShortURLHelper } from './html-engine-helpers/short-url.helper';
import { StripURLHelper } from './html-engine-helpers/strip-url.helper';
Expand Down Expand Up @@ -73,10 +75,12 @@ export class HtmlEngineHelpers {
this.registerHelper(bars, 'short-url', new ShortURLHelper());
this.registerHelper(bars, 'strip-url', new StripURLHelper());
this.registerHelper(bars, 't', new I18nHelper());
this.registerHelper(bars, 'capitalize', new CapitalizeHelper());
this.registerHelper(bars, 'parse-property', new ParsePropertyHelper());
}

private registerHelper(bars, key: string, helper: IHtmlEngineHelper) {
Handlebars.registerHelper(key, function() {
Handlebars.registerHelper(key, function () {
// tslint:disable-next-line:no-invalid-this
return helper.helperFunc.apply(helper, [this, ..._.slice(arguments as any)]);
});
Expand Down
3 changes: 2 additions & 1 deletion src/app/engines/html.engine.ts
Expand Up @@ -63,7 +63,8 @@ export class HtmlEngine {
'miscellaneous-typealiases',
'miscellaneous-enumerations',
'additional-page',
'package-dependencies'
'package-dependencies',
'package-properties'
];
if (templatePath) {
if (
Expand Down
1 change: 1 addition & 0 deletions src/app/interfaces/configuration-file.interface.ts
Expand Up @@ -37,6 +37,7 @@ export interface ConfigurationFileInterface {
disableRoutesGraph: boolean;
disableSearch: boolean;
disableDependencies: boolean;
disableProperties: boolean;
minimal: boolean;
customFavicon: string;
customLogo: string;
Expand Down
2 changes: 2 additions & 0 deletions src/app/interfaces/main-data.interface.ts
Expand Up @@ -57,6 +57,7 @@ export interface MainDataInterface {
disableRoutesGraph: boolean;
disableSearch: boolean;
disableDependencies: boolean;
disableProperties: boolean;
watch: boolean;
mainGraph: string;
coverageTest: boolean;
Expand All @@ -75,6 +76,7 @@ export interface MainDataInterface {
customLogo: string;
packageDependencies: Object[];
packagePeerDependencies: Object[];
packageProperties: any;
gaID: string;
gaSite: string;
angularProject: boolean;
Expand Down
7 changes: 7 additions & 0 deletions src/config/schema.json
Expand Up @@ -284,6 +284,13 @@
"default": false,
"examples": [false]
},
"disableProperties": {
"$id": "/properties/disableProperties",
"type": "boolean",
"title": "Do not add the properties list",
"default": false,
"examples": [false]
},
"minimal": {
"$id": "/properties/minimal",
"type": "boolean",
Expand Down
12 changes: 12 additions & 0 deletions src/index-cli.ts
Expand Up @@ -174,6 +174,11 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
'Do not add the dependencies list',
COMPODOC_DEFAULTS.disableDependencies
)
.option(
'--disableProperties',
'Do not add the properties list',
COMPODOC_DEFAULTS.disableProperties
)
.option(
'--minimal',
'Minimal mode with only documentation. No search, no graph, no coverage.',
Expand Down Expand Up @@ -520,6 +525,13 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
Configuration.mainData.disableDependencies = programOptions.disableDependencies;
}

if (configFile.disableProperties) {
Configuration.mainData.disableProperties = configFile.disableProperties;
}
if (programOptions.disableProperties) {
Configuration.mainData.disableProperties = programOptions.disableProperties;
}

if (configFile.minimal) {
Configuration.mainData.disableSearch = true;
Configuration.mainData.disableRoutesGraph = true;
Expand Down
10 changes: 9 additions & 1 deletion src/resources/styles/compodoc.css
Expand Up @@ -1071,4 +1071,12 @@ ul.index-list {
.dark-mode-switch {
top: 15px;
}
}
}

ul.properties-list {
list-style: none;
padding-left: 0;
}
.properties-list li {
margin-bottom: 10px;
}
6 changes: 6 additions & 0 deletions src/templates/page.hbs
Expand Up @@ -119,6 +119,12 @@
{{/compare}}
{{/unless}}

{{#unless data.disableProperties}}
{{#compare data.context "===" 'package-properties'}}
{{~> package-properties data ~}}
{{/compare}}
{{/unless}}


{{#compare data.context "===" 'miscellaneous-functions'}}
{{~> miscellaneous-functions data ~}}
Expand Down
9 changes: 9 additions & 0 deletions src/templates/partials/menu.hbs
Expand Up @@ -65,6 +65,15 @@ customElements.define('compodoc-menu', class extends HTMLElement {
</li>
{{/orLength}}
{{/unless}}
{{#unless disableProperties}}
{{#orLength packageProperties}}
<li class="link">
<a href="properties.html" data-type="chapter-link">
<span class="icon ion-ios-apps"></span>{{t "properties" }}
</a>
</li>
{{/orLength}}
{{/unless}}
</ul>
</li>
{{#if additionalPages}}
Expand Down
11 changes: 11 additions & 0 deletions src/templates/partials/package-properties.hbs
@@ -0,0 +1,11 @@
{{#if packageProperties}}
<ol class="breadcrumb">
<li>{{t "properties" }}</li>
</ol>
<ul class="properties-list">
{{#each packageProperties}}
<li>
<b>{{capitalize @key}}</b> : {{{parse-property this}}}</li>
{{/each}}
</ul>
{{/if}}
1 change: 1 addition & 0 deletions src/utils/defaults.ts
Expand Up @@ -27,6 +27,7 @@ export const COMPODOC_DEFAULTS = {
disableLifeCycleHooks: false,
disableRoutesGraph: false,
disableDependencies: false,
disableProperties: false,
PAGE_TYPES: {
ROOT: 'root',
INTERNAL: 'internal'
Expand Down
12 changes: 11 additions & 1 deletion test/fixtures/todomvc-ng2/package.json
Expand Up @@ -12,5 +12,15 @@
"devDependencies": {
"@compodoc/compodoc": "https://github.com/compodoc/compodoc/tarball/develop",
"typescript": "~3.1.1"
}
},
"description": "Demo for project",
"keywords": [
"documentation",
"angular"
],
"homepage": "https://github.com/just-a-repo",
"bugs": "https://github.com/just-a-repo/issues",
"url": "https://github.com/just-a-repo",
"repository": "https://github.com/just-a-repo",
"author": "The author"
}
30 changes: 28 additions & 2 deletions test/src/cli/cli-disable-options.spec.ts
Expand Up @@ -287,7 +287,7 @@ describe('CLI disable flags', () => {
describe('disabling dependencies with --disableDependencies', () => {
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
const ls = shell('node', [
'./bin/index-cli.js',
'-p',
'./test/fixtures/sample-files/tsconfig.simple.json',
Expand All @@ -305,11 +305,37 @@ describe('CLI disable flags', () => {
after(() => tmp.clean(distFolder));

it('should not generate the dependencies list', () => {
let file = read(`${distFolder}/js/menu-wc.js`);
const file = read(`${distFolder}/js/menu-wc.js`);
expect(file).not.to.contain('href="dependencies.html"');
});
});

describe('disabling properties with --disableProperties', () => {
before(function (done) {
tmp.create(distFolder);
const ls = shell('node', [
'./bin/index-cli.js',
'-p',
'./test/fixtures/sample-files/tsconfig.simple.json',
'--disableProperties',
'-d',
distFolder
]);

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
done();
});
after(() => tmp.clean(distFolder));

it('should not generate the properties list', () => {
const file = read(`${distFolder}/js/menu-wc.js`);
expect(file).not.to.contain('href="properties.html"');
});
});

describe('minimal with --minimal', () => {
let fileContents;

Expand Down
9 changes: 9 additions & 0 deletions test/src/cli/cli-generation-big-app.spec.ts
Expand Up @@ -584,6 +584,15 @@ describe('CLI simple generation - big app', () => {
expect(dependencies).to.contain('angular/forms');
});

it('should display project properties', () => {
const file = exists(distFolder + '/properties.html');
expect(file).to.be.true;
const properties = read(distFolder + '/properties.html');
expect(properties).to.contain('Demo for project');
expect(properties).to.contain('The author');
expect(properties).to.contain('https://github.com/just-a-repo');
});

it('should display project local TypeScript version', () => {
expect(stdoutString).to.contain('TypeScript version of current project');
});
Expand Down

0 comments on commit b091e19

Please sign in to comment.