@@ -68,49 +68,57 @@ export class FrontendGenerator extends AbstractGenerator {
6868 }
6969
7070 protected compileIndexJs ( frontendModules : Map < string , string > ) : string {
71- return `// @ts-check
71+ const compiledModuleImports = this . compileFrontendModuleImports ( frontendModules )
72+ // fix the generated indentation
73+ . replace ( / ^ / g, ' ' ) ;
74+ return `\
75+ // @ts-check
7276${ this . ifBrowser ( "require('es6-promise/auto');" ) }
7377require('reflect-metadata');
7478require('setimmediate');
7579const { Container } = require('inversify');
7680const { FrontendApplicationConfigProvider } = require('@theia/core/lib/browser/frontend-application-config-provider');
77- FrontendApplicationConfigProvider.set(${ this . prettyStringify ( this . pck . props . frontend . config ) } );
78- const { FrontendApplication } = require('@theia/core/lib/browser');
79- const { frontendApplicationModule } = require('@theia/core/lib/browser/frontend-application-module');
80- const { messagingFrontendModule } = require('@theia/core/lib/${ this . pck . isBrowser ( )
81- ? 'browser/messaging/messaging-frontend-module'
82- : 'electron-browser/messaging/electron-messaging-frontend-module' } ');
83- const { loggerFrontendModule } = require('@theia/core/lib/browser/logger-frontend-module');
84- const { ThemeService } = require('@theia/core/lib/browser/theming');
85-
86- const container = new Container();
87- container.load(frontendApplicationModule);
88- container.load(messagingFrontendModule);
89- container.load(loggerFrontendModule);
9081
91- function load(raw) {
92- return Promise.resolve(raw.default).then(module =>
93- container.load(module)
94- )
95- }
82+ FrontendApplicationConfigProvider.set(${ this . prettyStringify ( this . pck . props . frontend . config ) } );
9683
97- function start() {
98- (window['theia'] = window['theia'] || {}).container = container ;
84+ const { ThemeService } = require('@theia/core/lib/browser/theming');
85+ ThemeService.get().loadUserTheme() ;
9986
100- const themeService = ThemeService.get();
101- themeService.loadUserTheme();
87+ const nls = require('@theia/core/lib/browser/nls');
10288
103- const application = container.get(FrontendApplication);
104- return application.start();
105- }
89+ // nls translations MUST be loaded before requiring any code that uses them
90+ module.exports = nls.loadTranslations().then(() => {
91+ const { FrontendApplication } = require('@theia/core/lib/browser');
92+ const { frontendApplicationModule } = require('@theia/core/lib/browser/frontend-application-module');
93+ const { messagingFrontendModule } = require('@theia/core/lib/${ this . pck . isBrowser ( )
94+ ? 'browser/messaging/messaging-frontend-module'
95+ : 'electron-browser/messaging/electron-messaging-frontend-module' } ');
96+ const { loggerFrontendModule } = require('@theia/core/lib/browser/logger-frontend-module');
97+
98+ const container = new Container();
99+ container.load(frontendApplicationModule);
100+ container.load(messagingFrontendModule);
101+ container.load(loggerFrontendModule);
102+
103+ return Promise.resolve()${ compiledModuleImports }
104+ .then(start).catch(reason => {
105+ console.error('Failed to start the frontend application.');
106+ if (reason) {
107+ console.error(reason);
108+ }
109+ });
110+
111+ function load(jsModule) {
112+ return Promise.resolve(jsModule.default)
113+ .then(containerModule => container.load(containerModule));
114+ }
106115
107- module.exports = Promise.resolve()${ this . compileFrontendModuleImports ( frontendModules ) }
108- .then(start).catch(reason => {
109- console.error('Failed to start the frontend application.');
110- if (reason) {
111- console.error(reason);
112- }
113- });` ;
116+ function start() {
117+ (window['theia'] = window['theia'] || {}).container = container;
118+ return container.get(FrontendApplication).start();
119+ }
120+ });
121+ ` ;
114122 }
115123
116124 protected compileElectronMain ( electronMainModules ?: Map < string , string > ) : string {
0 commit comments