import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex } from '../../index-DAUqbQ6h.js'; import { SimpleLogger } from '@homer0/simple-logger'; import { SimpleConfig } from '@homer0/simple-config'; import { FrontendFs } from '../frontend/frontendFs.js'; import { DeferredPromise } from '@homer0/deferred'; import '../../types/express.js'; import 'express'; import '../../types/http.js'; import 'https'; import 'http'; import 'spdy'; import 'node-fetch'; import '../../types/utils.js'; import '@homer0/path-utils'; import '@homer0/events-hub'; import 'node:fs/promises'; /** * The options to customize a {@link HTMLGenerator} instance. * * @group Services/HTMLGenerator */ type HTMLGeneratorOptions = { /** * The name of the file it should use as template. * * @default 'index.tpl.html' */ template: string; /** * The name of the generated file. * * @default 'index.html' */ file: string; /** * If `true`, it won't log messages on the terminal when generating the file. * * @default false */ silent: boolean; /** * Whether or not to delete the template after generating the file. * * @default true */ deleteTemplateAfter: boolean; /** * The placeholder string where the information will be written. * * @default /\{\{appConfig(?:uration)?\}\}/ */ replacePlaceholder: string | RegExp; /** * A regular expression for dynamic placeholders that will be replaced by values when * the file is generated. * * @default /\{\{(.*?)\}\}/gi */ placeholderExpression: RegExp; /** * The name of the variable that will have the information on the file. * * @default 'appConfig' */ variableName: string; /** * A list of settings from the app configuration that will be used as the information to * inject on the file. * * @default ['features', 'version', 'postMessagesPrefix'] */ configKeys: string[]; }; /** * An external service that can be used to provide the values the generator will replace * in the template. * * @group Services/HTMLGenerator */ type HTMLGeneratorValuesService = { /** * A function that will be called to get the values to replace in the template. * * @param options The service customization options. */ getValues: (options: HTMLGeneratorOptions) => Promise>; }; /** * The options to construct a {@link HTMLGenerator}. * * @group Services/HTMLGenerator */ type HTMLGeneratorConstructorOptions = Partial & { /** * A dictionary with the dependencies to inject. */ inject: { config: SimpleConfig; logger: SimpleLogger; frontendFs: FrontendFs; /** * A service that can provide the values to replace in the template. If specified, the * values from `configKeys` will be ignored. */ valuesService?: HTMLGeneratorValuesService; }; }; /** * Custom options for the provider that will register an instance of {@link HTMLGenerator} * as a service. * * @group Services/HTMLGenerator */ type HTMLGeneratorProviderOptions = Partial & { /** * The name that will be used to register the service on the container. This is to allow * multiple "instances" of the service to be created. * * @default 'htmlGenerator' */ serviceName?: string; /** * The name of a service that the generator will use in order to read the values that * will be replaced on the template. If the service is available, the values from * `configKeys` will be ignored. * * @default 'htmlGeneratorValues' */ valuesServiceName?: string; }; /** * This is a utility service that generates an HTML file with custom information when the * application is started. * * @group Services * @group Services/HTMLGenerator */ declare class HTMLGenerator { /** * The service customization options. */ protected readonly _options: HTMLGeneratorOptions; /** * The application configuration service, to get the settings specified by the * `configKeys` option. */ protected readonly _config: SimpleConfig; /** * The service that logs messages on the terminal, in case the `silent` option is `false`. */ protected readonly _logger: SimpleLogger; /** * The service that interacts with the filesystem. */ protected readonly _frontendFs: FrontendFs; /** * A service that can provide values to be replaced in the template. */ protected readonly _valuesService?: HTMLGeneratorValuesService; /** * Whether or not the file was already generated. */ protected _fileReady: boolean; /** * A deferred promise to return when another service asks if the file has been * generated. Once this service finishes generating the file, the promise will be * resolved for all implementations that hold a reference to this deferred. */ protected _fileDeferred?: DeferredPromise; /** * @param options The options to construct the class. * @throws If `valuesService` is specified but it doesn't have a `getValues` * method. */ constructor({ inject: { config, logger, frontendFs, valuesService }, ...options }: HTMLGeneratorConstructorOptions); /** * Gets a promise that will be resolved when the file has been generated. */ whenReady(): Promise; /** * Generates the HTML file. */ generateHTML(): Promise; /** * Gets the customization options. */ get options(): Readonly; /** * Helper method to get the values that will be replaced in the template. If a "values * service" was specified in the constructor, it will get the values from there, * otherwise, it will use the `configKeys` option to get the values from the * application configuration. */ protected _getValues(): Promise>; /** * Processes the HTML template by replacing the placeholders with the actual values. * * @param template The template for the HTML file. * @param values The values dictionary that should be replaced in the template. */ protected _processHTML(template: string, values: Record): string; } /** * The service provider that once registered on the container will set an instance of * {@link HTMLGenerator} as the `htmlGenerator` service. it will also hook itself to the * `after-start` event of the application in order to trigger the generator of the HTML * file. * * @example * * Basic usage * * // Register it on the container * container.register(htmlGeneratorProvider); * // Getting access to the service instance * const htmlGenerator = container.get('htmlGenerator'); * * @example * * Using with custom options * * container.register( * htmlGeneratorProvider({ * serviceName: 'myHtmlGenerator', * valuesServiceName: 'myValuesService', * template: 'my-template.tpl.html', * }), * ); * * @group Providers * @group Services/HTMLGenerator */ declare const htmlGeneratorProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: HTMLGeneratorProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn>; export { HTMLGenerator, type HTMLGeneratorConstructorOptions, type HTMLGeneratorOptions, type HTMLGeneratorProviderOptions, type HTMLGeneratorValuesService, htmlGeneratorProvider };