1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.startDevServer = void 0;
|
4 | const dev_server_core_1 = require("@web/dev-server-core");
|
5 | const mergeConfigs_js_1 = require("./config/mergeConfigs.js");
|
6 | const parseConfig_js_1 = require("./config/parseConfig.js");
|
7 | const readCliArgs_js_1 = require("./config/readCliArgs.js");
|
8 | const readFileConfig_js_1 = require("./config/readFileConfig.js");
|
9 | const DevServerStartError_js_1 = require("./DevServerStartError.js");
|
10 | const createLogger_js_1 = require("./logger/createLogger.js");
|
11 | const openBrowser_js_1 = require("./openBrowser.js");
|
12 |
|
13 |
|
14 |
|
15 | async function startDevServer(options = {}) {
|
16 | var _a;
|
17 | const { config: extraConfig, readCliArgs: readCliArgsFlag = true, readFileConfig: readFileConfigFlag = true, configName, autoExitProcess = true, logStartMessage = true, argv = process.argv, } = options;
|
18 | try {
|
19 | const cliArgs = readCliArgsFlag ? (0, readCliArgs_js_1.readCliArgs)({ argv }) : {};
|
20 | const rawConfig = readFileConfigFlag
|
21 | ? await (0, readFileConfig_js_1.readFileConfig)({ configName, configPath: cliArgs.config })
|
22 | : {};
|
23 | const mergedConfig = (0, mergeConfigs_js_1.mergeConfigs)(extraConfig, rawConfig);
|
24 | const config = await (0, parseConfig_js_1.parseConfig)(mergedConfig, cliArgs);
|
25 | const { logger, loggerPlugin } = (0, createLogger_js_1.createLogger)({
|
26 | debugLogging: !!config.debug,
|
27 | clearTerminalOnReload: !!config.watch && !!config.clearTerminalOnReload,
|
28 | logStartMessage: !!logStartMessage,
|
29 | });
|
30 | config.plugins = (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
|
31 | config.plugins.unshift(loggerPlugin);
|
32 | const server = new dev_server_core_1.DevServer(config, logger);
|
33 | if (autoExitProcess) {
|
34 | process.on('uncaughtException', error => {
|
35 |
|
36 | console.error(error);
|
37 | });
|
38 | process.on('SIGINT', async () => {
|
39 | await server.stop();
|
40 | process.exit(0);
|
41 | });
|
42 | }
|
43 | await server.start();
|
44 | if (config.open != null && config.open !== false) {
|
45 | await (0, openBrowser_js_1.openBrowser)(config);
|
46 | }
|
47 | return server;
|
48 | }
|
49 | catch (error) {
|
50 | if (error instanceof DevServerStartError_js_1.DevServerStartError) {
|
51 | console.error(error.message);
|
52 | }
|
53 | else {
|
54 | console.error(error);
|
55 | }
|
56 | process.exit(1);
|
57 | }
|
58 | }
|
59 | exports.startDevServer = startDevServer;
|
60 |
|
\ | No newline at end of file |