zcatalyst-cli 1.9.0 → 1.11.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 (190) hide show
  1. package/README.md +29 -29
  2. package/docs/client-utils.toml +5 -0
  3. package/docs/command_needs/auth.toml +5 -0
  4. package/docs/commands/iac/export.toml +4 -0
  5. package/docs/commands/iac/import.toml +4 -0
  6. package/docs/commands/iac/status.toml +4 -0
  7. package/docs/commands/project/use.toml +6 -0
  8. package/docs/iac/status/bundle.toml +4 -0
  9. package/docs/plugin-loader.toml +4 -0
  10. package/docs/serve/server/index.toml +4 -0
  11. package/docs/serve/server/lib/web_client/server.toml +4 -0
  12. package/lib/api-timer.js +81 -0
  13. package/lib/apig-utils.js +17 -14
  14. package/lib/archiver.js +83 -45
  15. package/lib/authentication/login.js +4 -2
  16. package/lib/bin/catalyst.js +0 -1
  17. package/lib/client-utils.js +55 -26
  18. package/lib/client.js +0 -3
  19. package/lib/command_needs/auth.js +12 -3
  20. package/lib/command_needs/rc.js +12 -7
  21. package/lib/commands/apig/disable.js +1 -1
  22. package/lib/commands/apig/enable.js +1 -1
  23. package/lib/commands/apig/status.js +7 -5
  24. package/lib/commands/client/delete.js +4 -5
  25. package/lib/commands/client/setup.js +1 -1
  26. package/lib/commands/deploy.js +4 -2
  27. package/lib/commands/ds/export.js +4 -2
  28. package/lib/commands/ds/import.js +4 -2
  29. package/lib/commands/ds/status.js +146 -150
  30. package/lib/commands/event/generate/index.js +5 -14
  31. package/lib/commands/event/generate/integ.js +1 -1
  32. package/lib/commands/functions/add.js +1 -1
  33. package/lib/commands/functions/config.js +1 -1
  34. package/lib/commands/functions/delete.js +1 -1
  35. package/lib/commands/functions/setup.js +1 -1
  36. package/lib/commands/functions/shell.js +1 -1
  37. package/lib/commands/help.js +0 -22
  38. package/lib/commands/iac/export.js +85 -0
  39. package/lib/commands/iac/import.js +189 -0
  40. package/lib/commands/iac/pack.js +129 -0
  41. package/lib/commands/iac/status.js +63 -0
  42. package/lib/commands/index.js +4 -0
  43. package/lib/commands/init.js +35 -28
  44. package/lib/commands/login.js +1 -1
  45. package/lib/commands/logout.js +1 -1
  46. package/lib/commands/project/list.js +11 -7
  47. package/lib/commands/project/reset.js +1 -1
  48. package/lib/commands/project/use.js +42 -25
  49. package/lib/commands/pull.js +2 -2
  50. package/lib/commands/run.js +1 -1
  51. package/lib/commands/serve.js +3 -2
  52. package/lib/commands/token/generate.js +1 -1
  53. package/lib/commands/token/list.js +1 -1
  54. package/lib/commands/token/revoke.js +1 -1
  55. package/lib/commands/whoami.js +1 -1
  56. package/lib/deploy/features/functions/index.js +2 -1
  57. package/lib/deploy/index.js +3 -1
  58. package/lib/endpoints/lib/iac.js +134 -0
  59. package/lib/error.js +33 -3
  60. package/lib/errorOut.js +4 -3
  61. package/lib/fn-utils/lib/common.js +37 -16
  62. package/lib/fn-utils/lib/java.js +7 -9
  63. package/lib/fn-utils/lib/node.js +7 -1
  64. package/lib/iac/status/bundle.js +82 -0
  65. package/lib/iac/status/deploy.js +74 -0
  66. package/lib/iac/status/util/index.js +26 -0
  67. package/lib/index.js +13 -19
  68. package/lib/init/dependencies/npm-install.js +2 -9
  69. package/lib/init/features/client/index.js +47 -0
  70. package/lib/init/features/client/initializers/angular.js +88 -0
  71. package/lib/init/features/client/initializers/basic.js +27 -0
  72. package/lib/init/features/client/initializers/lyte.js +44 -0
  73. package/lib/init/features/client/initializers/react.js +53 -0
  74. package/lib/init/features/functions/languages/java.js +2 -5
  75. package/lib/init/features/functions/languages/node.js +5 -6
  76. package/lib/init/features/index.js +18 -6
  77. package/lib/init/features/project.js +72 -34
  78. package/lib/init/util/client.js +12 -0
  79. package/lib/init/util/functions.js +20 -0
  80. package/lib/init/util/project.js +35 -0
  81. package/lib/internal/api.js +6 -9
  82. package/lib/internal/command.js +6 -3
  83. package/lib/internal/config.js +7 -4
  84. package/lib/migration/index.js +10 -6
  85. package/lib/option-filter.js +4 -1
  86. package/lib/optional-import.js +11 -25
  87. package/lib/plugin-loader.js +8 -2
  88. package/lib/port-resolver.js +20 -16
  89. package/lib/prompt/index.js +92 -0
  90. package/lib/prompt/types/file-path.js +95 -0
  91. package/lib/pull/features/client.js +1 -1
  92. package/lib/pull/features/functions/index.js +5 -7
  93. package/lib/pull/index.js +4 -1
  94. package/lib/serve/features/index.js +3 -1
  95. package/lib/serve/index.js +6 -1
  96. package/lib/serve/server/index.js +74 -29
  97. package/lib/serve/server/lib/master.js +28 -12
  98. package/lib/serve/server/lib/web_client/index.js +30 -0
  99. package/lib/serve/server/lib/web_client/server.js +171 -0
  100. package/lib/serve/server/lib/web_client/utils.js +10 -0
  101. package/lib/shell/dependencies/http-functions.js +1 -1
  102. package/lib/shell/index.js +3 -1
  103. package/lib/track.js +3 -1
  104. package/lib/util_modules/char.js +1 -1
  105. package/lib/util_modules/config/lib/apig.js +2 -1
  106. package/lib/util_modules/constants/index.js +5 -1
  107. package/lib/util_modules/constants/lib/file-names.js +2 -1
  108. package/lib/util_modules/constants/lib/iac.js +8 -0
  109. package/lib/util_modules/constants/lib/placeholders.js +3 -1
  110. package/lib/util_modules/constants/lib/plugin.js +28 -0
  111. package/lib/util_modules/constants/lib/regex.js +2 -1
  112. package/lib/util_modules/constants/lib/scopes.js +5 -0
  113. package/lib/util_modules/constants/lib/template.js +11 -1
  114. package/lib/util_modules/constants/lib/urls.js +8 -0
  115. package/lib/util_modules/constants/project.js +6 -0
  116. package/lib/util_modules/{contextHelp.js → context-help.js} +5 -1
  117. package/lib/util_modules/env.js +14 -16
  118. package/lib/util_modules/fs/index.js +9 -1
  119. package/lib/util_modules/fs/lib/async.js +29 -22
  120. package/lib/util_modules/global-space.js +99 -0
  121. package/lib/util_modules/js.js +6 -0
  122. package/lib/util_modules/option.js +5 -1
  123. package/lib/util_modules/parser/toml.js +5 -1
  124. package/lib/util_modules/project.js +3 -0
  125. package/lib/util_modules/shell.js +9 -8
  126. package/lib/winston.js +1 -1
  127. package/package.json +11 -5
  128. package/templates/iacSuccess.html +391 -0
  129. package/templates/init/.DS_Store +0 -0
  130. package/templates/init/client/.DS_Store +0 -0
  131. package/templates/init/client/{client-package.json → basic/client-package.json} +0 -0
  132. package/templates/init/client/{index.html → basic/index.html} +0 -0
  133. package/templates/init/client/{main.css → basic/main.css} +0 -0
  134. package/templates/init/client/{main.js → basic/main.js} +0 -0
  135. package/templates/init/client/lyte/build/build.js +301 -0
  136. package/templates/init/client/lyte/build/scripts/cliDownloadScript.js +54 -0
  137. package/templates/init/client/lyte/client-package.json +5 -0
  138. package/templates/init/client/lyte/components/javascript/welcome-comp.js +13 -0
  139. package/templates/init/client/lyte/components/styles/welcome-comp.css +0 -0
  140. package/templates/init/client/lyte/components/templates/welcome-comp.html +8 -0
  141. package/templates/init/client/lyte/data-store/adapters/.gitkeep +0 -0
  142. package/templates/init/client/lyte/data-store/models/.gitkeep +0 -0
  143. package/templates/init/client/lyte/data-store/serializers/.gitkeep +0 -0
  144. package/templates/init/client/lyte/index.html +17 -0
  145. package/templates/init/client/lyte/package.json +12 -0
  146. package/templates/init/client/lyte/router.js +14 -0
  147. package/templates/init/client/lyte/routes/index.js +54 -0
  148. package/templates/init/client/react/.DS_Store +0 -0
  149. package/templates/init/client/react/react_js/package.json +11 -0
  150. package/templates/init/client/react/react_js/template/README.md +70 -0
  151. package/templates/init/client/react/react_js/template/client-package.json +5 -0
  152. package/templates/init/client/react/react_js/template/gitignore +23 -0
  153. package/templates/init/client/react/react_js/template/public/favicon.ico +0 -0
  154. package/templates/init/client/react/react_js/template/public/index.html +43 -0
  155. package/templates/init/client/react/react_js/template/public/logo192.png +0 -0
  156. package/templates/init/client/react/react_js/template/public/logo512.png +0 -0
  157. package/templates/init/client/react/react_js/template/public/manifest.json +25 -0
  158. package/templates/init/client/react/react_js/template/public/robots.txt +3 -0
  159. package/templates/init/client/react/react_js/template/src/App.css +38 -0
  160. package/templates/init/client/react/react_js/template/src/App.js +25 -0
  161. package/templates/init/client/react/react_js/template/src/App.test.js +8 -0
  162. package/templates/init/client/react/react_js/template/src/index.css +13 -0
  163. package/templates/init/client/react/react_js/template/src/index.js +17 -0
  164. package/templates/init/client/react/react_js/template/src/logo.svg +1 -0
  165. package/templates/init/client/react/react_js/template/src/reportWebVitals.js +13 -0
  166. package/templates/init/client/react/react_js/template/src/setupTests.js +5 -0
  167. package/templates/init/client/react/react_js/template.json +13 -0
  168. package/templates/init/client/react/react_ts/package.json +11 -0
  169. package/templates/init/client/react/react_ts/template/README.md +46 -0
  170. package/templates/init/client/react/react_ts/template/client-package.json +5 -0
  171. package/templates/init/client/react/react_ts/template/gitignore +23 -0
  172. package/templates/init/client/react/react_ts/template/public/favicon.ico +0 -0
  173. package/templates/init/client/react/react_ts/template/public/index.html +43 -0
  174. package/templates/init/client/react/react_ts/template/public/logo192.png +0 -0
  175. package/templates/init/client/react/react_ts/template/public/logo512.png +0 -0
  176. package/templates/init/client/react/react_ts/template/public/manifest.json +25 -0
  177. package/templates/init/client/react/react_ts/template/public/robots.txt +3 -0
  178. package/templates/init/client/react/react_ts/template/src/App.css +38 -0
  179. package/templates/init/client/react/react_ts/template/src/App.test.tsx +9 -0
  180. package/templates/init/client/react/react_ts/template/src/App.tsx +26 -0
  181. package/templates/init/client/react/react_ts/template/src/index.css +13 -0
  182. package/templates/init/client/react/react_ts/template/src/index.tsx +17 -0
  183. package/templates/init/client/react/react_ts/template/src/logo.svg +1 -0
  184. package/templates/init/client/react/react_ts/template/src/reportWebVitals.ts +15 -0
  185. package/templates/init/client/react/react_ts/template/src/setupTests.ts +5 -0
  186. package/templates/init/client/react/react_ts/template.json +18 -0
  187. package/templates/web-socket.txt +21 -0
  188. package/lib/init/features/client.js +0 -51
  189. package/lib/prompt.js +0 -49
  190. package/lib/serve/server/lib/client.js +0 -30
@@ -75,7 +75,7 @@ function setFnConfig(featureName, add) {
75
75
  const config = runtime_store_1.default.get('config');
76
76
  featureContextArr.forEach((context) => {
77
77
  var _a, _b;
78
- const targetSourceDir = featureName === 'functions' ? path_1.dirname(context.source) : path_1.basename(context.source);
78
+ const targetSourceDir = featureName === 'functions' ? path_1.dirname(context.source) : context.source;
79
79
  const targetSource = path_1.relative(project_1.getProjectRoot(), targetSourceDir);
80
80
  switch (featureName) {
81
81
  case 'functions':
@@ -98,6 +98,13 @@ function setFnConfig(featureName, add) {
98
98
  break;
99
99
  case 'client':
100
100
  config.set('client.source', targetSource);
101
+ const plugin = runtime_store_1.default.get('payload.client.plugin', false);
102
+ if (plugin) {
103
+ config.set('client.plugin', plugin);
104
+ }
105
+ else {
106
+ config.unset('client.plugin');
107
+ }
101
108
  break;
102
109
  case 'apig':
103
110
  config.set('apig.rules', targetSource);
@@ -109,23 +116,23 @@ function setFnConfig(featureName, add) {
109
116
  exports.setFnConfig = setFnConfig;
110
117
  function functions(add = false) {
111
118
  return __awaiter(this, void 0, void 0, function* () {
112
- yield (yield Promise.resolve().then(() => __importStar(require('./functions')))).default();
119
+ yield (yield Promise.resolve().then(() => __importStar(require('./functions/index.js')))).default();
113
120
  setFnConfig('functions', add);
114
121
  });
115
122
  }
116
123
  exports.functions = functions;
117
124
  function client() {
118
125
  return __awaiter(this, void 0, void 0, function* () {
119
- yield (yield Promise.resolve().then(() => __importStar(require('./client')))).default();
126
+ yield (yield Promise.resolve().then(() => __importStar(require('./client/index.js')))).default();
120
127
  setFnConfig('client', false);
121
128
  });
122
129
  }
123
130
  exports.client = client;
124
131
  function project() {
125
132
  return __awaiter(this, void 0, void 0, function* () {
126
- yield (yield Promise.resolve().then(() => __importStar(require('./project')))).default();
133
+ yield (yield Promise.resolve().then(() => __importStar(require('./project.js')))).default();
127
134
  const projectPayload = runtime_store_1.default.get('payload.project', null);
128
- if (projectPayload === null) {
135
+ if (!projectPayload) {
129
136
  return;
130
137
  }
131
138
  yield project_1.upsertProject(projectPayload, {
@@ -133,10 +140,15 @@ function project() {
133
140
  active: true
134
141
  });
135
142
  yield upsertEnvArr(runtime_store_1.default.get('payload.env', null));
136
- if (runtime_store_1.default.get('project.new', false)) {
143
+ if (runtime_store_1.default.get('payload.project.new', false)) {
137
144
  logger_1.message('New Project has been successfully created and associated with this directory.');
138
145
  }
139
146
  logger_1.message(ansi_colors_1.bold(constants_1.FILENAME.rc) + ' file has be successfully created with project details.');
147
+ const isImport = runtime_store_1.default.get('payload.project.import', false);
148
+ if (isImport) {
149
+ setFnConfig('functions', true);
150
+ setFnConfig('client', false);
151
+ }
140
152
  });
141
153
  }
142
154
  exports.project = project;
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
+ const import_1 = require("../../commands/iac/import");
16
17
  const endpoints_1 = require("../../endpoints");
17
18
  const error_1 = __importDefault(require("../../error"));
18
19
  const prompt_1 = __importDefault(require("../../prompt"));
@@ -21,43 +22,53 @@ const constants_1 = require("../../util_modules/constants");
21
22
  const js_1 = require("../../util_modules/js");
22
23
  const logger_1 = require("../../util_modules/logger");
23
24
  const option_1 = require("../../util_modules/option");
25
+ const yaml_1 = __importDefault(require("yaml"));
24
26
  const project_1 = require("../../util_modules/project");
27
+ const path_1 = require("path");
28
+ const functions_1 = require("../util/functions");
29
+ const project_2 = require("../util/project");
30
+ const client_1 = require("../util/client");
31
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
32
+ const fn_utils_1 = require("../../fn-utils");
33
+ const client_utils_1 = require("../../client-utils");
25
34
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
35
+ var _a, _b;
26
36
  const projectAPI = yield endpoints_1.projectAPI();
27
37
  const defaultRCProjectName = project_1.getDefaultProjectName(null);
28
38
  const defaultRCProjectId = project_1.getDefaultProjectId(null);
29
39
  if (defaultRCProjectName !== null &&
30
40
  defaultRCProjectId !== null &&
31
41
  !option_1.getOptionValue('force', false)) {
32
- logger_1.message(constants_1.FILENAME.rc +
33
- ' already has ' +
34
- ansi_colors_1.bold(defaultRCProjectName) +
35
- ' as a default project. To overwrite use ' +
36
- ansi_colors_1.bold('--force') +
37
- ' option');
42
+ logger_1.message(constants_1.FILENAME.rc + ' already has ' + ansi_colors_1.bold(defaultRCProjectName) + ' as a default project.');
38
43
  try {
39
44
  yield projectAPI.getProject(defaultRCProjectId);
40
- logger_1.warning('skipping project setup. since project directory contains a default project. To overwrite use --force option');
41
- return;
45
+ throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option');
42
46
  }
43
47
  catch (err) {
44
- if (js_1.JS.get(err, 'context.response.statusCode') === 404) {
45
- logger_1.error('default project not found');
48
+ if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
49
+ throw err;
46
50
  }
47
- throw err;
51
+ logger_1.warning('cleaning up ' +
52
+ constants_1.FILENAME.rc +
53
+ ' since the current default project for this folder is not found in remote');
54
+ yield project_1.removeProject(defaultRCProjectId + '');
48
55
  }
49
56
  }
50
- logger_1.message('Setting up a default project for this folder\n');
57
+ logger_1.message('Setting up a new default project for this folder\n');
51
58
  const allProjects = (yield projectAPI.getAllProjects());
52
59
  if (allProjects.length === 0) {
53
60
  throw new error_1.default('Visit ' +
54
- ansi_colors_1.underline(constants_1.ORIGIN.admin) +
61
+ ansi_colors_1.underline(constants_1.ORIGIN.console) +
55
62
  ' for creation of your first project before you continue.', { exit: 1 });
56
63
  }
57
64
  const projectChoices = [
58
65
  prompt_1.default.choice('[create a new project]', {
59
- value: null,
66
+ value: 0,
60
67
  short: 'New-Project'
68
+ }),
69
+ prompt_1.default.choice('[import a existing project]', {
70
+ value: 1,
71
+ short: 'Import-project'
61
72
  })
62
73
  ];
63
74
  allProjects.forEach((project) => {
@@ -66,32 +77,59 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
66
77
  short: project.project_name
67
78
  }));
68
79
  });
69
- const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Note: This process cannot be undone!\n ' +
70
- 'Select a default Catalyst project for this directory: ', {
80
+ const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Select a default Catalyst project for this directory: ', {
71
81
  type: 'list',
72
82
  choices: js_1.JS.reverse(projectChoices)
73
83
  }));
74
84
  let selectedProject = projectAns.project;
75
- if (selectedProject === null) {
76
- const projectNameAns = yield prompt_1.default.ask(prompt_1.default.question('projectName', 'Provide a name for your new project?', {
77
- validate: (ans) => {
78
- if (ans.match(constants_1.REGEX.project.name)) {
79
- return true;
80
- }
81
- return 'Invalid project name';
82
- }
85
+ if (typeof selectedProject !== 'number') {
86
+ return project_2.fillProjectPayload(selectedProject);
87
+ }
88
+ if (selectedProject === 0) {
89
+ const projectNameAns = yield prompt_1.default.ask(prompt_1.default.question('projectName', 'Provide a name for your new project:', {
90
+ validate: (ans) => (ans.match(constants_1.REGEX.project.name) ? true : 'Invalid project name')
83
91
  }));
84
92
  selectedProject = yield projectAPI.createProject(projectNameAns.projectName);
85
- runtime_store_1.default.set('payload.project.new', true);
93
+ return project_2.fillProjectPayload(selectedProject, true);
86
94
  }
87
- runtime_store_1.default.set('payload.project', selectedProject);
88
- runtime_store_1.default.set('project', project_1.transformProject(selectedProject));
89
- const envAPI = yield endpoints_1.envAPI();
90
- const envArr = (yield envAPI.getEnvs(project_1.getProjectId()));
91
- const envObj = js_1.JS.find(envArr, { env_name: constants_1.DEFAULT.env_name });
92
- if (envObj === undefined) {
93
- throw new error_1.default('There is no development environment found for this project. kindly contact support.');
95
+ const [zipArchive, template, importRes] = yield import_1.iacImport();
96
+ yield zipArchive
97
+ .extract(runtime_store_1.default.get('cwd'), '/', { recursive: true, ignoreInitial: false })
98
+ .finalize();
99
+ const parsedJSON = js_1.JS.parseJSON(template);
100
+ const templateJson = parsedJSON ? parsedJSON : yaml_1.default.parse(template);
101
+ const functions = ((_a = templateJson.components) === null || _a === void 0 ? void 0 : _a.Functions) || [];
102
+ const client = ((_b = templateJson.components) === null || _b === void 0 ? void 0 : _b.WebClient) || [];
103
+ yield Promise.all(functions.map(({ properties }) => __awaiter(void 0, void 0, void 0, function* () {
104
+ const source = properties.code.path.replace('/', path_1.sep).replace('.zip', '');
105
+ const stack = properties.stack.toLowerCase();
106
+ const refinedTargets = yield fn_utils_1.fnUtils.common.refineTargets([source], false);
107
+ const fnUtil = stack.startsWith(runtime_1.default.language.nodejs)
108
+ ? fn_utils_1.fnUtils.node
109
+ : stack.startsWith(runtime_1.default.language.java)
110
+ ? fn_utils_1.fnUtils.java
111
+ : null;
112
+ if (fnUtil === null) {
113
+ logger_1.warning(`skipping setup of function(${refinedTargets[0].name}) since provided stack ${stack} is not supported.`);
114
+ return;
115
+ }
116
+ yield fnUtil.validate(refinedTargets, 0);
117
+ if (!refinedTargets[0].valid) {
118
+ logger_1.debug('Invalid target : ' +
119
+ refinedTargets[0].name +
120
+ ' reason : ' +
121
+ refinedTargets[0].failure_reason);
122
+ logger_1.warning(`skipping setup of function(${refinedTargets[0].name}) since the package is invalid. \nContact catalyst support with debug log.`);
123
+ return;
124
+ }
125
+ functions_1.fillFunctionsInitPayload(source, properties.name, properties.stack, properties.type);
126
+ })));
127
+ if (client.length > 0) {
128
+ const { properties } = client[0];
129
+ const source = properties.code.path.replace('/', path_1.sep).replace('.zip', '');
130
+ yield client_utils_1.clientUtils.validate(source);
131
+ client_1.fillClientInitPayload(source, properties.app_name);
94
132
  }
95
- runtime_store_1.default.set('payload.env', envArr);
96
- runtime_store_1.default.set('project.env', project_1.transformEnv(envObj));
133
+ const projectDetails = yield projectAPI.getProject(importRes.project_details.id);
134
+ return project_2.fillProjectPayload(projectDetails, true, true);
97
135
  });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fillClientInitPayload = void 0;
7
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
8
+ const fillClientInitPayload = (source, name) => {
9
+ runtime_store_1.default.set('payload.client.source', source);
10
+ runtime_store_1.default.set('payload.client.name', name);
11
+ };
12
+ exports.fillClientInitPayload = fillClientInitPayload;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fillFunctionsInitPayload = void 0;
7
+ const path_1 = require("path");
8
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
9
+ const fillFunctionsInitPayload = (source, name, stack, type) => {
10
+ const existingFns = runtime_store_1.default.get('payload.functions.targets', []);
11
+ existingFns.push({
12
+ source,
13
+ name,
14
+ stack,
15
+ type
16
+ });
17
+ runtime_store_1.default.set('payload.functions.targets', existingFns);
18
+ runtime_store_1.default.set('payload.functions.source', path_1.dirname(source));
19
+ };
20
+ exports.fillFunctionsInitPayload = fillFunctionsInitPayload;
@@ -0,0 +1,35 @@
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
+ exports.fillProjectPayload = void 0;
16
+ const endpoints_1 = require("../../endpoints");
17
+ const error_1 = __importDefault(require("../../error"));
18
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
19
+ const constants_1 = require("../../util_modules/constants");
20
+ const project_1 = require("../../util_modules/project");
21
+ const fillProjectPayload = (selectedProject, isNew = false, isImport = false) => __awaiter(void 0, void 0, void 0, function* () {
22
+ runtime_store_1.default.set('payload.project', selectedProject);
23
+ runtime_store_1.default.set('project', project_1.transformProject(selectedProject));
24
+ const envAPI = yield endpoints_1.envAPI();
25
+ const envArr = (yield envAPI.getEnvs(project_1.getProjectId()));
26
+ const envObj = envArr.find((env) => env.env_name === constants_1.DEFAULT.env_name);
27
+ if (envObj === undefined) {
28
+ throw new error_1.default('There is no development environment found for this project. Kindly contact support.', { exit: 2 });
29
+ }
30
+ runtime_store_1.default.set('payload.env', envArr);
31
+ runtime_store_1.default.set('project.env', project_1.transformEnv(envObj));
32
+ runtime_store_1.default.set('payload.project.new', isNew);
33
+ runtime_store_1.default.set('payload.project.import', isImport);
34
+ });
35
+ exports.fillProjectPayload = fillProjectPayload;
@@ -116,7 +116,8 @@ class API {
116
116
  body = JSON.parse(rawResponseData.toString());
117
117
  }
118
118
  catch (e) {
119
- logger_1.debug('API Parsing Error: ' + e.message);
119
+ const err = error_1.default.getErrorInstance(e);
120
+ logger_1.debug('API Parsing Error: ' + err.message);
120
121
  }
121
122
  }
122
123
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
@@ -165,14 +166,10 @@ class API {
165
166
  try {
166
167
  resolve(yield this._retry(err));
167
168
  }
168
- catch (error) {
169
- if (error instanceof error_1.default) {
170
- reject(error);
171
- }
172
- reject(new error_1.default('API Error: ' + err.message, {
173
- original: error,
174
- exit: 2
175
- }));
169
+ catch (e) {
170
+ const error = error_1.default.getErrorInstance(e);
171
+ error.exit = 2;
172
+ reject(error);
176
173
  }
177
174
  break;
178
175
  }
@@ -127,15 +127,15 @@ class Command {
127
127
  try {
128
128
  yield runner.apply(this, programArgs);
129
129
  const duration = Date.now() - start;
130
+ errorOut_1.default();
130
131
  yield track_1.default(this.cmdName, 'success', duration);
131
- process.exitCode = 0;
132
132
  }
133
133
  catch (err) {
134
134
  const duration = Date.now() - start;
135
135
  const errorEvent = err.exit === 1 ? 'Error (User)' : 'Error (Unexpected)';
136
136
  const preppedMessage = strip_ansi_1.default(err.message || '');
137
+ errorOut_1.default(err);
137
138
  yield track_1.default(errorEvent, preppedMessage, duration);
138
- return errorOut_1.default(err);
139
139
  }
140
140
  }));
141
141
  return cmd;
@@ -167,7 +167,10 @@ class Command {
167
167
  args.push({});
168
168
  }
169
169
  const [opts, command] = args.slice(-2);
170
- runtime_store_1.default.set('opts', Object.assign({ _name: command.name() }, opts));
170
+ const unknownOpts = this.allowUnknownOptions
171
+ ? command.parseOptions(process.argv).unknown
172
+ : undefined;
173
+ runtime_store_1.default.set('opts', Object.assign({ _name: command.name(), unknownOpts }, opts));
171
174
  this._prepare(command);
172
175
  try {
173
176
  yield migration_1.default(runtime_store_1.default.get('context.cli.package.version'));
@@ -68,11 +68,14 @@ class Config {
68
68
  }
69
69
  }
70
70
  catch (e) {
71
- throw new error_1.default('There was an error loading a file', {
72
- exit: 1,
73
- errorId: 'CONFIG-1',
74
- arg: [ansi_colors_1.bold(constants_1.FILENAME.config), e.message]
71
+ const err = error_1.default.getErrorInstance(e, {
72
+ message: 'There was an error loading a file',
73
+ skipHelp: false,
74
+ fileName: __filename
75
75
  });
76
+ err.errorId = 'CONFIG-1';
77
+ err.arg = [ansi_colors_1.bold(constants_1.FILENAME.config), err.message];
78
+ throw err;
76
79
  }
77
80
  if (canIgnore) {
78
81
  return new Config(path_1.join(pd, constants_1.FILENAME.config));
@@ -63,10 +63,12 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
63
63
  completed: false
64
64
  });
65
65
  rc.syncSave();
66
- throw new error_1.default('Unable to run migration file ' + migFile, {
67
- original: e,
68
- exit: 2
66
+ const err = error_1.default.getErrorInstance(e, {
67
+ message: 'Unable to run migration file ' + migFile,
68
+ skipHelp: false
69
69
  });
70
+ err.exit = 2;
71
+ throw err;
70
72
  }
71
73
  rc.set(['migration', currentMigFileVersion], {
72
74
  completed: true
@@ -102,10 +104,12 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
102
104
  error: util_1.inspect(e),
103
105
  completed: false
104
106
  });
105
- throw new error_1.default('Unable to run migration file ' + migFile, {
106
- original: e,
107
- exit: 2
107
+ const err = error_1.default.getErrorInstance(e, {
108
+ message: 'Unable to run migration file ' + migFile,
109
+ skipHelp: false
108
110
  });
111
+ err.exit = 2;
112
+ throw err;
109
113
  }
110
114
  config_store_1.default.set('migration.' + currentMigFileVersion.replace(new RegExp('\\.', 'g'), '\\.'), {
111
115
  completed: true
@@ -175,7 +175,7 @@ function filterPorts() {
175
175
  });
176
176
  }
177
177
  exports.filterPorts = filterPorts;
178
- function filterTargets() {
178
+ function filterTargets(pathSense = true) {
179
179
  const validTargetResultants = validateTargets();
180
180
  const config = runtime_store_1.default.get('config');
181
181
  let targets = validGlobalTargets.filter((t) => config.has(t));
@@ -185,6 +185,9 @@ function filterTargets() {
185
185
  if (target === 'apig' && option_1.getCurrentCommand() === 'serve') {
186
186
  return true;
187
187
  }
188
+ if (!pathSense) {
189
+ return true;
190
+ }
188
191
  const targetRoot = project_1.resolveProjectPath(CONFIG[(target + 'Config')].source());
189
192
  return (fs_1.SYNC.isPathInside(targetRoot, runtime_store_1.default.get('cwd')) ||
190
193
  runtime_store_1.default.get('cwd') === targetRoot);
@@ -31,34 +31,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- const path_1 = __importDefault(require("path"));
35
34
  const app_module_path_1 = __importDefault(require("app-module-path"));
36
- const logger_1 = require("./util_modules/logger");
37
35
  const project_1 = require("./util_modules/project");
38
- const global_dirs_1 = __importDefault(require("global-dirs"));
36
+ const global_space_1 = __importDefault(require("./util_modules/global-space"));
37
+ const path_1 = require("path");
39
38
  exports.default = (name) => __awaiter(void 0, void 0, void 0, function* () {
40
- try {
41
- if (name.startsWith('./')) {
42
- const projectModulePath = project_1.resolveProjectPath(name);
43
- app_module_path_1.default.addPath(projectModulePath);
44
- return Promise.resolve().then(() => __importStar(require(projectModulePath)));
45
- }
46
- else {
47
- for (const manager of ['npm', 'yarn']) {
48
- try {
49
- const packageName = path_1.default.join(global_dirs_1.default[manager].packages, name);
50
- app_module_path_1.default.addPath(packageName);
51
- return Promise.resolve().then(() => __importStar(require(packageName)));
52
- }
53
- catch (e) {
54
- logger_1.debug(e);
55
- }
56
- }
57
- return;
58
- }
39
+ if (name !== path_1.basename(name)) {
40
+ const projectModulePath = project_1.resolveProjectPath(name);
41
+ app_module_path_1.default.addPath(projectModulePath);
42
+ return Promise.resolve().then(() => __importStar(require(projectModulePath)));
59
43
  }
60
- catch (err) {
61
- logger_1.debug(err);
62
- return;
44
+ const packageName = yield global_space_1.default(name);
45
+ if (typeof packageName === 'string') {
46
+ app_module_path_1.default.addPath(packageName);
47
+ return Promise.resolve().then(() => __importStar(require(packageName)));
63
48
  }
49
+ return;
64
50
  });
@@ -31,6 +31,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
+ const ansi_colors_1 = require("ansi-colors");
35
+ const error_1 = __importDefault(require("./error"));
34
36
  const optional_import_1 = __importDefault(require("./optional-import"));
35
37
  const runtime_store_1 = __importDefault(require("./runtime-store"));
36
38
  const config = __importStar(require("./util_modules/config"));
@@ -57,10 +59,14 @@ function pluginLoader(feature, name, source) {
57
59
  pluginMod = loadedPlugins[specificPlugin];
58
60
  }
59
61
  else {
60
- pluginMod = (yield optional_import_1.default(specificPlugin));
62
+ pluginMod = yield optional_import_1.default(specificPlugin);
61
63
  }
62
64
  if (pluginMod === undefined) {
63
- return;
65
+ throw new error_1.default(`Configured plugin could not be found for [${feature}:${name}] - ${specificPlugin}`, {
66
+ exit: 1,
67
+ errorId: 'PLG-LDR-1',
68
+ arg: [ansi_colors_1.italic.red(specificPlugin), ansi_colors_1.bold(name), ansi_colors_1.bold(feature)]
69
+ });
64
70
  }
65
71
  loadedPlugins[specificPlugin] = pluginMod;
66
72
  if (typeof pluginMod === 'function') {
@@ -68,25 +68,29 @@ class PortResolver {
68
68
  }
69
69
  catch (e) {
70
70
  if (searchSpan === 0) {
71
- throw new error_1.default(`Provided port '${port}' is not available`, {
72
- exit: 1,
73
- original: e,
74
- errorId: 'PORT-RESOLVER-1',
75
- arg: [
76
- ansi_colors_1.bold.red(port + ''),
77
- type === 'debug' ? 'debugging' : 'serving',
78
- ansi_colors_1.bold(feature),
79
- name,
80
- type
81
- ]
71
+ const err = error_1.default.getErrorInstance(e, {
72
+ message: `Provided port '${port}' is not available`,
73
+ skipHelp: false,
74
+ fileName: __filename
82
75
  });
76
+ err.errorId = 'PORT-RESOLVER-1';
77
+ err.arg = [
78
+ ansi_colors_1.bold.red(port + ''),
79
+ type === 'debug' ? 'debugging' : 'serving',
80
+ ansi_colors_1.bold(feature),
81
+ name,
82
+ type
83
+ ];
84
+ throw err;
83
85
  }
84
- throw new error_1.default(`No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`, {
85
- exit: 1,
86
- original: e,
87
- errorId: 'PORT-RESOLVER-2',
88
- arg: [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)]
86
+ const cerr = error_1.default.getErrorInstance(e, {
87
+ message: `No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`,
88
+ skipHelp: false,
89
+ fileName: __filename
89
90
  });
91
+ cerr.errorId = 'PORT-RESOLVER-2';
92
+ cerr.arg = [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)];
93
+ throw cerr;
90
94
  }
91
95
  if (finalPort !== port) {
92
96
  logger_1.debug(`${type} port : '${port}' is not available. Hence port '${finalPort}' will be used instead.`);
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __rest = (this && this.__rest) || function (s, e) {
31
+ var t = {};
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
33
+ t[p] = s[p];
34
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
35
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
36
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
37
+ t[p[i]] = s[p[i]];
38
+ }
39
+ return t;
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const inquirer_1 = __importDefault(require("inquirer"));
46
+ const error_1 = __importDefault(require("../error"));
47
+ const choice = (name, _a = {}) => {
48
+ var { value = name, short = name, disabled = false, checked = false } = _a, otherOpts = __rest(_a, ["value", "short", "disabled", "checked"]);
49
+ return Object.assign({ name,
50
+ value,
51
+ short,
52
+ disabled,
53
+ checked }, otherOpts);
54
+ };
55
+ exports.default = {
56
+ register: (type) => __awaiter(void 0, void 0, void 0, function* () {
57
+ switch (type) {
58
+ case 'file-path':
59
+ const filePathExt = yield Promise.resolve().then(() => __importStar(require('./types/file-path')));
60
+ inquirer_1.default.registerPrompt('file-path', filePathExt.default);
61
+ break;
62
+ default:
63
+ throw new error_1.default('No such type registered', { exit: 2 });
64
+ }
65
+ }),
66
+ seperator: (line) => {
67
+ return new inquirer_1.default.Separator(line);
68
+ },
69
+ choice,
70
+ ask: (...questions) => {
71
+ return inquirer_1.default.prompt(questions);
72
+ },
73
+ question: (name, question, _a = {}) => {
74
+ var { type = 'input', defaultAns, choices = [], validate = () => {
75
+ return true;
76
+ }, filter = (ans) => {
77
+ return ans;
78
+ }, when = () => {
79
+ return true;
80
+ }, prefix = '', suffix = '' } = _a, otheropts = __rest(_a, ["type", "defaultAns", "choices", "validate", "filter", "when", "prefix", "suffix"]);
81
+ if (choices.length > 0 && typeof choices[0] === 'string') {
82
+ choices = choices.map((strChoice) => choice(strChoice));
83
+ }
84
+ return Object.assign({ type,
85
+ name, message: question, default: defaultAns, choices,
86
+ validate,
87
+ filter,
88
+ when,
89
+ prefix,
90
+ suffix }, otheropts);
91
+ }
92
+ };