From 29550b2f852499c7d1f168412bdbbb603059a807 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 21 Jun 2023 00:39:20 +0200 Subject: [PATCH] Simplify generator infrastructure --- .../src/generator/abstract-generator.ts | 28 ------------------- .../src/generator/backend-generator.ts | 8 ++++-- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/dev-packages/application-manager/src/generator/abstract-generator.ts b/dev-packages/application-manager/src/generator/abstract-generator.ts index 1a1154c3c7c29..849ec82c80354 100644 --- a/dev-packages/application-manager/src/generator/abstract-generator.ts +++ b/dev-packages/application-manager/src/generator/abstract-generator.ts @@ -14,7 +14,6 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** -import * as os from 'os'; import * as fs from 'fs-extra'; import { ApplicationPackage } from '@theia/application-package'; @@ -30,33 +29,6 @@ export abstract class AbstractGenerator { protected options: GeneratorOptions = {} ) { } - protected compileFrontendModuleImports(modules: Map, indentation = 1): string { - const splitFrontend = this.options.splitFrontend ?? this.options.mode !== 'production'; - return this.compileModuleImports(modules, splitFrontend ? 'import' : 'require', indentation); - } - - protected compileBackendModuleImports(modules: Map): string { - return this.compileModuleImports(modules, 'require'); - } - - protected compileElectronMainModuleImports(modules?: Map): string { - return modules && this.compileModuleImports(modules, 'require') || ''; - } - - protected compileModuleImports(modules: Map, fn: 'import' | 'require', indentation = 1): string { - if (modules.size === 0) { - return ''; - } - const lines = Array.from(modules.keys()).map(moduleName => { - const invocation = `${fn}('${modules.get(moduleName)}')`; - if (fn === 'require') { - return `Promise.resolve(${invocation})`; - } - return invocation; - }).map(statement => `${' '.repeat(indentation * 4)}.then(function () { return ${statement}.then(load) })`); - return os.EOL + lines.join(os.EOL); - } - protected ifBrowser(value: string, defaultValue: string = ''): string { return this.pck.ifBrowser(value, defaultValue); } diff --git a/dev-packages/application-manager/src/generator/backend-generator.ts b/dev-packages/application-manager/src/generator/backend-generator.ts index cce70a8bf7101..0c045fbea8759 100644 --- a/dev-packages/application-manager/src/generator/backend-generator.ts +++ b/dev-packages/application-manager/src/generator/backend-generator.ts @@ -84,8 +84,12 @@ async function start() { await application.start(config); } -module.exports = Promise.resolve()${this.compileElectronMainModuleImports(electronMainModules)} - .then(start).catch(reason => { +module.exports = async () => { + try { + ${Array.from(electronMainModules?.values() ?? [], jsModulePath => `\ + await load(container, import('${jsModulePath}'));`).join('\n')} + await start(); + } catch (reason) { console.error('Failed to start the electron application.'); if (reason) { console.error(reason);