"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const LocalDevApp_1 = require("./LocalDevApp");
const api_1 = require("@webruntime/api");
const services_1 = require("@webruntime/services");
const services_2 = require("@communities-webruntime/services");
const ResourceUrlService_1 = require("../services/ResourceUrlService");
const ApexContinuationService_1 = require("../services/ApexContinuationService");
const LWCMessageService_1 = require("../services/LWCMessageService");
const plugin_alias_1 = __importDefault(require("@rollup/plugin-alias"));
class WebruntimeConfig {
    constructor(project) {
        this.projectDir = path_1.default.join(__dirname, '..', '..', '..');
        this.buildDir = path_1.default.join(project.directory, '.localdevserver');
        this.moduleDir = project.modulesSourceDirectory;
        this.defaultMode = api_1.CompileMode.dev;
        this.defaultLocale = 'en_US';
        this.server = {
            port: project.configuration.port,
            resourceRoot: '/webruntime',
            basePath: '',
            extensions: []
        };
        this.app = {
            defaultComponent: 'localdevserver/app',
            defaultTemplate: path_1.default.join(this.projectDir, 'dist', 'client', 'index.html'),
            definition: LocalDevApp_1.LocalDevApp
        };
        this.services = [
            ApexContinuationService_1.ApexContinuationService,
            services_2.ApexService,
            services_1.AppBootstrapService,
            services_1.ImportMapService,
            ResourceUrlService_1.ResourceUrlService,
            services_2.SchemaService,
            LWCMessageService_1.LWCMessageService
        ];
        this.bundle = [
            '@webruntime/app',
            'webruntime_navigation/*',
            'lightning/configProvider'
        ];
        this.preloadModules = [];
        this.externals = [
            'webruntime_loader/loader',
            '@app/basePath',
            '@app/csrfToken',
            'lightning/navigation'
        ];
        this.compilerConfig = {
            formatConfig: {
                amd: { define: 'Webruntime.define' }
            },
            lwcOptions: {
                exclude: [/@salesforce\/(?!lwc-dev-server).*/],
                experimentalDynamicComponent: {
                    loader: 'webruntime_loader/loader',
                    strictSpecifier: false
                },
                modules: []
            },
            plugins: [
                plugin_alias_1.default({
                    entries: [
                        {
                            find: 'transport',
                            replacement: 'webruntime/transport'
                        }
                    ]
                })
            ],
            inlineConfig: [
                {
                    descriptor: '*/*',
                    exclude: ['lwc', 'wire-service']
                }
            ]
        };
    }
    addMiddleware(middleware) {
        this.server.extensions = [...middleware, ...this.server.extensions];
    }
    addRoutes(routes) {
        this.server.extensions = [...this.server.extensions, ...routes];
    }
    addModules(modules) {
        if (!this.compilerConfig.lwcOptions) {
            this.compilerConfig.lwcOptions = {};
        }
        if (!this.compilerConfig.lwcOptions.modules) {
            this.compilerConfig.lwcOptions.modules = [];
        }
        this.compilerConfig.lwcOptions.modules = [
            ...this.compilerConfig.lwcOptions.modules,
            ...modules
        ];
    }
    addPlugins(plugins) {
        if (!this.compilerConfig.plugins) {
            this.compilerConfig.plugins = [];
        }
        this.compilerConfig.plugins = [
            ...this.compilerConfig.plugins,
            ...plugins
        ];
    }
    addServices(services) {
        this.services = [...this.services, ...services];
    }
}
exports.default = WebruntimeConfig;
//# sourceMappingURL=WebruntimeConfig.js.map