@dainprotocol/cli 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/dev.js +58 -8
- package/package.json +1 -1
package/dist/commands/dev.js
CHANGED
|
@@ -82,20 +82,24 @@ function cleanup() {
|
|
|
82
82
|
}
|
|
83
83
|
function dev(options) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var config, command, watchPaths;
|
|
85
|
+
var config, command, proxyServer, watchPaths, error_1;
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
89
|
process.env.PORT = options.port;
|
|
90
90
|
config = (0, utils_1.getDainConfig)();
|
|
91
91
|
command = "ts-node ".concat(config['main-file']);
|
|
92
|
+
proxyServer = null;
|
|
93
|
+
_a.label = 1;
|
|
94
|
+
case 1:
|
|
95
|
+
_a.trys.push([1, 4, , 5]);
|
|
92
96
|
startProcess(command);
|
|
93
|
-
if (!!options.noproxy) return [3 /*break*/,
|
|
97
|
+
if (!!options.noproxy) return [3 /*break*/, 3];
|
|
94
98
|
return [4 /*yield*/, (0, utils_1.setupProxy)(options.port)];
|
|
95
|
-
case 1:
|
|
96
|
-
_a.sent();
|
|
97
|
-
_a.label = 2;
|
|
98
99
|
case 2:
|
|
100
|
+
proxyServer = _a.sent();
|
|
101
|
+
_a.label = 3;
|
|
102
|
+
case 3:
|
|
99
103
|
watchPaths = [
|
|
100
104
|
path_1.default.dirname(config['main-file']),
|
|
101
105
|
(0, utils_1.getStaticFilesPath)()
|
|
@@ -110,9 +114,55 @@ function dev(options) {
|
|
|
110
114
|
});
|
|
111
115
|
(0, utils_1.logInfo)('Watching for file changes...');
|
|
112
116
|
// Add signal handlers for graceful shutdown
|
|
113
|
-
process.on('SIGINT',
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
process.on('SIGINT', function () {
|
|
118
|
+
cleanup();
|
|
119
|
+
if (proxyServer) {
|
|
120
|
+
proxyServer.close(function () {
|
|
121
|
+
(0, utils_1.logInfo)('Proxy server closed.');
|
|
122
|
+
process.exit(0);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
process.on('SIGTERM', function () {
|
|
130
|
+
cleanup();
|
|
131
|
+
if (proxyServer) {
|
|
132
|
+
proxyServer.close(function () {
|
|
133
|
+
(0, utils_1.logInfo)('Proxy server closed.');
|
|
134
|
+
process.exit(0);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Handle uncaught exceptions and unhandled rejections
|
|
142
|
+
process.on('uncaughtException', function (error) {
|
|
143
|
+
(0, utils_1.logError)('Uncaught Exception:', error);
|
|
144
|
+
cleanup();
|
|
145
|
+
if (proxyServer)
|
|
146
|
+
proxyServer.close();
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
|
149
|
+
process.on('unhandledRejection', function (reason, promise) {
|
|
150
|
+
(0, utils_1.logError)('Unhandled Rejection at:', promise + '\n\nreason:' + reason);
|
|
151
|
+
cleanup();
|
|
152
|
+
if (proxyServer)
|
|
153
|
+
proxyServer.close();
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
156
|
+
return [3 /*break*/, 5];
|
|
157
|
+
case 4:
|
|
158
|
+
error_1 = _a.sent();
|
|
159
|
+
(0, utils_1.logError)('Error in dev process:', error_1);
|
|
160
|
+
cleanup();
|
|
161
|
+
if (proxyServer)
|
|
162
|
+
proxyServer.close();
|
|
163
|
+
process.exit(1);
|
|
164
|
+
return [3 /*break*/, 5];
|
|
165
|
+
case 5: return [2 /*return*/];
|
|
116
166
|
}
|
|
117
167
|
});
|
|
118
168
|
});
|