1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | var __importStar = (this && this.__importStar) || function (mod) {
|
6 | if (mod && mod.__esModule) return mod;
|
7 | var result = {};
|
8 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9 | result["default"] = mod;
|
10 | return result;
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const inquirer_1 = require("../utils/inquirer");
|
14 | const appConfig_1 = __importDefault(require("../config/appConfig"));
|
15 | const choosePort_1 = __importDefault(require("art-dev-utils/lib/choosePort"));
|
16 | const webpackDevServer_1 = __importDefault(require("../config/webpackDevServer"));
|
17 | const createServeCompiler_1 = __importDefault(require("../utils/createServeCompiler"));
|
18 | const config_1 = require("../config");
|
19 | const prepareProxy_1 = __importDefault(require("art-dev-utils/lib/prepareProxy"));
|
20 | const prepareUrls_1 = __importDefault(require("art-dev-utils/lib/prepareUrls"));
|
21 | const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
22 | const clearConsole_1 = __importDefault(require("art-dev-utils/lib/clearConsole"));
|
23 | const chalkColors_1 = require("art-dev-utils/lib/chalkColors");
|
24 | const executeNodeScript_1 = __importDefault(require("art-dev-utils/lib/executeNodeScript"));
|
25 | const path = __importStar(require("path"));
|
26 | const paths_1 = __importDefault(require("../config/paths"));
|
27 | const envName = appConfig_1.default.get('NODE_ENV');
|
28 | const HOST = process.env.HOST || '0.0.0.0';
|
29 | const DEFAULT_PORT = appConfig_1.default.get(`devPort:${envName}`);
|
30 | const isInteractive = process.stdout.isTTY;
|
31 | let nodeServerHasLunched = false;
|
32 | const lunchNodeServer = (port) => {
|
33 | const artModules = appConfig_1.default.get('ART_MODULES');
|
34 | if (nodeServerHasLunched) {
|
35 | return;
|
36 | }
|
37 | if (isInteractive) {
|
38 | clearConsole_1.default();
|
39 | }
|
40 | const mockServerPath = path.join(__dirname, '../../../art-server-mock/dist/index.js');
|
41 | const nodemonPath = path.join(require.resolve('nodemon'), '../../bin/nodemon.js');
|
42 | executeNodeScript_1.default(nodemonPath, '--watch', paths_1.default.appMockServer, '--ignore', paths_1.default.appMockServer, '-e', 'js, jsx, ts', mockServerPath, '--ART_MODULES', `${JSON.stringify(artModules)}`, '--ART_WEBPACK_PORT', `${port}`);
|
43 | nodeServerHasLunched = true;
|
44 | };
|
45 | let compileMockServerHasLunched = false;
|
46 | const compileMockServer = () => {
|
47 | if (compileMockServerHasLunched) {
|
48 | return;
|
49 | }
|
50 | executeNodeScript_1.default(process.env.STAGE === 'dev' ?
|
51 | '../../node_modules/.bin/tsc' :
|
52 | path.join(process.cwd(), 'node_modules/.bin/tsc'), '-p', `${paths_1.default.appMockServerConfig}`, '-w');
|
53 | compileMockServerHasLunched = true;
|
54 | };
|
55 | const confirmModulesCb = (answer) => {
|
56 | if (answer.availableModulesOk === false) {
|
57 | return;
|
58 | }
|
59 | choosePort_1.default(HOST, DEFAULT_PORT)
|
60 | .then((port) => {
|
61 | if (port === null) {
|
62 | return;
|
63 | }
|
64 |
|
65 | appConfig_1.default.set(`devPort:${envName}`, port);
|
66 | const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
67 | const urls = prepareUrls_1.default(protocol, HOST, port);
|
68 | const webpackconfig = config_1.getWebpackConfig();
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | const compiler = createServeCompiler_1.default(webpackconfig, (success) => {
|
74 | if (success) {
|
75 | console.log('Compiler instance created successfully.');
|
76 | lunchNodeServer(port);
|
77 | compileMockServer();
|
78 | }
|
79 | });
|
80 | if (compiler === null) {
|
81 | return;
|
82 | }
|
83 | const proxySetting = appConfig_1.default.get('art:proxy');
|
84 | const proxyConfig = prepareProxy_1.default(proxySetting);
|
85 | const devServerConfig = webpackDevServer_1.default(proxyConfig, urls.lanUrlForConfig);
|
86 | const devServer = new webpack_dev_server_1.default(compiler, devServerConfig);
|
87 | devServer.listen(port, HOST, (error) => {
|
88 | if (error) {
|
89 | return console.log(error);
|
90 | }
|
91 | console.log(chalkColors_1.cyanText(`Starting compilers to compiling modules hold on...\n`));
|
92 | });
|
93 | ['SIGINT', 'SIGTERM'].forEach((sig) => {
|
94 | process.on(sig, () => {
|
95 | devServer.close();
|
96 | process.exit();
|
97 | });
|
98 | });
|
99 | })
|
100 | .catch((error) => {
|
101 | if (error && error.message) {
|
102 | console.log(error.message);
|
103 | }
|
104 | process.exit(1);
|
105 | });
|
106 | };
|
107 | inquirer_1.confirmModules(confirmModulesCb);
|