zcatalyst-cli 1.8.0 → 1.10.0
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/README.md +31 -10
- package/docs/command_needs/auth.toml +5 -0
- package/docs/commands/iac/export.toml +4 -0
- package/docs/commands/iac/import.toml +4 -0
- package/docs/commands/iac/status.toml +4 -0
- package/docs/commands/project/use.toml +6 -0
- package/docs/iac/status/bundle.toml +4 -0
- package/lib/api-timer.js +81 -0
- package/lib/apig-utils.js +16 -14
- package/lib/archiver.js +83 -45
- package/lib/authentication/login.js +4 -2
- package/lib/bin/catalyst.js +0 -1
- package/lib/client-utils.js +22 -22
- package/lib/client.js +0 -3
- package/lib/command_needs/auth.js +12 -3
- package/lib/command_needs/rc.js +12 -7
- package/lib/commands/apig/disable.js +1 -1
- package/lib/commands/apig/enable.js +1 -1
- package/lib/commands/apig/status.js +7 -5
- package/lib/commands/client/delete.js +3 -5
- package/lib/commands/client/setup.js +1 -1
- package/lib/commands/deploy.js +4 -2
- package/lib/commands/ds/export.js +4 -2
- package/lib/commands/ds/import.js +4 -2
- package/lib/commands/ds/status.js +146 -150
- package/lib/commands/event/generate/index.js +1 -1
- package/lib/commands/event/generate/integ.js +1 -1
- package/lib/commands/functions/add.js +1 -1
- package/lib/commands/functions/config.js +1 -1
- package/lib/commands/functions/delete.js +1 -1
- package/lib/commands/functions/setup.js +1 -1
- package/lib/commands/functions/shell.js +1 -1
- package/lib/commands/help.js +0 -22
- package/lib/commands/iac/export.js +85 -0
- package/lib/commands/iac/import.js +187 -0
- package/lib/commands/iac/pack.js +129 -0
- package/lib/commands/iac/status.js +63 -0
- package/lib/commands/index.js +4 -0
- package/lib/commands/init.js +34 -27
- package/lib/commands/login.js +1 -1
- package/lib/commands/logout.js +1 -1
- package/lib/commands/project/list.js +11 -7
- package/lib/commands/project/reset.js +1 -1
- package/lib/commands/project/use.js +42 -25
- package/lib/commands/pull.js +1 -1
- package/lib/commands/run.js +1 -1
- package/lib/commands/serve.js +6 -5
- package/lib/commands/token/generate.js +1 -1
- package/lib/commands/token/list.js +1 -1
- package/lib/commands/token/revoke.js +1 -1
- package/lib/commands/whoami.js +1 -1
- package/lib/deploy/features/functions/index.js +2 -1
- package/lib/deploy/index.js +3 -1
- package/lib/endpoints/lib/iac.js +134 -0
- package/lib/error.js +43 -9
- package/lib/errorOut.js +9 -2
- package/lib/express_middlewares/unknownReqProxy.js +18 -7
- package/lib/fn-utils/lib/common.js +32 -12
- package/lib/fn-utils/lib/java.js +8 -9
- package/lib/fn-utils/lib/node.js +7 -1
- package/lib/fn-watcher.js +67 -0
- package/lib/iac/status/bundle.js +82 -0
- package/lib/iac/status/deploy.js +74 -0
- package/lib/iac/status/util/index.js +26 -0
- package/lib/index.js +13 -19
- package/lib/init/features/client.js +2 -3
- package/lib/init/features/functions/languages/java.js +2 -5
- package/lib/init/features/functions/languages/node.js +2 -5
- package/lib/init/features/index.js +8 -3
- package/lib/init/features/project.js +70 -33
- package/lib/init/util/client.js +12 -0
- package/lib/init/util/functions.js +20 -0
- package/lib/init/util/project.js +35 -0
- package/lib/internal/api.js +6 -9
- package/lib/internal/command.js +3 -3
- package/lib/internal/config.js +6 -4
- package/lib/migration/index.js +10 -6
- package/lib/option-filter.js +4 -1
- package/lib/port-resolver.js +18 -16
- package/lib/prompt/index.js +92 -0
- package/lib/prompt/types/file-path.js +95 -0
- package/lib/pull/features/client.js +1 -1
- package/lib/pull/features/functions/index.js +5 -7
- package/lib/pull/index.js +4 -1
- package/lib/serve/features/index.js +3 -1
- package/lib/serve/index.js +8 -4
- package/lib/serve/server/index.js +134 -64
- package/lib/serve/server/lib/master.js +5 -4
- package/lib/shell/dependencies/http-functions.js +46 -21
- package/lib/shell/dependencies/local-function.js +17 -48
- package/lib/shell/index.js +9 -10
- package/lib/shell/prepare/index.js +1 -5
- package/lib/shell/prepare/languages/index.js +14 -3
- package/lib/track.js +3 -1
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/file-names.js +2 -1
- package/lib/util_modules/constants/lib/iac.js +8 -0
- package/lib/util_modules/constants/lib/regex.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +5 -0
- package/lib/util_modules/constants/project.js +6 -0
- package/lib/util_modules/contextHelp.js +25 -14
- package/lib/util_modules/env.js +2 -5
- package/lib/util_modules/fs/index.js +9 -1
- package/lib/util_modules/fs/lib/async.js +29 -22
- package/lib/util_modules/js.js +6 -0
- package/lib/util_modules/logger.js +11 -10
- package/lib/util_modules/parser/toml.js +5 -1
- package/lib/util_modules/project.js +34 -19
- package/lib/util_modules/shell.js +6 -5
- package/package.json +12 -7
- package/scripts/postInstall.js +31 -0
- package/templates/iacSuccess.html +391 -0
- package/lib/prompt.js +0 -49
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -28,26 +39,26 @@ class Server {
|
|
|
28
39
|
constructor() {
|
|
29
40
|
this.targetDetailsArr = [];
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
_addBasicFnDetails() {
|
|
43
|
+
const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
44
|
+
if (fnTargets.length === 0) {
|
|
45
|
+
logger_1.debug('No basic functions to add');
|
|
46
|
+
}
|
|
47
|
+
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
48
|
+
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
49
|
+
if (!isNaN(httpPort)) {
|
|
50
|
+
fnTargets
|
|
51
|
+
.filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
|
|
52
|
+
.map((t) => js_1.JS.omit(t, ['zip_stream', 'localFn']))
|
|
53
|
+
.forEach((t) => {
|
|
54
|
+
this.targetDetailsArr.push({
|
|
55
|
+
type: 'functions',
|
|
56
|
+
httpPort,
|
|
57
|
+
debugPort,
|
|
58
|
+
target: t
|
|
47
59
|
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
_spinUpJavaServer(details, masterPort) {
|
|
53
64
|
var _a, _b, _c, _d;
|
|
@@ -98,10 +109,11 @@ class Server {
|
|
|
98
109
|
var _a, _b, _c;
|
|
99
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
111
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
112
|
+
const _d = details.target, { ['watcher']: _ } = _d, serialisableTarget = __rest(_d, ['watcher']);
|
|
101
113
|
const opts = [
|
|
102
114
|
path_1.join(__dirname, 'lib', details.type === 'client' ? 'client.js' : 'node.js'),
|
|
103
115
|
details.httpPort + '',
|
|
104
|
-
JSON.stringify(
|
|
116
|
+
JSON.stringify(serialisableTarget)
|
|
105
117
|
];
|
|
106
118
|
if (details.debugPort !== -1) {
|
|
107
119
|
logger_1.labeled(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
|
|
@@ -142,44 +154,49 @@ class Server {
|
|
|
142
154
|
debugPort
|
|
143
155
|
});
|
|
144
156
|
}
|
|
157
|
+
startServer(details, masterPort) {
|
|
158
|
+
var _a;
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (details.target === undefined) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let currentProcess;
|
|
164
|
+
if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
165
|
+
currentProcess = yield this._spinUpJavaServer(details, masterPort);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
currentProcess = yield this._spinUpProcess(details, masterPort);
|
|
169
|
+
}
|
|
170
|
+
details.process = currentProcess;
|
|
171
|
+
const stdout = currentProcess.stdout;
|
|
172
|
+
if (stdout && typeof stdout.pipe === 'function') {
|
|
173
|
+
stdout.pipe(process.stdout);
|
|
174
|
+
}
|
|
175
|
+
const stderr = currentProcess.stderr;
|
|
176
|
+
if (stderr && typeof stderr.pipe === 'function') {
|
|
177
|
+
stderr.pipe(process.stderr);
|
|
178
|
+
}
|
|
179
|
+
return new Promise((res) => setTimeout(res, 100));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
145
182
|
start() {
|
|
146
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
184
|
const masterPort = runtime_store_1.default.get(`context.port.http.master`, -1);
|
|
148
185
|
if (masterPort === -1) {
|
|
149
186
|
throw new error_1.default('master port cannot be undefined', { exit: 2 });
|
|
150
187
|
}
|
|
151
|
-
yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
|
|
153
|
-
if (details.target === undefined) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
let currentProcess;
|
|
157
|
-
if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
158
|
-
currentProcess = yield this._spinUpJavaServer(details, masterPort);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
currentProcess = yield this._spinUpProcess(details, masterPort);
|
|
162
|
-
}
|
|
163
|
-
Server.process = [...Server.process, currentProcess];
|
|
164
|
-
const stdout = currentProcess.stdout;
|
|
165
|
-
if (stdout && typeof stdout.pipe === 'function') {
|
|
166
|
-
stdout.pipe(process.stdout);
|
|
167
|
-
}
|
|
168
|
-
const stderr = currentProcess.stderr;
|
|
169
|
-
if (stderr && typeof stderr.pipe === 'function') {
|
|
170
|
-
stderr.pipe(process.stderr);
|
|
171
|
-
}
|
|
172
|
-
})));
|
|
173
|
-
const masterServer = yield this._spinUpMaster(masterPort);
|
|
188
|
+
yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () { return this.startServer(details, masterPort); })));
|
|
189
|
+
this._addBasicFnDetails();
|
|
174
190
|
if (this.targetDetailsArr.length === 0) {
|
|
175
|
-
throw new error_1.default('master server
|
|
191
|
+
throw new error_1.default('Trying to start master server before other server', {
|
|
176
192
|
exit: 2
|
|
177
193
|
});
|
|
178
194
|
}
|
|
179
|
-
|
|
195
|
+
const server = yield master_1.default(masterPort, this.targetDetailsArr);
|
|
196
|
+
this.masterServer = server;
|
|
180
197
|
return new Promise((res) => {
|
|
181
|
-
|
|
182
|
-
|
|
198
|
+
server.on('listening', () => {
|
|
199
|
+
this.targetDetailsArr.forEach((targetDetails) => { var _a; return (_a = targetDetails.process) === null || _a === void 0 ? void 0 : _a.emit('start'); });
|
|
183
200
|
res();
|
|
184
201
|
});
|
|
185
202
|
});
|
|
@@ -187,35 +204,88 @@ class Server {
|
|
|
187
204
|
}
|
|
188
205
|
wait() {
|
|
189
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
if (
|
|
191
|
-
logger_1.debug('
|
|
207
|
+
if (!this.masterServer) {
|
|
208
|
+
logger_1.debug('Master server is not started yet.');
|
|
192
209
|
throw new error_1.default('Server cannot be put to wait state.', { exit: 2 });
|
|
193
210
|
}
|
|
211
|
+
this.targetDetailsArr.forEach((targetdetails) => {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
const target = targetdetails.target;
|
|
214
|
+
if (targetdetails.type === 'functions' || !target || !targetdetails.process) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
yield this.kill(targetdetails.process);
|
|
219
|
+
}));
|
|
220
|
+
(_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
yield this.restart(target);
|
|
222
|
+
logger_1.labeled(`server[${target.name}]`, 'ready!').MESSAGE();
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
var _a;
|
|
225
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
226
|
+
}, 1000);
|
|
227
|
+
}));
|
|
228
|
+
}, this);
|
|
194
229
|
return new Promise((res) => {
|
|
195
230
|
['SIGINT', 'SIGTERM'].forEach((sig) => process.on(sig, res));
|
|
196
231
|
});
|
|
197
232
|
});
|
|
198
233
|
}
|
|
199
|
-
|
|
234
|
+
kill(serverProcess) {
|
|
200
235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
serverProcess.close(() => resolve());
|
|
206
|
-
}
|
|
207
|
-
catch (e) {
|
|
208
|
-
serverProcess.emit('close');
|
|
209
|
-
}
|
|
236
|
+
return new Promise((resolve) => {
|
|
237
|
+
if (serverProcess.pid === undefined) {
|
|
238
|
+
try {
|
|
239
|
+
serverProcess.close(() => resolve());
|
|
210
240
|
}
|
|
211
|
-
|
|
212
|
-
serverProcess.
|
|
241
|
+
catch (e) {
|
|
242
|
+
serverProcess.emit('close');
|
|
213
243
|
}
|
|
214
|
-
|
|
244
|
+
}
|
|
245
|
+
if (serverProcess.exitCode === null) {
|
|
246
|
+
serverProcess.kill('SIGINT');
|
|
247
|
+
}
|
|
248
|
+
resolve();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
restart(target) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const targetIdx = this.targetDetailsArr.findIndex((targetDetails) => { var _a; return target.source === ((_a = targetDetails.target) === null || _a === void 0 ? void 0 : _a.source); });
|
|
255
|
+
if (targetIdx === -1) {
|
|
256
|
+
throw new error_1.default('Unknown target given for restart.', { exit: 2 });
|
|
257
|
+
}
|
|
258
|
+
if (this.targetDetailsArr[targetIdx].type === 'functions') {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const targetProcess = this.targetDetailsArr[targetIdx].process;
|
|
262
|
+
if (!targetProcess) {
|
|
263
|
+
throw new error_1.default('Process is not defined for this target.', { exit: 2 });
|
|
264
|
+
}
|
|
265
|
+
yield this.kill(targetProcess);
|
|
266
|
+
yield this.startServer(this.targetDetailsArr[targetIdx], runtime_store_1.default.get(`context.port.http.master`, -1));
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
stop() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
yield Promise.all(this.targetDetailsArr.map((targetdetails) => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
var _a;
|
|
273
|
+
const target = targetdetails.target;
|
|
274
|
+
if (!target) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
yield ((_a = target.watcher) === null || _a === void 0 ? void 0 : _a.close());
|
|
278
|
+
if (targetdetails.process) {
|
|
279
|
+
return this.kill(targetdetails.process);
|
|
280
|
+
}
|
|
281
|
+
})));
|
|
282
|
+
if (this.masterServer) {
|
|
283
|
+
const masterServer = this.masterServer;
|
|
284
|
+
return new Promise((res, rej) => {
|
|
285
|
+
masterServer.close((err) => (err ? rej(err) : res()));
|
|
215
286
|
});
|
|
216
|
-
}
|
|
287
|
+
}
|
|
217
288
|
});
|
|
218
289
|
}
|
|
219
290
|
}
|
|
220
|
-
Server.process = [];
|
|
221
291
|
exports.default = Server;
|
|
@@ -29,6 +29,7 @@ const constants_1 = require("../../../util_modules/constants");
|
|
|
29
29
|
const js_1 = require("../../../util_modules/js");
|
|
30
30
|
const logger_2 = require("../../../util_modules/logger");
|
|
31
31
|
const project_2 = require("../../../util_modules/project");
|
|
32
|
+
const option_1 = require("../../../util_modules/option");
|
|
32
33
|
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
33
34
|
const redirectByAuth = (req, res, redirectUrl) => {
|
|
34
35
|
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
@@ -90,11 +91,11 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
90
91
|
key: project_2.getDomainKey(),
|
|
91
92
|
env_name: project_2.getEnvName()
|
|
92
93
|
};
|
|
93
|
-
const bindPort = parseInt(runtime_store_1.default.get('context.port.bind', '-1'), 10);
|
|
94
94
|
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
95
|
+
const customProxyUrl = option_1.getOptionValue('proxy');
|
|
95
96
|
const app = express_1.default();
|
|
96
|
-
let systemRoutes;
|
|
97
97
|
const connections = {};
|
|
98
|
+
let systemRoutes;
|
|
98
99
|
app.use(logger_1.default);
|
|
99
100
|
app.use(cookie_parser_1.default);
|
|
100
101
|
app.use(authenticator_1.default);
|
|
@@ -206,7 +207,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
209
|
});
|
|
209
|
-
app.use('/', unknownReqProxy_1.default(proxy,
|
|
210
|
+
app.use('/', unknownReqProxy_1.default(proxy, customProxyUrl));
|
|
210
211
|
app.use(error_handler_1.default);
|
|
211
212
|
const expressServer = app.listen(listenPort).on('error', (err) => {
|
|
212
213
|
if (proxy) {
|
|
@@ -215,7 +216,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
215
216
|
console.error(err);
|
|
216
217
|
});
|
|
217
218
|
expressServer.maxConnections = 100;
|
|
218
|
-
process.once('SIGINT', () => Object.keys(connections).forEach((sokcetId) => connections[sokcetId].destroy()));
|
|
219
|
+
process.once('SIGINT', () => Object.keys(connections).forEach((sokcetId) => { var _a; return (_a = connections[sokcetId]) === null || _a === void 0 ? void 0 : _a.destroy(); }));
|
|
219
220
|
expressServer.on('connection', (socket) => {
|
|
220
221
|
const offset = Math.floor(Math.random() * 10);
|
|
221
222
|
const id = Date.now() + offset + '';
|
|
@@ -30,6 +30,9 @@ const js_1 = require("../../util_modules/js");
|
|
|
30
30
|
const logger_2 = require("../../util_modules/logger");
|
|
31
31
|
const project_2 = require("../../util_modules/project");
|
|
32
32
|
const shell_1 = require("../../util_modules/shell");
|
|
33
|
+
const logUrl = (name, pthName, httpPort, masterPort) => {
|
|
34
|
+
logger_2.labeled(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
|
|
35
|
+
};
|
|
33
36
|
class HttpFunctions {
|
|
34
37
|
constructor(repl) {
|
|
35
38
|
this.repl = repl;
|
|
@@ -44,6 +47,7 @@ class HttpFunctions {
|
|
|
44
47
|
this.responseFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_res_body');
|
|
45
48
|
this.metaFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_meta.json');
|
|
46
49
|
this.runningSlaves = [];
|
|
50
|
+
this.targets = [];
|
|
47
51
|
this.q = new better_queue_1.default((opts, cb) => {
|
|
48
52
|
var _a, _b;
|
|
49
53
|
fs_1.SYNC.ensureFile(this.responseFile, true);
|
|
@@ -67,7 +71,7 @@ class HttpFunctions {
|
|
|
67
71
|
}
|
|
68
72
|
}).RAW();
|
|
69
73
|
(_a = slave.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
70
|
-
logger_2.info(data);
|
|
74
|
+
logger_2.info(Buffer.isBuffer(data) ? data.toString() : data);
|
|
71
75
|
});
|
|
72
76
|
(_b = slave.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
73
77
|
const errorStr = data.toString().trim();
|
|
@@ -106,6 +110,12 @@ class HttpFunctions {
|
|
|
106
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
111
|
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
108
112
|
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
113
|
+
if (this.repl !== undefined) {
|
|
114
|
+
this.app.use((_req, _res, next) => {
|
|
115
|
+
shell_1.clearLine(process.stdout);
|
|
116
|
+
next();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
109
119
|
this.app.use(logger_1.default);
|
|
110
120
|
this.app.use(cookie_parser_1.default);
|
|
111
121
|
this.app.use(authenticator_1.default);
|
|
@@ -225,10 +235,13 @@ class HttpFunctions {
|
|
|
225
235
|
};
|
|
226
236
|
shell_1.clearLine(process.stdout);
|
|
227
237
|
const masterPort = runtime_store_1.default.get(`context.port.http.master`, -1);
|
|
228
|
-
const fnTargets = runtime_store_1.default.get('context.functions.targets');
|
|
238
|
+
const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
229
239
|
fnTargets
|
|
230
240
|
.filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
|
|
231
|
-
.map((t) =>
|
|
241
|
+
.map((t) => {
|
|
242
|
+
this.targets.push(t);
|
|
243
|
+
return js_1.JS.omit(t, ['zip_stream', 'watcher', 'localFn']);
|
|
244
|
+
})
|
|
232
245
|
.forEach((t) => {
|
|
233
246
|
var _a;
|
|
234
247
|
if ((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
@@ -237,9 +250,7 @@ class HttpFunctions {
|
|
|
237
250
|
const pthName = new url_1.URL(t.url).pathname;
|
|
238
251
|
if (pthName !== null) {
|
|
239
252
|
this.app.use(pthName, reqHandler(t));
|
|
240
|
-
|
|
241
|
-
(masterPort === -1 ? httpPort : masterPort) +
|
|
242
|
-
pthName).MESSAGE();
|
|
253
|
+
logUrl(t.name, pthName, httpPort, masterPort);
|
|
243
254
|
}
|
|
244
255
|
if (t.url_with_id !== undefined) {
|
|
245
256
|
const pathWithId = new url_1.URL(t.url_with_id).pathname;
|
|
@@ -250,6 +261,26 @@ class HttpFunctions {
|
|
|
250
261
|
});
|
|
251
262
|
return new Promise((res) => {
|
|
252
263
|
const server = this.app.listen(httpPort, () => {
|
|
264
|
+
this.targets.forEach((target) => {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => {
|
|
267
|
+
if (this.repl && !this.repl.paused) {
|
|
268
|
+
this.repl.pause();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
(_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => {
|
|
272
|
+
logger_2.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
|
|
273
|
+
logUrl(target.name, new url_1.URL(target.url).pathname, httpPort, masterPort);
|
|
274
|
+
if (this.repl && this.repl.paused) {
|
|
275
|
+
this.repl.resume();
|
|
276
|
+
this.repl.showPrompt();
|
|
277
|
+
}
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
var _a;
|
|
280
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
281
|
+
}, 1000);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
253
284
|
if (this.repl !== undefined) {
|
|
254
285
|
this.repl.showPrompt();
|
|
255
286
|
}
|
|
@@ -271,28 +302,22 @@ class HttpFunctions {
|
|
|
271
302
|
}
|
|
272
303
|
stop() {
|
|
273
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
-
return new Promise((
|
|
305
|
+
return new Promise((res) => {
|
|
275
306
|
this.runningSlaves.forEach((slave) => {
|
|
276
307
|
slave.kill('SIGINT');
|
|
277
308
|
});
|
|
278
|
-
this.q.destroy(() => {
|
|
309
|
+
this.q.destroy(() => __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
yield Promise.all(this.targets.map((target) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.close(); })));
|
|
279
311
|
if (HttpFunctions.server !== null) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
catch (e) {
|
|
285
|
-
HttpFunctions.server.emit('close');
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
HttpFunctions.server.kill('SIGINT');
|
|
290
|
-
}
|
|
312
|
+
HttpFunctions.server.close((err) => {
|
|
313
|
+
logger_2.debug(err);
|
|
314
|
+
res();
|
|
315
|
+
});
|
|
291
316
|
}
|
|
292
317
|
else {
|
|
293
|
-
|
|
318
|
+
res();
|
|
294
319
|
}
|
|
295
|
-
});
|
|
320
|
+
}));
|
|
296
321
|
});
|
|
297
322
|
});
|
|
298
323
|
}
|
|
@@ -24,26 +24,14 @@ const js_1 = require("../../util_modules/js");
|
|
|
24
24
|
const logger_1 = require("../../util_modules/logger");
|
|
25
25
|
const project_1 = require("../../util_modules/project");
|
|
26
26
|
const shell_1 = require("../../util_modules/shell");
|
|
27
|
-
const languages_1 = require("../prepare/languages");
|
|
28
|
-
function prepareTarget(target) {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
if ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
32
|
-
return languages_1.java([target]);
|
|
33
|
-
}
|
|
34
|
-
if ((_b = target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.nodejs)) {
|
|
35
|
-
return languages_1.node([target]);
|
|
36
|
-
}
|
|
37
|
-
throw new error_1.default('Unknown stack received', { exit: 2 });
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
27
|
class LocalFunction {
|
|
41
28
|
constructor(repl, target) {
|
|
42
|
-
var _a;
|
|
29
|
+
var _a, _b, _c;
|
|
43
30
|
if (target.type === undefined || !Object.values(constants_1.FN_TYPE).includes(target.type)) {
|
|
44
31
|
throw new error_1.default('target type is not defined', { exit: 2 });
|
|
45
32
|
}
|
|
46
33
|
this.repl = repl;
|
|
34
|
+
this.watcher = target.watcher;
|
|
47
35
|
this.target = js_1.JS.omit(target, ['zip_stream', 'watcher']);
|
|
48
36
|
this.slave = null;
|
|
49
37
|
this.nodeInvoker = path_1.normalize(path_1.join(__dirname, './invoker', target.type, 'node.js'));
|
|
@@ -54,38 +42,22 @@ class LocalFunction {
|
|
|
54
42
|
this.responseFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_res_body');
|
|
55
43
|
this.metaFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_meta.json');
|
|
56
44
|
this.call = this._call.bind(this);
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
target.watcher.on('all', (eventName, pth) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
(_b = this.watcher) === null || _b === void 0 ? void 0 : _b.on('preparing', () => {
|
|
46
|
+
if (!this.repl.paused) {
|
|
60
47
|
this.repl.pause();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.exitTimer = setTimeout(() => {
|
|
75
|
-
logger_1.info('\n(To exit, press ^C)');
|
|
76
|
-
}, 2000);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
logger_1.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
|
|
81
|
-
if (this.exitTimer) {
|
|
82
|
-
clearTimeout(this.exitTimer);
|
|
83
|
-
}
|
|
84
|
-
this.repl.resume();
|
|
85
|
-
this.repl.showPrompt();
|
|
86
|
-
}
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
(_c = this.watcher) === null || _c === void 0 ? void 0 : _c.on('compiled', () => {
|
|
51
|
+
logger_1.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
|
|
52
|
+
if (this.repl.paused) {
|
|
53
|
+
repl.resume();
|
|
54
|
+
repl.showPrompt();
|
|
55
|
+
}
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
59
|
+
}, 1000);
|
|
60
|
+
});
|
|
89
61
|
}
|
|
90
62
|
_call(rawData = {}) {
|
|
91
63
|
let data;
|
|
@@ -236,9 +208,6 @@ class LocalFunction {
|
|
|
236
208
|
if (this.slave) {
|
|
237
209
|
this.slave.kill('SIGINT');
|
|
238
210
|
}
|
|
239
|
-
if (this.exitTimer) {
|
|
240
|
-
clearTimeout(this.exitTimer);
|
|
241
|
-
}
|
|
242
211
|
if (this.watcher) {
|
|
243
212
|
this.watcher.close().then(res).catch(res);
|
|
244
213
|
}
|
package/lib/shell/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const chokidar_1 = require("chokidar");
|
|
16
15
|
const path_1 = require("path");
|
|
17
16
|
const util_1 = require("util");
|
|
18
17
|
const repl_server_1 = __importDefault(require("../repl-server"));
|
|
@@ -27,6 +26,7 @@ const option_1 = require("../util_modules/option");
|
|
|
27
26
|
const http_functions_1 = __importDefault(require("./dependencies/http-functions"));
|
|
28
27
|
const local_function_1 = __importDefault(require("./dependencies/local-function"));
|
|
29
28
|
const prepare_1 = __importDefault(require("./prepare"));
|
|
29
|
+
const fn_watcher_1 = __importDefault(require("../fn-watcher"));
|
|
30
30
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
31
|
const replServer = new repl_server_1.default({
|
|
32
32
|
prompt: 'functions > ',
|
|
@@ -46,7 +46,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
46
46
|
const httpServer = new http_functions_1.default(replServer);
|
|
47
47
|
try {
|
|
48
48
|
yield prepare_1.default([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.cron, constants_1.FN_TYPE.event, constants_1.FN_TYPE.integration]);
|
|
49
|
-
const targets = runtime_store_1.default
|
|
49
|
+
const targets = runtime_store_1.default
|
|
50
|
+
.get('context.functions.targets', [])
|
|
51
|
+
.filter((target) => {
|
|
50
52
|
if (!target.valid) {
|
|
51
53
|
logger_1.warning('target [' +
|
|
52
54
|
target.name +
|
|
@@ -62,18 +64,15 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
replServer.start();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
cwd: target.source,
|
|
70
|
-
ignoreInitial: true
|
|
71
|
-
});
|
|
67
|
+
const watchOpt = option_1.getOptionValue('watch', false);
|
|
68
|
+
yield Promise.all(targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
if (watchOpt) {
|
|
70
|
+
yield fn_watcher_1.default(target);
|
|
72
71
|
}
|
|
73
72
|
const localFn = new local_function_1.default(replServer, target);
|
|
74
73
|
replServer.setContext(target.name, localFn.call);
|
|
75
74
|
target.localFn = localFn;
|
|
76
|
-
});
|
|
75
|
+
})));
|
|
77
76
|
if (runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], false)) {
|
|
78
77
|
yield httpServer.start();
|
|
79
78
|
}
|
|
@@ -16,7 +16,6 @@ const fn_utils_1 = require("../../fn-utils");
|
|
|
16
16
|
const common_1 = require("../../fn-utils/lib/common");
|
|
17
17
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
18
18
|
const constants_1 = require("../../util_modules/constants");
|
|
19
|
-
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
20
19
|
const languages_1 = require("./languages");
|
|
21
20
|
exports.default = (fnTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
21
|
fn_utils_1.fnUtils.common.executeHook({ prefix: 'pre', command: 'serve' });
|
|
@@ -33,10 +32,7 @@ exports.default = (fnTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
33
32
|
return target;
|
|
34
33
|
});
|
|
35
34
|
runtime_store_1.default.set('context.functions.targets', refinedTargets);
|
|
36
|
-
yield
|
|
37
|
-
languages_1.node(refinedTargets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) && target.valid; })),
|
|
38
|
-
languages_1.java(refinedTargets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) && target.valid; }))
|
|
39
|
-
]);
|
|
35
|
+
yield languages_1.prepareFunctions(refinedTargets);
|
|
40
36
|
yield common_1.resolveAllFnPorts(refinedTargets);
|
|
41
37
|
return refinedTargets;
|
|
42
38
|
});
|
|
@@ -27,17 +27,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
30
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.
|
|
34
|
+
exports.prepareFunctions = void 0;
|
|
35
|
+
const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/runtime"));
|
|
32
36
|
function node(targets) {
|
|
33
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
38
|
return (yield Promise.resolve().then(() => __importStar(require('./node')))).default(targets);
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
|
-
exports.node = node;
|
|
38
41
|
function java(targets) {
|
|
39
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
43
|
return (yield Promise.resolve().then(() => __importStar(require('./java')))).default(targets);
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
function prepareFunctions(targets) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return Promise.all([
|
|
49
|
+
node(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) && target.valid; })),
|
|
50
|
+
java(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) && target.valid; }))
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.prepareFunctions = prepareFunctions;
|
package/lib/track.js
CHANGED
|
@@ -16,6 +16,7 @@ const path_1 = require("path");
|
|
|
16
16
|
const readline_1 = require("readline");
|
|
17
17
|
const config_store_1 = __importDefault(require("./config-store"));
|
|
18
18
|
const endpoints_1 = require("./endpoints");
|
|
19
|
+
const error_1 = __importDefault(require("./error"));
|
|
19
20
|
const runtime_store_1 = __importDefault(require("./runtime-store"));
|
|
20
21
|
const fs_1 = require("./util_modules/fs");
|
|
21
22
|
const logger_1 = require("./util_modules/logger");
|
|
@@ -52,7 +53,8 @@ exports.default = (event, message, duration) => __awaiter(void 0, void 0, void 0
|
|
|
52
53
|
yield httpLogger.log(logInput);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
catch (
|
|
56
|
+
catch (e) {
|
|
57
|
+
const err = error_1.default.getErrorInstance(e);
|
|
56
58
|
logger_1.debug('Unable to send debug log to server: ' + err.message);
|
|
57
59
|
}
|
|
58
60
|
});
|