zcatalyst-cli 1.8.0 → 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 (113) hide show
  1. package/README.md +31 -10
  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/disable.js +1 -1
  18. package/lib/commands/apig/enable.js +1 -1
  19. package/lib/commands/apig/status.js +7 -5
  20. package/lib/commands/client/delete.js +3 -5
  21. package/lib/commands/client/setup.js +1 -1
  22. package/lib/commands/deploy.js +4 -2
  23. package/lib/commands/ds/export.js +4 -2
  24. package/lib/commands/ds/import.js +4 -2
  25. package/lib/commands/ds/status.js +146 -150
  26. package/lib/commands/event/generate/index.js +1 -1
  27. package/lib/commands/event/generate/integ.js +1 -1
  28. package/lib/commands/functions/add.js +1 -1
  29. package/lib/commands/functions/config.js +1 -1
  30. package/lib/commands/functions/delete.js +1 -1
  31. package/lib/commands/functions/setup.js +1 -1
  32. package/lib/commands/functions/shell.js +1 -1
  33. package/lib/commands/help.js +0 -22
  34. package/lib/commands/iac/export.js +85 -0
  35. package/lib/commands/iac/import.js +187 -0
  36. package/lib/commands/iac/pack.js +129 -0
  37. package/lib/commands/iac/status.js +63 -0
  38. package/lib/commands/index.js +4 -0
  39. package/lib/commands/init.js +34 -27
  40. package/lib/commands/login.js +1 -1
  41. package/lib/commands/logout.js +1 -1
  42. package/lib/commands/project/list.js +11 -7
  43. package/lib/commands/project/reset.js +1 -1
  44. package/lib/commands/project/use.js +42 -25
  45. package/lib/commands/pull.js +1 -1
  46. package/lib/commands/run.js +1 -1
  47. package/lib/commands/serve.js +6 -5
  48. package/lib/commands/token/generate.js +1 -1
  49. package/lib/commands/token/list.js +1 -1
  50. package/lib/commands/token/revoke.js +1 -1
  51. package/lib/commands/whoami.js +1 -1
  52. package/lib/deploy/features/functions/index.js +2 -1
  53. package/lib/deploy/index.js +3 -1
  54. package/lib/endpoints/lib/iac.js +134 -0
  55. package/lib/error.js +43 -9
  56. package/lib/errorOut.js +9 -2
  57. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  58. package/lib/fn-utils/lib/common.js +32 -12
  59. package/lib/fn-utils/lib/java.js +8 -9
  60. package/lib/fn-utils/lib/node.js +7 -1
  61. package/lib/fn-watcher.js +67 -0
  62. package/lib/iac/status/bundle.js +82 -0
  63. package/lib/iac/status/deploy.js +74 -0
  64. package/lib/iac/status/util/index.js +26 -0
  65. package/lib/index.js +13 -19
  66. package/lib/init/features/client.js +2 -3
  67. package/lib/init/features/functions/languages/java.js +2 -5
  68. package/lib/init/features/functions/languages/node.js +2 -5
  69. package/lib/init/features/index.js +8 -3
  70. package/lib/init/features/project.js +70 -33
  71. package/lib/init/util/client.js +12 -0
  72. package/lib/init/util/functions.js +20 -0
  73. package/lib/init/util/project.js +35 -0
  74. package/lib/internal/api.js +6 -9
  75. package/lib/internal/command.js +3 -3
  76. package/lib/internal/config.js +6 -4
  77. package/lib/migration/index.js +10 -6
  78. package/lib/option-filter.js +4 -1
  79. package/lib/port-resolver.js +18 -16
  80. package/lib/prompt/index.js +92 -0
  81. package/lib/prompt/types/file-path.js +95 -0
  82. package/lib/pull/features/client.js +1 -1
  83. package/lib/pull/features/functions/index.js +5 -7
  84. package/lib/pull/index.js +4 -1
  85. package/lib/serve/features/index.js +3 -1
  86. package/lib/serve/index.js +8 -4
  87. package/lib/serve/server/index.js +134 -64
  88. package/lib/serve/server/lib/master.js +5 -4
  89. package/lib/shell/dependencies/http-functions.js +46 -21
  90. package/lib/shell/dependencies/local-function.js +17 -48
  91. package/lib/shell/index.js +9 -10
  92. package/lib/shell/prepare/index.js +1 -5
  93. package/lib/shell/prepare/languages/index.js +14 -3
  94. package/lib/track.js +3 -1
  95. package/lib/util_modules/constants/index.js +3 -1
  96. package/lib/util_modules/constants/lib/file-names.js +2 -1
  97. package/lib/util_modules/constants/lib/iac.js +8 -0
  98. package/lib/util_modules/constants/lib/regex.js +2 -1
  99. package/lib/util_modules/constants/lib/scopes.js +5 -0
  100. package/lib/util_modules/constants/project.js +6 -0
  101. package/lib/util_modules/contextHelp.js +25 -14
  102. package/lib/util_modules/env.js +2 -5
  103. package/lib/util_modules/fs/index.js +9 -1
  104. package/lib/util_modules/fs/lib/async.js +29 -22
  105. package/lib/util_modules/js.js +6 -0
  106. package/lib/util_modules/logger.js +11 -10
  107. package/lib/util_modules/parser/toml.js +5 -1
  108. package/lib/util_modules/project.js +34 -19
  109. package/lib/util_modules/shell.js +6 -5
  110. package/package.json +12 -7
  111. package/scripts/postInstall.js +31 -0
  112. package/templates/iacSuccess.html +391 -0
  113. package/lib/prompt.js +0 -49
@@ -18,23 +18,24 @@ const error_1 = __importDefault(require("../../error"));
18
18
  const command_1 = __importDefault(require("../../internal/command"));
19
19
  const prompt_1 = __importDefault(require("../../prompt"));
20
20
  const constants_1 = require("../../util_modules/constants");
21
+ const project_1 = __importDefault(require("../../util_modules/constants/project"));
21
22
  const js_1 = require("../../util_modules/js");
22
23
  const logger_1 = require("../../util_modules/logger");
23
- const project_1 = require("../../util_modules/project");
24
+ const project_2 = require("../../util_modules/project");
25
+ const makeActive = (currentProjectId, optedProject) => __awaiter(void 0, void 0, void 0, function* () {
26
+ yield project_2.upsertProject(optedProject, {
27
+ active: true,
28
+ base: js_1.JS.isNull(currentProjectId)
29
+ });
30
+ logger_1.success('Successfully made project active');
31
+ });
24
32
  exports.default = new command_1.default('project:use [name_or_project_id]')
25
33
  .description('Set an active Catalyst project for your working directory')
26
34
  .needs('auth', [constants_1.SCOPE.projects])
27
35
  .needs('config', { optional: true, resolveOnNotFound: true })
28
36
  .needs('rc', { optional: true, resolveOnNotFound: true })
29
37
  .action((newActive) => __awaiter(void 0, void 0, void 0, function* () {
30
- const currentProjectId = project_1.getProjectId(null);
31
- const makeActive = (optedProject) => __awaiter(void 0, void 0, void 0, function* () {
32
- yield project_1.upsertProject(optedProject, {
33
- active: true,
34
- base: js_1.JS.isNull(currentProjectId)
35
- });
36
- logger_1.success('Successfully made project active');
37
- });
38
+ const currentProjectId = project_2.getProjectId(null);
38
39
  const allProjects = (yield (yield endpoints_1.projectAPI()).getAllProjects().catch(() => {
39
40
  throw new error_1.default('Unable to get projects', {
40
41
  exit: 2
@@ -48,13 +49,27 @@ exports.default = new command_1.default('project:use [name_or_project_id]')
48
49
  }
49
50
  if (allProjects.length === 1) {
50
51
  logger_1.message('only one project found in remote, ignoring user input and making it as active');
51
- return makeActive(allProjects[0]);
52
+ return makeActive(currentProjectId, allProjects[0]);
52
53
  }
53
- const transformedProjects = allProjects.map((project) => project_1.transformProject(project));
54
+ const transformedProjects = allProjects.map(project_2.transformProject);
54
55
  if (newActive !== undefined) {
55
56
  const optedProject = parseInt(newActive, 10)
56
57
  ? transformedProjects.find((proj) => proj.id + '' === newActive)
57
58
  : transformedProjects.find((proj) => proj.name === newActive);
59
+ if ((optedProject === null || optedProject === void 0 ? void 0 : optedProject.type) && !project_1.default.accepted_types.includes(optedProject.type)) {
60
+ throw new error_1.default('provided project cannot be used since its not live', {
61
+ exit: 1,
62
+ errorId: 'PROJ-USE-3',
63
+ arg: [
64
+ ansi_colors_1.bold(newActive),
65
+ ansi_colors_1.bold(allProjects
66
+ .filter((proj) => proj.project_type &&
67
+ project_1.default.accepted_types.includes(proj.project_type))
68
+ .map((project) => '* ' + project.project_name)
69
+ .join('\n'))
70
+ ]
71
+ });
72
+ }
58
73
  if (optedProject === undefined) {
59
74
  throw new error_1.default('provided project does not match any project in remote', {
60
75
  exit: 1,
@@ -65,20 +80,22 @@ exports.default = new command_1.default('project:use [name_or_project_id]')
65
80
  ]
66
81
  });
67
82
  }
68
- return makeActive(optedProject);
83
+ return makeActive(currentProjectId, optedProject);
69
84
  }
70
- else {
71
- const choices = transformedProjects.map((project) => {
72
- return prompt_1.default.choice(project.name, {
73
- value: project,
74
- short: project.name,
75
- disabled: currentProjectId === project.id + '' ? 'currently active project' : false
76
- });
85
+ const choices = transformedProjects.map((project) => {
86
+ return prompt_1.default.choice(project.name, {
87
+ value: project,
88
+ short: project.name,
89
+ disabled: currentProjectId === project.id + ''
90
+ ? 'currently active project'
91
+ : project.type && !project_1.default.accepted_types.includes(project.type)
92
+ ? project.type
93
+ : false
77
94
  });
78
- const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Which project do you wish to make active ? ', {
79
- type: 'list',
80
- choices
81
- }));
82
- return makeActive(projectAns.project);
83
- }
95
+ });
96
+ const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Which project do you wish to make active ? ', {
97
+ type: 'list',
98
+ choices
99
+ }));
100
+ return makeActive(currentProjectId, projectAns.project);
84
101
  }));
@@ -42,7 +42,7 @@ const fs_1 = require("../util_modules/fs");
42
42
  const js_1 = require("../util_modules/js");
43
43
  const logger_1 = require("../util_modules/logger");
44
44
  exports.default = new command_1.default('pull [feature]')
45
- .description('Pull an existing project from Catalyst')
45
+ .description('Pull resources of your project from the remote console to the local directory')
46
46
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.webapp])
47
47
  .needs('config', { optional: true })
48
48
  .needs('rc')
@@ -38,7 +38,7 @@ const constants_1 = require("../util_modules/constants");
38
38
  const logger_1 = require("../util_modules/logger");
39
39
  exports.default = new command_1.default('run-script [command]')
40
40
  .alias('run')
41
- .description('run a particular command script')
41
+ .description('Run a particular command script defined in catalyst.json')
42
42
  .needs('auth')
43
43
  .needs('config')
44
44
  .needs('rc', { optional: true, resolveOnNotFound: true })
@@ -34,13 +34,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../internal/command"));
35
35
  const constants_1 = require("../util_modules/constants");
36
36
  exports.default = new command_1.default('serve')
37
- .description('Serve your code for local testing without affecting the production')
37
+ .description('Serve Basic I/O and Advanced I/O functions, and the client, to test them locally')
38
38
  .option('--http <port>', 'start the server at specified port ')
39
- .option('--debug <type:port>', 'the functions are invoked from local environment enabling debugging options on provided or default ports ' +
40
- '(e.g. "advancedio:8000,basicio:8080")' +
41
- `(default: advancedio:<name>:${constants_1.DEFAULT.serve_port.debug.advancedio},basicio:${constants_1.DEFAULT.serve_port.debug.basicio})`)
42
- .option('--bind <port>', 'the port on which functions are running in http mode using functions:shell')
39
+ .option('--debug <type:port>', 'the functions are invoked from local environment enabling debugging options on provided ports ' +
40
+ `(example: advancedio:<name>:${constants_1.DEFAULT.serve_port.debug.advancedio},basicio:${constants_1.DEFAULT.serve_port.debug.basicio})`)
41
+ .option('--proxy <url>', 'proxy url to proxy any unknown request to the given url ' +
42
+ '(e.g. "http://localhost:8080")')
43
43
  .option('--only <targets>', 'only serve specified, comma-separated targets (e.g. "client,functions:f1")')
44
+ .option('--watch', 'watch for file and directory changes and enable hot reload')
44
45
  .option('--except <targets>', 'serve all targets except specified (e.g. "client")')
45
46
  .option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
46
47
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp])
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../../internal/command"));
35
35
  const logger_1 = require("../../util_modules/logger");
36
36
  exports.default = new command_1.default('token:generate')
37
- .description('Create a CLI token in order to use in CI systems')
37
+ .description('Generate a token to authenticate accessing the CLI from a remote system')
38
38
  .option('--current', 'prints out the existing token used by this CLI')
39
39
  .needs('auth')
40
40
  .ignore(['token'])
@@ -35,7 +35,7 @@ const ansi_colors_1 = require("ansi-colors");
35
35
  const command_1 = __importDefault(require("../../internal/command"));
36
36
  const logger_1 = require("../../util_modules/logger");
37
37
  exports.default = new command_1.default('token:list')
38
- .description('List all the available tokens created from this cli')
38
+ .description('List all the available tokens generated in this CLI')
39
39
  .ignore(['token'])
40
40
  .needs('auth')
41
41
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../../internal/command"));
35
35
  const logger_1 = require("../../util_modules/logger");
36
36
  exports.default = new command_1.default('token:revoke <id>')
37
- .description('Revoke the token created from this CLI')
37
+ .description('Revoke a token generated in this CLI')
38
38
  .needs('auth')
39
39
  .ignore(['token'])
40
40
  .action((input) => __awaiter(void 0, void 0, void 0, function* () {
@@ -18,7 +18,7 @@ const dc_1 = require("../dc");
18
18
  const command_1 = __importDefault(require("../internal/command"));
19
19
  const logger_1 = require("../util_modules/logger");
20
20
  exports.default = new command_1.default('whoami')
21
- .description('prints out the current logged in user email id')
21
+ .description('Print the email address of the user currently logged in')
22
22
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
23
23
  const activeDC = dc_1.getActiveDC();
24
24
  const user = config_store_1.default.get(`${activeDC}.user`);
@@ -70,7 +70,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
70
70
  target.id = resp.id + '';
71
71
  fn_utils_1.fnUtils.common.generateUrlForTarget(target);
72
72
  }
73
- catch (err) {
73
+ catch (e) {
74
+ const err = error_1.default.getErrorInstance(e);
74
75
  logger_1.debug(err.stack);
75
76
  target.valid = false;
76
77
  target.failure_reason = err.message;
@@ -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,9 +3,9 @@ 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
- const path_1 = require("path");
9
9
  class CatalystError extends Error {
10
10
  constructor(message, options = {}) {
11
11
  var _a;
@@ -17,14 +17,48 @@ class CatalystError extends Error {
17
17
  this.context = options.context;
18
18
  this.errorId = options.errorId;
19
19
  this.arg = options.arg;
20
- const stackArr = ((_a = this.stack) === null || _a === void 0 ? void 0 : _a.split(new RegExp('\n {4}at '))) || [];
21
- this.fileName =
22
- options.fileName === undefined && stackArr[1] !== undefined
23
- ? stackArr[1]
24
- .replace(new RegExp('\\.[^.]+$', 'g'), '')
25
- .replace(new RegExp(`^[^${path_1.sep}]+`), '')
26
- : options.fileName;
27
- runtime_store_1.default.set('log.' + this.fileName, runtime_store_1.default.get('log.' + this.fileName, []).concat(this));
20
+ this.skipHelp = options.skipHelp || false;
21
+ try {
22
+ if (!this.skipHelp) {
23
+ const stackArr = ((_a = this.stack) === null || _a === void 0 ? void 0 : _a.split(/\n {4}at /)) || [];
24
+ this.fileName =
25
+ options.fileName === undefined && stackArr[1] !== undefined
26
+ ? stackArr[1].replace(/\.[^.]+$/, '').replace(/^[^(]+\(/, '')
27
+ : options.fileName;
28
+ runtime_store_1.default.set('log.' + this.fileName, runtime_store_1.default.get('log.' + this.fileName, []).concat(this));
29
+ }
30
+ }
31
+ catch (e) {
32
+ runtime_store_1.default.set('log.faultyError', runtime_store_1.default.get('log.faultyError', []).concat(this));
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;
28
62
  }
29
63
  }
30
64
  exports.default = CatalystError;
package/lib/errorOut.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 logger_1 = require("./util_modules/logger");
6
7
  const error_1 = __importDefault(require("./error"));
7
8
  const constants_1 = require("./util_modules/constants");
8
9
  const contextHelp_1 = __importDefault(require("./util_modules/contextHelp"));
@@ -21,6 +22,12 @@ exports.default = (error, status) => {
21
22
  exit: 2
22
23
  });
23
24
  }
24
- contextHelp_1.default();
25
- process.exitCode = error ? error.exit : 2;
25
+ try {
26
+ const exitCode = contextHelp_1.default();
27
+ process.exitCode = typeof exitCode === 'number' ? exitCode : 2;
28
+ }
29
+ catch (err) {
30
+ logger_1.debug('HELP ERROR: ' + err.stack);
31
+ process.exitCode = 2;
32
+ }
26
33
  };
@@ -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 {
@@ -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
  }
@@ -376,7 +374,8 @@ function validate(targets, idx) {
376
374
  throw new error_1.default('there was a compilation error!', {
377
375
  exit: 1,
378
376
  errorId: 'JAVA-7',
379
- original: err
377
+ original: err,
378
+ skipHelp: !!option_1.getOptionValue('watch', false)
380
379
  });
381
380
  });
382
381
  currentTarget.valid = true;