zcatalyst-cli 1.9.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +3 -3
  2. package/docs/command_needs/auth.toml +5 -0
  3. package/docs/commands/iac/export.toml +4 -0
  4. package/docs/commands/iac/import.toml +4 -0
  5. package/docs/commands/iac/status.toml +4 -0
  6. package/docs/commands/project/use.toml +6 -0
  7. package/docs/iac/status/bundle.toml +4 -0
  8. package/lib/api-timer.js +81 -0
  9. package/lib/apig-utils.js +16 -14
  10. package/lib/archiver.js +83 -45
  11. package/lib/authentication/login.js +4 -2
  12. package/lib/bin/catalyst.js +0 -1
  13. package/lib/client-utils.js +22 -22
  14. package/lib/client.js +0 -3
  15. package/lib/command_needs/auth.js +12 -3
  16. package/lib/command_needs/rc.js +12 -7
  17. package/lib/commands/apig/status.js +6 -4
  18. package/lib/commands/client/delete.js +2 -4
  19. package/lib/commands/client/setup.js +1 -1
  20. package/lib/commands/deploy.js +3 -1
  21. package/lib/commands/ds/export.js +3 -1
  22. package/lib/commands/ds/import.js +3 -1
  23. package/lib/commands/ds/status.js +145 -149
  24. package/lib/commands/functions/config.js +1 -1
  25. package/lib/commands/functions/setup.js +1 -1
  26. package/lib/commands/help.js +1 -23
  27. package/lib/commands/iac/export.js +85 -0
  28. package/lib/commands/iac/import.js +187 -0
  29. package/lib/commands/iac/pack.js +129 -0
  30. package/lib/commands/iac/status.js +63 -0
  31. package/lib/commands/index.js +4 -0
  32. package/lib/commands/init.js +33 -26
  33. package/lib/commands/project/list.js +10 -6
  34. package/lib/commands/project/use.js +42 -25
  35. package/lib/deploy/features/functions/index.js +2 -1
  36. package/lib/deploy/index.js +3 -1
  37. package/lib/endpoints/lib/iac.js +134 -0
  38. package/lib/error.js +29 -0
  39. package/lib/errorOut.js +3 -2
  40. package/lib/fn-utils/lib/common.js +32 -12
  41. package/lib/fn-utils/lib/java.js +6 -8
  42. package/lib/fn-utils/lib/node.js +7 -1
  43. package/lib/iac/status/bundle.js +82 -0
  44. package/lib/iac/status/deploy.js +74 -0
  45. package/lib/iac/status/util/index.js +26 -0
  46. package/lib/index.js +8 -14
  47. package/lib/init/features/client.js +2 -3
  48. package/lib/init/features/functions/languages/java.js +2 -5
  49. package/lib/init/features/functions/languages/node.js +2 -5
  50. package/lib/init/features/index.js +8 -3
  51. package/lib/init/features/project.js +70 -33
  52. package/lib/init/util/client.js +12 -0
  53. package/lib/init/util/functions.js +20 -0
  54. package/lib/init/util/project.js +35 -0
  55. package/lib/internal/api.js +6 -9
  56. package/lib/internal/command.js +2 -2
  57. package/lib/internal/config.js +6 -4
  58. package/lib/migration/index.js +10 -6
  59. package/lib/option-filter.js +4 -1
  60. package/lib/port-resolver.js +18 -16
  61. package/lib/prompt/index.js +92 -0
  62. package/lib/prompt/types/file-path.js +95 -0
  63. package/lib/pull/features/client.js +1 -1
  64. package/lib/pull/features/functions/index.js +5 -7
  65. package/lib/pull/index.js +4 -1
  66. package/lib/serve/features/index.js +3 -1
  67. package/lib/shell/dependencies/http-functions.js +1 -1
  68. package/lib/shell/index.js +3 -1
  69. package/lib/track.js +3 -1
  70. package/lib/util_modules/constants/index.js +3 -1
  71. package/lib/util_modules/constants/lib/file-names.js +2 -1
  72. package/lib/util_modules/constants/lib/iac.js +8 -0
  73. package/lib/util_modules/constants/lib/regex.js +2 -1
  74. package/lib/util_modules/constants/lib/scopes.js +5 -0
  75. package/lib/util_modules/constants/project.js +6 -0
  76. package/lib/util_modules/contextHelp.js +5 -1
  77. package/lib/util_modules/env.js +2 -5
  78. package/lib/util_modules/fs/index.js +9 -1
  79. package/lib/util_modules/fs/lib/async.js +29 -22
  80. package/lib/util_modules/js.js +6 -0
  81. package/lib/util_modules/parser/toml.js +5 -1
  82. package/lib/util_modules/project.js +3 -0
  83. package/lib/util_modules/shell.js +3 -6
  84. package/package.json +7 -4
  85. package/templates/iacSuccess.html +391 -0
  86. package/lib/prompt.js +0 -49
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const error_1 = __importDefault(require("../error"));
15
16
  const runtime_store_1 = __importDefault(require("../runtime-store"));
16
17
  const logger_1 = require("../util_modules/logger");
17
18
  const features_1 = __importDefault(require("./features"));
@@ -31,7 +32,8 @@ function deploy() {
31
32
  runtime_store_1.default.set('payload.targets', runtime_store_1.default.get('payload.targets', []).concat(currentTarget));
32
33
  yield featureModule();
33
34
  }
34
- catch (error) {
35
+ catch (e) {
36
+ const error = error_1.default.getErrorInstance(e);
35
37
  logger_1.debug(`${currentTarget} deploy unsuccessful, reason : ${error.stack}`);
36
38
  logger_1.labeled(currentTarget, error.message).WARN();
37
39
  }
@@ -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 error_1 = __importDefault(require("../../error"));
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ const logger_1 = require("../../util_modules/logger");
18
+ const project_1 = require("../../util_modules/project");
19
+ class IacAPI {
20
+ constructor(projectId, opts) {
21
+ this.opts = opts || { env: project_1.getEnvName() };
22
+ this.projectId = projectId || project_1.getProjectId('');
23
+ }
24
+ deploy(projectName, format, file, schedule = false) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const res = yield new api_1.default(this.opts).post('/baas/v1/project/import', {
27
+ formData: {
28
+ project_name: projectName,
29
+ template_format: format,
30
+ code: file,
31
+ schedule: schedule.toString()
32
+ },
33
+ json: false
34
+ });
35
+ if (res.body && res.body.data) {
36
+ return res.body.data;
37
+ }
38
+ logger_1.debug('deploy response from server : ' + JSON.stringify(res.body));
39
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
40
+ });
41
+ }
42
+ bundle(format) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/export`, {
45
+ body: {
46
+ template_format: format
47
+ },
48
+ json: true
49
+ });
50
+ if (res.body && res.body.data) {
51
+ return res.body.data;
52
+ }
53
+ logger_1.debug('bundle response from server : ' + JSON.stringify(res.body));
54
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
55
+ });
56
+ }
57
+ bundleStatus() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/export/status`);
60
+ if (res.body && res.body.data) {
61
+ return res.body.data;
62
+ }
63
+ logger_1.debug('bundle status response from server : ' + JSON.stringify(res.body));
64
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
65
+ });
66
+ }
67
+ bundleDownload() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/export/download`, {
70
+ json: false,
71
+ encoding: null,
72
+ log: {
73
+ progress: {
74
+ title: 'Project ZIP'
75
+ }
76
+ }
77
+ });
78
+ if (res.body) {
79
+ return res.body;
80
+ }
81
+ logger_1.debug('bundle status response from server : ' + JSON.stringify(res.body));
82
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
83
+ });
84
+ }
85
+ allDeploys() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import`);
88
+ if (res.body && res.body.data) {
89
+ return res.body.data;
90
+ }
91
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
92
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
93
+ });
94
+ }
95
+ deployStatus(importId) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import/${importId}`);
98
+ if (res.body && res.body.data) {
99
+ return res.body.data;
100
+ }
101
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
102
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
103
+ });
104
+ }
105
+ deployDelete(importId) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const res = yield new api_1.default(this.opts).delete(`/baas/v1/project/import/${importId}`);
108
+ if (res.body && res.body.data) {
109
+ return res.body.data;
110
+ }
111
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
112
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
113
+ });
114
+ }
115
+ deployDownload(importId) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import/${importId}/download`, {
118
+ json: false,
119
+ encoding: null,
120
+ log: {
121
+ progress: {
122
+ title: 'Staged project archive'
123
+ }
124
+ }
125
+ });
126
+ if (res.body) {
127
+ return res.body;
128
+ }
129
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
130
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
131
+ });
132
+ }
133
+ }
134
+ exports.default = IacAPI;
package/lib/error.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = require("util");
6
7
  const runtime_store_1 = __importDefault(require("./runtime-store"));
7
8
  const default_1 = __importDefault(require("./util_modules/constants/lib/default"));
8
9
  class CatalystError extends Error {
@@ -31,5 +32,33 @@ class CatalystError extends Error {
31
32
  runtime_store_1.default.set('log.faultyError', runtime_store_1.default.get('log.faultyError', []).concat(this));
32
33
  }
33
34
  }
35
+ static getErrorInstance(unknownError, { message, skipHelp } = {}) {
36
+ if (unknownError instanceof CatalystError) {
37
+ if (message) {
38
+ unknownError.message = message;
39
+ }
40
+ return unknownError;
41
+ }
42
+ if (unknownError instanceof Error) {
43
+ return new CatalystError(message || unknownError.message, {
44
+ original: unknownError,
45
+ skipHelp: skipHelp === undefined ? true : skipHelp
46
+ });
47
+ }
48
+ const newError = new CatalystError(message || 'Malformed error', {
49
+ original: util_1.inspect(unknownError),
50
+ skipHelp: skipHelp === undefined ? true : skipHelp
51
+ });
52
+ if ('message' in unknownError) {
53
+ newError.message = unknownError.message;
54
+ }
55
+ if ('stack' in unknownError) {
56
+ newError.stack = unknownError.stack;
57
+ }
58
+ if ('name' in unknownError) {
59
+ newError.name = unknownError.name;
60
+ }
61
+ return newError;
62
+ }
34
63
  }
35
64
  exports.default = CatalystError;
package/lib/errorOut.js CHANGED
@@ -23,10 +23,11 @@ exports.default = (error, status) => {
23
23
  });
24
24
  }
25
25
  try {
26
- contextHelp_1.default();
26
+ const exitCode = contextHelp_1.default();
27
+ process.exitCode = typeof exitCode === 'number' ? exitCode : 2;
27
28
  }
28
29
  catch (err) {
29
30
  logger_1.debug('HELP ERROR: ' + err.stack);
31
+ process.exitCode = 2;
30
32
  }
31
- process.exitCode = error ? error.exit : 2;
32
33
  };
@@ -124,10 +124,9 @@ exports.validate = validate;
124
124
  function refineTargets(rawTargets, mapRemoteFn = true) {
125
125
  return __awaiter(this, void 0, void 0, function* () {
126
126
  let remoteFnIdMap = {};
127
- let runtimeDetails = { runtimes: [] };
127
+ let runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime', { runtimes: [] });
128
128
  if (mapRemoteFn) {
129
129
  const fnAPI = yield endpoints_1.functionsAPI();
130
- runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime');
131
130
  let allRemoteFns = [];
132
131
  [allRemoteFns, runtimeDetails] = yield Promise.all([
133
132
  fnAPI.getAllFunctions(),
@@ -164,17 +163,18 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
164
163
  yield validatePlugin(option_1.getCurrentCommand(), fnPath, runtime_store_1.default, catalystJson);
165
164
  }
166
165
  catch (e) {
167
- throw new error_1.default(e, {
166
+ throw new error_1.default(e.message, {
168
167
  exit: 1,
169
168
  errorId: 'COMMON-4',
170
169
  original: e,
171
- arg: ['validating', e]
170
+ arg: ['validating', e.toString()]
172
171
  });
173
172
  }
174
173
  }
175
174
  const fnName = js_1.JS.get(catalystJson, 'deployment.name');
176
175
  const userStack = js_1.JS.get(catalystJson, 'deployment.stack');
177
- if (!userStack || !runtimeDetails.runtimes.includes(userStack)) {
176
+ if (!userStack ||
177
+ (runtimeDetails.runtimes.length > 0 && !runtimeDetails.runtimes.includes(userStack))) {
178
178
  return {
179
179
  name: path_1.basename(fnPath),
180
180
  source: fnPath,
@@ -259,11 +259,11 @@ function pack(target) {
259
259
  source = outputDir;
260
260
  }
261
261
  catch (e) {
262
- throw new error_1.default(e, {
262
+ throw new error_1.default(e.message, {
263
263
  exit: 1,
264
264
  errorId: 'COMMON-4',
265
265
  original: e,
266
- arg: ['building', e]
266
+ arg: ['building', e.toString()]
267
267
  });
268
268
  }
269
269
  }
@@ -276,8 +276,8 @@ function pack(target) {
276
276
  });
277
277
  }
278
278
  else {
279
- const ignore = config_1.functionsConfig.ignore(source);
280
- const files = yield fs_1.ASYNC.walk(source, ignore);
279
+ const exclude = config_1.functionsConfig.ignore(source);
280
+ const files = yield fs_1.ASYNC.walk(source, { exclude });
281
281
  files.forEach((file) => {
282
282
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
283
283
  });
@@ -289,7 +289,7 @@ function pack(target) {
289
289
  }
290
290
  catch (err) {
291
291
  target.valid = false;
292
- target.failure_reason = err;
292
+ target.failure_reason = err.message;
293
293
  }
294
294
  });
295
295
  }
@@ -368,6 +368,26 @@ function resolveAllFnPorts(targets, idx = 0) {
368
368
  });
369
369
  }
370
370
  exports.resolveAllFnPorts = resolveAllFnPorts;
371
+ function fnDirDelete(conf) {
372
+ return __awaiter(this, void 0, void 0, function* () {
373
+ const fnSource = conf.get('functions.source', false);
374
+ if (!fnSource) {
375
+ logger_1.debug('Unable to get the functions source directory');
376
+ return;
377
+ }
378
+ const fnDir = project_1.resolveProjectPath(fnSource);
379
+ const dirContents = yield fs_1.ASYNC.walk(fnDir);
380
+ const delFnDir = yield prompt_1.default.ask(prompt_1.default.question('delDir', `All the Catalyst functions configured in the ${constants_1.FILENAME.config} file has been deleted.\n Would you like to delete the ${fnSource} directory too ?`, {
381
+ type: 'confirm',
382
+ when: () => dirContents.length > 0
383
+ }));
384
+ if (delFnDir.delDir === undefined ||
385
+ (typeof delFnDir.delDir === 'boolean' && delFnDir.delDir)) {
386
+ yield fs_1.ASYNC.deleteDir(fnDir);
387
+ }
388
+ return conf.unset('functions');
389
+ });
390
+ }
371
391
  function deleteFunctionLocal(path) {
372
392
  return __awaiter(this, void 0, void 0, function* () {
373
393
  const isDirectory = yield fs_1.ASYNC.dirExists(path);
@@ -376,7 +396,7 @@ function deleteFunctionLocal(path) {
376
396
  yield fs_1.ASYNC.deleteDir(path);
377
397
  }
378
398
  const fnTargets = conf.get('functions.targets').filter((fn) => (typeof fn === 'string' ? !path.endsWith(fn) : !path.endsWith(fn.source)));
379
- conf.set('functions.targets', fnTargets);
399
+ fnTargets.length === 0 ? yield fnDirDelete(conf) : conf.set('functions.targets', fnTargets);
380
400
  return conf.syncSave();
381
401
  });
382
402
  }
@@ -396,7 +416,7 @@ function getSDK(fnType, dest, stack, options = {}) {
396
416
  }
397
417
  yield new archiver_1.default()
398
418
  .load(sdkZip)
399
- .extract(new RegExp(`catalyst-${stack}`), dest, { isFolder: true })
419
+ .extract(dest, new RegExp(`catalyst-${stack}`))
400
420
  .finalize();
401
421
  });
402
422
  }
@@ -115,7 +115,7 @@ function rewriteClasspath(pth, libPth) {
115
115
  if (content === undefined) {
116
116
  throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 2 });
117
117
  }
118
- const files = yield fs_1.ASYNC.walk(path_1.dirname(libPth), ['**/.output']);
118
+ const files = yield fs_1.ASYNC.walk(path_1.dirname(libPth), { exclude: ['**/.output'] });
119
119
  const result = yield xml2js_1.default.parseStringPromise(content);
120
120
  const classPathEntries = js_1.JS.chain(files)
121
121
  .filter((jarPth) => path_1.extname(jarPth) === '.jar')
@@ -208,7 +208,7 @@ function compileTarget(target) {
208
208
  yield fs_1.ASYNC.ensureDir(outputFolder);
209
209
  yield fs_1.ASYNC.emptyDir(outputFolder);
210
210
  const ignore = config_1.functionsConfig.ignore(targetSource);
211
- const allFiles = yield fs_1.ASYNC.walk(targetSource, ['**/.output', ...ignore]);
211
+ const allFiles = yield fs_1.ASYNC.walk(targetSource, { exclude: ['**/.output', ...ignore] });
212
212
  const cleanUpFiles = [...allFiles];
213
213
  while (allFiles.length > 0) {
214
214
  const limit = allFiles.length < 20 ? allFiles.length : 20;
@@ -216,8 +216,7 @@ function compileTarget(target) {
216
216
  const targetPth = file.includes(path_1.sep + 'lib' + path_1.sep)
217
217
  ? file.replace(targetSource + path_1.sep + 'lib', '')
218
218
  : file.replace(targetSource, '');
219
- const target = path_1.join(outputFolder, targetPth);
220
- return fs_1.ASYNC.copyFile(file, target);
219
+ return fs_1.ASYNC.copyFile(file, path_1.join(outputFolder, targetPth));
221
220
  }));
222
221
  }
223
222
  yield Promise.all(entries.map((file) => {
@@ -234,11 +233,11 @@ function compileTarget(target) {
234
233
  }));
235
234
  const currentCommand = option_1.getCurrentCommand();
236
235
  switch (currentCommand) {
237
- case 'pull': {
236
+ case 'pull':
237
+ case 'init':
238
238
  yield cleanUp(cleanUpFiles);
239
239
  break;
240
- }
241
- case 'deploy': {
240
+ case 'deploy':
242
241
  const classPath = path_1.join(outputFolder, constants_1.FILENAME.functions.java_classpath);
243
242
  if (yield fs_1.ASYNC.fileExists(classPath)) {
244
243
  const classPathFile = yield fs_1.ASYNC.readFile(classPath);
@@ -247,7 +246,6 @@ function compileTarget(target) {
247
246
  }
248
247
  }
249
248
  break;
250
- }
251
249
  }
252
250
  });
253
251
  }
@@ -19,6 +19,7 @@ const error_1 = __importDefault(require("../../error"));
19
19
  const constants_1 = require("../../util_modules/constants");
20
20
  const fs_1 = require("../../util_modules/fs");
21
21
  const js_1 = require("../../util_modules/js");
22
+ const shell_1 = require("../../util_modules/shell");
22
23
  function validate(targets, idx) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
25
  if (targets.length < idx + 1) {
@@ -47,10 +48,15 @@ function validate(targets, idx) {
47
48
  ]
48
49
  });
49
50
  }
51
+ const nodeModuleExists = yield fs_1.ASYNC.dirExists(path_1.join(currentTarget.source, constants_1.FILENAME.node_modules));
52
+ if (!nodeModuleExists) {
53
+ yield shell_1.spawn('npm', ['install'], { cwd: currentTarget.source }).ASYNC();
54
+ }
50
55
  currentTarget.valid = true;
51
56
  return validate(targets, ++idx);
52
57
  }
53
- catch (err) {
58
+ catch (e) {
59
+ const err = error_1.default.getErrorInstance(e);
54
60
  currentTarget.valid = false;
55
61
  currentTarget.failure_reason = err.message;
56
62
  return validate(targets, ++idx);
@@ -0,0 +1,82 @@
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 iac_1 = __importDefault(require("../../endpoints/lib/iac"));
16
+ const api_timer_1 = __importDefault(require("../../api-timer"));
17
+ const error_1 = __importDefault(require("../../error"));
18
+ const throbber_1 = __importDefault(require("../../throbber"));
19
+ const logger_1 = require("../../util_modules/logger");
20
+ const util_1 = require("./util");
21
+ const prompt_1 = __importDefault(require("../../prompt"));
22
+ const fs_1 = require("../../util_modules/fs");
23
+ const path_1 = require("path");
24
+ const option_1 = require("../../util_modules/option");
25
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const env = option_1.getOptionValue('production', false) ? 'Production' : 'Development';
27
+ const getSpinnerTxt = util_1.getSpinnerTxt('bundle');
28
+ const iacAPI = new iac_1.default(undefined, { env });
29
+ const bundleStatus = yield iacAPI.bundleStatus();
30
+ if (bundleStatus === undefined) {
31
+ throw new error_1.default('No export project available in server.', {
32
+ exit: 1,
33
+ errorId: 'B-1'
34
+ });
35
+ }
36
+ const throbber = throbber_1.default.getInstance();
37
+ const spinner = bundleStatus.id;
38
+ throbber.add(spinner, {
39
+ text: getSpinnerTxt(bundleStatus)
40
+ });
41
+ const timerAPI = new api_timer_1.default(iacAPI.bundleStatus.bind(iacAPI), 2000, 1);
42
+ timerAPI.on('data', (data) => __awaiter(void 0, void 0, void 0, function* () {
43
+ switch (data.status) {
44
+ case 'Scheduled':
45
+ case 'Processing':
46
+ throbber.update(spinner, {
47
+ text: getSpinnerTxt(data) + '\nPress CTRL + C to exit listening to the status'
48
+ });
49
+ break;
50
+ case 'Error_Processing':
51
+ throbber.fail(spinner, {
52
+ text: getSpinnerTxt(data, 'failed')
53
+ });
54
+ timerAPI.end();
55
+ break;
56
+ case 'Completed':
57
+ throbber.succeed(spinner, {
58
+ text: getSpinnerTxt(data)
59
+ });
60
+ timerAPI.end(undefined, true);
61
+ break;
62
+ default:
63
+ logger_1.debug('Unknown status received : ', data.status);
64
+ timerAPI.end();
65
+ }
66
+ }));
67
+ timerAPI.on('error', (e) => {
68
+ logger_1.debug('Error encounted :', e);
69
+ });
70
+ timerAPI.on('end', () => throbber.stopAll());
71
+ timerAPI.start();
72
+ const isCompleted = yield timerAPI.waitForEnd();
73
+ if (isCompleted) {
74
+ const ans = yield prompt_1.default.ask(prompt_1.default.question('download', 'Would you like to download the export zip of this job to your cmd execution directory?', { type: 'confirm', defaultAns: true }));
75
+ if (ans.download) {
76
+ const hrTime = process.hrtime();
77
+ const fileName = `export_${bundleStatus.id}_${hrTime[0] * 1000000000 + hrTime[1]}.zip`;
78
+ const bundlezip = yield iacAPI.bundleDownload();
79
+ return fs_1.ASYNC.writeFile(path_1.join(process.cwd(), fileName), bundlezip);
80
+ }
81
+ }
82
+ });
@@ -0,0 +1,74 @@
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 iac_1 = __importDefault(require("../../endpoints/lib/iac"));
16
+ const api_timer_1 = __importDefault(require("../../api-timer"));
17
+ const option_1 = require("../../util_modules/option");
18
+ const error_1 = __importDefault(require("../../error"));
19
+ const throbber_1 = __importDefault(require("../../throbber"));
20
+ const logger_1 = require("../../util_modules/logger");
21
+ const util_1 = require("./util");
22
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
23
+ const getSpinnerTxt = util_1.getSpinnerTxt('deploy');
24
+ const idOpt = option_1.getOptionValue('id', false);
25
+ const iacAPI = new iac_1.default();
26
+ const allDeploys = yield iacAPI.allDeploys();
27
+ if (allDeploys.length <= 0) {
28
+ throw new error_1.default('No import projects available in server.');
29
+ }
30
+ const neededDeploys = allDeploys.filter((deploy) => deploy.id === idOpt || deploy.status === 'Scheduled');
31
+ if (neededDeploys.length <= 0) {
32
+ throw new error_1.default(idOpt
33
+ ? 'No import projects with given id exists.'
34
+ : 'No import projects currently scheduled.');
35
+ }
36
+ const deployDetails = neededDeploys[0];
37
+ const throbber = throbber_1.default.getInstance();
38
+ const spinner = deployDetails.id;
39
+ throbber.add(spinner, {
40
+ text: getSpinnerTxt(deployDetails)
41
+ });
42
+ const timerAPI = new api_timer_1.default(iacAPI.deployStatus.bind(iacAPI, deployDetails.id), 2000, 1);
43
+ timerAPI.on('data', (data) => __awaiter(void 0, void 0, void 0, function* () {
44
+ switch (data.status) {
45
+ case 'Scheduled':
46
+ case 'Processing':
47
+ throbber.update(spinner, {
48
+ text: getSpinnerTxt(data) + '\nPress CTRL + C to exit listening to the status'
49
+ });
50
+ break;
51
+ case 'Error_Processing':
52
+ throbber.fail(spinner, {
53
+ text: getSpinnerTxt(data, 'failed')
54
+ });
55
+ timerAPI.end();
56
+ break;
57
+ case 'Completed':
58
+ throbber.succeed(spinner, {
59
+ text: getSpinnerTxt(data)
60
+ });
61
+ timerAPI.end(undefined, true);
62
+ break;
63
+ default:
64
+ logger_1.debug('Unknown status received : ', data.status);
65
+ timerAPI.end();
66
+ }
67
+ }));
68
+ timerAPI.on('error', (e) => {
69
+ logger_1.debug('Error encounted : ', e);
70
+ });
71
+ timerAPI.on('end', () => throbber.stopAll());
72
+ timerAPI.start();
73
+ yield timerAPI.waitForEnd();
74
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpinnerTxt = void 0;
4
+ const getSpinnerTxt = (type) => (deployDetails, status) => {
5
+ var _a, _b;
6
+ const logs = [];
7
+ const processError = (_a = deployDetails.logs) === null || _a === void 0 ? void 0 : _a.processing_errors;
8
+ const validationError = (_b = deployDetails.logs) === null || _b === void 0 ? void 0 : _b.validation_errors;
9
+ if (processError) {
10
+ if (typeof processError === 'string') {
11
+ logs.push(`Error Message: ${processError}`);
12
+ }
13
+ else {
14
+ logs.push(`Error while processing "${processError.component}"`, `Error Message: ${processError.error_message}`);
15
+ }
16
+ }
17
+ if (validationError) {
18
+ logs.push('Error while validating : ');
19
+ logs.push(...validationError);
20
+ }
21
+ return [
22
+ `${type === 'bundle' ? 'Export' : 'Import'} Project "${deployDetails.project_details.project_name}" ${status ? status : deployDetails.status.toLowerCase()}`,
23
+ ...logs
24
+ ].join('\n' + ' '.repeat(status ? 2 : 4));
25
+ };
26
+ exports.getSpinnerTxt = getSpinnerTxt;
package/lib/index.js CHANGED
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ansi_colors_1 = require("ansi-colors");
7
6
  const commander_1 = require("commander");
8
- const meant_1 = __importDefault(require("meant"));
9
7
  const client_1 = require("./client");
10
8
  const runtime_store_1 = __importDefault(require("./runtime-store"));
9
+ const fs_1 = require("./util_modules/fs");
10
+ const constants_1 = require("./util_modules/constants");
11
+ const ansi_colors_1 = require("ansi-colors");
11
12
  const packageJson = runtime_store_1.default.get('context.cli.package');
12
13
  const { description, version } = packageJson;
13
14
  const program = new commander_1.Command();
@@ -17,17 +18,10 @@ program.option('-p, --project <name|project_id>', 'Specify the Catalyst project
17
18
  program.option('--token <token>', 'Supply an authentication token for a command');
18
19
  program.option('--dc <us|eu|in>', 'Supply a data center for a command');
19
20
  program.option('--verbose', 'Change the log level to verbose for debugging purposes');
21
+ program.helpOption('-h, --help', 'Display help for a Catalyst command');
22
+ program.showSuggestionAfterError();
23
+ program.showHelpAfterError(`For more usage information use the ${ansi_colors_1.bold('catalyst help')} command`);
24
+ program.addHelpText('before', fs_1.SYNC.readFile(constants_1.TEMPLATE.banner, 'utf-8') || '');
25
+ program.addHelpText('afterAll', `\nFor detailed documentations please visit ${ansi_colors_1.underline('https://www.zoho.com/catalyst/help/cli-command-reference.html')}`);
20
26
  const cli = new client_1.Client(program);
21
- cli.onUnknownCommand((_OPTS, cmd) => {
22
- const commandNames = cli.getAllCommandNames();
23
- console.error();
24
- console.error('"' + ansi_colors_1.bold(cmd.args.join(' ')) + '" is not a catalyst command');
25
- let suggestion = meant_1.default(cmd.args.join(' '), commandNames);
26
- suggestion = suggestion || meant_1.default(cmd.args.join(':'), commandNames);
27
- if (suggestion && suggestion.length) {
28
- console.error('Did you mean ' + ansi_colors_1.bold(suggestion.join(', ')) + ' ?');
29
- }
30
- console.error();
31
- process.exit(1);
32
- });
33
27
  exports.default = cli;
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
16
  const prompt_1 = __importDefault(require("../../prompt"));
17
- const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
17
  const constants_1 = require("../../util_modules/constants");
19
18
  const fs_1 = require("../../util_modules/fs");
20
19
  const logger_1 = require("../../util_modules/logger");
21
20
  const project_1 = require("../../util_modules/project");
21
+ const client_1 = require("../util/client");
22
22
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
23
23
  logger_1.message('A directory ' + ansi_colors_1.cyan.bold('client') + ' will be created with a webapp pre-configured.');
24
24
  const clientDirPath = project_1.resolveProjectPath(constants_1.FOLDERNAME.client);
@@ -46,6 +46,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
46
46
  }
47
47
  }));
48
48
  yield fs_1.ASYNC.findAndReplace(clientDirPath)(constants_1.PLACEHOLDER.client.package.name, clientNameAns.clientName);
49
- runtime_store_1.default.set('payload.client.source', project_1.resolveProjectPath(constants_1.FOLDERNAME.client));
50
- runtime_store_1.default.set('payload.client.name', clientNameAns.clientName);
49
+ return client_1.fillClientInitPayload(project_1.resolveProjectPath(constants_1.FOLDERNAME.client), clientNameAns.clientName);
51
50
  });
@@ -24,6 +24,7 @@ const js_1 = require("../../../../util_modules/js");
24
24
  const integ_1 = require("../../../../fn-utils/lib/integ");
25
25
  const common_1 = require("../../../../fn-utils/lib/common");
26
26
  const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
27
+ const functions_1 = require("../../../util/functions");
27
28
  exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
28
29
  const fnType = runtime_store_1.default.get('context.functions.type');
29
30
  const fnDirPath = path_1.join(runtime_store_1.default.get('context.functions.dir_path'));
@@ -85,9 +86,5 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
85
86
  const userFnClassPath = path_1.join(fnDirPath, functionAns.name, constants_1.FILENAME.functions.java_classpath);
86
87
  const userFnLibPath = path_1.join(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib);
87
88
  yield fn_utils_1.fnUtils.java.rewriteClasspath(userFnClassPath, userFnLibPath);
88
- runtime_store_1.default.set('payload.functions.source', targetPath);
89
- runtime_store_1.default.set('payload.functions.stack', stack);
90
- runtime_store_1.default.set('payload.functions.name', functionAns.name);
91
- runtime_store_1.default.set('payload.functions.class', functionAns.class);
92
- runtime_store_1.default.set('payload.functions.type', fnType);
89
+ return functions_1.fillFunctionsInitPayload(targetPath, functionAns.name, stack, fnType);
93
90
  });