zcatalyst-cli 1.9.0 → 1.11.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 +29 -29
- package/docs/client-utils.toml +5 -0
- 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/docs/plugin-loader.toml +4 -0
- package/docs/serve/server/index.toml +4 -0
- package/docs/serve/server/lib/web_client/server.toml +4 -0
- package/lib/api-timer.js +81 -0
- package/lib/apig-utils.js +17 -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 +55 -26
- 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 +4 -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 +5 -14
- 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 +189 -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 +35 -28
- 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 +2 -2
- package/lib/commands/run.js +1 -1
- package/lib/commands/serve.js +3 -2
- 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 +33 -3
- package/lib/errorOut.js +4 -3
- package/lib/fn-utils/lib/common.js +37 -16
- package/lib/fn-utils/lib/java.js +7 -9
- package/lib/fn-utils/lib/node.js +7 -1
- 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/dependencies/npm-install.js +2 -9
- package/lib/init/features/client/index.js +47 -0
- package/lib/init/features/client/initializers/angular.js +88 -0
- package/lib/init/features/client/initializers/basic.js +27 -0
- package/lib/init/features/client/initializers/lyte.js +44 -0
- package/lib/init/features/client/initializers/react.js +53 -0
- package/lib/init/features/functions/languages/java.js +2 -5
- package/lib/init/features/functions/languages/node.js +5 -6
- package/lib/init/features/index.js +18 -6
- package/lib/init/features/project.js +72 -34
- 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 +6 -3
- package/lib/internal/config.js +7 -4
- package/lib/migration/index.js +10 -6
- package/lib/option-filter.js +4 -1
- package/lib/optional-import.js +11 -25
- package/lib/plugin-loader.js +8 -2
- package/lib/port-resolver.js +20 -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 +6 -1
- package/lib/serve/server/index.js +74 -29
- package/lib/serve/server/lib/master.js +28 -12
- package/lib/serve/server/lib/web_client/index.js +30 -0
- package/lib/serve/server/lib/web_client/server.js +171 -0
- package/lib/serve/server/lib/web_client/utils.js +10 -0
- package/lib/shell/dependencies/http-functions.js +1 -1
- package/lib/shell/index.js +3 -1
- package/lib/track.js +3 -1
- package/lib/util_modules/char.js +1 -1
- package/lib/util_modules/config/lib/apig.js +2 -1
- package/lib/util_modules/constants/index.js +5 -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/placeholders.js +3 -1
- package/lib/util_modules/constants/lib/plugin.js +28 -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/lib/template.js +11 -1
- package/lib/util_modules/constants/lib/urls.js +8 -0
- package/lib/util_modules/constants/project.js +6 -0
- package/lib/util_modules/{contextHelp.js → context-help.js} +5 -1
- package/lib/util_modules/env.js +14 -16
- package/lib/util_modules/fs/index.js +9 -1
- package/lib/util_modules/fs/lib/async.js +29 -22
- package/lib/util_modules/global-space.js +99 -0
- package/lib/util_modules/js.js +6 -0
- package/lib/util_modules/option.js +5 -1
- package/lib/util_modules/parser/toml.js +5 -1
- package/lib/util_modules/project.js +3 -0
- package/lib/util_modules/shell.js +9 -8
- package/lib/winston.js +1 -1
- package/package.json +11 -5
- package/templates/iacSuccess.html +391 -0
- package/templates/init/.DS_Store +0 -0
- package/templates/init/client/.DS_Store +0 -0
- package/templates/init/client/{client-package.json → basic/client-package.json} +0 -0
- package/templates/init/client/{index.html → basic/index.html} +0 -0
- package/templates/init/client/{main.css → basic/main.css} +0 -0
- package/templates/init/client/{main.js → basic/main.js} +0 -0
- package/templates/init/client/lyte/build/build.js +301 -0
- package/templates/init/client/lyte/build/scripts/cliDownloadScript.js +54 -0
- package/templates/init/client/lyte/client-package.json +5 -0
- package/templates/init/client/lyte/components/javascript/welcome-comp.js +13 -0
- package/templates/init/client/lyte/components/styles/welcome-comp.css +0 -0
- package/templates/init/client/lyte/components/templates/welcome-comp.html +8 -0
- package/templates/init/client/lyte/data-store/adapters/.gitkeep +0 -0
- package/templates/init/client/lyte/data-store/models/.gitkeep +0 -0
- package/templates/init/client/lyte/data-store/serializers/.gitkeep +0 -0
- package/templates/init/client/lyte/index.html +17 -0
- package/templates/init/client/lyte/package.json +12 -0
- package/templates/init/client/lyte/router.js +14 -0
- package/templates/init/client/lyte/routes/index.js +54 -0
- package/templates/init/client/react/.DS_Store +0 -0
- package/templates/init/client/react/react_js/package.json +11 -0
- package/templates/init/client/react/react_js/template/README.md +70 -0
- package/templates/init/client/react/react_js/template/client-package.json +5 -0
- package/templates/init/client/react/react_js/template/gitignore +23 -0
- package/templates/init/client/react/react_js/template/public/favicon.ico +0 -0
- package/templates/init/client/react/react_js/template/public/index.html +43 -0
- package/templates/init/client/react/react_js/template/public/logo192.png +0 -0
- package/templates/init/client/react/react_js/template/public/logo512.png +0 -0
- package/templates/init/client/react/react_js/template/public/manifest.json +25 -0
- package/templates/init/client/react/react_js/template/public/robots.txt +3 -0
- package/templates/init/client/react/react_js/template/src/App.css +38 -0
- package/templates/init/client/react/react_js/template/src/App.js +25 -0
- package/templates/init/client/react/react_js/template/src/App.test.js +8 -0
- package/templates/init/client/react/react_js/template/src/index.css +13 -0
- package/templates/init/client/react/react_js/template/src/index.js +17 -0
- package/templates/init/client/react/react_js/template/src/logo.svg +1 -0
- package/templates/init/client/react/react_js/template/src/reportWebVitals.js +13 -0
- package/templates/init/client/react/react_js/template/src/setupTests.js +5 -0
- package/templates/init/client/react/react_js/template.json +13 -0
- package/templates/init/client/react/react_ts/package.json +11 -0
- package/templates/init/client/react/react_ts/template/README.md +46 -0
- package/templates/init/client/react/react_ts/template/client-package.json +5 -0
- package/templates/init/client/react/react_ts/template/gitignore +23 -0
- package/templates/init/client/react/react_ts/template/public/favicon.ico +0 -0
- package/templates/init/client/react/react_ts/template/public/index.html +43 -0
- package/templates/init/client/react/react_ts/template/public/logo192.png +0 -0
- package/templates/init/client/react/react_ts/template/public/logo512.png +0 -0
- package/templates/init/client/react/react_ts/template/public/manifest.json +25 -0
- package/templates/init/client/react/react_ts/template/public/robots.txt +3 -0
- package/templates/init/client/react/react_ts/template/src/App.css +38 -0
- package/templates/init/client/react/react_ts/template/src/App.test.tsx +9 -0
- package/templates/init/client/react/react_ts/template/src/App.tsx +26 -0
- package/templates/init/client/react/react_ts/template/src/index.css +13 -0
- package/templates/init/client/react/react_ts/template/src/index.tsx +17 -0
- package/templates/init/client/react/react_ts/template/src/logo.svg +1 -0
- package/templates/init/client/react/react_ts/template/src/reportWebVitals.ts +15 -0
- package/templates/init/client/react/react_ts/template/src/setupTests.ts +5 -0
- package/templates/init/client/react/react_ts/template.json +18 -0
- package/templates/web-socket.txt +21 -0
- package/lib/init/features/client.js +0 -51
- package/lib/prompt.js +0 -49
- package/lib/serve/server/lib/client.js +0 -30
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const choices_1 = __importDefault(require("inquirer/lib/objects/choices"));
|
|
16
|
+
const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
|
|
17
|
+
const fuzzy_1 = __importDefault(require("fuzzy"));
|
|
18
|
+
const fs_1 = require("../../util_modules/fs");
|
|
19
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
20
|
+
function getPaths(rootPath, pattern, exclude, defaultItem) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const nodeList = yield fs_1.ASYNC.walk(rootPath, { exclude, excludeDir: false });
|
|
23
|
+
const filteredNodes = fuzzy_1.default.filter(pattern || '', nodeList).map((e) => e.string);
|
|
24
|
+
if (!pattern && defaultItem) {
|
|
25
|
+
filteredNodes.unshift(defaultItem);
|
|
26
|
+
}
|
|
27
|
+
return filteredNodes;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
|
|
31
|
+
constructor(question, rl, answers) {
|
|
32
|
+
const { rootPath = '.', exclude = [] } = question;
|
|
33
|
+
const questionBase = Object.assign({
|
|
34
|
+
emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
|
|
35
|
+
ansi_colors_1.cyan('<return> ') +
|
|
36
|
+
'key'
|
|
37
|
+
}, question, {
|
|
38
|
+
source: (_, pattern) => getPaths(rootPath, pattern, exclude, question.default)
|
|
39
|
+
});
|
|
40
|
+
super(questionBase, rl, answers);
|
|
41
|
+
}
|
|
42
|
+
search(searchTerm) {
|
|
43
|
+
const _super = Object.create(null, {
|
|
44
|
+
search: { get: () => super.search }
|
|
45
|
+
});
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield _super.search.call(this, searchTerm);
|
|
48
|
+
this.currentChoices.getChoice = (choiceIndex) => {
|
|
49
|
+
const choice = choices_1.default.prototype.getChoice.call(this.currentChoices, choiceIndex);
|
|
50
|
+
return {
|
|
51
|
+
value: choice === null || choice === void 0 ? void 0 : choice.value,
|
|
52
|
+
name: choice === null || choice === void 0 ? void 0 : choice.name,
|
|
53
|
+
short: choice === null || choice === void 0 ? void 0 : choice.short
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
onSubmitAfterValidation(line) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const choice = this.currentChoices.getChoice(this.selected);
|
|
61
|
+
const value = (choice === null || choice === void 0 ? void 0 : choice.value) || line;
|
|
62
|
+
this.answerName = (choice === null || choice === void 0 ? void 0 : choice.name) || line;
|
|
63
|
+
this.shortAnswer = (choice === null || choice === void 0 ? void 0 : choice.short) || line;
|
|
64
|
+
this.answer = this.opt.filter ? this.opt.filter(value, this.answers) : value;
|
|
65
|
+
choice.value = this.answer;
|
|
66
|
+
this.status = 'answered';
|
|
67
|
+
this.render(undefined);
|
|
68
|
+
this.screen.done();
|
|
69
|
+
if (this.done) {
|
|
70
|
+
this.done(choice.value);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
checkValidationResult(validationResult, lineOrRl) {
|
|
75
|
+
if (validationResult !== true) {
|
|
76
|
+
this.render(validationResult || 'try giving valid complete path..');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.onSubmitAfterValidation(lineOrRl);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
onSubmit(line) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const lineOrRl = line || this.rl.line;
|
|
85
|
+
if (typeof this.opt.validate !== 'function') {
|
|
86
|
+
return this.onSubmitAfterValidation(lineOrRl);
|
|
87
|
+
}
|
|
88
|
+
const choice = this.currentChoices.getChoice(this.selected);
|
|
89
|
+
choice.value = choice.value ? choice.value : lineOrRl;
|
|
90
|
+
const validationResult = yield this.opt.validate(choice, this.answers);
|
|
91
|
+
this.checkValidationResult(validationResult, lineOrRl);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.default = InquirerFilePath;
|
|
@@ -59,7 +59,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
59
59
|
choices
|
|
60
60
|
}));
|
|
61
61
|
const clientZip = (yield webappAPI.download(historyAns.history));
|
|
62
|
-
yield new archiver_1.default().load(clientZip).extract(
|
|
62
|
+
yield new archiver_1.default().load(clientZip).extract(clientDirPath).finalize();
|
|
63
63
|
yield client_utils_1.clientUtils.validate();
|
|
64
64
|
runtime_store_1.default.set('payload.client', runtime_store_1.default.get('context.client'));
|
|
65
65
|
runtime_store_1.default.set('payload.client.source', project_1.resolveProjectPath(clientDirName));
|
|
@@ -26,6 +26,7 @@ const js_1 = require("../../../util_modules/js");
|
|
|
26
26
|
const logger_1 = require("../../../util_modules/logger");
|
|
27
27
|
const project_1 = require("../../../util_modules/project");
|
|
28
28
|
const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/runtime"));
|
|
29
|
+
const error_1 = __importDefault(require("../../../error"));
|
|
29
30
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
31
|
const fnAPI = yield endpoints_1.functionsAPI();
|
|
31
32
|
const fnDirName = config_1.functionsConfig.source();
|
|
@@ -108,10 +109,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
108
109
|
var _a, _b;
|
|
109
110
|
yield fs_1.ASYNC.ensureDir(fn.source);
|
|
110
111
|
const buffer = (yield fnAPI.download(fn.id));
|
|
111
|
-
yield new archiver_1.default()
|
|
112
|
-
.load(buffer)
|
|
113
|
-
.extract('/', path_1.join(fnDirPath, fn.name), { isFolder: true })
|
|
114
|
-
.finalize();
|
|
112
|
+
yield new archiver_1.default().load(buffer).extract(path_1.join(fnDirPath, fn.name)).finalize();
|
|
115
113
|
if ((_a = fn.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) {
|
|
116
114
|
yield languages_1.node(fn);
|
|
117
115
|
}
|
|
@@ -122,9 +120,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
122
120
|
})));
|
|
123
121
|
targets = targets.filter((target) => {
|
|
124
122
|
if (!target.valid) {
|
|
125
|
-
logger_1.debug('Invalid target : ' + target + ' reason : ' + target.failure_reason);
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
logger_1.debug('Invalid target : ' + target.name + ' reason : ' + target.failure_reason);
|
|
124
|
+
logger_1.warning(`skipping pull of function(${target.name}) since the package is invalid. \nContact catalyst support with debug log.`);
|
|
125
|
+
new error_1.default('invalid package: ' + target.name, { exit: 2 });
|
|
128
126
|
}
|
|
129
127
|
return target.valid;
|
|
130
128
|
});
|
package/lib/pull/index.js
CHANGED
|
@@ -39,7 +39,10 @@ function pull() {
|
|
|
39
39
|
}
|
|
40
40
|
const MODULE = features_1.default[feature];
|
|
41
41
|
logger_1.info(ansi_colors_1.bold('\n' + ansi_colors_1.white('===> ') + js_1.JS.capitalize(feature) + ' Setup'));
|
|
42
|
-
yield MODULE()
|
|
42
|
+
yield MODULE().catch((err) => {
|
|
43
|
+
logger_1.info();
|
|
44
|
+
logger_1.warning(`Skipping pull of ${feature}. Since ${err.message}.\nContact Catalyst Support with catalyst-debug.log file.`);
|
|
45
|
+
});
|
|
43
46
|
if (runtime_store_1.default.get('payload.' + feature, false)) {
|
|
44
47
|
runtime_store_1.default.set('payload.features', runtime_store_1.default.get('payload.features', []).concat(feature));
|
|
45
48
|
}
|
|
@@ -32,6 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
34
|
exports.apig = exports.functions = exports.client = void 0;
|
|
35
|
+
const error_1 = __importDefault(require("../../error"));
|
|
35
36
|
const port_resolver_1 = __importDefault(require("../../port-resolver"));
|
|
36
37
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
37
38
|
const constants_1 = require("../../util_modules/constants");
|
|
@@ -42,7 +43,8 @@ function client() {
|
|
|
42
43
|
try {
|
|
43
44
|
yield clientModule.default();
|
|
44
45
|
}
|
|
45
|
-
catch (
|
|
46
|
+
catch (e) {
|
|
47
|
+
const err = error_1.default.getErrorInstance(e);
|
|
46
48
|
logger_1.info();
|
|
47
49
|
logger_1.warning('Skipping the serve of Client because of the error: ' + err.message);
|
|
48
50
|
logger_1.info();
|
package/lib/serve/index.js
CHANGED
|
@@ -54,7 +54,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
54
54
|
runtime_store_1.default.set('context.port.http.master', masterPort);
|
|
55
55
|
yield Promise.all(serveTargets.map((target) => features[target]()));
|
|
56
56
|
const rawTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
57
|
-
|
|
57
|
+
const watchOpt = option_1.getOptionValue('watch', false);
|
|
58
|
+
if (watchOpt) {
|
|
58
59
|
yield Promise.all(rawTargets.map((target) => __awaiter(void 0, void 0, void 0, function* () { return (target.valid ? fn_watcher_1.default(target) : undefined); })));
|
|
59
60
|
}
|
|
60
61
|
const funtionTargets = rawTargets.filter((target) => {
|
|
@@ -73,6 +74,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
73
74
|
if (serveTargets.includes('client')) {
|
|
74
75
|
const client = runtime_store_1.default.get('context.client', false);
|
|
75
76
|
if (client && client.valid) {
|
|
77
|
+
client.opts = {
|
|
78
|
+
open: option_1.getOptionValue('open', false),
|
|
79
|
+
watch: watchOpt
|
|
80
|
+
};
|
|
76
81
|
advancedServer.add('client', client);
|
|
77
82
|
}
|
|
78
83
|
else {
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,29 +54,31 @@ const js_1 = require("../../util_modules/js");
|
|
|
35
54
|
const logger_1 = require("../../util_modules/logger");
|
|
36
55
|
const shell_1 = require("../../util_modules/shell");
|
|
37
56
|
const master_1 = __importDefault(require("./lib/master"));
|
|
57
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
38
58
|
class Server {
|
|
39
59
|
constructor() {
|
|
40
60
|
this.targetDetailsArr = [];
|
|
41
61
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
_addBasicFnDetails() {
|
|
63
|
+
const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
64
|
+
if (fnTargets.length === 0) {
|
|
65
|
+
logger_1.debug('No basic functions to add');
|
|
66
|
+
}
|
|
67
|
+
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
68
|
+
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
69
|
+
if (!isNaN(httpPort)) {
|
|
70
|
+
fnTargets
|
|
71
|
+
.filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
|
|
72
|
+
.map((t) => js_1.JS.omit(t, ['zip_stream', 'localFn']))
|
|
73
|
+
.forEach((t) => {
|
|
74
|
+
this.targetDetailsArr.push({
|
|
75
|
+
type: 'functions',
|
|
76
|
+
httpPort,
|
|
77
|
+
debugPort,
|
|
78
|
+
target: t
|
|
57
79
|
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
61
82
|
}
|
|
62
83
|
_spinUpJavaServer(details, masterPort) {
|
|
63
84
|
var _a, _b, _c, _d;
|
|
@@ -84,8 +105,8 @@ class Server {
|
|
|
84
105
|
opts.push(details.httpPort + '');
|
|
85
106
|
const targetSource = (_c = details.target) === null || _c === void 0 ? void 0 : _c.source;
|
|
86
107
|
const configType = details.type === 'server' ? 'functions' : details.type;
|
|
87
|
-
const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource);
|
|
88
|
-
if (servePlugin
|
|
108
|
+
const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource).catch((err) => logger_1.debug(err));
|
|
109
|
+
if (typeof servePlugin === 'function') {
|
|
89
110
|
const event = servePlugin(details, masterPort);
|
|
90
111
|
logger_1.labeled(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
|
|
91
112
|
return event;
|
|
@@ -110,7 +131,7 @@ class Server {
|
|
|
110
131
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
111
132
|
const _d = details.target, { ['watcher']: _ } = _d, serialisableTarget = __rest(_d, ['watcher']);
|
|
112
133
|
const opts = [
|
|
113
|
-
path_1.join(__dirname, 'lib',
|
|
134
|
+
path_1.join(__dirname, 'lib', 'node.js'),
|
|
114
135
|
details.httpPort + '',
|
|
115
136
|
JSON.stringify(serialisableTarget)
|
|
116
137
|
];
|
|
@@ -120,12 +141,28 @@ class Server {
|
|
|
120
141
|
}
|
|
121
142
|
const targetSource = (_b = details.target) === null || _b === void 0 ? void 0 : _b.source;
|
|
122
143
|
const configType = details.type === 'server' ? 'functions' : details.type;
|
|
123
|
-
const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource);
|
|
124
|
-
if (servePlugin
|
|
125
|
-
const event = servePlugin(details, masterPort)
|
|
144
|
+
const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource).catch((err) => logger_1.debug(err));
|
|
145
|
+
if (typeof servePlugin === 'function') {
|
|
146
|
+
const event = servePlugin(details, masterPort).catch((e) => {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
const err = error_1.default.getErrorInstance(e, {
|
|
149
|
+
fileName: __filename,
|
|
150
|
+
skipHelp: false
|
|
151
|
+
});
|
|
152
|
+
err.errorId = 'SERVE-IDX-1';
|
|
153
|
+
err.arg = [
|
|
154
|
+
configType,
|
|
155
|
+
ansi_colors_1.bold(((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.start)[targetSource] || 'start'),
|
|
156
|
+
ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
|
|
157
|
+
];
|
|
158
|
+
throw err;
|
|
159
|
+
});
|
|
126
160
|
logger_1.labeled(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
|
|
127
161
|
return event;
|
|
128
162
|
}
|
|
163
|
+
if (details.type === 'client') {
|
|
164
|
+
return yield (yield Promise.resolve().then(() => __importStar(require('./lib/web_client/index.js')))).default(details, masterPort);
|
|
165
|
+
}
|
|
129
166
|
const child = shell_1.spawn('node', opts, {
|
|
130
167
|
cwd: targetSource,
|
|
131
168
|
stdio: 'pipe',
|
|
@@ -135,7 +172,7 @@ class Server {
|
|
|
135
172
|
X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
|
|
136
173
|
}
|
|
137
174
|
}).RAW();
|
|
138
|
-
logger_1.labeled(label, `URL : http://localhost:${masterPort}/${
|
|
175
|
+
logger_1.labeled(label, `URL : http://localhost:${masterPort}/server/${(_c = details.target) === null || _c === void 0 ? void 0 : _c.name}/`).MESSAGE();
|
|
139
176
|
logger_1.info();
|
|
140
177
|
return child;
|
|
141
178
|
});
|
|
@@ -185,17 +222,25 @@ class Server {
|
|
|
185
222
|
throw new error_1.default('master port cannot be undefined', { exit: 2 });
|
|
186
223
|
}
|
|
187
224
|
yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () { return this.startServer(details, masterPort); })));
|
|
188
|
-
|
|
189
|
-
if (
|
|
225
|
+
this._addBasicFnDetails();
|
|
226
|
+
if (this.targetDetailsArr.length === 0) {
|
|
190
227
|
throw new error_1.default('Trying to start master server before other server', {
|
|
191
228
|
exit: 2
|
|
192
229
|
});
|
|
193
230
|
}
|
|
194
|
-
const server = yield
|
|
231
|
+
const server = yield master_1.default(masterPort, this.targetDetailsArr);
|
|
195
232
|
this.masterServer = server;
|
|
196
233
|
return new Promise((res) => {
|
|
197
234
|
server.on('listening', () => {
|
|
198
|
-
this.targetDetailsArr.forEach((targetDetails) => {
|
|
235
|
+
this.targetDetailsArr.forEach((targetDetails) => {
|
|
236
|
+
var _a;
|
|
237
|
+
if (targetDetails.process &&
|
|
238
|
+
'send' in targetDetails.process) {
|
|
239
|
+
targetDetails.process.send('start');
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
(_a = targetDetails.process) === null || _a === void 0 ? void 0 : _a.emit('start');
|
|
243
|
+
});
|
|
199
244
|
res();
|
|
200
245
|
});
|
|
201
246
|
});
|
|
@@ -82,6 +82,10 @@ const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
const generateConnectionId = () => {
|
|
86
|
+
const offset = Math.floor(Math.random() * 10);
|
|
87
|
+
return Date.now() + offset + '';
|
|
88
|
+
};
|
|
85
89
|
function spinUpMaster(listenPort, otherServerDetails) {
|
|
86
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
91
|
const projectDetails = {
|
|
@@ -122,26 +126,36 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
122
126
|
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
123
127
|
}
|
|
124
128
|
const proxy = http_proxy_1.createProxyServer()
|
|
125
|
-
.on('error', (err, req) => {
|
|
129
|
+
.on('error', (err, req, res) => {
|
|
130
|
+
res.writeHead(503, { 'Content-Type': 'json' });
|
|
131
|
+
res.write(JSON.stringify({ error: 'unable to proxy request' }));
|
|
132
|
+
res.end();
|
|
126
133
|
console.log('unable to proxy request ', req.url);
|
|
127
134
|
console.error(err);
|
|
128
135
|
})
|
|
129
|
-
.on('proxyRes', proxyResponseHandler(systemRoutes))
|
|
136
|
+
.on('proxyRes', proxyResponseHandler(systemRoutes))
|
|
137
|
+
.on('proxyReq', (proxyReq) => {
|
|
138
|
+
const id = generateConnectionId();
|
|
139
|
+
connections[id] = proxyReq;
|
|
140
|
+
proxyReq.on('finish', () => {
|
|
141
|
+
delete connections[id];
|
|
142
|
+
});
|
|
143
|
+
})
|
|
144
|
+
.on('close', () => logger_2.debug('proxy closed'));
|
|
130
145
|
otherServerDetails.forEach((serverDetail) => {
|
|
131
146
|
var _a, _b, _c, _d, _e, _f;
|
|
132
147
|
switch (serverDetail.type) {
|
|
133
148
|
case 'client':
|
|
134
149
|
const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
|
|
135
150
|
app.use('/app', (req, res) => {
|
|
136
|
-
|
|
137
|
-
if (req.url.startsWith('/local-redirect') &&
|
|
138
|
-
|
|
139
|
-
const isUrl = serverDetail.target.login_redirect.startsWith('/');
|
|
151
|
+
const target = serverDetail.target;
|
|
152
|
+
if (req.url.startsWith('/local-redirect') && target.login_redirect) {
|
|
153
|
+
const isUrl = target.login_redirect.startsWith('/');
|
|
140
154
|
if (isUrl) {
|
|
141
|
-
res.redirect(
|
|
155
|
+
res.redirect(target.login_redirect);
|
|
142
156
|
}
|
|
143
157
|
else {
|
|
144
|
-
res.redirect('/app/' +
|
|
158
|
+
res.redirect('/app/' + target.login_redirect);
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
else {
|
|
@@ -192,7 +206,8 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
192
206
|
ws: true
|
|
193
207
|
});
|
|
194
208
|
});
|
|
195
|
-
app.use('/baas/v1/project/:projectId/function/' +
|
|
209
|
+
app.use('/baas/v1/project/:projectId/function/' +
|
|
210
|
+
((_f = serverDetail.target) === null || _f === void 0 ? void 0 : _f.id), (req, res) => {
|
|
196
211
|
var _a;
|
|
197
212
|
proxy.web(req, res, {
|
|
198
213
|
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${(_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.id}`,
|
|
@@ -216,10 +231,11 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
216
231
|
console.error(err);
|
|
217
232
|
});
|
|
218
233
|
expressServer.maxConnections = 100;
|
|
219
|
-
process.
|
|
234
|
+
process.on('SIGINT', () => Object.keys(connections).forEach((connectionId) => {
|
|
235
|
+
connections[connectionId].destroy();
|
|
236
|
+
}));
|
|
220
237
|
expressServer.on('connection', (socket) => {
|
|
221
|
-
const
|
|
222
|
-
const id = Date.now() + offset + '';
|
|
238
|
+
const id = generateConnectionId();
|
|
223
239
|
connections[id] = socket;
|
|
224
240
|
socket.on('close', () => {
|
|
225
241
|
delete connections[id];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const open_1 = __importDefault(require("open"));
|
|
16
|
+
const logger_1 = require("../../../../util_modules/logger");
|
|
17
|
+
const server_js_1 = __importDefault(require("./server.js"));
|
|
18
|
+
exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
const target = details.target;
|
|
21
|
+
const clientListner = yield server_js_1.default(details.httpPort, target.source, target.homepage, ((_a = target.opts) === null || _a === void 0 ? void 0 : _a.watch) || false);
|
|
22
|
+
clientListner.addListener('start', () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const appUrl = 'http://localhost:' + masterPort;
|
|
25
|
+
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
26
|
+
logger_1.labeled(label, `URL : ${appUrl}/app/`).MESSAGE();
|
|
27
|
+
((_b = details.target.opts) === null || _b === void 0 ? void 0 : _b.open) && open_1.default(appUrl).catch();
|
|
28
|
+
});
|
|
29
|
+
return clientListner;
|
|
30
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const express_1 = __importDefault(require("express"));
|
|
16
|
+
const utils_js_1 = require("./utils.js");
|
|
17
|
+
const chokidar_1 = require("chokidar");
|
|
18
|
+
const logger_js_1 = require("../../../../util_modules/logger.js");
|
|
19
|
+
const index_js_1 = require("../../../../util_modules/constants/index.js");
|
|
20
|
+
const error_js_1 = __importDefault(require("../../../../error.js"));
|
|
21
|
+
const index_js_2 = require("../../../../util_modules/fs/index.js");
|
|
22
|
+
const path_1 = require("path");
|
|
23
|
+
const ws_1 = require("ws");
|
|
24
|
+
const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
|
|
25
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
26
|
+
function prepareScriptFile(dir, port) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const scriptFile = yield index_js_2.ASYNC.readFile(index_js_1.TEMPLATE.client.basic.socket);
|
|
29
|
+
if (!scriptFile) {
|
|
30
|
+
throw new error_js_1.default('Unable to read the script file', { exit: 2 });
|
|
31
|
+
}
|
|
32
|
+
const scriptReady = scriptFile.replace(new RegExp(index_js_1.PLACEHOLDER.client.port, 'g'), port + '');
|
|
33
|
+
yield index_js_2.ASYNC.ensureDir(dir);
|
|
34
|
+
const scriptFilePath = path_1.join(dir, 'reload-script.js');
|
|
35
|
+
yield index_js_2.ASYNC.writeFile(scriptFilePath, scriptReady);
|
|
36
|
+
return scriptFilePath;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function stringInjector(source, anchorIdx, marker, inject) {
|
|
40
|
+
const headLastIdx = anchorIdx + marker.length;
|
|
41
|
+
const scriptPrefix = source.slice(0, headLastIdx);
|
|
42
|
+
const scriptSufix = source.slice(headLastIdx + 1);
|
|
43
|
+
return scriptPrefix + inject + scriptSufix;
|
|
44
|
+
}
|
|
45
|
+
function injectScript(scriptLocale, indexHtml) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const headIdx = indexHtml.search(/<head>/gi);
|
|
48
|
+
const scriptTag = `\n<!-- Catalyst web client reload script -->\n<script type="text/javascript" src="${scriptLocale}"></script>\n`;
|
|
49
|
+
if (headIdx !== -1) {
|
|
50
|
+
return stringInjector(indexHtml, headIdx, '<head>', scriptTag);
|
|
51
|
+
}
|
|
52
|
+
const htmlIdx = indexHtml.search(/<html>/gi);
|
|
53
|
+
const headTag = `\n<head>${scriptTag}</head>\n`;
|
|
54
|
+
return stringInjector(indexHtml, htmlIdx, '<html>', headTag);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function reloadApp(event, path, liveSockets) {
|
|
58
|
+
logger_js_1.info(ansi_colors_1.cyan(`${event} detected in ${path} of the Web-Client.`));
|
|
59
|
+
liveSockets.forEach((socket) => socket.send('reload'));
|
|
60
|
+
}
|
|
61
|
+
function webClientServer(httpPort, source, homepage, enableWatch) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const eventListner = new utils_js_1.WebClientEvent();
|
|
64
|
+
const catalystTempDir = path_1.join(source, '.catalyst');
|
|
65
|
+
const socketServerPort = yield port_resolver_js_1.default.getFreePort(httpPort, 20, true);
|
|
66
|
+
const reloadScriptSrc = enableWatch
|
|
67
|
+
? path_1.relative(source, yield prepareScriptFile(catalystTempDir, socketServerPort))
|
|
68
|
+
: undefined;
|
|
69
|
+
if (reloadScriptSrc) {
|
|
70
|
+
const clientWatcher = chokidar_1.watch(source, {
|
|
71
|
+
ignoreInitial: true,
|
|
72
|
+
ignored: ['node_modules/**/*']
|
|
73
|
+
});
|
|
74
|
+
const liveSockets = [];
|
|
75
|
+
let watcherReady = false;
|
|
76
|
+
clientWatcher.on('error', (err) => {
|
|
77
|
+
watcherReady = false;
|
|
78
|
+
eventListner.emit('error', new error_js_1.default('client watcher error', {
|
|
79
|
+
original: err,
|
|
80
|
+
exit: 1,
|
|
81
|
+
skipHelp: true
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
84
|
+
clientWatcher.on('ready', () => {
|
|
85
|
+
watcherReady = true;
|
|
86
|
+
const socketServer = new ws_1.WebSocketServer({
|
|
87
|
+
port: socketServerPort,
|
|
88
|
+
path: '/client-reload'
|
|
89
|
+
})
|
|
90
|
+
.on('connection', (clientSocket) => {
|
|
91
|
+
if (!watcherReady) {
|
|
92
|
+
clientSocket.send('watcher not ready');
|
|
93
|
+
clientSocket.close();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
clientSocket.on('close', () => {
|
|
97
|
+
const socketIdx = liveSockets.findIndex((socket) => socket === clientSocket);
|
|
98
|
+
liveSockets.splice(socketIdx, 1);
|
|
99
|
+
});
|
|
100
|
+
liveSockets.push(clientSocket);
|
|
101
|
+
clientSocket.send('connected');
|
|
102
|
+
})
|
|
103
|
+
.on('error', (err) => logger_js_1.debug(err));
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
clientWatcher.on('change', (path) => {
|
|
106
|
+
reloadApp('Change(s) is', path_1.relative(source, path), liveSockets);
|
|
107
|
+
});
|
|
108
|
+
clientWatcher.on('add', (path) => {
|
|
109
|
+
reloadApp('Addition of file(s) is', path_1.relative(source, path), liveSockets);
|
|
110
|
+
});
|
|
111
|
+
clientWatcher.on('unlink', (path) => {
|
|
112
|
+
reloadApp('Deletion of file(s) is', path_1.relative(source, path), liveSockets);
|
|
113
|
+
});
|
|
114
|
+
}, 1000);
|
|
115
|
+
eventListner.addListener('close', () => socketServer === null || socketServer === void 0 ? void 0 : socketServer.close());
|
|
116
|
+
});
|
|
117
|
+
eventListner.addListener('close', () => {
|
|
118
|
+
if (clientWatcher) {
|
|
119
|
+
clientWatcher.close();
|
|
120
|
+
}
|
|
121
|
+
liveSockets.forEach((socket) => socket.close());
|
|
122
|
+
index_js_2.SYNC.deleteDir(catalystTempDir);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const app = express_1.default();
|
|
126
|
+
app.use('/app', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const requestedFile = req.url === '/' ? homepage : decodeURIComponent(req.path);
|
|
128
|
+
if (enableWatch &&
|
|
129
|
+
requestedFile === homepage &&
|
|
130
|
+
(requestedFile.includes('.html') || requestedFile.includes('.htm'))) {
|
|
131
|
+
const homepageFile = yield index_js_2.ASYNC.readFile(path_1.join(source, homepage));
|
|
132
|
+
if (!homepageFile) {
|
|
133
|
+
eventListner.emit('error', new error_js_1.default('Unable to read the homepage file', {
|
|
134
|
+
exit: 1,
|
|
135
|
+
errorId: 'WEB-CLIENT-SERVER-1',
|
|
136
|
+
arg: [ansi_colors_1.red.italic(homepage)]
|
|
137
|
+
}));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const injectedHomePage = reloadScriptSrc
|
|
141
|
+
? yield injectScript(encodeURIComponent(reloadScriptSrc), homepageFile)
|
|
142
|
+
: undefined;
|
|
143
|
+
res.contentType('text/html');
|
|
144
|
+
res.status(200);
|
|
145
|
+
res.send(injectedHomePage || homepageFile);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
res.sendFile(path_1.join(source, requestedFile), (err) => {
|
|
149
|
+
if (err) {
|
|
150
|
+
logger_js_1.error('Unable to serve the requested file: ' + path_1.join(source, requestedFile));
|
|
151
|
+
logger_js_1.debug(err.stack || err.message);
|
|
152
|
+
res.status(404);
|
|
153
|
+
res.send('Resource not found');
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}));
|
|
157
|
+
const server = app.listen(httpPort).on('error', (err) => {
|
|
158
|
+
eventListner.emit('error', err);
|
|
159
|
+
});
|
|
160
|
+
eventListner.on('error', (err) => {
|
|
161
|
+
logger_js_1.error('Error when serving the web-client: ' + err.message);
|
|
162
|
+
logger_js_1.info('Please exit the command to get more info');
|
|
163
|
+
eventListner.emit('close');
|
|
164
|
+
});
|
|
165
|
+
eventListner.on('close', () => {
|
|
166
|
+
server.close(() => logger_js_1.debug('client server closed'));
|
|
167
|
+
});
|
|
168
|
+
return new Promise((res) => server.on('listening', () => res(eventListner)));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
exports.default = webClientServer;
|