zcatalyst-cli 1.7.1 → 1.9.1

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 (179) hide show
  1. package/README.md +31 -10
  2. package/docs/apig-utils.toml +69 -0
  3. package/docs/authentication/index.toml +15 -0
  4. package/docs/authentication/login.toml +14 -0
  5. package/docs/client-utils.toml +24 -0
  6. package/docs/command_needs/auth.toml +4 -0
  7. package/docs/command_needs/rc.toml +24 -0
  8. package/docs/commands/apig/disable.toml +4 -0
  9. package/docs/commands/apig/enable.toml +4 -0
  10. package/docs/commands/apig/status.toml +4 -0
  11. package/docs/commands/client/delete.toml +34 -0
  12. package/docs/commands/ds/export.toml +4 -0
  13. package/docs/commands/ds/import.toml +15 -0
  14. package/docs/commands/ds/status.toml +9 -0
  15. package/docs/commands/event/generate/index.toml +29 -0
  16. package/docs/commands/event/generate/integ.toml +4 -0
  17. package/docs/commands/functions/config.toml +11 -0
  18. package/docs/commands/functions/delete.toml +29 -0
  19. package/docs/commands/project/use.toml +9 -0
  20. package/docs/dc.toml +4 -0
  21. package/docs/deploy/features/apig.toml +4 -0
  22. package/docs/deploy/features/functions/index.toml +4 -0
  23. package/docs/event_generate/cache.toml +4 -0
  24. package/docs/event_generate/custom.toml +4 -0
  25. package/docs/event_generate/datastore.toml +4 -0
  26. package/docs/event_generate/filestore.toml +4 -0
  27. package/docs/event_generate/integration/cliq.toml +9 -0
  28. package/docs/execute-script.toml +19 -0
  29. package/docs/fn-utils/lib/common.toml +25 -0
  30. package/docs/fn-utils/lib/java.toml +34 -0
  31. package/docs/fn-utils/lib/node.toml +4 -0
  32. package/docs/init/index.toml +4 -0
  33. package/docs/internal/command.toml +4 -0
  34. package/docs/internal/config.toml +9 -0
  35. package/docs/internal/credential.toml +14 -0
  36. package/docs/option-filter.toml +45 -0
  37. package/docs/port-resolver.toml +9 -0
  38. package/docs/pull/index.toml +4 -0
  39. package/docs/serve/index.toml +4 -0
  40. package/docs/shell/index.toml +4 -0
  41. package/docs/util_modules/project.toml +9 -0
  42. package/lib/apig-utils.js +133 -43
  43. package/lib/archiver.js +4 -2
  44. package/lib/authentication/index.js +44 -9
  45. package/lib/authentication/login.js +51 -8
  46. package/lib/bin/catalyst.js +14 -7
  47. package/lib/client-utils.js +47 -14
  48. package/lib/client.js +1 -1
  49. package/lib/command_needs/auth.js +5 -3
  50. package/lib/command_needs/rc.js +35 -13
  51. package/lib/commands/apig/disable.js +8 -3
  52. package/lib/commands/apig/enable.js +8 -3
  53. package/lib/commands/apig/status.js +29 -9
  54. package/lib/commands/client/delete.js +65 -26
  55. package/lib/commands/client/setup.js +2 -2
  56. package/lib/commands/deploy.js +2 -2
  57. package/lib/commands/ds/export.js +16 -8
  58. package/lib/commands/ds/import.js +20 -14
  59. package/lib/commands/ds/status.js +22 -11
  60. package/lib/commands/event/generate/index.js +62 -12
  61. package/lib/commands/event/generate/integ.js +7 -3
  62. package/lib/commands/functions/add.js +2 -2
  63. package/lib/commands/functions/config.js +11 -3
  64. package/lib/commands/functions/delete.js +36 -13
  65. package/lib/commands/functions/setup.js +2 -2
  66. package/lib/commands/functions/shell.js +2 -2
  67. package/lib/commands/help.js +1 -1
  68. package/lib/commands/index.js +2 -3
  69. package/lib/commands/init.js +4 -4
  70. package/lib/commands/login.js +2 -2
  71. package/lib/commands/logout.js +2 -2
  72. package/lib/commands/project/list.js +2 -2
  73. package/lib/commands/project/reset.js +1 -1
  74. package/lib/commands/project/use.js +18 -2
  75. package/lib/commands/pull.js +5 -5
  76. package/lib/commands/run.js +2 -2
  77. package/lib/commands/serve.js +7 -6
  78. package/lib/commands/token/generate.js +2 -2
  79. package/lib/commands/token/list.js +2 -2
  80. package/lib/commands/token/revoke.js +2 -2
  81. package/lib/commands/whoami.js +1 -1
  82. package/lib/dc.js +11 -1
  83. package/lib/deploy/features/apig.js +33 -33
  84. package/lib/deploy/features/client.js +12 -19
  85. package/lib/deploy/features/functions/index.js +14 -4
  86. package/lib/deploy/features/index.js +1 -1
  87. package/lib/deploy/index.js +2 -9
  88. package/lib/endpoints/index.js +5 -2
  89. package/lib/endpoints/lib/apig.js +15 -5
  90. package/lib/endpoints/lib/applogic.js +12 -4
  91. package/lib/endpoints/lib/cache.js +9 -3
  92. package/lib/endpoints/lib/catalyst-details.js +37 -0
  93. package/lib/endpoints/lib/client.js +15 -5
  94. package/lib/endpoints/lib/datastore.js +6 -2
  95. package/lib/endpoints/lib/ds-bulk.js +15 -5
  96. package/lib/endpoints/lib/env.js +3 -1
  97. package/lib/endpoints/lib/event-bus.js +3 -1
  98. package/lib/endpoints/lib/filestore.js +6 -2
  99. package/lib/endpoints/lib/functions.js +12 -4
  100. package/lib/endpoints/lib/project.js +9 -3
  101. package/lib/endpoints/lib/queue.js +9 -3
  102. package/lib/endpoints/lib/sdk.js +3 -1
  103. package/lib/endpoints/lib/zcql.js +3 -1
  104. package/lib/error.js +18 -0
  105. package/lib/errorOut.js +10 -7
  106. package/lib/event_generate/cache.js +9 -1
  107. package/lib/event_generate/custom.js +6 -1
  108. package/lib/event_generate/datastore.js +12 -2
  109. package/lib/event_generate/filestore.js +9 -1
  110. package/lib/event_generate/integration/cliq.js +10 -2
  111. package/lib/execute-script.js +35 -6
  112. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  113. package/lib/fn-utils/index.js +1 -1
  114. package/lib/fn-utils/lib/common.js +95 -17
  115. package/lib/fn-utils/lib/integ.js +4 -3
  116. package/lib/fn-utils/lib/java.js +49 -13
  117. package/lib/fn-utils/lib/node.js +15 -6
  118. package/lib/fn-watcher.js +67 -0
  119. package/lib/index.js +13 -12
  120. package/lib/init/dependencies/package-json.js +3 -1
  121. package/lib/init/features/functions/index.js +41 -29
  122. package/lib/init/features/functions/languages/java.js +5 -4
  123. package/lib/init/features/functions/languages/node.js +6 -5
  124. package/lib/init/features/index.js +8 -4
  125. package/lib/init/index.js +10 -3
  126. package/lib/internal/api.js +9 -9
  127. package/lib/internal/command.js +19 -14
  128. package/lib/internal/config.js +15 -15
  129. package/lib/internal/credential.js +33 -7
  130. package/lib/internal/rc.js +18 -10
  131. package/lib/migration/global/1.4.0.js +4 -2
  132. package/lib/migration/global/1.6.2.js +4 -2
  133. package/lib/migration/index.js +1 -1
  134. package/lib/option-filter.js +79 -22
  135. package/lib/optional-import.js +1 -1
  136. package/lib/plugin-loader.js +1 -1
  137. package/lib/port-resolver.js +23 -3
  138. package/lib/prompt.js +1 -1
  139. package/lib/pull/features/functions/index.js +7 -7
  140. package/lib/pull/features/index.js +1 -1
  141. package/lib/pull/index.js +10 -3
  142. package/lib/repl-server.js +9 -5
  143. package/lib/serve/features/index.js +11 -2
  144. package/lib/serve/index.js +19 -9
  145. package/lib/serve/server/index.js +137 -60
  146. package/lib/serve/server/lib/client.js +1 -1
  147. package/lib/serve/server/lib/master.js +16 -3
  148. package/lib/serve/server/lib/node.js +1 -1
  149. package/lib/shell/dependencies/http-functions.js +120 -90
  150. package/lib/shell/dependencies/invoker/integ/node.js +1 -1
  151. package/lib/shell/dependencies/local-function.js +86 -119
  152. package/lib/shell/index.js +10 -10
  153. package/lib/shell/prepare/index.js +1 -4
  154. package/lib/shell/prepare/languages/index.js +15 -4
  155. package/lib/track.js +4 -1
  156. package/lib/util_modules/config/index.js +1 -1
  157. package/lib/util_modules/config/lib/apig.js +3 -3
  158. package/lib/util_modules/config/lib/client.js +3 -3
  159. package/lib/util_modules/config/lib/functions.js +5 -5
  160. package/lib/util_modules/constants/index.js +22 -20
  161. package/lib/util_modules/constants/lib/regex.js +3 -2
  162. package/lib/util_modules/constants/lib/runtime.js +9 -0
  163. package/lib/util_modules/contextHelp.js +63 -123
  164. package/lib/util_modules/fs/index.js +1 -1
  165. package/lib/util_modules/fs/lib/async.js +19 -2
  166. package/lib/util_modules/fs/lib/sync.js +13 -1
  167. package/lib/util_modules/logger.js +12 -20
  168. package/lib/util_modules/option.js +1 -13
  169. package/lib/util_modules/project.js +75 -26
  170. package/lib/util_modules/shell.js +8 -2
  171. package/package.json +45 -45
  172. package/scripts/postInstall.js +31 -0
  173. package/lib/cjson.js +0 -20
  174. package/lib/log-error.js +0 -18
  175. package/lib/util_modules/big-json.js +0 -16
  176. package/lib/util_modules/constants/lib/stack.js +0 -6
  177. package/templates/init/functions/.DS_Store +0 -0
  178. package/templates/init/functions/node/.DS_Store +0 -0
  179. package/templates/init/functions/node/integ/.DS_Store +0 -0
@@ -1,16 +1,27 @@
1
1
  'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (proxyInstance, portDetails) => (req, res) => {
6
+ const runtime_store_1 = __importDefault(require("../runtime-store"));
7
+ const logger_1 = require("../util_modules/logger");
8
+ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
4
9
  if (req.url.length === 1 && req.url.startsWith('/')) {
5
10
  res.redirect('/app/');
6
11
  }
7
- else if (portDetails.bindPort !== undefined &&
8
- !isNaN(portDetails.bindPort) &&
9
- portDetails.bindPort !== -1 &&
10
- req.url.match(/\/baas\/v1\/project\/[0-9]+\/function\/[A-z0-9]+\/execute.*/g)) {
12
+ else if (typeof customProxyUrl === 'string' &&
13
+ !req.url.match(/^(\/baas|\/app|\/server|\/oauthorize|\/__catalyst).*/g)) {
14
+ logger_1.debug(`proxying "${req.url}" to "${customProxyUrl}"`);
11
15
  proxyInstance.web(req, res, {
12
- target: 'http://127.0.0.1:' + portDetails.bindPort,
13
- ws: true
16
+ target: customProxyUrl,
17
+ ws: true,
18
+ changeOrigin: true,
19
+ secure: false,
20
+ headers: {
21
+ 'User-Agent': runtime_store_1.default.get('context.cli.package.name') +
22
+ '/' +
23
+ runtime_store_1.default.get('context.cli.package.version')
24
+ }
14
25
  });
15
26
  }
16
27
  else {
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -16,8 +16,8 @@ exports.updateFnConfig = exports.getSDK = exports.deleteFunctionLocal = exports.
16
16
  const ansi_colors_1 = require("ansi-colors");
17
17
  const path_1 = require("path");
18
18
  const archiver_1 = __importDefault(require("../../archiver"));
19
- const cjson_1 = __importDefault(require("../../cjson"));
20
19
  const endpoints_1 = require("../../endpoints");
20
+ const catalyst_details_1 = __importDefault(require("../../endpoints/lib/catalyst-details"));
21
21
  const error_1 = __importDefault(require("../../error"));
22
22
  const execute_script_1 = __importDefault(require("../../execute-script"));
23
23
  const plugin_loader_1 = __importDefault(require("../../plugin-loader"));
@@ -26,6 +26,7 @@ const prompt_1 = __importDefault(require("../../prompt"));
26
26
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
27
27
  const config_1 = require("../../util_modules/config");
28
28
  const constants_1 = require("../../util_modules/constants");
29
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
29
30
  const fs_1 = require("../../util_modules/fs");
30
31
  const js_1 = require("../../util_modules/js");
31
32
  const logger_1 = require("../../util_modules/logger");
@@ -36,13 +37,19 @@ function validate() {
36
37
  const sourceDir = project_1.resolveProjectPath(config_1.functionsConfig.source());
37
38
  const fnTargets = config_1.functionsConfig.targets();
38
39
  if (fnTargets === undefined || fnTargets.length === 0) {
39
- throw new error_1.default(ansi_colors_1.bold('targets') + ' was found to be empty. Please specify them in ' + constants_1.FILENAME.config, { exit: 1 });
40
+ throw new error_1.default('targets was found to be empty', {
41
+ exit: 1,
42
+ errorId: 'COMMON-1',
43
+ arg: [ansi_colors_1.bold('targets'), ansi_colors_1.bold(constants_1.FILENAME.config)]
44
+ });
40
45
  }
41
46
  const sourceExists = yield fs_1.ASYNC.dirExists(sourceDir);
42
47
  if (!sourceExists) {
43
- throw new error_1.default(ansi_colors_1.bold('"' + sourceDir + '"') +
44
- ' directory was not found. Please create it or specify a different source directory in ' +
45
- constants_1.FILENAME.config, { exit: 1 });
48
+ throw new error_1.default(sourceDir + ' directory was not found', {
49
+ exit: 1,
50
+ errorId: 'COMMON-2',
51
+ arg: [ansi_colors_1.bold(path_1.basename(sourceDir)), ansi_colors_1.bold(constants_1.FILENAME.config)]
52
+ });
46
53
  }
47
54
  const only = option_1.getOptionValue('only');
48
55
  let fnFilterGroups = [];
@@ -91,10 +98,20 @@ function validate() {
91
98
  }));
92
99
  });
93
100
  if (unmatchedFilters.length > 0) {
101
+ const formattedTargets = fnTargets.map((fn) => '* ' + fn).join('\n');
94
102
  throw new error_1.default('The filters ' +
95
103
  ansi_colors_1.bold(unmatchedFilters.join(', ')) +
96
104
  ' provided with --only option does not match with any functions in ' +
97
- constants_1.FILENAME.config, { exit: 1 });
105
+ constants_1.FILENAME.config, {
106
+ exit: 1,
107
+ errorId: 'COMMON-3',
108
+ arg: [
109
+ ansi_colors_1.bold(unmatchedFilters.join(', ')),
110
+ ansi_colors_1.bold('--only'),
111
+ ansi_colors_1.bold(constants_1.FILENAME.config),
112
+ ansi_colors_1.bold(formattedTargets)
113
+ ]
114
+ });
98
115
  }
99
116
  }
100
117
  const filteredFns = fnFilterGroups.length > 0 ? js_1.JS.intersection(fnTargets, fnFilterGroups) : fnTargets;
@@ -107,9 +124,18 @@ exports.validate = validate;
107
124
  function refineTargets(rawTargets, mapRemoteFn = true) {
108
125
  return __awaiter(this, void 0, void 0, function* () {
109
126
  let remoteFnIdMap = {};
127
+ let runtimeDetails = { runtimes: [] };
110
128
  if (mapRemoteFn) {
111
129
  const fnAPI = yield endpoints_1.functionsAPI();
112
- let allRemoteFns = (yield fnAPI.getAllFunctions());
130
+ runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime');
131
+ let allRemoteFns = [];
132
+ [allRemoteFns, runtimeDetails] = yield Promise.all([
133
+ fnAPI.getAllFunctions(),
134
+ runtimeDetails
135
+ ? Promise.resolve(runtimeDetails)
136
+ : new catalyst_details_1.default().getDetails('runtime')
137
+ ]);
138
+ runtime_store_1.default.set('context.catalyst.runtime', runtimeDetails);
113
139
  if (!Array.isArray(allRemoteFns) || allRemoteFns.length === 0) {
114
140
  allRemoteFns = [];
115
141
  }
@@ -120,8 +146,11 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
120
146
  }
121
147
  return Promise.all(rawTargets.map((fnPath) => __awaiter(this, void 0, void 0, function* () {
122
148
  const catalystJsonPth = path_1.join(fnPath, constants_1.FILENAME.catalyst_config);
123
- const configFileExists = yield fs_1.ASYNC.fileExists(catalystJsonPth);
124
- if (!configFileExists) {
149
+ const catalystJson = yield fs_1.ASYNC.readJSONFile(catalystJsonPth, {
150
+ checkpath: true,
151
+ throws: false
152
+ });
153
+ if (!catalystJson) {
125
154
  return {
126
155
  name: path_1.basename(fnPath),
127
156
  source: fnPath,
@@ -129,16 +158,55 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
129
158
  failure_reason: 'there is no valid ' + constants_1.FILENAME.catalyst_config + ' file present'
130
159
  };
131
160
  }
132
- const catalystJson = cjson_1.default(catalystJsonPth);
133
161
  const validatePlugin = yield plugin_loader_1.default('functions', 'validate', fnPath);
134
162
  if (validatePlugin !== undefined) {
135
163
  try {
136
164
  yield validatePlugin(option_1.getCurrentCommand(), fnPath, runtime_store_1.default, catalystJson);
137
165
  }
138
166
  catch (e) {
139
- throw new error_1.default(e, { exit: 1 });
167
+ throw new error_1.default(e, {
168
+ exit: 1,
169
+ errorId: 'COMMON-4',
170
+ original: e,
171
+ arg: ['validating', e]
172
+ });
140
173
  }
141
174
  }
175
+ const fnName = js_1.JS.get(catalystJson, 'deployment.name');
176
+ const userStack = js_1.JS.get(catalystJson, 'deployment.stack');
177
+ if (!userStack || !runtimeDetails.runtimes.includes(userStack)) {
178
+ return {
179
+ name: path_1.basename(fnPath),
180
+ source: fnPath,
181
+ valid: false,
182
+ failure_reason: 'deployment.stack is unknown in ' + constants_1.FILENAME.catalyst_config + ' file.'
183
+ };
184
+ }
185
+ const eol = runtimeDetails.eol_runtimes && runtimeDetails.eol_runtimes[userStack];
186
+ switch (eol) {
187
+ case 1:
188
+ case 2:
189
+ if (eol === 2 && remoteFnIdMap[fnName] === undefined) {
190
+ return {
191
+ name: fnName,
192
+ source: fnPath,
193
+ valid: false,
194
+ failure_reason: `Stack ${userStack} is no longer supported for creation. Kindly change the stack in ${constants_1.FILENAME.catalyst_config} and try again.`
195
+ };
196
+ }
197
+ logger_1.labeled(`functions(${fnName}) `, `Stack ${userStack} has reached EOL. Kindly update it as soon as possible.`).MESSAGE();
198
+ break;
199
+ case 3:
200
+ return {
201
+ name: fnName,
202
+ source: fnPath,
203
+ valid: false,
204
+ failure_reason: `Stack ${userStack} is no longer support. Kindly change the stack in ${constants_1.FILENAME.catalyst_config} and try again.`
205
+ };
206
+ default:
207
+ logger_1.debug(`unknown eol ${eol} hence skipping check`);
208
+ break;
209
+ }
142
210
  let deploymentType = js_1.JS.get(catalystJson, 'deployment.type');
143
211
  if (deploymentType && deploymentType === constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.applogic]) {
144
212
  deploymentType = constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.advanced];
@@ -147,8 +215,8 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
147
215
  yield fs_1.ASYNC.writeFile(catalystJsonPth, catalystJsonString, 'utf8');
148
216
  }
149
217
  const fnTarget = {
150
- name: js_1.JS.get(catalystJson, 'deployment.name'),
151
- stack: js_1.JS.get(catalystJson, 'deployment.stack'),
218
+ name: fnName,
219
+ stack: userStack,
152
220
  type: constants_1.REFERENCE.functions.type[js_1.JS.get(catalystJson, 'deployment.type')],
153
221
  index: js_1.JS.get(catalystJson, 'execution.main'),
154
222
  source: fnPath,
@@ -176,6 +244,7 @@ function executeHook({ prefix, command }) {
176
244
  }
177
245
  exports.executeHook = executeHook;
178
246
  function pack(target) {
247
+ var _a;
179
248
  return __awaiter(this, void 0, void 0, function* () {
180
249
  try {
181
250
  let source = target.source;
@@ -190,11 +259,16 @@ function pack(target) {
190
259
  source = outputDir;
191
260
  }
192
261
  catch (e) {
193
- throw new error_1.default(e, { exit: 1 });
262
+ throw new error_1.default(e, {
263
+ exit: 1,
264
+ errorId: 'COMMON-4',
265
+ original: e,
266
+ arg: ['building', e]
267
+ });
194
268
  }
195
269
  }
196
270
  const zip = new archiver_1.default(target.name);
197
- if (target.stack === constants_1.STACK.java8) {
271
+ if ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
198
272
  const outputFolder = path_1.join(source, '.output');
199
273
  const outputFiles = yield fs_1.ASYNC.walk(outputFolder);
200
274
  outputFiles.forEach((file) => {
@@ -288,7 +362,7 @@ function resolveAllFnPorts(targets, idx = 0) {
288
362
  }
289
363
  break;
290
364
  default:
291
- throw new error_1.default('Unknown command');
365
+ throw new error_1.default('Unknown command', { exit: 2 });
292
366
  }
293
367
  return resolveAllFnPorts(targets, idx + 1);
294
368
  });
@@ -346,7 +420,11 @@ function updateFnConfig(target) {
346
420
  ? parseInt(memoryPrompt.memory)
347
421
  : parseInt(memOption);
348
422
  if (!memValue) {
349
- throw new error_1.default('Invalid memory value specified: ' + ansi_colors_1.bold(memOption + ''));
423
+ throw new error_1.default('value not a number', {
424
+ exit: 1,
425
+ errorId: 'COMMON-5',
426
+ arg: [ansi_colors_1.bold.red(memOption + ''), ansi_colors_1.bold('--memory')]
427
+ });
350
428
  }
351
429
  const consent = yield prompt_1.default.ask(prompt_1.default.question('confirm', `Do you want to update the memory configuration for the function ${target.name}(${target.id}) from ${targetConfig.memory + ' MB'} to ${memValue + ' MB ?'}`, {
352
430
  type: 'confirm',
@@ -19,6 +19,7 @@ const error_1 = __importDefault(require("../../error"));
19
19
  const prompt_1 = __importDefault(require("../../prompt"));
20
20
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
21
21
  const constants_1 = require("../../util_modules/constants");
22
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
22
23
  const fs_1 = require("../../util_modules/fs");
23
24
  const js_1 = require("../../util_modules/js");
24
25
  function integHelper() {
@@ -67,7 +68,7 @@ function integHelper() {
67
68
  });
68
69
  }
69
70
  exports.integHelper = integHelper;
70
- function copyIntegHandlers(templatePath, targetPath, stack) {
71
+ function copyIntegHandlers(templatePath, targetPath, lang) {
71
72
  return __awaiter(this, void 0, void 0, function* () {
72
73
  const service = runtime_store_1.default.get('context.functions.integration.service', false);
73
74
  if (!service) {
@@ -77,7 +78,7 @@ function copyIntegHandlers(templatePath, targetPath, stack) {
77
78
  switch (service) {
78
79
  case constants_1.INTEG.services.cliq:
79
80
  const handlers = runtime_store_1.default.get('context.function.integration.cliq.handlers', []);
80
- if (stack === constants_1.STACK.node10) {
81
+ if (lang === runtime_1.default.language.nodejs) {
81
82
  const filePaths = constants_1.CLIQ.node_template_contents_initial_copy.map((path) => {
82
83
  return path_1.join(templatePath, path);
83
84
  });
@@ -91,7 +92,7 @@ function copyIntegHandlers(templatePath, targetPath, stack) {
91
92
  yield fs_1.ASYNC.copyFiles(handlerPaths, path_1.join(targetPath, constants_1.CLIQ.node_handlers_template_dir));
92
93
  integ_config.handlers = integHandlerConfig;
93
94
  }
94
- else if (stack === constants_1.STACK.java8) {
95
+ else if (lang === runtime_1.default.language.java) {
95
96
  const filePaths = constants_1.CLIQ.java_template_contents_initial_copy.map((path) => {
96
97
  return path_1.join(templatePath, path);
97
98
  });
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.validate = exports.projectFileValidation = exports.ensureJavaInvoker = exports.compileTarget = exports.normaliseClasspath = exports.rewriteClasspath = exports.isValidClassName = exports.containsKeyWord = exports.classPathSep = void 0;
16
+ const ansi_colors_1 = require("ansi-colors");
16
17
  const path_1 = require("path");
17
18
  const semver_1 = require("semver");
18
19
  const xml2js_1 = __importDefault(require("xml2js"));
@@ -112,7 +113,7 @@ function rewriteClasspath(pth, libPth) {
112
113
  yield fs_1.ASYNC.ensureDir(libPth);
113
114
  const content = yield fs_1.ASYNC.readFile(pth);
114
115
  if (content === undefined) {
115
- throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 1 });
116
+ throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 2 });
116
117
  }
117
118
  const files = yield fs_1.ASYNC.walk(path_1.dirname(libPth), ['**/.output']);
118
119
  const result = yield xml2js_1.default.parseStringPromise(content);
@@ -141,10 +142,11 @@ function normaliseClasspath(pth, libFolder) {
141
142
  return __awaiter(this, void 0, void 0, function* () {
142
143
  const content = yield fs_1.ASYNC.readFile(pth);
143
144
  if (content === undefined) {
144
- throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 1 });
145
+ throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 2 });
145
146
  }
146
147
  const result = yield xml2js_1.default.parseStringPromise(content);
147
148
  const classPathEntries = js_1.JS.get(result, 'classpath.classpathentry', []);
149
+ const jarFilesList = [];
148
150
  yield Promise.all(classPathEntries.map((entry) => __awaiter(this, void 0, void 0, function* () {
149
151
  const row = entry.$;
150
152
  if (row.kind && row.kind === 'lib' && row.path) {
@@ -156,7 +158,12 @@ function normaliseClasspath(pth, libFolder) {
156
158
  yield fs_1.ASYNC.copyFile(libPath, path_1.join(libFolder, jarName));
157
159
  }
158
160
  catch (err) {
159
- throw new error_1.default(libPath + ' mentioned in .classpath file missing');
161
+ throw new error_1.default(libPath + ' mentioned in .classpath file missing', {
162
+ exit: 1,
163
+ errorId: 'JAVA-1',
164
+ original: err,
165
+ arg: [ansi_colors_1.bold(libPath), ansi_colors_1.bold('.classpath')]
166
+ });
160
167
  }
161
168
  }
162
169
  row.path = path_1.join(path_1.basename(libFolder), jarName);
@@ -166,12 +173,19 @@ function normaliseClasspath(pth, libFolder) {
166
173
  }
167
174
  catch (err) {
168
175
  throw new error_1.default(libPath +
169
- ' mentioned in .classpath file missing. The .classpath file in the targets directory seems to be corrupted.');
176
+ ' mentioned in .classpath file missing. The .classpath file in the target directory seems to be corrupted.', {
177
+ exit: 1,
178
+ errorId: 'JAVA-2',
179
+ original: err,
180
+ arg: [ansi_colors_1.bold('.classpath'), ansi_colors_1.bold(path_1.dirname(pth))]
181
+ });
170
182
  }
171
183
  }
184
+ jarFilesList.push(path_1.join(libFolder, jarName));
172
185
  }
173
186
  })));
174
187
  js_1.JS.set(result, 'classpath.classpathentry', classPathEntries);
188
+ runtime_store_1.default.set('context.functions.java.libJarFiles', jarFilesList);
175
189
  const builder = new xml2js_1.default.Builder();
176
190
  return fs_1.ASYNC.writeFile(pth, builder.buildObject(result));
177
191
  });
@@ -266,12 +280,16 @@ function projectFileValidation(pth, target) {
266
280
  }
267
281
  const content = yield fs_1.ASYNC.readFile(pth);
268
282
  if (content === undefined) {
269
- throw new error_1.default('Content of ' + pth + ' is undefined');
283
+ throw new error_1.default('Content of ' + pth + ' is undefined', { exit: 2 });
270
284
  }
271
285
  const result = yield xml2js_1.default.parseStringPromise(content);
272
286
  const name = js_1.JS.get(result, 'projectDescription.name')[0];
273
287
  if (name !== target.name) {
274
- throw new error_1.default('project name mismatch in .project file for function ' + target.name, { exit: 1 });
288
+ throw new error_1.default('project name mismatch in .project file for function ' + target.name, {
289
+ exit: 1,
290
+ errorId: 'JAVA-3',
291
+ arg: [ansi_colors_1.bold(name), ansi_colors_1.bold(path_1.basename(pth)), ansi_colors_1.bold(target.name)]
292
+ });
275
293
  }
276
294
  });
277
295
  }
@@ -306,12 +324,18 @@ function checkJavaCompatibility() {
306
324
  : javacVersionDetails;
307
325
  const javacVersion = semver_1.valid(semver_1.coerce(javacVersionDetails.split(' ')[1]));
308
326
  if (javacVersion === '' || javacVersion === null) {
309
- throw new error_1.default('Unable to check the javac version. Kindly ensure that javac is installed and try again', { exit: 1 });
327
+ throw new error_1.default('Unable to check the javac version', {
328
+ exit: 0,
329
+ errorId: 'JAVA-4',
330
+ arg: [ansi_colors_1.bold('javac')]
331
+ });
310
332
  }
311
333
  if (semver_1.gtr(javacVersion, new semver_1.Range('<1.9', { includePrerelease: true }))) {
312
- throw new error_1.default('javac version is above the compatible version "1.8.x". ' +
313
- ' Kindly downgrade to version 1.8 or lower \n' +
314
- 'You can verify your javac version by executing javac --version or javac -version', { exit: 1 });
334
+ throw new error_1.default('javac version is above the compatible version', {
335
+ exit: 0,
336
+ errorId: 'JAVA-5',
337
+ arg: [ansi_colors_1.bold('javac'), ansi_colors_1.bold('1.8.x'), ansi_colors_1.bold('1.8')]
338
+ });
315
339
  }
316
340
  });
317
341
  }
@@ -330,7 +354,15 @@ function validate(targets, idx) {
330
354
  const entryFileExists = yield fs_1.ASYNC.fileExists(entry);
331
355
  const classPathExists = yield fs_1.ASYNC.fileExists(classpath);
332
356
  if (!entryFileExists) {
333
- throw new error_1.default(path_1.basename(entry) + ' file is missing');
357
+ throw new error_1.default(path_1.basename(entry) + ' file is missing', {
358
+ exit: 1,
359
+ errorId: 'JAVA-6',
360
+ arg: [
361
+ ansi_colors_1.bold(path_1.basename(entry)),
362
+ ansi_colors_1.bold(constants_1.FILENAME.catalyst_config),
363
+ ansi_colors_1.bold(currentTarget.name)
364
+ ]
365
+ });
334
366
  }
335
367
  if (!classPathExists) {
336
368
  const templatePath = getTemplatePath(currentTarget);
@@ -341,8 +373,12 @@ function validate(targets, idx) {
341
373
  yield projectFileValidation(projectPath, currentTarget);
342
374
  yield checkJavaCompatibility();
343
375
  yield compileTarget(currentTarget).catch((err) => {
344
- logger_1.debug(err);
345
- throw new error_1.default('there was a compilation error!', { exit: 1, original: err });
376
+ throw new error_1.default('there was a compilation error!', {
377
+ exit: 1,
378
+ errorId: 'JAVA-7',
379
+ original: err,
380
+ skipHelp: !!option_1.getOptionValue('watch', false)
381
+ });
346
382
  });
347
383
  currentTarget.valid = true;
348
384
  return validate(targets, ++idx);
@@ -13,8 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.validate = void 0;
16
+ const ansi_colors_1 = require("ansi-colors");
16
17
  const path_1 = require("path");
17
- const cjson_1 = __importDefault(require("../../cjson"));
18
18
  const error_1 = __importDefault(require("../../error"));
19
19
  const constants_1 = require("../../util_modules/constants");
20
20
  const fs_1 = require("../../util_modules/fs");
@@ -27,16 +27,25 @@ function validate(targets, idx) {
27
27
  const currentTarget = targets[idx];
28
28
  try {
29
29
  const catalystFile = path_1.join(currentTarget.source, constants_1.FILENAME.catalyst_config);
30
- const catalystFileExists = yield fs_1.ASYNC.fileExists(catalystFile);
31
- if (!catalystFileExists) {
32
- throw new error_1.default('no ' + constants_1.FILENAME.catalyst_config + ' file found', { exit: 1 });
30
+ const data = yield fs_1.ASYNC.readJSONFile(catalystFile, { checkpath: true });
31
+ if (data === undefined) {
32
+ throw new error_1.default('no ' + constants_1.FILENAME.catalyst_config + ' file found', {
33
+ exit: 1
34
+ });
33
35
  }
34
- const data = cjson_1.default(catalystFile);
35
36
  const indexFile = path_1.join(currentTarget.source, js_1.JS.get(data, 'execution.main', 'index.js'));
36
37
  currentTarget.index = indexFile;
37
38
  const indexFileExists = yield fs_1.ASYNC.fileExists(indexFile);
38
39
  if (!indexFileExists) {
39
- throw new error_1.default('main file does not exists');
40
+ throw new error_1.default('main file does not exists', {
41
+ errorId: 'NODE-1',
42
+ exit: 1,
43
+ arg: [
44
+ ansi_colors_1.bold(currentTarget.index || 'undefined'),
45
+ ansi_colors_1.bold(constants_1.FILENAME.catalyst_config),
46
+ ansi_colors_1.bold(currentTarget.name)
47
+ ]
48
+ });
40
49
  }
41
50
  currentTarget.valid = true;
42
51
  return validate(targets, ++idx);
@@ -0,0 +1,67 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const chokidar_1 = require("chokidar");
13
+ const languages_1 = require("./shell/prepare/languages");
14
+ const logger_1 = require("./util_modules/logger");
15
+ const shell_1 = require("./util_modules/shell");
16
+ exports.default = (target) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return new Promise((res) => {
18
+ let paused = false;
19
+ let latestEvent;
20
+ const watcher = chokidar_1.watch(target.source, {
21
+ ignored: /(^|[\/\\])\../,
22
+ cwd: target.source,
23
+ ignoreInitial: true
24
+ });
25
+ watcher.on('next', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ if (latestEvent === undefined) {
27
+ paused = false;
28
+ return;
29
+ }
30
+ const currentLatestEvent = latestEvent;
31
+ shell_1.clearStdout(true);
32
+ logger_1.info(`\n${currentLatestEvent.evnt} of ${currentLatestEvent.pth} in ${target.name} detected. Preparing your function, please wait...`);
33
+ watcher.emit('preparing');
34
+ target.failure_reason = undefined;
35
+ target.valid = true;
36
+ yield languages_1.prepareFunctions([target]);
37
+ if (currentLatestEvent.at === latestEvent.at) {
38
+ latestEvent = undefined;
39
+ }
40
+ if (target.valid) {
41
+ watcher.emit('compiled');
42
+ return;
43
+ }
44
+ logger_1.warning('target [' + target.name + '] is not a valid one reason : ' + target.failure_reason);
45
+ logger_1.info('Waiting for correction..');
46
+ logger_1.info('\n(To exit, press ^C)');
47
+ watcher.emit('next');
48
+ }));
49
+ watcher.on('all', (evnt, pth) => {
50
+ latestEvent = { evnt, pth, at: Date.now() };
51
+ if (paused) {
52
+ return;
53
+ }
54
+ paused = true;
55
+ watcher.emit('next');
56
+ });
57
+ watcher.on('ready', () => {
58
+ target.watcher = watcher;
59
+ res();
60
+ });
61
+ watcher.on('error', (err) => {
62
+ logger_1.debug(err);
63
+ logger_1.warning(`Unable to start watcher for target [${target.name}]. Skipping watch mode.`);
64
+ res();
65
+ });
66
+ });
67
+ });
package/lib/index.js CHANGED
@@ -4,25 +4,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ansi_colors_1 = require("ansi-colors");
7
- const commander_1 = __importDefault(require("commander"));
7
+ const commander_1 = require("commander");
8
8
  const meant_1 = __importDefault(require("meant"));
9
9
  const client_1 = require("./client");
10
10
  const runtime_store_1 = __importDefault(require("./runtime-store"));
11
11
  const packageJson = runtime_store_1.default.get('context.cli.package');
12
12
  const { description, version } = packageJson;
13
- commander_1.default.description(description);
14
- commander_1.default.version(version, '-v, --version');
15
- commander_1.default.option('-p, --project <name|project_id>', 'the catalyst project to use for this command');
16
- commander_1.default.option('--token <token>', 'supply an auth token for this command');
17
- commander_1.default.option('--dc <us|eu>', 'supply a DC to use for this command');
18
- commander_1.default.option('--verbose', 'changes the log level to verbose for debug purpose');
19
- const cli = new client_1.Client(commander_1.default);
20
- cli.onUnknownCommand((_CMD, cmd2) => {
13
+ const program = new commander_1.Command();
14
+ program.description(description);
15
+ program.version(version, '-v, --version', 'Print the Catalyst CLI version number');
16
+ program.option('-p, --project <name|project_id>', 'Specify the Catalyst project to be used for a command');
17
+ program.option('--token <token>', 'Supply an authentication token for a command');
18
+ program.option('--dc <us|eu|in>', 'Supply a data center for a command');
19
+ program.option('--verbose', 'Change the log level to verbose for debugging purposes');
20
+ const cli = new client_1.Client(program);
21
+ cli.onUnknownCommand((_OPTS, cmd) => {
21
22
  const commandNames = cli.getAllCommandNames();
22
23
  console.error();
23
- console.error('"' + ansi_colors_1.bold(cmd2.join(' ')) + '" is not a catalyst command');
24
- let suggestion = meant_1.default(cmd2.join(' '), commandNames);
25
- suggestion = suggestion || meant_1.default(cmd2.join(':'), commandNames);
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);
26
27
  if (suggestion && suggestion.length) {
27
28
  console.error('Did you mean ' + ansi_colors_1.bold(suggestion.join(', ')) + ' ?');
28
29
  }
@@ -63,7 +63,9 @@ exports.default = (templateJsonDir = 'package.json', keys) => __awaiter(void 0,
63
63
  const answers = yield prompt_1.default.ask(...qns);
64
64
  let content = yield fs_1.ASYNC.readFile(templateJsonPath);
65
65
  if (content === undefined) {
66
- throw new error_1.default('content of : ' + templateJsonPath + ' is undefined', { exit: 2 });
66
+ throw new error_1.default('content of : ' + templateJsonPath + ' is undefined', {
67
+ exit: 2
68
+ });
67
69
  }
68
70
  Object.keys(answers).forEach((placeholder) => {
69
71
  if (answers[placeholder] !== undefined) {