Skip to content

Commit

Permalink
feat: add custom logo to where the title name is located
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Feldman authored and Zach Feldman committed Sep 6, 2018
1 parent c80504a commit f68475b
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/app/application.ts
Expand Up @@ -2544,7 +2544,7 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
// tslint:disable-line
if (errorCopyFavicon) {
logger.error(
'Error during resources copy ',
'Error during resources copy of favicon',
errorCopyFavicon
);
} else {
Expand All @@ -2555,6 +2555,30 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
} else {
onComplete();
}
if (this.configuration.mainData.customLogo !== '') {
logger.info(`Custom logo supplied`);
fs.copy(
path.resolve(
process.cwd() +
path.sep +
this.configuration.mainData.customLogo
),
path.resolve(finalOutput + '/images/logo.png'),
errorCopyLogo => {
// tslint:disable-line
if (errorCopyLogo) {
logger.error(
'Error during resources copy of logo',
errorCopyLogo
);
} else {
onComplete();
}
}
);
} else {
onComplete();
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/configuration.ts
Expand Up @@ -68,6 +68,7 @@ export class Configuration implements ConfigurationInterface {
exportFormat: COMPODOC_DEFAULTS.exportFormat,
coverageData: {},
customFavicon: '',
customLogo: '',
packageDependencies: [],
packagePeerDependencies: [],
gaID: '',
Expand Down
1 change: 1 addition & 0 deletions src/app/interfaces/main-data.interface.ts
Expand Up @@ -63,6 +63,7 @@ export interface MainDataInterface {
exportFormat: string;
coverageData: Object;
customFavicon: string;
customLogo: string;
packageDependencies: Object[];
packagePeerDependencies: Object[];
gaID: string;
Expand Down
9 changes: 9 additions & 0 deletions src/config/schema.json
Expand Up @@ -342,6 +342,15 @@
""
]
},
"customLogo": {
"$id": "/properties/customLogo",
"type": "string",
"title": "Use a custom logo",
"default": "",
"examples": [
""
]
},
"gaID": {
"$id": "/properties/gaID",
"type": "string",
Expand Down
8 changes: 8 additions & 0 deletions src/index-cli.ts
Expand Up @@ -159,6 +159,7 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
false
)
.option('--customFavicon [path]', 'Use a custom favicon')
.option('--customLogo [path]', 'Use a custom logo')
.option('--gaID [id]', 'Google Analytics tracking ID')
.option('--gaSite [site]', 'Google Analytics site name', COMPODOC_DEFAULTS.gaSite)
.parse(process.argv);
Expand Down Expand Up @@ -477,6 +478,13 @@ Note: Certain tabs will only be shown if applicable to a given dependency`,
this.configuration.mainData.customFavicon = program.customFavicon;
}

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

if (configFile.gaID) {
this.configuration.mainData.gaID = configFile.gaID;
}
Expand Down
9 changes: 8 additions & 1 deletion src/templates/partials/menu.hbs
Expand Up @@ -14,8 +14,15 @@ customElements.define('compodoc-menu', class extends HTMLElement {
let tp = lithtml.html(`<nav>
<ul class="list">
<li class="title">
<a href="index.html" data-type="index-link">{{documentationMainName}}</a>
{{#if customLogo}}
<a href="index.html" data-type="index-link">
<img alt="" class="img-responsive" data-type="compodoc-logo" src="images/logo.png">
</a>
{{else}}
<a href="index.html" data-type="index-link">{{documentationMainName}}</a>
{{/if}}
</li>

<li class="divider"></li>
${ isNormalMode ? `{{#unless disableSearch}}{{> search-input }}{{/unless}}` : '' }
<li class="chapter">
Expand Down
41 changes: 41 additions & 0 deletions test/src/cli/cli-custom-logo.spec.ts
@@ -0,0 +1,41 @@
import * as chai from 'chai';
import {temporaryDir, shell, pkg, exists, exec, read, shellAsync, stats} from '../helpers';
const expect = chai.expect,
tmp = temporaryDir();

interface Image {
size: number;
}

describe('CLI custom logo', () => {

const distFolder = tmp.name + '-logo';

describe('when specifying a custom logo', () => {
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
'./bin/index-cli.js',
'-p', './test/src/todomvc-ng2/src/tsconfig.json',
'-d', distFolder,
'--customLogo', './test/src/todomvc-ng2/logo.png']);

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

done();
});
after(() => tmp.clean(distFolder));

it('should have copied the customLogo', () => {
let isFileExists = exists(`${distFolder}/images/logo.png`);
expect(isFileExists).to.be.true;
let originalFileSize = (stats('test/src/todomvc-ng2/logo.png') as Image).size,
copiedFileSize = (stats(`${distFolder}/images/logo.png`) as Image).size;
expect(originalFileSize).to.equal(copiedFileSize);
});
});

});
5 changes: 5 additions & 0 deletions test/src/cli/cli-options.spec.ts
Expand Up @@ -171,6 +171,11 @@ Note: Certain tabs will only be shown if applicable to a given dependency`);
expect(runHelp.stdout.toString()).to.contain('Use a custom favicon');
});

it(`--customLogo`, () => {
expect(runHelp.stdout.toString()).to.contain('--customLogo [path]');
expect(runHelp.stdout.toString()).to.contain('Use a custom logo');
});

});

});
Binary file added test/src/todomvc-ng2/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f68475b

Please sign in to comment.