Skip to content

Commit

Permalink
Support preload HTML template
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Moran <rob.moran@arm.com>
  • Loading branch information
thegecko committed Feb 7, 2019
1 parent 5550757 commit 8192a13
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/

import { AbstractGenerator } from './abstract-generator';
import { existsSync, readFileSync } from 'fs';

export class FrontendGenerator extends AbstractGenerator {

Expand All @@ -27,6 +28,20 @@ export class FrontendGenerator extends AbstractGenerator {
}
}

protected compileIndexPreload(frontendModules: Map<string, string>): string {
const template = this.pck.props.generator.config.preloadTemplate;
if (!template) {
return '';
}

// Support path to html file
if (existsSync(template)) {
return readFileSync(template).toString();
}

return template;
}

protected compileIndexHtml(frontendModules: Map<string, string>): string {
return `<!DOCTYPE html>
<html>
Expand All @@ -36,7 +51,7 @@ export class FrontendGenerator extends AbstractGenerator {
</head>
<body>
<div class="theia-preload"></div>
<div class="theia-preload">${this.compileIndexPreload(frontendModules)}</div>
</body>
</html>`;
Expand Down
21 changes: 21 additions & 0 deletions dev-packages/application-package/src/application-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export interface ApplicationProps extends NpmRegistryProps {
*/
readonly backend: Readonly<{ config: BackendApplicationConfig }>;

/**
* Generator specific properties.
*/
readonly generator: Readonly<{ config: GeneratorConfig }>;
}
export namespace ApplicationProps {

Expand All @@ -72,6 +76,11 @@ export namespace ApplicationProps {
config: {
applicationName: 'Theia'
}
},
generator: {
config: {
preloadTemplate: ''
}
}
};

Expand Down Expand Up @@ -115,3 +124,15 @@ export interface BackendApplicationConfig extends ApplicationConfig {
readonly startupTimeout?: number;

}

/**
* Configuration for the generator.
*/
export interface GeneratorConfig {

/**
* Template to use for extra preload content markup (file path or HTML)
*/
readonly preloadTemplate: string;

}

0 comments on commit 8192a13

Please sign in to comment.