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
@@ -13,18 +13,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- const ansi_colors_1 = require("ansi-colors");
17
- const path_1 = __importDefault(require("path"));
18
- const util_1 = require("util");
19
- const cjson_1 = __importDefault(require("../cjson"));
16
+ const path_1 = require("path");
17
+ const fs_1 = require("../util_modules/fs");
20
18
  const runtime_store_1 = __importDefault(require("../runtime-store"));
21
- const pkg = cjson_1.default(path_1.default.resolve(__dirname, '../../package.json'));
19
+ const pkg = fs_1.SYNC.readJSONFile(path_1.resolve(__dirname, '../../package.json'), {
20
+ checkpath: true,
21
+ throws: false
22
+ });
22
23
  runtime_store_1.default.set('context.cli.package', pkg);
24
+ if (!pkg) {
25
+ console.error('Package corrupted!!. Re-install zcatalyst-cli and try again.');
26
+ process.exit(1);
27
+ }
28
+ const util_1 = require("util");
29
+ const ansi_colors_1 = require("ansi-colors");
23
30
  const __1 = __importDefault(require(".."));
24
31
  const config_store_1 = __importDefault(require("../config-store"));
25
32
  const constants_1 = require("../util_modules/constants");
26
33
  const env_1 = require("../util_modules/env");
27
- const fs_1 = require("../util_modules/fs");
28
34
  const js_1 = require("../util_modules/js");
29
35
  const logger_1 = require("../util_modules/logger");
30
36
  const errorOut_1 = __importDefault(require("../errorOut"));
@@ -68,7 +74,7 @@ process.on('exit', (code) => {
68
74
  if (env_1.isPrimaryShell()) {
69
75
  fs_1.SYNC.deleteTempDir();
70
76
  }
71
- const logFile = path_1.default.join(process.cwd(), constants_1.FILENAME.log);
77
+ const logFile = path_1.join(process.cwd(), constants_1.FILENAME.log);
72
78
  if (code < 2 && fs_1.SYNC.fileExists(logFile)) {
73
79
  fs_1.SYNC.deleteFile(logFile);
74
80
  }
@@ -76,6 +82,7 @@ process.on('exit', (code) => {
76
82
  pkg,
77
83
  updateCheckInterval: 1000 * 60 * 15
78
84
  }).notify({ defer: false, isGlobal: true });
85
+ errorOut_1.default();
79
86
  });
80
87
  process.on('uncaughtException', (err) => {
81
88
  errorOut_1.default(err);
@@ -16,7 +16,6 @@ exports.clientUtils = void 0;
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 error_1 = __importDefault(require("./error"));
21
20
  const execute_script_1 = __importDefault(require("./execute-script"));
22
21
  const plugin_loader_1 = __importDefault(require("./plugin-loader"));
@@ -34,24 +33,38 @@ exports.clientUtils = {
34
33
  const packageJsonFile = path_1.join(sourceDir, constants_1.FILENAME.client.package_json);
35
34
  const sourceDirExists = yield fs_1.ASYNC.dirExists(sourceDir);
36
35
  if (!sourceDirExists) {
37
- throw new error_1.default(ansi_colors_1.bold('"' + sourceDir + '"') +
38
- ' directory was not found. Please create it or specify a different source directory in ' +
39
- constants_1.FILENAME.config, { exit: 1 });
36
+ throw new error_1.default('source directory does not exist', {
37
+ exit: 1,
38
+ errorId: 'CLIENT-UTILS-1',
39
+ arg: [ansi_colors_1.italic.red(sourceDir), ansi_colors_1.bold(constants_1.FILENAME.config), ansi_colors_1.bold('catalyst client:setup')]
40
+ });
40
41
  }
41
- const packageExists = yield fs_1.ASYNC.fileExists(packageJsonFile);
42
- if (!packageExists) {
43
- throw new error_1.default(ansi_colors_1.bold('"' + packageJsonFile + '"') + ' file was not found.', {
44
- exit: 1
42
+ const packageJson = yield fs_1.ASYNC.readJSONFile(packageJsonFile, {
43
+ checkpath: true
44
+ }).catch((e) => {
45
+ throw new error_1.default(constants_1.FILENAME.client.package_json + ' file cannot be parsed.', {
46
+ exit: 1,
47
+ original: e,
48
+ errorId: 'CLIENT-UTILS-2',
49
+ arg: [ansi_colors_1.bold(packageJsonFile), ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(e.message)]
50
+ });
51
+ });
52
+ if (packageJson === undefined) {
53
+ throw new error_1.default(constants_1.FILENAME.client.package_json + ' file was not found.', {
54
+ exit: 1,
55
+ errorId: 'CLIENT-UTILS-3',
56
+ arg: [ansi_colors_1.bold(packageJsonFile), ansi_colors_1.bold(constants_1.FILENAME.client.package_json)]
45
57
  });
46
58
  }
47
- const packageJson = cjson_1.default(packageJsonFile);
48
59
  const name = js_1.JS.get(packageJson, 'name', null);
49
60
  const homepage = js_1.JS.get(packageJson, 'homepage', null);
50
61
  const loginRedirect = runtime_store_1.default.get('context.client.login_redirect', packageJson.login_redirect);
51
62
  if (js_1.JS.isNull(name) || js_1.JS.isNull(homepage)) {
52
- throw new error_1.default(ansi_colors_1.bold('"' + packageJsonFile + '"') +
53
- ' file is corrupted. \n' +
54
- 'check if name and homepage is set properly.', { exit: 1 });
63
+ throw new error_1.default(constants_1.FILENAME.client.package_json + ' file is corrupted.', {
64
+ exit: 1,
65
+ errorId: 'CLIENT-UTILS-4',
66
+ arg: [ansi_colors_1.bold(packageJsonFile), ansi_colors_1.bold('name'), ansi_colors_1.bold('homepage')]
67
+ });
55
68
  }
56
69
  runtime_store_1.default.set('context.client.name', name);
57
70
  runtime_store_1.default.set('context.client.homepage', homepage);
@@ -60,14 +73,25 @@ exports.clientUtils = {
60
73
  runtime_store_1.default.set('context.client.package_json', packageJsonFile);
61
74
  const validatePlugin = yield plugin_loader_1.default('client', 'validate');
62
75
  if (validatePlugin === undefined) {
76
+ runtime_store_1.default.set('context.client.valid', true);
63
77
  return packageJson;
64
78
  }
65
79
  try {
66
80
  yield validatePlugin(option_1.getCurrentCommand(), sourceDir, runtime_store_1.default, packageJson);
67
81
  }
68
82
  catch (e) {
69
- throw new error_1.default(e, { exit: 1 });
83
+ throw new error_1.default(e, {
84
+ exit: 1,
85
+ errorId: 'CLIENT-UTILS-5',
86
+ original: e,
87
+ arg: [
88
+ 'validating',
89
+ ansi_colors_1.bold(config_1.clientConfig.plugin('validate') || 'unknown'),
90
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(e.message)
91
+ ]
92
+ });
70
93
  }
94
+ runtime_store_1.default.set('context.client.valid', true);
71
95
  return packageJson;
72
96
  }),
73
97
  executeHook: ({ prefix, command }) => {
@@ -94,7 +118,16 @@ exports.clientUtils = {
94
118
  source = outputDir;
95
119
  }
96
120
  catch (e) {
97
- throw new error_1.default(e, { exit: 1 });
121
+ throw new error_1.default(e, {
122
+ exit: 1,
123
+ errorId: 'CLIENT-UTILS-5',
124
+ original: e,
125
+ arg: [
126
+ 'building',
127
+ ansi_colors_1.bold(config_1.clientConfig.plugin('build') || 'unknown'),
128
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(e.message)
129
+ ]
130
+ });
98
131
  }
99
132
  }
100
133
  const ignore = config_1.clientConfig.ignore(source);
package/lib/client.js CHANGED
@@ -35,7 +35,7 @@ class Client {
35
35
  }
36
36
  getCommand(name) {
37
37
  for (const command of this.cli.commands) {
38
- if (command._name === name || command._alias === name) {
38
+ if (command.name() === name || command.alias() === name) {
39
39
  return command;
40
40
  }
41
41
  }
@@ -34,9 +34,11 @@ exports.default = (inScopes = []) => {
34
34
  ];
35
35
  const tokenObj = tokenOpts.find((opts) => typeof opts.token === 'string');
36
36
  if (tokenObj === undefined) {
37
- throw new error_1.default('Command requires authentication, please run ' +
38
- ansi_colors_1.bold('catalyst login') +
39
- ', or provide auth token via --token param', { exit: 0 });
37
+ throw new error_1.default('Command requires authentication', {
38
+ exit: 0,
39
+ errorId: 'AUTH-1',
40
+ arg: [ansi_colors_1.bold('catalyst login'), ansi_colors_1.bold('--token')]
41
+ });
40
42
  }
41
43
  logger_1.debug(`> authorizing via ${tokenObj.option} option`);
42
44
  const commandScopes = [constants_1.SCOPE.projects, ...inScopes].filter((value, index, self) => self.indexOf(value) === index);
@@ -54,9 +54,15 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
54
54
  const projectArr = (yield projectApi.getAllProjects());
55
55
  const project = js_1.JS.find(projectArr, { project_name: projectOpt });
56
56
  if (project === undefined) {
57
- throw new error_1.default('project provided with option --project ' +
58
- projectOpt +
59
- ' is not available in remote console', { exit: 1 });
57
+ throw new error_1.default('invalid project provided with the --project option', {
58
+ exit: 1,
59
+ errorId: 'RC-1',
60
+ arg: [
61
+ ansi_colors_1.bold(projectOpt),
62
+ ansi_colors_1.bold('--project'),
63
+ ansi_colors_1.bold(projectArr.map((project) => '* ' + project.project_name).join('\n'))
64
+ ]
65
+ });
60
66
  }
61
67
  convertProjectToProperties(project);
62
68
  const envArr = (yield envApi.getEnvs(project.id + ''));
@@ -73,16 +79,23 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
73
79
  logger_1.debug('Reason: ' + err);
74
80
  return { loaded: false };
75
81
  }
76
- throw new error_1.default('Not in a Catalyst app directory (Unable to locate or load ' +
77
- constants_1.FILENAME.rc +
78
- ' file) run catalyst init', { exit: 1, original: err });
82
+ throw new error_1.default('Unable to load the ' + constants_1.FILENAME.rc + 'file', {
83
+ exit: 1,
84
+ original: err,
85
+ errorId: 'RC-2',
86
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.rc)]
87
+ });
79
88
  });
80
89
  runtime_store_1.default.set('rc', rcInstance);
81
90
  if (!rcInstance.loaded) {
82
91
  if (optional || ignoreRC) {
83
92
  return;
84
93
  }
85
- throw new error_1.default('Not in a Catalyst app directory run catalyst init', { exit: 1 });
94
+ throw new error_1.default('Not in a Catalyst app directory run catalyst init', {
95
+ exit: 0,
96
+ errorId: 'RC-3',
97
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.rc), ansi_colors_1.bold('catalyst init'), ansi_colors_1.bold('--project')]
98
+ });
86
99
  }
87
100
  if (ignoreRC) {
88
101
  return;
@@ -99,7 +112,11 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
99
112
  if (optional) {
100
113
  return;
101
114
  }
102
- throw new error_1.default(constants_1.FILENAME.rc + ' file is corrupted');
115
+ throw new error_1.default(constants_1.FILENAME.rc + ' file is corrupted', {
116
+ exit: 1,
117
+ errorId: 'RC-4',
118
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.rc), ansi_colors_1.bold('catalyst init project'), ansi_colors_1.bold('--option')]
119
+ });
103
120
  }
104
121
  if (projectOpt === null) {
105
122
  finalProjectObj = rcInstance.activeProject;
@@ -117,7 +134,11 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
117
134
  }
118
135
  if (finalProjectObj === undefined) {
119
136
  logger_1.debug('finalProject came to be empty, default project details is possibly not defined in RC file');
120
- throw new error_1.default(constants_1.FILENAME.rc + ' file is corrupted');
137
+ throw new error_1.default(constants_1.FILENAME.rc + ' file is corrupted', {
138
+ exit: 1,
139
+ errorId: 'RC-4',
140
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.rc), ansi_colors_1.bold('catalyst init project'), ansi_colors_1.bold('--option')]
141
+ });
121
142
  }
122
143
  yield projectApi.getProject(finalProjectObj.id + '').catch((err) => __awaiter(void 0, void 0, void 0, function* () {
123
144
  if (js_1.JS.hasIn(err, 'context.response.statusCode') &&
@@ -130,10 +151,11 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
130
151
  finalProjectObj = undefined;
131
152
  return;
132
153
  }
133
- throw new error_1.default('the project which is currently active doesnt seems to be present in remote console. \n' +
134
- 'Use ' +
135
- ansi_colors_1.bold.underline('catalyst project:use') +
136
- ' in order to change the existing active project');
154
+ throw new error_1.default('active project not found in remote', {
155
+ exit: 1,
156
+ errorId: 'RC-5',
157
+ arg: [ansi_colors_1.bold('catalyst project:use')]
158
+ });
137
159
  }
138
160
  throw err;
139
161
  }));
@@ -12,13 +12,15 @@ 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 ansi_colors_1 = require("ansi-colors");
15
16
  const endpoints_1 = require("../../endpoints");
17
+ const error_1 = __importDefault(require("../../error"));
16
18
  const command_1 = __importDefault(require("../../internal/command"));
17
19
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
20
  const constants_1 = require("../../util_modules/constants");
19
21
  const logger_1 = require("../../util_modules/logger");
20
22
  exports.default = new command_1.default('apig:disable')
21
- .description('disable api gateway if not already disabled')
23
+ .description('Disable API Gateway for your project')
22
24
  .needs('auth', [constants_1.SCOPE.projects])
23
25
  .needs('config')
24
26
  .needs('rc')
@@ -27,8 +29,11 @@ exports.default = new command_1.default('apig:disable')
27
29
  const response = (yield api.getAPIGStatus());
28
30
  logger_1.info();
29
31
  if (response.scheduled) {
30
- logger_1.error('Cannot update since there is a scheduler in progress!');
31
- return;
32
+ throw new error_1.default('Scheduler in progress', {
33
+ exit: 0,
34
+ errorId: 'DIS-1',
35
+ arg: [ansi_colors_1.bold('catalyst apig:status')]
36
+ });
32
37
  }
33
38
  if (response.status) {
34
39
  yield api.updateAPIGStatus(false);
@@ -12,13 +12,15 @@ 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 ansi_colors_1 = require("ansi-colors");
15
16
  const endpoints_1 = require("../../endpoints");
17
+ const error_1 = __importDefault(require("../../error"));
16
18
  const command_1 = __importDefault(require("../../internal/command"));
17
19
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
20
  const constants_1 = require("../../util_modules/constants");
19
21
  const logger_1 = require("../../util_modules/logger");
20
22
  exports.default = new command_1.default('apig:enable')
21
- .description('enables api gateway if not already enabled')
23
+ .description('Enable API Gateway for your project')
22
24
  .needs('auth', [constants_1.SCOPE.projects])
23
25
  .needs('config')
24
26
  .needs('rc')
@@ -27,8 +29,11 @@ exports.default = new command_1.default('apig:enable')
27
29
  const response = (yield api.getAPIGStatus());
28
30
  logger_1.info();
29
31
  if (response.scheduled) {
30
- logger_1.error('Cannot update since there is a scheduler in progress!');
31
- return;
32
+ throw new error_1.default('Scheduler in progress', {
33
+ exit: 0,
34
+ errorId: 'EN-1',
35
+ arg: [ansi_colors_1.bold('catalyst apig:status')]
36
+ });
32
37
  }
33
38
  if (!response.status) {
34
39
  yield api.updateAPIGStatus(true);
@@ -22,7 +22,7 @@ const constants_1 = require("../../util_modules/constants");
22
22
  const logger_1 = require("../../util_modules/logger");
23
23
  const option_1 = require("../../util_modules/option");
24
24
  exports.default = new command_1.default('apig:status')
25
- .description('Displays the status of catalyst api gateway and schedule progress')
25
+ .description('Obtain the current status of API Gateway for your project and the schedule progress')
26
26
  .option('--previous', 'show previous schedule status instead of current one')
27
27
  .needs('auth', [constants_1.SCOPE.projects])
28
28
  .needs('config')
@@ -36,17 +36,21 @@ exports.default = new command_1.default('apig:status')
36
36
  return;
37
37
  }
38
38
  logger_1.info(`${ansi_colors_1.bold('API Gateway')}: ${ansi_colors_1.green('ENABLED')}`);
39
+ const previousOpt = option_1.getOptionValue('previous', false);
40
+ if (apigStatus.scheduled === false && !previousOpt) {
41
+ return;
42
+ }
39
43
  logger_1.info();
40
44
  let report;
41
- const previousOpt = option_1.getOptionValue('previous', false);
42
45
  try {
43
46
  report = (yield api.getScheduleReport(previousOpt));
44
47
  }
45
48
  catch (e) {
46
49
  if (e.status && e.status === 404) {
47
- throw new error_1.default('There is no report available. ' +
48
- 'Kindly deploy APIG from CLI to generate one.' +
49
- (previousOpt ? '' : ' Or use --previous option.'), { exit: 1 });
50
+ throw new error_1.default('There is no report available.', {
51
+ exit: 0,
52
+ errorId: 'STAT-1'
53
+ });
50
54
  }
51
55
  throw e;
52
56
  }
@@ -110,22 +114,38 @@ exports.default = new command_1.default('apig:status')
110
114
  switch (report.state) {
111
115
  case 0:
112
116
  reportMainTable.unshift([
113
- { hAlign: 'center', colSpan: 2, content: ansi_colors_1.yellow.bold('Yet to start') }
117
+ {
118
+ hAlign: 'center',
119
+ colSpan: 2,
120
+ content: ansi_colors_1.yellow.bold('Yet to start')
121
+ }
114
122
  ]);
115
123
  break;
116
124
  case 1:
117
125
  reportMainTable.unshift([
118
- { hAlign: 'center', colSpan: 2, content: ansi_colors_1.yellow.bold('Creating APIs') }
126
+ {
127
+ hAlign: 'center',
128
+ colSpan: 2,
129
+ content: ansi_colors_1.yellow.bold('Creating APIs')
130
+ }
119
131
  ]);
120
132
  break;
121
133
  case 2:
122
134
  reportMainTable.unshift([
123
- { hAlign: 'center', colSpan: 2, content: ansi_colors_1.yellow.bold('Updating APIs') }
135
+ {
136
+ hAlign: 'center',
137
+ colSpan: 2,
138
+ content: ansi_colors_1.yellow.bold('Updating APIs')
139
+ }
124
140
  ]);
125
141
  break;
126
142
  case 3:
127
143
  reportMainTable.unshift([
128
- { hAlign: 'center', colSpan: 2, content: ansi_colors_1.yellow.bold('Deleting APIs') }
144
+ {
145
+ hAlign: 'center',
146
+ colSpan: 2,
147
+ content: ansi_colors_1.yellow.bold('Deleting APIs')
148
+ }
129
149
  ]);
130
150
  break;
131
151
  case 4:
@@ -14,7 +14,6 @@ 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 path_1 = require("path");
17
- const cjson_1 = __importDefault(require("../../cjson"));
18
17
  const client_utils_1 = require("../../client-utils");
19
18
  const endpoints_1 = require("../../endpoints");
20
19
  const error_1 = __importDefault(require("../../error"));
@@ -29,7 +28,7 @@ const logger_1 = require("../../util_modules/logger");
29
28
  const option_1 = require("../../util_modules/option");
30
29
  const project_1 = require("../../util_modules/project");
31
30
  exports.default = new command_1.default('client:delete [client_version]')
32
- .description('Removes the selected version of client')
31
+ .description('Delete a version of the client from the remote console or the local directory')
33
32
  .option('--local', 'removes the client from local machine')
34
33
  .option('--remote', 'removes the selected client from remote console')
35
34
  .needs('auth', [constants_1.SCOPE.webapp])
@@ -43,7 +42,11 @@ exports.default = new command_1.default('client:delete [client_version]')
43
42
  let remoteOpt = option_1.getOptionValue('remote', false);
44
43
  const appsToBeDeleted = [];
45
44
  if (localOpt && remoteOpt) {
46
- throw new error_1.default('Cannot specify both --local and --remote options in the same command');
45
+ throw new error_1.default('both options specified', {
46
+ exit: 1,
47
+ errorId: 'CDEL-1',
48
+ arg: [ansi_colors_1.bold('--local'), ansi_colors_1.bold('--remote')]
49
+ });
47
50
  }
48
51
  if (!localOpt && !remoteOpt) {
49
52
  const locationAns = yield prompt_1.default.ask(prompt_1.default.question('location', 'Choose a location to get more information', {
@@ -74,47 +77,84 @@ exports.default = new command_1.default('client:delete [client_version]')
74
77
  location: local
75
78
  };
76
79
  try {
77
- const configFile = cjson_1.default(packageJsonFile);
80
+ const configFile = fs_1.ASYNC.readJSONFile(packageJsonFile, {
81
+ checkpath: true
82
+ });
83
+ if (configFile === undefined) {
84
+ throw new error_1.default('File not found', { exit: 2 });
85
+ }
78
86
  const version = js_1.JS.get(configFile, 'version', '[unknown]');
79
87
  localDel.version = version;
80
88
  }
81
89
  catch (error) {
82
- logger_1.debug('Failed to read client-config.json. Reason: ' + error.message);
90
+ logger_1.debug('Failed to read ' +
91
+ constants_1.FILENAME.client.package_json +
92
+ ' Reason: ' +
93
+ error.message);
83
94
  }
84
95
  if (clientVersion !== undefined && clientVersion !== localDel.version) {
85
- logger_1.error('The provided version is not found in the local machine\n' +
86
- `Run ${ansi_colors_1.bold('catalyst client:delete --local')} command to delete the current version in local`);
87
- return;
96
+ throw new error_1.default('version unavailable in local', {
97
+ exit: 1,
98
+ errorId: 'CDEL-2',
99
+ arg: [ansi_colors_1.bold(localDel.version)]
100
+ });
88
101
  }
89
102
  appsToBeDeleted.push(localDel);
90
103
  }
91
104
  else {
92
- logger_1.error('No client found in local');
93
105
  const conf = runtime_store_1.default.get('config');
94
106
  if (conf.get('client') !== undefined) {
95
- logger_1.debug('Removing the entry for client in ' + constants_1.FILENAME.config);
107
+ logger_1.debug('No client directory found. Removing the entry for client in ' +
108
+ constants_1.FILENAME.config);
96
109
  conf.unset('client');
97
110
  yield conf.save();
98
111
  }
99
- return;
112
+ throw new error_1.default('No client directory found in local', {
113
+ exit: 0,
114
+ errorId: 'CDEL-3',
115
+ arg: [ansi_colors_1.bold('catalyst client:setup')]
116
+ });
100
117
  }
101
118
  }
102
119
  if (remoteOpt) {
103
120
  const choicesArray = [];
104
121
  let historyArr = (yield clientApi.getAllHistory());
122
+ if (js_1.JS.isEmpty(historyArr)) {
123
+ throw new error_1.default('No clients available', {
124
+ exit: 0,
125
+ errorId: 'CDEL-4',
126
+ arg: [ansi_colors_1.bold('catalyst deploy --only client')]
127
+ });
128
+ }
105
129
  if (clientVersion !== undefined) {
106
130
  const ipVersion = js_1.JS.find(historyArr, (history) => history.app_version === clientVersion);
107
131
  if (ipVersion === undefined) {
108
- logger_1.error('The provided version is not found in the Catalyst remote console\n' +
109
- `Run ${ansi_colors_1.bold('catalyst client:delete --remote')} command to list available clients to delete in remote`);
110
- return;
132
+ const avlVer = historyArr
133
+ .filter((his) => {
134
+ const status = js_1.JS.get(his, 'status', false);
135
+ return !status;
136
+ })
137
+ .map((his) => {
138
+ return '* ' + his.app_version;
139
+ });
140
+ throw new error_1.default('Version unavailble in remote', {
141
+ exit: 1,
142
+ errorId: 'CDEL-5',
143
+ arg: [
144
+ ansi_colors_1.bold(clientVersion),
145
+ ansi_colors_1.bold(avlVer.length > 0 ? avlVer.join('\n') : 'None')
146
+ ]
147
+ });
148
+ }
149
+ if (ipVersion.status) {
150
+ throw new error_1.default('attempt to delete a live web client', {
151
+ exit: 0,
152
+ errorId: 'CDEL-6',
153
+ arg: [ansi_colors_1.bold(ipVersion.app_version)]
154
+ });
111
155
  }
112
156
  historyArr = [ipVersion];
113
157
  }
114
- if (js_1.JS.isEmpty(historyArr)) {
115
- logger_1.error('No versions of client found in the remote console to delete.');
116
- return;
117
- }
118
158
  choicesArray.push(prompt_1.default.seperator('-------REMOTE-------'));
119
159
  js_1.JS.forEach(historyArr, (history) => {
120
160
  const version = js_1.JS.get(history, 'status', false)
@@ -132,14 +172,6 @@ exports.default = new command_1.default('client:delete [client_version]')
132
172
  : false
133
173
  }));
134
174
  });
135
- if (js_1.JS.isEmpty(choicesArray)) {
136
- throw new error_1.default('No clients available to delete', { exit: 1 });
137
- }
138
- if (choicesArray.length === 2 && choicesArray[1].disabled) {
139
- logger_1.warning('Attempt to delete a Live Web Client. ' +
140
- 'You cannot delete the Live version of Web Client.');
141
- return;
142
- }
143
175
  const choiceAns = yield prompt_1.default.ask(prompt_1.default.question('choice', 'Select all the client versions you want to delete', {
144
176
  type: 'checkbox',
145
177
  choices: choicesArray,
@@ -159,6 +191,13 @@ exports.default = new command_1.default('client:delete [client_version]')
159
191
  else if (choicesArray.length === 2 && !choicesArray[1].disabled) {
160
192
  appsToBeDeleted.push(choicesArray[1].value);
161
193
  }
194
+ else if (choicesArray.length === 2 && choicesArray[1].disabled) {
195
+ throw new error_1.default('Only live client available', {
196
+ exit: 1,
197
+ errorId: 'CDEL-7',
198
+ arg: [ansi_colors_1.bold(historyArr[0].app_version)]
199
+ });
200
+ }
162
201
  else {
163
202
  throw new error_1.default('No clients selected from remote', { exit: 2 });
164
203
  }
@@ -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
  };
@@ -37,7 +37,7 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
37
37
  const constants_1 = require("../../util_modules/constants");
38
38
  const logger_1 = require("../../util_modules/logger");
39
39
  exports.default = new command_1.default('client:setup')
40
- .description('Setup, Configure and deploy Client Files')
40
+ .description('Set up the client directory in your project directory')
41
41
  .needs('auth', [constants_1.SCOPE.webapp])
42
42
  .needs('config')
43
43
  .needs('rc')
@@ -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
  };
@@ -36,7 +36,7 @@ const runtime_store_1 = __importDefault(require("../runtime-store"));
36
36
  const constants_1 = require("../util_modules/constants");
37
37
  const logger_1 = require("../util_modules/logger");
38
38
  exports.default = new command_1.default('deploy')
39
- .description('Deploy your code from working directory to your Catalyst Project')
39
+ .description('Deploy the Catalyst project and project resources to the remote console from the local directory')
40
40
  .option('--only <targets>', 'only deploy specified, comma-separated targets (e.g. "functions,client").' +
41
41
  ' For Functions you can specify which functions to deploy with colon notation' +
42
42
  ' (e.g. "--only functions:<function_name>,functions:<function_name>"). ')