zcatalyst-cli 1.15.0-beta.5 → 1.15.0-beta.7

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 (43) hide show
  1. package/docs/serve/server/index.toml +5 -0
  2. package/docs/serve/server/lib/appsail/index.toml +4 -0
  3. package/lib/archiver.js +8 -3
  4. package/lib/client-utils.js +5 -1
  5. package/lib/commands/iac/pack.js +9 -8
  6. package/lib/deploy/features/appsail/index.js +15 -5
  7. package/lib/deploy/features/client.js +1 -1
  8. package/lib/deploy/features/functions/index.js +7 -4
  9. package/lib/endpoints/lib/applogic.js +14 -2
  10. package/lib/endpoints/lib/appsail.js +11 -2
  11. package/lib/endpoints/lib/client.js +11 -2
  12. package/lib/endpoints/lib/functions.js +14 -2
  13. package/lib/express_middlewares/logger.js +6 -2
  14. package/lib/fn-utils/lib/common.js +78 -48
  15. package/lib/fn-utils/lib/java.js +10 -10
  16. package/lib/fn-utils/lib/python.js +1 -1
  17. package/lib/init/features/appsail/index.js +2 -2
  18. package/lib/internal/api.js +33 -8
  19. package/lib/option-filter.js +4 -4
  20. package/lib/port-resolver.js +24 -11
  21. package/lib/progress.js +3 -2
  22. package/lib/prompt/types/file-path.js +3 -1
  23. package/lib/serve/features/appsail.js +14 -3
  24. package/lib/serve/features/index.js +1 -1
  25. package/lib/serve/index.js +7 -2
  26. package/lib/serve/server/index.js +317 -123
  27. package/lib/serve/server/lib/appsail/index.js +28 -10
  28. package/lib/serve/server/lib/appsail/start.js +4 -15
  29. package/lib/serve/server/lib/master.js +10 -10
  30. package/lib/serve/server/lib/web_client/index.js +5 -5
  31. package/lib/shell/dependencies/http-functions.js +11 -15
  32. package/lib/shell/prepare/languages/java.js +9 -4
  33. package/lib/util_modules/constants/lib/default.js +4 -1
  34. package/lib/util_modules/constants/lib/scopes.js +1 -0
  35. package/lib/util_modules/fs/lib/async.js +11 -17
  36. package/lib/util_modules/fs/lib/sync.js +5 -1
  37. package/package.json +1 -1
  38. package/templates/init/functions/java/integ/convokraft/FallbackHandler.java +1 -0
  39. package/templates/init/functions/node/integ/convokraft/fallback.js +1 -0
  40. package/templates/init/functions/python/integ/convokraft/fallback_handler.py +2 -1
  41. package/templates/init/functions/node/.DS_Store +0 -0
  42. package/templates/init/functions/node/integ/.DS_Store +0 -0
  43. package/templates/init/functions/node/integ/convokraft/.DS_Store +0 -0
@@ -2,3 +2,8 @@
2
2
  context = '''Error when serving the ${arg[0]} with the ${arg[1]} plugin.'''
3
3
  aid = '''Please rectify the below error to serve the ${arg[0]}: \n${arg[2]}'''
4
4
  link = ''
5
+
6
+ [SERVE-IDX-2]
7
+ context = '''No components were successfully started for serve'''
8
+ aid = '''Please rectify the errors if any'''
9
+ link = ''
@@ -0,0 +1,4 @@
1
+ [SERVE-APPSAIL-1]
2
+ context = '''The provided build path (${arg[0]}) for the AppSail ${arg[1]} does not exists.'''
3
+ aid = '''Please provide a valid build path'''
4
+ link = ''
package/lib/archiver.js CHANGED
@@ -179,9 +179,12 @@ class Archiver {
179
179
  getUnixPath(pth) {
180
180
  return pth.split(path_1.sep).join('/');
181
181
  }
182
- add(pth, content, { createFolders = true } = {}) {
182
+ add(pth, content, { createFolders = true, mode } = {}) {
183
183
  this.promiseArr.push(this.jszip.then((zip) => {
184
- return zip.file(this.getUnixPath(pth), content, { createFolders });
184
+ return zip.file(this.getUnixPath(pth), content, {
185
+ createFolders,
186
+ unixPermissions: mode
187
+ });
185
188
  }));
186
189
  return this;
187
190
  }
@@ -223,18 +226,20 @@ class Archiver {
223
226
  const zip = yield this.jszip;
224
227
  const content = yield zip.generateAsync({
225
228
  type: 'nodebuffer',
229
+ platform: 'UNIX',
226
230
  compression: 'DEFLATE',
227
231
  compressionOptions: {
228
232
  level: 9
229
233
  }
230
234
  });
231
235
  yield fs_1.ASYNC.writeFile(tempFilePath, content);
232
- return fs_1.SYNC.getReadStream(tempFilePath);
236
+ return { stream: fs_1.SYNC.getReadStream(tempFilePath), length: content.length };
233
237
  }),
234
238
  writeZip: (pth) => __awaiter(this, void 0, void 0, function* () {
235
239
  const zip = yield this.jszip;
236
240
  const content = yield zip.generateAsync({
237
241
  type: 'nodebuffer',
242
+ platform: 'UNIX',
238
243
  compression: 'DEFLATE',
239
244
  compressionOptions: {
240
245
  level: 9
@@ -171,7 +171,11 @@ exports.clientUtils = {
171
171
  const files = yield fs_1.ASYNC.walk(source, { filter: { exclude, excludeDir: true } });
172
172
  const zip = new archiver_1.default();
173
173
  files.forEach((file) => {
174
- zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
174
+ zip.add(file.path.replace(source + path_1.sep, ''), file.stats.isSymbolicLink()
175
+ ? fs_1.SYNC.readSymLink(file.path)
176
+ : fs_1.SYNC.getReadStream(file.path), {
177
+ mode: file.stats.mode
178
+ });
175
179
  });
176
180
  const zipFinalizer = yield zip.finalize();
177
181
  return zipFinalizer.fsStream();
@@ -55,14 +55,14 @@ exports.default = new command_1.default('iac:pack [zip_name]')
55
55
  .needs('auth')
56
56
  .needs('config')
57
57
  .action((userZipName) => __awaiter(void 0, void 0, void 0, function* () {
58
- var _a, _b;
58
+ var _a, _b, _c;
59
59
  const config = runtime_store_1.default.get('config');
60
60
  const rootDir = (0, path_1.dirname)(config.configPath);
61
61
  const filesAtRoot = yield fs_1.ASYNC.walk(rootDir, {
62
62
  filter: { excludeDir: true, exclude: [] },
63
63
  depth: 1
64
64
  });
65
- const templateFilePth = filesAtRoot.find((fileName) => fileName.match(constants_1.REGEX.project.template));
65
+ const templateFilePth = (_a = filesAtRoot.find((file) => file.path.match(constants_1.REGEX.project.template))) === null || _a === void 0 ? void 0 : _a.path;
66
66
  if (templateFilePth === undefined) {
67
67
  throw new error_1.default('No template file found', { exit: 1 });
68
68
  }
@@ -71,8 +71,8 @@ exports.default = new command_1.default('iac:pack [zip_name]')
71
71
  throw new error_1.default('Unable to read template file', { exit: 1 });
72
72
  }
73
73
  const templateJson = js_1.JS.parseJSON(templateFile) || (0, yaml_1.parse)(templateFile);
74
- const templateFns = ((_a = templateJson.components) === null || _a === void 0 ? void 0 : _a.Functions) || [];
75
- const templateClient = ((_b = templateJson.components) === null || _b === void 0 ? void 0 : _b.WebClient) || [];
74
+ const templateFns = ((_b = templateJson.components) === null || _b === void 0 ? void 0 : _b.Functions) || [];
75
+ const templateClient = ((_c = templateJson.components) === null || _c === void 0 ? void 0 : _c.WebClient) || [];
76
76
  const hrTime = process.hrtime();
77
77
  const archiveName = (userZipName === null || userZipName === void 0 ? void 0 : userZipName.replace('.zip', '')) || `iac_${hrTime[0] * 1000000000 + hrTime[1]}`;
78
78
  const finalZip = new archiver_1.default(archiveName);
@@ -114,21 +114,22 @@ exports.default = new command_1.default('iac:pack [zip_name]')
114
114
  ...(packedPythonFns || [])
115
115
  ];
116
116
  packedFns.forEach((fn) => {
117
+ var _a;
117
118
  if (!fn.valid) {
118
119
  throw new error_1.default(`Unable to pack since "${fn.name}" is not valid. Reason: ${fn.failure_reason}`);
119
120
  }
120
- finalZip.add(fnNameByCodePath[fn.name], fn.zip_stream);
121
+ finalZip.add(fnNameByCodePath[fn.name], (_a = fn.zip_stream) === null || _a === void 0 ? void 0 : _a.stream);
121
122
  });
122
123
  break;
123
124
  case 'client':
124
125
  yield client_utils_1.clientUtils.validate();
125
126
  const clientName = runtime_store_1.default.get('context.client.name');
126
- const clientTeamplateConfig = templateClient.find((tClient) => clientName === tClient.properties.app_name);
127
- if (!clientTeamplateConfig) {
127
+ const clientTemplateConfig = templateClient.find((tClient) => clientName === tClient.properties.app_name);
128
+ if (!clientTemplateConfig) {
128
129
  throw new error_1.default(`No property found for client ${clientName} in project template`, { exit: 1 });
129
130
  }
130
131
  const clientZipStream = yield client_utils_1.clientUtils.pack();
131
- finalZip.add(clientTeamplateConfig.properties.code.path, clientZipStream);
132
+ finalZip.add(clientTemplateConfig.properties.code.path, clientZipStream.stream);
132
133
  break;
133
134
  default:
134
135
  (0, logger_1.debug)(`skipping ${component} since there is no processing needed`);
@@ -30,6 +30,7 @@ const logger_1 = require("../../../util_modules/logger");
30
30
  const option_1 = require("../../../util_modules/option");
31
31
  const project_1 = require("../../../util_modules/project");
32
32
  const utils_1 = require("./utils");
33
+ const throbber_1 = __importDefault(require("../../../throbber"));
33
34
  function executeHook(script, name, moduleSource) {
34
35
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
35
36
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -175,6 +176,7 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
175
176
  });
176
177
  }
177
178
  const sailAPI = yield (0, endpoints_1.appSailAPI)();
179
+ const throbber = throbber_1.default.getInstance();
178
180
  const deployRes = yield validTargets.reduce((result, _targ) => __awaiter(void 0, void 0, void 0, function* () {
179
181
  var _a, _b;
180
182
  const targ = _targ.appSail;
@@ -183,6 +185,10 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
183
185
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
184
186
  executeHook(targ.scripts.predeploy, 'predeploy', targ.source);
185
187
  }
188
+ const throbberName = `prepare_appsail_${targ.name}`;
189
+ throbber.add(throbberName, {
190
+ text: `Preparing AppSail[${targ.name}]`
191
+ });
186
192
  const zip = new archiver_1.default();
187
193
  const folderPath = (0, project_1.resolveProjectPath)(targ.buildPath);
188
194
  const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(folderPath, constants_1.FILENAME.catalyst_ignore));
@@ -199,20 +205,24 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
199
205
  }
200
206
  });
201
207
  folderContents.forEach((content) => {
202
- zip.add(content === folderPath
203
- ? (0, path_1.basename)(content)
204
- : content.replace(folderPath + path_1.sep, ''), fs_1.SYNC.getReadStream(content));
208
+ zip.add(content.path === folderPath
209
+ ? (0, path_1.basename)(content.path)
210
+ : content.path.replace(folderPath + path_1.sep, ''), content.stats.isSymbolicLink()
211
+ ? fs_1.SYNC.readSymLink(content.path)
212
+ : fs_1.SYNC.getReadStream(content.path), { mode: content.stats.mode });
205
213
  });
206
214
  const finalized = yield zip.finalize();
207
215
  const zipStream = yield finalized.fsStream();
216
+ throbber.remove(throbberName);
208
217
  const { stack, name, command, memory, platform, env_variables } = targ;
209
- const apiRes = yield sailAPI.deploy(zipStream, {
218
+ const apiRes = yield sailAPI.deploy(zipStream.stream, {
210
219
  stack,
211
220
  name,
212
221
  memory,
213
222
  platform,
214
223
  command,
215
- envVariables: env_variables
224
+ envVariables: env_variables,
225
+ contentLength: zipStream.length
216
226
  });
217
227
  _targ.url = apiRes.url;
218
228
  if ((_b = targ.scripts) === null || _b === void 0 ? void 0 : _b.postdeploy) {
@@ -20,7 +20,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
20
20
  client_utils_1.clientUtils.executeHook({ prefix: 'pre', command: 'deploy' });
21
21
  yield client_utils_1.clientUtils.validate();
22
22
  const readStream = yield client_utils_1.clientUtils.pack();
23
- const resp = (yield (yield (0, endpoints_1.clientAPI)()).deploy(readStream));
23
+ const resp = (yield (yield (0, endpoints_1.clientAPI)()).deploy(readStream.stream, readStream.length));
24
24
  const homepage = runtime_store_1.default.get('context.client.homepage', '');
25
25
  runtime_store_1.default.set('payload.client.url', 'https://' +
26
26
  resp.url_prefix +
@@ -56,17 +56,19 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
56
56
  const limit = combinedTarget.length > batchSize ? batchSize : combinedTarget.length;
57
57
  const targetBatch = combinedTarget.splice(0, limit);
58
58
  yield Promise.all(targetBatch.map((target) => __awaiter(void 0, void 0, void 0, function* () {
59
+ var _a, _b, _c, _d;
59
60
  if (!target) {
60
61
  return;
61
62
  }
62
63
  try {
63
64
  let resp;
64
65
  if (target.type !== undefined && target.type === constants_1.FN_TYPE.advanced) {
65
- resp = (yield appAPI.deploy(target.zip_stream, {
66
+ resp = (yield appAPI.deploy((_a = target.zip_stream) === null || _a === void 0 ? void 0 : _a.stream, {
66
67
  stack: target.stack,
67
68
  name: target.name,
68
69
  memory: target.memory,
69
- envVariables: target.env_var
70
+ envVariables: target.env_var,
71
+ contentLength: (_b = target.zip_stream) === null || _b === void 0 ? void 0 : _b.length
70
72
  }));
71
73
  }
72
74
  else {
@@ -74,7 +76,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
74
76
  stack: target.stack,
75
77
  name: target.name,
76
78
  type: constants_1.REMOTE_REF.functions.type[target.type],
77
- envVariables: target.env_var
79
+ envVariables: target.env_var,
80
+ contentLength: (_c = target.zip_stream) === null || _c === void 0 ? void 0 : _c.length
78
81
  };
79
82
  if (target.type === constants_1.FN_TYPE.browserLogic && !target.memory && !target.id) {
80
83
  deployOptions.memory = 512;
@@ -82,7 +85,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
82
85
  else {
83
86
  deployOptions.memory = target.memory;
84
87
  }
85
- resp = (yield fnAPI.deploy(target.zip_stream, deployOptions));
88
+ resp = (yield fnAPI.deploy((_d = target.zip_stream) === null || _d === void 0 ? void 0 : _d.stream, deployOptions));
86
89
  }
87
90
  target.id = resp.id + '';
88
91
  fn_utils_1.fnUtils.common.generateUrlForTarget(target);
@@ -20,7 +20,7 @@ class Applogic {
20
20
  this.opts = opts;
21
21
  this.projectId = projectId;
22
22
  }
23
- deploy(sourceFsStream, { stack, name, memory, envVariables }) {
23
+ deploy(sourceFsStream, { stack, name, memory, envVariables, contentLength }) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const formData = {
26
26
  stack,
@@ -41,12 +41,24 @@ class Applogic {
41
41
  if (Object.keys(configuration).length > 0) {
42
42
  formData.configuration = JSON.stringify(configuration);
43
43
  }
44
+ const log = contentLength
45
+ ? {
46
+ uploadProgress: {
47
+ title: `[${name}]`,
48
+ total: contentLength,
49
+ progressType: 'upload'
50
+ },
51
+ stream: sourceFsStream,
52
+ awaitingSpinner: `deploying function [${name}]`
53
+ }
54
+ : undefined;
44
55
  const res = yield new api_1.default(this.opts).put(`/baas/v1/project/${this.projectId}/server/upsert`, {
45
56
  formData,
46
57
  headers: {
47
58
  'Content-Type': 'application/zip'
48
59
  },
49
- json: false
60
+ json: false,
61
+ log
50
62
  });
51
63
  if (res.body && res.body.data) {
52
64
  return res.body.data;
@@ -21,7 +21,7 @@ class AppSail {
21
21
  this.opts = opts;
22
22
  this.projectId = projectId;
23
23
  }
24
- deploy(sourceFsStream, { stack, name, command, memory, platform, envVariables = {} }) {
24
+ deploy(sourceFsStream, { stack, name, contentLength, command, memory, platform, envVariables = {} }) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  const formData = {
27
27
  stack,
@@ -48,7 +48,16 @@ class AppSail {
48
48
  }
49
49
  const res = yield new api_1.default(this.opts).put(`/baas/v1/project/${this.projectId}/appsail/upsert`, {
50
50
  formData,
51
- json: false
51
+ json: false,
52
+ log: {
53
+ uploadProgress: {
54
+ title: `AppSail[${name}]`,
55
+ total: contentLength,
56
+ progressType: 'upload'
57
+ },
58
+ stream: sourceFsStream,
59
+ awaitingSpinner: `deploying Appsail[${name}]`
60
+ }
52
61
  });
53
62
  if (res.body && res.body.data) {
54
63
  return res.body.data;
@@ -20,13 +20,22 @@ class Client {
20
20
  this.opts = opts;
21
21
  this.projectId = projectId;
22
22
  }
23
- deploy(sourceStream) {
23
+ deploy(sourceStream, contentLength) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/webapp`, {
26
26
  formData: {
27
27
  app_zip: sourceStream
28
28
  },
29
- json: false
29
+ json: false,
30
+ log: {
31
+ uploadProgress: {
32
+ title: 'Web_Client',
33
+ total: contentLength,
34
+ progressType: 'upload'
35
+ },
36
+ stream: sourceStream,
37
+ awaitingSpinner: 'deploying Web Client'
38
+ }
30
39
  });
31
40
  if (res.body && res.body.data) {
32
41
  return res.body.data;
@@ -73,7 +73,7 @@ class Functions {
73
73
  });
74
74
  });
75
75
  }
76
- deploy(sourceFsStream, { stack, name, type, memory, envVariables }) {
76
+ deploy(sourceFsStream, { stack, name, type, memory, envVariables, contentLength }) {
77
77
  return __awaiter(this, void 0, void 0, function* () {
78
78
  const formData = {
79
79
  stack,
@@ -95,9 +95,21 @@ class Functions {
95
95
  if (Object.keys(configuration).length > 0) {
96
96
  formData.configuration = JSON.stringify(configuration);
97
97
  }
98
+ const log = contentLength
99
+ ? {
100
+ uploadProgress: {
101
+ title: `[${name}]`,
102
+ total: contentLength,
103
+ progressType: 'upload'
104
+ },
105
+ stream: sourceFsStream,
106
+ awaitingSpinner: `deploying function [${name}]`
107
+ }
108
+ : undefined;
98
109
  const res = yield new api_1.default(this.opts).put(`/baas/v1/project/${this.projectId}/function/upsert`, {
99
110
  formData,
100
- json: false
111
+ json: false,
112
+ log
101
113
  });
102
114
  if (res.body && res.body.data) {
103
115
  return res.body.data;
@@ -1,10 +1,14 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ansi_colors_1 = require("ansi-colors");
4
- exports.default = (req, _RES, next) => {
4
+ exports.default = (appSailDetails) => (req, _RES, next) => {
5
+ var _a, _b;
5
6
  console.log('[' +
6
7
  new Date().getTime() +
7
- ']' +
8
+ '] ' +
9
+ (appSailDetails
10
+ ? (0, ansi_colors_1.cyan)(` Appsail[${(_b = (_a = appSailDetails === null || appSailDetails === void 0 ? void 0 : appSailDetails.target) === null || _a === void 0 ? void 0 : _a.appSail) === null || _b === void 0 ? void 0 : _b.name}] `)
11
+ : '') +
8
12
  ' "' +
9
13
  (0, ansi_colors_1.cyan)(req.method) +
10
14
  '" ' +
@@ -300,14 +300,22 @@ function pack(target) {
300
300
  const outputFolder = (0, path_1.join)(source, constants_1.FOLDERNAME.output);
301
301
  const outputFiles = yield fs_1.ASYNC.walk(outputFolder);
302
302
  outputFiles.forEach((file) => {
303
- zip.add(file.replace(outputFolder + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
303
+ zip.add(file.path.replace(outputFolder + path_1.sep, ''), file.stats.isSymbolicLink()
304
+ ? fs_1.SYNC.readSymLink(file.path)
305
+ : fs_1.SYNC.getReadStream(file.path), {
306
+ mode: file.stats.mode
307
+ });
304
308
  });
305
309
  }
306
310
  else {
307
311
  const exclude = config_1.functionsConfig.ignore(source);
308
312
  const files = yield fs_1.ASYNC.walk(source, { filter: { exclude, excludeDir: true } });
309
313
  files.forEach((file) => {
310
- zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
314
+ zip.add(file.path.replace(source + path_1.sep, ''), file.stats.isSymbolicLink()
315
+ ? fs_1.SYNC.readSymLink(file.path)
316
+ : fs_1.SYNC.getReadStream(file.path), {
317
+ mode: file.stats.mode
318
+ });
311
319
  });
312
320
  }
313
321
  if ((_b = target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.python.value)) {
@@ -320,7 +328,11 @@ function pack(target) {
320
328
  yield (0, pip_install_1.installRequirements)(reqFile, tmpDir, target.stack.replace('python_', ''), true);
321
329
  const files = yield fs_1.ASYNC.walk(tmpDir);
322
330
  files.forEach((file) => {
323
- zip.add(file.replace(tmpDir + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
331
+ zip.add(file.path.replace(tmpDir + path_1.sep, ''), file.stats.isSymbolicLink()
332
+ ? fs_1.SYNC.readSymLink(file.path)
333
+ : fs_1.SYNC.getReadStream(file.path), {
334
+ mode: file.stats.mode
335
+ });
324
336
  });
325
337
  }
326
338
  }
@@ -365,53 +377,71 @@ function findAndReplaceConfigProps(dir, { stack, type, integ_config }) {
365
377
  });
366
378
  }
367
379
  exports.findAndReplaceConfigProps = findAndReplaceConfigProps;
368
- function resolveAllFnPorts(targets, idx = 0) {
369
- var _a;
380
+ function resolveAllFnServePort(targets) {
370
381
  return __awaiter(this, void 0, void 0, function* () {
371
- if (targets.length < idx + 1) {
372
- return;
373
- }
374
- const currentTarget = targets[idx];
375
- const currentTargetType = currentTarget.type;
376
- if (!currentTarget.valid) {
377
- return resolveAllFnPorts(targets, idx + 1);
382
+ let isBioHttp = false;
383
+ const debugOpts = runtime_store_1.default.get('context.port.debug', false);
384
+ yield Promise.all(targets.map((target) => __awaiter(this, void 0, void 0, function* () {
385
+ var _a;
386
+ if (!target.valid) {
387
+ return;
388
+ }
389
+ let curTargetType = target.type;
390
+ if (curTargetType === constants_1.FN_TYPE.basic &&
391
+ ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value))) {
392
+ curTargetType = constants_1.FN_TYPE.advanced;
393
+ }
394
+ if (debugOpts && target.name in (debugOpts[curTargetType] || {})) {
395
+ const debugPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[curTargetType], 'debug', {
396
+ name: target.name,
397
+ duplicateCheck: false,
398
+ searchSpan: 0
399
+ });
400
+ runtime_store_1.default.set('context.port.debug.functions.' + target.name, debugPort);
401
+ }
402
+ if (curTargetType === constants_1.FN_TYPE.basic && isBioHttp) {
403
+ return;
404
+ }
405
+ const httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[curTargetType], 'http', {
406
+ name: target.name,
407
+ duplicateCheck: curTargetType === constants_1.FN_TYPE.advanced || curTargetType === constants_1.FN_TYPE.browserLogic
408
+ });
409
+ if (curTargetType === constants_1.FN_TYPE.basic) {
410
+ runtime_store_1.default.set('context.port.http.' + constants_1.REMOTE_REF.functions.type.bio, httpPort);
411
+ isBioHttp = true;
412
+ }
413
+ else {
414
+ runtime_store_1.default.set('context.port.http.functions.' + target.name, httpPort);
415
+ }
416
+ })));
417
+ if (debugOpts && 'basicio' in debugOpts) {
418
+ const bioDebugPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type.bio, 'debug', { duplicateCheck: false, searchSpan: 0 });
419
+ runtime_store_1.default.set('context.port.debug.basicio', bioDebugPort);
378
420
  }
379
- let httpPort = -1;
380
- let debugPort = -1;
421
+ });
422
+ }
423
+ function resolveAllFnPorts(targets) {
424
+ return __awaiter(this, void 0, void 0, function* () {
381
425
  switch ((0, option_1.getCurrentCommand)()) {
382
- case 'serve':
383
- const isPyBio = currentTargetType === constants_1.FN_TYPE.basic &&
384
- ((_a = currentTarget.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value));
385
- httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'http', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced ||
386
- currentTargetType === constants_1.FN_TYPE.browserLogic, isPyBio);
387
- runtime_store_1.default.set('context.port.http.functions.' + currentTarget.name, httpPort);
388
- const debugOptValue = (0, option_1.getOptionValue)('debug', false);
389
- if (debugOptValue &&
390
- (debugOptValue + '').includes(constants_1.REMOTE_REF.functions.type[currentTargetType]) &&
391
- ((debugOptValue + '').includes(currentTarget.name) ||
392
- currentTargetType === constants_1.FN_TYPE.basic)) {
393
- debugPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'debug', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced);
394
- runtime_store_1.default.set('context.port.debug.functions.' + currentTarget.name, debugPort);
395
- }
396
- if (currentTargetType === constants_1.FN_TYPE.basic && !isPyBio) {
397
- runtime_store_1.default.set('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], httpPort);
398
- runtime_store_1.default.set('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], debugPort);
426
+ case 'serve': {
427
+ if (!targets) {
428
+ throw new error_1.default('Invalid targets', { exit: 2 });
399
429
  }
400
- break;
401
- case 'functions:shell':
402
- if (currentTargetType === constants_1.FN_TYPE.basic && (0, option_1.getOptionValue)('http', false)) {
403
- httpPort = yield port_resolver_1.default.getPort('basicio', 'http', currentTarget.name, false);
404
- runtime_store_1.default.set('context.port.http.' + constants_1.REMOTE_REF.functions.type[currentTargetType], httpPort);
405
- }
406
- if ((0, option_1.getOptionValue)('debug', false)) {
407
- debugPort = yield port_resolver_1.default.getPort('basicio', 'debug', '', false);
408
- runtime_store_1.default.set('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], debugPort);
430
+ return resolveAllFnServePort(targets);
431
+ }
432
+ case 'functions:shell': {
433
+ if (runtime_store_1.default.get('context.port.http.basicio', false)) {
434
+ const bioHttpPort = yield port_resolver_1.default.getPort('basicio', 'http', {
435
+ duplicateCheck: false
436
+ });
437
+ runtime_store_1.default.set('context.port.http.' + constants_1.REMOTE_REF.functions.type.bio, bioHttpPort);
409
438
  }
410
439
  break;
411
- default:
412
- throw new error_1.default('Unknown command', { exit: 2 });
440
+ }
441
+ default: {
442
+ throw new error_1.default('Invalid catalyst command', { exit: 2 });
443
+ }
413
444
  }
414
- return resolveAllFnPorts(targets, idx + 1);
415
445
  });
416
446
  }
417
447
  exports.resolveAllFnPorts = resolveAllFnPorts;
@@ -531,15 +561,15 @@ function copyModDirPerm(src, dest, perm, { replace = true } = {}) {
531
561
  yield Promise.all(srcContents.map((content) => {
532
562
  return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
533
563
  try {
534
- const isDir = yield fs_1.ASYNC.dirExists(content);
564
+ const isDir = content.stats.isDirectory();
535
565
  if (isDir) {
536
- const destFolder = (0, path_1.join)(dest, (0, path_1.basename)(content));
566
+ const destFolder = (0, path_1.join)(dest, (0, path_1.basename)(content.path));
537
567
  yield fs_1.ASYNC.ensureDir(destFolder);
538
- yield copyModDirPerm(content, destFolder, perm);
568
+ yield copyModDirPerm(content.path, destFolder, perm);
539
569
  return res();
540
570
  }
541
- const destFile = (0, path_1.join)(dest, (0, path_1.basename)(content));
542
- yield fs_1.ASYNC.copyFile(content, destFile, replace ? fs_2.constants.COPYFILE_FICLONE : fs_2.constants.COPYFILE_EXCL).catch((err) => {
571
+ const destFile = (0, path_1.join)(dest, (0, path_1.basename)(content.path));
572
+ yield fs_1.ASYNC.copyFile(content.path, destFile, replace ? fs_2.constants.COPYFILE_FICLONE : fs_2.constants.COPYFILE_EXCL).catch((err) => {
543
573
  if (!replace && err.code === 'EEXIST') {
544
574
  return;
545
575
  }
@@ -120,14 +120,14 @@ function rewriteClasspath(pth, libPth) {
120
120
  });
121
121
  const result = yield xml2js_1.default.parseStringPromise(content);
122
122
  const classPathEntries = js_1.JS.chain(files)
123
- .filter((jarPth) => (0, path_1.extname)(jarPth) === '.jar')
124
- .map((jarPth) => {
123
+ .filter((jar) => (0, path_1.extname)(jar.path) === '.jar')
124
+ .map((jar) => {
125
125
  return {
126
126
  $: {
127
127
  kind: 'lib',
128
- path: (0, path_1.basename)((0, path_1.dirname)(jarPth)) === 'lib'
129
- ? 'lib/' + (0, path_1.basename)(jarPth)
130
- : (0, path_1.basename)(jarPth)
128
+ path: (0, path_1.basename)((0, path_1.dirname)(jar.path)) === 'lib'
129
+ ? 'lib/' + (0, path_1.basename)(jar.path)
130
+ : (0, path_1.basename)(jar.path)
131
131
  }
132
132
  };
133
133
  })
@@ -215,14 +215,14 @@ function compileTarget(target) {
215
215
  const allFiles = yield fs_1.ASYNC.walk(targetSource, {
216
216
  filter: { exclude: ['**/.output', ...ignore], excludeDir: true }
217
217
  });
218
- const cleanUpFiles = [...allFiles];
218
+ const cleanUpFiles = allFiles.map((file) => file.path);
219
219
  while (allFiles.length > 0) {
220
220
  const limit = allFiles.length < 20 ? allFiles.length : 20;
221
221
  yield Promise.all(allFiles.splice(0, limit).map((file) => {
222
- const targetPth = file.includes(path_1.sep + 'lib' + path_1.sep)
223
- ? file.replace(targetSource + path_1.sep + 'lib', '')
224
- : file.replace(targetSource, '');
225
- return fs_1.ASYNC.copyFile(file, (0, path_1.join)(outputFolder, targetPth));
222
+ const targetPth = file.path.includes(path_1.sep + 'lib' + path_1.sep)
223
+ ? file.path.replace(targetSource + path_1.sep + 'lib', '')
224
+ : file.path.replace(targetSource, '');
225
+ return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(outputFolder, targetPth));
226
226
  }));
227
227
  }
228
228
  yield Promise.all(entries.map((file) => {
@@ -114,7 +114,7 @@ function removeRequirements(reqFile, target) {
114
114
  yield (0, pip_install_1.installRequirements)(reqFile, tmpDir, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', ''), true);
115
115
  const files = yield fs_1.ASYNC.walk(tmpDir, { depth: 1, includeDirPaths: true });
116
116
  yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
117
- yield fs_1.ASYNC.deleteFile((0, path_1.join)(target.source, path_1.default.basename(file)));
117
+ yield fs_1.ASYNC.deleteFile((0, path_1.join)(target.source, path_1.default.basename(file.path)));
118
118
  })));
119
119
  });
120
120
  }
@@ -79,8 +79,8 @@ function getAppSailZip() {
79
79
  lang: 'python'
80
80
  },
81
81
  scripts: {
82
- preserve: 'python3 -m pip install -r ./requirements.txt -t ./',
83
- predeploy: 'python3 -m pip install -r ./requirements.txt -t ./'
82
+ preserve: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade',
83
+ predeploy: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade'
84
84
  },
85
85
  memory: 256
86
86
  },