zcatalyst-cli 1.15.0-beta.3 → 1.15.0-beta.4

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.
Files changed (121) hide show
  1. package/lib/appsail-utils.js +84 -0
  2. package/lib/archiver.js +18 -1
  3. package/lib/code-deck.js +114 -0
  4. package/lib/command_needs/rc.js +7 -6
  5. package/lib/commands/appsail/add.js +55 -0
  6. package/lib/commands/codelib/install.js +143 -0
  7. package/lib/commands/config/set.js +1 -1
  8. package/lib/commands/deploy/appsail.js +62 -0
  9. package/lib/commands/{deploy.js → deploy/index.js} +20 -14
  10. package/lib/commands/iac/pack.js +3 -3
  11. package/lib/commands/index.js +2 -0
  12. package/lib/commands/init.js +5 -1
  13. package/lib/commands/pull.js +1 -1
  14. package/lib/commands/serve.js +1 -1
  15. package/lib/commands/whoami.js +2 -1
  16. package/lib/deploy/features/appsail/index.js +246 -0
  17. package/lib/deploy/features/appsail/utils.js +91 -0
  18. package/lib/deploy/features/functions/index.js +12 -10
  19. package/lib/deploy/features/index.js +3 -0
  20. package/lib/deploy/index.js +3 -3
  21. package/lib/endpoints/index.js +22 -1
  22. package/lib/endpoints/lib/appsail.js +98 -0
  23. package/lib/endpoints/lib/code-deck.js +71 -0
  24. package/lib/endpoints/lib/common.js +8 -5
  25. package/lib/endpoints/lib/git-hub.js +148 -0
  26. package/lib/endpoints/lib/iac.js +15 -0
  27. package/lib/endpoints/lib/sdk.js +4 -1
  28. package/lib/execute-script.js +35 -27
  29. package/lib/fn-utils/lib/browserLogic.js +17 -20
  30. package/lib/fn-utils/lib/common.js +3 -4
  31. package/lib/fn-utils/lib/integ.js +3 -3
  32. package/lib/fn-utils/lib/java.js +7 -1
  33. package/lib/fn-watcher.js +3 -0
  34. package/lib/iac/status/deploy.js +26 -4
  35. package/lib/iac/status/util/index.js +3 -0
  36. package/lib/init/dependencies/python/ensure-python.js +2 -2
  37. package/lib/init/dependencies/python/pip-install.js +4 -4
  38. package/lib/init/features/appsail/index.js +213 -0
  39. package/lib/init/features/functions/index.js +5 -72
  40. package/lib/init/features/functions/languages/java.js +7 -3
  41. package/lib/init/features/functions/languages/node.js +9 -7
  42. package/lib/init/features/functions/languages/python.js +1 -1
  43. package/lib/init/features/index.js +28 -12
  44. package/lib/init/features/project.js +3 -3
  45. package/lib/init/index.js +1 -1
  46. package/lib/init/util/common.js +103 -0
  47. package/lib/internal/api.js +5 -5
  48. package/lib/internal/command.js +26 -3
  49. package/lib/option-filter.js +40 -21
  50. package/lib/prompt/index.js +5 -0
  51. package/lib/prompt/types/file-path.js +4 -1
  52. package/lib/prompt/types/tree.js +297 -0
  53. package/lib/pull/features/functions/index.js +70 -47
  54. package/lib/serve/features/appsail.js +37 -0
  55. package/lib/serve/features/index.js +8 -1
  56. package/lib/serve/index.js +23 -6
  57. package/lib/serve/server/index.js +111 -233
  58. package/lib/serve/server/lib/appsail/index.js +134 -0
  59. package/lib/serve/server/lib/appsail/start.js +75 -0
  60. package/lib/serve/server/lib/java/index.js +54 -0
  61. package/lib/serve/server/lib/master.js +84 -60
  62. package/lib/serve/server/lib/node/index.js +85 -74
  63. package/lib/serve/server/lib/node/server/index.js +77 -0
  64. package/lib/serve/server/lib/python/index.js +46 -0
  65. package/lib/serve/server/lib/web_client/index.js +33 -0
  66. package/lib/serve/server/lib/web_client/server.js +3 -0
  67. package/lib/shell/dependencies/http-functions.js +7 -7
  68. package/lib/shell/dependencies/local-function.js +6 -6
  69. package/lib/shell/prepare/index.js +1 -1
  70. package/lib/shell/prepare/languages/index.js +3 -3
  71. package/lib/shell/prepare/languages/java.js +2 -2
  72. package/lib/util_modules/config/index.js +3 -1
  73. package/lib/util_modules/config/lib/appSail.js +89 -0
  74. package/lib/util_modules/constants/index.js +3 -1
  75. package/lib/util_modules/constants/lib/default.js +4 -2
  76. package/lib/util_modules/constants/lib/file-names.js +4 -1
  77. package/lib/util_modules/constants/lib/runtime.js +12 -3
  78. package/lib/util_modules/constants/lib/scopes.js +4 -0
  79. package/lib/util_modules/constants/lib/template.js +23 -20
  80. package/lib/util_modules/constants/lib/urls.js +5 -0
  81. package/lib/util_modules/context-help.js +3 -0
  82. package/lib/util_modules/fs/lib/async.js +10 -3
  83. package/lib/util_modules/fs/lib/sync.js +2 -2
  84. package/lib/util_modules/js.js +4 -0
  85. package/lib/util_modules/project.js +2 -2
  86. package/lib/util_modules/server.js +2 -1
  87. package/package.json +1 -1
  88. package/scripts/postInstall.js +27 -18
  89. package/templates/init/functions/java/browserLogic/playwright/sample.java +1 -1
  90. package/templates/init/functions/java/browserLogic/selenium/sample.java +1 -1
  91. package/templates/init/functions/node/browserlogic/playwright/sample.js +1 -1
  92. package/templates/init/functions/node/browserlogic/puppeteer/sample.js +1 -1
  93. package/templates/init/functions/node/browserlogic/selenium/sample.js +1 -1
  94. package/templates/init/functions/python/aio/requirements.txt +1 -1
  95. package/templates/init/functions/python/bio/requirements.txt +1 -1
  96. package/templates/init/functions/python/cron/requirements.txt +1 -1
  97. package/templates/init/functions/python/event/requirements.txt +1 -1
  98. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -1
  99. /package/lib/serve/server/lib/java/{JavaaioServer.java → aio_server/JavaaioServer.java} +0 -0
  100. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  101. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-function-sdk-1.0.0.jar +0 -0
  102. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-java-runtime-1.0.0.jar +0 -0
  103. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/gradle-wrapper.jar +0 -0
  104. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-http-9.3.24.v20180605.jar +0 -0
  105. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-io-9.3.24.v20180605.jar +0 -0
  106. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-security-9.3.24.v20180605.jar +0 -0
  107. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-server-9.3.24.v20180605.jar +0 -0
  108. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-servlet-9.3.24.v20180605.jar +0 -0
  109. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-util-9.3.24.v20180605.jar +0 -0
  110. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/org.json.jar +0 -0
  111. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/servlet-api-3.1.jar +0 -0
  112. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/zip4j-2.5.0.jar +0 -0
  113. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-playwright.js +0 -0
  114. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-puppeteer.js +0 -0
  115. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-selenium.js +0 -0
  116. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/index.js +0 -0
  117. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/deferred_promise.js +0 -0
  118. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/playwright-handler.js +0 -0
  119. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/puppeteer-handler.js +0 -0
  120. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/selenium-handler.js +0 -0
  121. /package/lib/serve/server/lib/node/{package.json → server/package.json} +0 -0
@@ -1,27 +1,4 @@
1
1
  'use strict';
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,38 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
9
  });
33
10
  };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
45
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
13
  };
48
14
  Object.defineProperty(exports, "__esModule", { value: true });
49
- const path_1 = require("path");
50
15
  const error_1 = __importDefault(require("../../error"));
51
- const fn_utils_1 = require("../../fn-utils");
52
- const plugin_loader_1 = __importDefault(require("../../plugin-loader"));
53
- const userConfig_1 = __importDefault(require("../../userConfig"));
54
16
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
55
17
  const constants_1 = require("../../util_modules/constants");
56
18
  const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
57
19
  const js_1 = require("../../util_modules/js");
58
20
  const logger_1 = require("../../util_modules/logger");
59
- const shell_1 = require("../../util_modules/shell");
60
21
  const master_1 = __importDefault(require("./lib/master"));
61
- const ansi_colors_1 = require("ansi-colors");
62
- const stream_1 = require("stream");
63
- const project_1 = require("../../util_modules/project");
64
- const http_functions_1 = require("../../shell/dependencies/http-functions");
22
+ const index_js_1 = __importDefault(require("./lib/java/index.js"));
23
+ const index_js_2 = __importDefault(require("./lib/node/index.js"));
24
+ const index_js_3 = __importDefault(require("./lib/python/index.js"));
25
+ const index_js_4 = __importDefault(require("./lib/web_client/index.js"));
26
+ const index_js_5 = __importDefault(require("./lib/appsail/index.js"));
65
27
  const cli_table_1 = require("../../cli_table");
28
+ const ansi_colors_1 = require("ansi-colors");
66
29
  const bioLogUrl = (name, pthName, httpPort, masterPort) => {
67
30
  (0, logger_1.labeled)(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
68
31
  };
@@ -73,7 +36,12 @@ const aioLogUrl = (details, masterPort) => {
73
36
  };
74
37
  class Server {
75
38
  constructor() {
76
- this.targetDetailsArr = [];
39
+ this.targetsMap = {
40
+ functions: [],
41
+ server: [],
42
+ client: [],
43
+ appSail: []
44
+ };
77
45
  }
78
46
  _addBasicFnDetails() {
79
47
  const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
@@ -88,11 +56,11 @@ class Server {
88
56
  var _a;
89
57
  return t.url !== undefined &&
90
58
  t.type === constants_1.FN_TYPE.basic &&
91
- !((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python));
59
+ !((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value));
92
60
  })
93
61
  .map((t) => js_1.JS.omit(t, ['zip_stream', 'localFn']))
94
62
  .forEach((t) => {
95
- this.targetDetailsArr.push({
63
+ this.targetsMap.functions.push({
96
64
  type: 'functions',
97
65
  httpPort,
98
66
  debugPort,
@@ -101,138 +69,36 @@ class Server {
101
69
  });
102
70
  }
103
71
  }
104
- _spinUpJavaServer(details, masterPort) {
105
- var _a, _b, _c;
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const projectRoot = runtime_store_1.default.get('project.root');
108
- const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
109
- const targetDir = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
110
- const label = `${details.type}[${(_b = details.target) === null || _b === void 0 ? void 0 : _b.name}]`;
111
- const opts = [
112
- '-cp',
113
- (0, path_1.join)(targetDir, '*') + fn_utils_1.fnUtils.java.classPathSep + targetDir + path_1.sep,
114
- `-DCATALYST_FUNCTION_TYPE=${constants_1.REMOTE_REF.functions.type[details.target.type]}`
115
- ];
116
- if (details.debugPort !== -1) {
117
- (0, logger_1.labeled)(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
118
- opts.push('-Xdebug');
119
- opts.push('-Xrunjdwp:transport=dt_socket,address=' + details.debugPort + ',server=y,suspend=y');
120
- }
121
- opts.push((0, path_1.basename)(javaServer));
122
- opts.push(details.httpPort + '');
123
- const targetSource = (_c = details.target) === null || _c === void 0 ? void 0 : _c.source;
124
- const configType = details.type === 'server' ? 'functions' : details.type;
125
- const servePlugin = yield (0, plugin_loader_1.default)(configType, 'start', targetSource).catch((err) => (0, logger_1.debug)(err));
126
- if (typeof servePlugin === 'function') {
127
- const event = servePlugin(details, masterPort);
128
- (0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
129
- return event;
130
- }
131
- if (details.target.type === constants_1.FN_TYPE.browserLogic) {
132
- details.target.env_var = Object.assign({ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true }, details.target.env_var);
133
- }
134
- const child = (0, shell_1.spawn)('java', opts, {
135
- cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
136
- stdio: 'pipe',
137
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
138
- }).RAW();
139
- return child;
140
- });
141
- }
142
- _spinUpProcess(details, masterPort) {
143
- var _a, _b;
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
146
- const _c = details.target, { ['watcher']: _ } = _c, serialisableTarget = __rest(_c, ['watcher']);
147
- const projectRoot = runtime_store_1.default.get('project.root');
148
- serialisableTarget.index = serialisableTarget.index
149
- ? serialisableTarget.index.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build))
150
- : undefined;
151
- const opts = [
152
- (0, path_1.join)(__dirname, 'lib', 'node'),
153
- details.httpPort + '',
154
- JSON.stringify(serialisableTarget)
155
- ];
156
- if (details.debugPort !== -1) {
157
- (0, logger_1.labeled)(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
158
- opts.unshift('--inspect=' + details.debugPort);
159
- }
160
- const targetSource = (_b = details.target) === null || _b === void 0 ? void 0 : _b.source;
161
- const configType = details.type === 'server' ? 'functions' : details.type;
162
- const servePlugin = yield (0, plugin_loader_1.default)(configType, 'start', targetSource).catch((err) => (0, logger_1.debug)(err));
163
- if (typeof servePlugin === 'function') {
164
- if (configType === 'client') {
165
- process.env.X_CATALYST_WEBAPP_PATH = targetSource;
166
- }
167
- const logStreamPlugin = yield (0, plugin_loader_1.default)(configType, 'logs', targetSource).catch((err) => (0, logger_1.debug)(err));
168
- if (typeof logStreamPlugin === 'function') {
169
- const stream = yield logStreamPlugin();
170
- if (stream instanceof stream_1.Stream) {
171
- const streamLogFn = (chunk) => (0, logger_1.log)('info', chunk.toString(), true);
172
- stream.on('data', streamLogFn);
173
- }
174
- }
175
- const event = servePlugin(details, masterPort).catch((e) => {
176
- var _a, _b;
177
- const err = error_1.default.getErrorInstance(e, {
178
- fileName: __filename,
179
- skipHelp: false
180
- });
181
- err.errorId = 'SERVE-IDX-1';
182
- err.arg = [
183
- configType,
184
- (0, 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'),
185
- (0, ansi_colors_1.bold)('Error: ') + ansi_colors_1.italic.red(err.message)
186
- ];
187
- throw err;
188
- });
189
- (0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
190
- return event;
191
- }
192
- if (details.type === 'client') {
193
- return yield (yield Promise.resolve().then(() => __importStar(require('./lib/web_client/index.js')))).default(details, masterPort);
194
- }
195
- const child = (0, shell_1.spawn)('node', opts, {
196
- cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
197
- stdio: 'pipe',
198
- env: Object.assign({ NODE_PATH: targetSource + path_1.sep + 'node_modules', X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
199
- }).RAW();
200
- return child;
201
- });
202
- }
203
- _spinUpPythonServer(details) {
204
- var _a, _b;
205
- return __awaiter(this, void 0, void 0, function* () {
206
- const projectRoot = runtime_store_1.default.get('project.root');
207
- const opts = ['-u', 'main.py'];
208
- const targetSource = (_a = details.target) === null || _a === void 0 ? void 0 : _a.source;
209
- const runtimesDir = constants_1.ENVPATH.runtimes.data;
210
- const stackVersion = (_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.replace('python_', '');
211
- return new Promise((res) => {
212
- const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
213
- cwd: (0, path_1.join)(runtimesDir, runtime_1.default.language.python, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`),
214
- stdio: 'pipe',
215
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
216
- }).RAW();
217
- child.on('spawn', () => __awaiter(this, void 0, void 0, function* () {
218
- yield (0, http_functions_1.checkIfRuntimeServerRunning)(details.httpPort.toString());
219
- }));
220
- res(child);
221
- });
222
- });
223
- }
224
72
  add(type, target) {
73
+ if (type === 'appsail') {
74
+ this.targetsMap.appSail.push({
75
+ type,
76
+ target: target,
77
+ httpPort: -1,
78
+ debugPort: -1
79
+ });
80
+ return;
81
+ }
225
82
  const httpPort = runtime_store_1.default.get(`context.port.http.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
226
83
  const debugPort = runtime_store_1.default.get(`context.port.debug.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
227
84
  if (httpPort === -1) {
228
- throw new error_1.default('http port is mandatory for target : ' + target.name + ' to start advanced server', { exit: 2 });
85
+ throw new error_1.default('http port is mandatory for target : ' +
86
+ target.name +
87
+ ' to start advanced server', { exit: 2 });
229
88
  }
230
- this.targetDetailsArr.push({
231
- type,
232
- target,
233
- httpPort,
234
- debugPort
235
- });
89
+ type === 'client'
90
+ ? this.targetsMap.client.push({
91
+ type,
92
+ target: target,
93
+ httpPort,
94
+ debugPort
95
+ })
96
+ : this.targetsMap.server.push({
97
+ type,
98
+ target: target,
99
+ httpPort,
100
+ debugPort
101
+ });
236
102
  }
237
103
  startServer(details, masterPort) {
238
104
  var _a, _b;
@@ -241,14 +107,31 @@ class Server {
241
107
  return;
242
108
  }
243
109
  let currentProcess;
244
- if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
245
- currentProcess = yield this._spinUpJavaServer(details, masterPort);
246
- }
247
- else if ((_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.python)) {
248
- currentProcess = yield this._spinUpPythonServer(details);
249
- }
250
- else {
251
- currentProcess = yield this._spinUpProcess(details, masterPort);
110
+ switch (details.type) {
111
+ case 'appsail': {
112
+ currentProcess = yield (0, index_js_5.default)(details.target, masterPort);
113
+ break;
114
+ }
115
+ case 'client': {
116
+ currentProcess = yield (0, index_js_4.default)(details, masterPort);
117
+ break;
118
+ }
119
+ case 'functions':
120
+ case 'server': {
121
+ if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java.value)) {
122
+ currentProcess = yield (0, index_js_1.default)(details, masterPort);
123
+ }
124
+ else if ((_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.node.value)) {
125
+ currentProcess = yield (0, index_js_2.default)(details, masterPort);
126
+ }
127
+ else {
128
+ currentProcess = yield (0, index_js_3.default)(details);
129
+ }
130
+ break;
131
+ }
132
+ default: {
133
+ throw new error_1.default('Invalid feature type', { exit: 2 });
134
+ }
252
135
  }
253
136
  details.process = currentProcess;
254
137
  const stdout = currentProcess.stdout;
@@ -272,19 +155,21 @@ class Server {
272
155
  if (masterPort === -1) {
273
156
  throw new error_1.default('master port cannot be undefined', { exit: 2 });
274
157
  }
275
- yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () { return this.startServer(details, masterPort); })));
158
+ const serveTargets = Object.values(this.targetsMap);
159
+ yield Promise.all(serveTargets.map((targetDetails) => Promise.all(targetDetails.map((details) => this.startServer(details, masterPort)))));
276
160
  this._addBasicFnDetails();
277
- if (this.targetDetailsArr.length === 0) {
161
+ const serveTargetsArr = serveTargets.flat();
162
+ if (serveTargetsArr.length === 0) {
278
163
  throw new error_1.default('Trying to start master server before other server', {
279
164
  exit: 2
280
165
  });
281
166
  }
282
- const server = yield (0, master_1.default)(masterPort, this.targetDetailsArr);
167
+ const server = yield (0, master_1.default)(masterPort, this.targetsMap);
283
168
  this.masterServer = server;
284
- this.targetDetailsArr.some((t) => {
169
+ this.targetsMap.server.every((t) => {
285
170
  var _a;
286
- if (t.debugPort != -1 &&
287
- ((_a = t.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python))) {
171
+ if (t.debugPort !== -1 &&
172
+ ((_a = t.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value))) {
288
173
  const table = (0, cli_table_1.getCustomColourTable)(ansi_colors_1.yellow);
289
174
  table.push(['As of now, local debugging for python is not supported']);
290
175
  (0, logger_1.info)(table.toString());
@@ -292,9 +177,7 @@ class Server {
292
177
  }
293
178
  return false;
294
179
  });
295
- this.targetDetailsArr
296
- .filter((t) => t.type == 'functions')
297
- .forEach((t) => {
180
+ this.targetsMap.functions.forEach((t) => {
298
181
  const target = t.target;
299
182
  if (!target.url) {
300
183
  throw new error_1.default('Target URL not found', { exit: 2 });
@@ -302,14 +185,12 @@ class Server {
302
185
  bioLogUrl(target.name, new URL(target.url).pathname, t.httpPort, masterPort);
303
186
  });
304
187
  (0, logger_1.info)();
305
- this.targetDetailsArr
306
- .filter((t) => t.type == 'server')
307
- .forEach((t) => {
188
+ this.targetsMap.server.forEach((t) => {
308
189
  aioLogUrl(t, masterPort);
309
190
  });
310
191
  return new Promise((res) => {
311
192
  server.on('listening', () => {
312
- this.targetDetailsArr.forEach((targetDetails) => {
193
+ serveTargetsArr.forEach((targetDetails) => {
313
194
  var _a;
314
195
  if (targetDetails.process &&
315
196
  'send' in targetDetails.process) {
@@ -330,36 +211,38 @@ class Server {
330
211
  (0, logger_1.debug)('Master server is not started yet.');
331
212
  throw new error_1.default('Server cannot be put to wait state.', { exit: 2 });
332
213
  }
333
- this.targetDetailsArr.forEach((targetdetails) => {
334
- var _a, _b;
335
- const target = targetdetails.target;
336
- if (!target || !targetdetails.process) {
337
- return;
338
- }
339
- (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => __awaiter(this, void 0, void 0, function* () {
340
- yield this.kill(targetdetails.process);
341
- }));
342
- (_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => __awaiter(this, void 0, void 0, function* () {
343
- yield this.restart(target);
344
- if (target.type === constants_1.FN_TYPE.basic) {
345
- (0, logger_1.labeled)(`functions(${target.name})`, 'ready!').MESSAGE();
346
- if (!target.url) {
347
- throw new error_1.default('Target URL not found while restarting server', {
348
- exit: 2
349
- });
350
- }
351
- bioLogUrl(target.name, new URL(target.url).pathname, targetdetails.httpPort, masterPort);
352
- }
353
- else if (target.type === constants_1.FN_TYPE.advanced) {
354
- (0, logger_1.labeled)(`server[${target.name}]`, 'ready!').MESSAGE();
355
- aioLogUrl(targetdetails, masterPort);
214
+ Object.values(this.targetsMap).forEach((details) => {
215
+ details.forEach((targetdetails) => {
216
+ var _a, _b;
217
+ const target = targetdetails.target;
218
+ if (!target || !targetdetails.process) {
219
+ return;
356
220
  }
357
- setTimeout(() => {
358
- var _a;
359
- (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
360
- }, 1000);
361
- }));
362
- }, this);
221
+ (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => __awaiter(this, void 0, void 0, function* () {
222
+ yield this.kill(targetdetails.process);
223
+ }));
224
+ (_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => __awaiter(this, void 0, void 0, function* () {
225
+ yield this.restart(targetdetails);
226
+ if (target.type === constants_1.FN_TYPE.basic) {
227
+ (0, logger_1.labeled)(`functions[${target.name}]`, 'ready!').MESSAGE();
228
+ if (!target.url) {
229
+ throw new error_1.default('Target URL not found while restarting server', {
230
+ exit: 2
231
+ });
232
+ }
233
+ bioLogUrl(target.name, new URL(target.url).pathname, targetdetails.httpPort, masterPort);
234
+ }
235
+ else if (target.type === constants_1.FN_TYPE.advanced) {
236
+ (0, logger_1.labeled)(`server[${target.name}]`, 'ready!').MESSAGE();
237
+ aioLogUrl(targetdetails, masterPort);
238
+ }
239
+ setTimeout(() => {
240
+ var _a;
241
+ (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
242
+ }, 1000);
243
+ }));
244
+ }, this);
245
+ });
363
246
  return new Promise((res) => {
364
247
  ['SIGINT', 'SIGTERM'].forEach((sig) => process.on(sig, res));
365
248
  });
@@ -385,21 +268,16 @@ class Server {
385
268
  }
386
269
  restart(target) {
387
270
  return __awaiter(this, void 0, void 0, function* () {
388
- const targetIdx = this.targetDetailsArr.findIndex((targetDetails) => { var _a; return target.source === ((_a = targetDetails.target) === null || _a === void 0 ? void 0 : _a.source); });
389
- if (targetIdx === -1) {
390
- throw new error_1.default('Unknown target given for restart.', { exit: 2 });
391
- }
392
- const targetProcess = this.targetDetailsArr[targetIdx].process;
393
- if (!targetProcess) {
271
+ if (!target.process) {
394
272
  throw new error_1.default('Process is not defined for this target.', { exit: 2 });
395
273
  }
396
- yield this.kill(targetProcess);
397
- yield this.startServer(this.targetDetailsArr[targetIdx], runtime_store_1.default.get(`context.port.http.master`, -1));
274
+ yield this.kill(target.process);
275
+ yield this.startServer(target, runtime_store_1.default.get(`context.port.http.master`, -1));
398
276
  });
399
277
  }
400
278
  stop() {
401
279
  return __awaiter(this, void 0, void 0, function* () {
402
- yield Promise.all(this.targetDetailsArr.map((targetdetails) => __awaiter(this, void 0, void 0, function* () {
280
+ yield Promise.all(Object.values(this.targetsMap).map((details) => Promise.all(details.map((targetdetails) => __awaiter(this, void 0, void 0, function* () {
403
281
  var _a;
404
282
  const target = targetdetails.target;
405
283
  if (!target) {
@@ -409,7 +287,7 @@ class Server {
409
287
  if (targetdetails.process) {
410
288
  return this.kill(targetdetails.process);
411
289
  }
412
- }))).catch((err) => (0, logger_1.debug)('Error stopping the servers: ', err));
290
+ }))))).catch((err) => (0, logger_1.debug)('Error stopping the servers: ', err));
413
291
  if (this.masterServer) {
414
292
  const masterServer = this.masterServer;
415
293
  return new Promise((res, rej) => {
@@ -0,0 +1,134 @@
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 path_1 = require("path");
16
+ const error_1 = __importDefault(require("../../../../error"));
17
+ const constants_1 = require("../../../../util_modules/constants");
18
+ const fs_1 = require("../../../../util_modules/fs");
19
+ const logger_1 = require("../../../../util_modules/logger");
20
+ const project_1 = require("../../../../util_modules/project");
21
+ const shell_1 = require("../../../../util_modules/shell");
22
+ const endpoints_1 = require("../../../../endpoints");
23
+ const archiver_1 = __importDefault(require("../../../../archiver"));
24
+ const option_1 = require("../../../../util_modules/option");
25
+ const execute_script_1 = require("../../../../execute-script");
26
+ function executeHook(script, name, moduleSource) {
27
+ if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
28
+ (0, logger_1.debug)(`skipping ${name} hook`);
29
+ return;
30
+ }
31
+ (0, execute_script_1.executeCommand)(script, { moduleSource, feature: name });
32
+ }
33
+ const startAppSail = (port, opts) => {
34
+ const startScriptPath = (0, path_1.join)(__dirname, 'start.js');
35
+ const _opts = [startScriptPath, '-t', opts.type];
36
+ if (opts.command) {
37
+ _opts.push('-c', opts.command);
38
+ }
39
+ return (0, shell_1.spawn)('node', _opts, {
40
+ cwd: opts.target,
41
+ stdio: 'pipe',
42
+ env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
43
+ }).RAW();
44
+ };
45
+ exports.default = (targetSail, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
46
+ var _a, _b, _c;
47
+ let child;
48
+ if (!targetSail.appSail) {
49
+ throw new error_1.default('AppSail details not found');
50
+ }
51
+ if ((_a = targetSail.appSail.scripts) === null || _a === void 0 ? void 0 : _a.preserve) {
52
+ executeHook(targetSail.appSail.scripts.preserve, `AppSail [PRESERVE] [${(_b = targetSail.appSail) === null || _b === void 0 ? void 0 : _b.name}]`, targetSail.appSail.source);
53
+ }
54
+ const target = (yield fs_1.ASYNC.isFile(targetSail.appSail.buildPath))
55
+ ? (0, path_1.dirname)(targetSail.appSail.buildPath)
56
+ : targetSail.appSail.buildPath;
57
+ switch (true) {
58
+ case targetSail.appSail.stack.startsWith('node'): {
59
+ child = startAppSail(targetSail.port, {
60
+ type: 'nodejs',
61
+ target,
62
+ command: targetSail.appSail.command,
63
+ memory: targetSail.appSail.memory || 256,
64
+ env: targetSail.appSail.env_variables
65
+ });
66
+ break;
67
+ }
68
+ case targetSail.appSail.stack.startsWith('python'): {
69
+ child = startAppSail(targetSail.port, {
70
+ type: 'python',
71
+ target,
72
+ command: targetSail.appSail.command,
73
+ memory: targetSail.appSail.memory || 256,
74
+ env: targetSail.appSail.env_variables
75
+ });
76
+ break;
77
+ }
78
+ case targetSail.appSail.stack.startsWith('java'): {
79
+ if (targetSail.appSail.platform === 'war') {
80
+ const jettyPath = (0, path_1.join)(constants_1.ENVPATH.runtimes.data, 'jetty');
81
+ if (!(yield fs_1.ASYNC.fileExists((0, path_1.join)(jettyPath, 'start.jar')).catch((err) => (0, logger_1.debug)(err)))) {
82
+ try {
83
+ yield fs_1.ASYNC.ensureDir(jettyPath);
84
+ const appxAPI = yield (0, endpoints_1.appSailAPI)();
85
+ const jettyZip = yield appxAPI.downloadJetty();
86
+ const zip = new archiver_1.default();
87
+ zip.load(jettyZip);
88
+ zip.extract(jettyPath, '/', {
89
+ ignoreInitial: false,
90
+ isFolder: true
91
+ });
92
+ yield zip.finalize();
93
+ }
94
+ catch (err) {
95
+ (0, logger_1.debug)('Unable to ensure Jetty Runtime');
96
+ throw err;
97
+ }
98
+ }
99
+ const jettyCommand = `java -jar ${(0, path_1.join)(jettyPath.replace(/ /g, '\\ '), 'start.jar')} -Djetty.deploy.monitoredPath=${(0, project_1.resolveProjectPath)(targetSail.appSail.buildPath)} -Djetty.http.port=${targetSail.port} --dry-run=opts,path,main,args`;
100
+ child = startAppSail(targetSail.port, {
101
+ target,
102
+ type: 'war',
103
+ command: jettyCommand,
104
+ memory: targetSail.appSail.memory || 256,
105
+ env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.appSail.env_variables)
106
+ });
107
+ break;
108
+ }
109
+ child = startAppSail(targetSail.port, {
110
+ target,
111
+ command: targetSail.appSail.command,
112
+ type: 'javase',
113
+ memory: targetSail.appSail.memory || 256,
114
+ env: targetSail.appSail.env_variables
115
+ });
116
+ break;
117
+ }
118
+ default: {
119
+ throw new error_1.default('Invalid AppSail stack');
120
+ }
121
+ }
122
+ (0, logger_1.labeled)(`AppSail(${targetSail.appSail.name})`, `URL : http://localhost:${masterPort}/appsail/${targetSail.appSail.name}/`).MESSAGE();
123
+ (0, logger_1.info)();
124
+ if ((_c = targetSail.appSail.scripts) === null || _c === void 0 ? void 0 : _c.postserve) {
125
+ child.once('exit', () => {
126
+ var _a, _b, _c, _d;
127
+ if (!((_a = targetSail.appSail) === null || _a === void 0 ? void 0 : _a.scripts)) {
128
+ return;
129
+ }
130
+ executeHook((_b = targetSail.appSail.scripts) === null || _b === void 0 ? void 0 : _b.postserve, `AppSail [POSTSERVE] [${(_c = targetSail.appSail) === null || _c === void 0 ? void 0 : _c.name}]`, (_d = targetSail.appSail) === null || _d === void 0 ? void 0 : _d.source);
131
+ });
132
+ }
133
+ return child;
134
+ });