UNPKG

3 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const appRootDir = require("app-root-dir");
12const build_yargs_1 = require("./build.yargs");
13const paths_1 = require("../../paths");
14const chokidar = require("chokidar");
15const child_process_1 = require("child_process");
16const notify_1 = require("../utils/notify");
17exports.default = (argv) => __awaiter(this, void 0, void 0, function* () {
18 let restarted = false;
19 let hasExited = false;
20 let hadError = false;
21 function getExecutable() {
22 let restartEnv = '';
23 if (restarted) {
24 restartEnv = ' SERVER_RESTART=true';
25 }
26 return `cross-env NODE_ENV=development CORTEXQL_COMMAND=develop${restartEnv} node -r ts-node/register -r tsconfig-paths/register ${paths_1.getRootPath()}`;
27 }
28 let child;
29 function restart() {
30 child = child_process_1.spawn(getExecutable(), [], {
31 shell: true,
32 detached: true,
33 cwd: appRootDir.get(),
34 stdio: 'inherit',
35 });
36 child.once('exit', (code, signal) => {
37 if (code > 0) {
38 notify_1.notify('✖️ An error has occured, check the terminal');
39 }
40 else {
41 notify_1.notify('✖️ Server has stopped on its own');
42 }
43 hasExited = true;
44 hadError = false;
45 });
46 }
47 const watcher = chokidar.watch('./**/*.ts', {
48 cwd: appRootDir.get(),
49 ignored: ['node_modules'],
50 }).on('change', () => {
51 hadError = false;
52 restarted = true;
53 console.log('\nRestarting...\n');
54 if (!hasExited) {
55 hasExited = false;
56 process.kill(-child.pid, 'SIGKILL');
57 }
58 child.removeAllListeners();
59 try {
60 child.kill('SIGKILL');
61 }
62 catch (error) { }
63 restart();
64 });
65 restart();
66 function destroy() {
67 if (child !== undefined && !hasExited) {
68 process.kill(-child.pid, 'SIGKILL');
69 }
70 process.exit(0);
71 }
72 process.on('SIGINT', destroy);
73 process.on('SIGTERM', destroy);
74 process.on('SIGUSR2', destroy);
75 process.on('exit', destroy);
76});
77if (!module.parent) {
78 build_yargs_1.handler(build_yargs_1.builder().argv)
79 .catch(err => {
80 console.log(err.stack);
81 });
82}
83//# sourceMappingURL=develop.js.map
\No newline at end of file