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
package/README.md CHANGED
@@ -70,36 +70,36 @@ Certain command are project specific and for it to work you must be inside a pro
70
70
 
71
71
  Command | Description
72
72
  ------- | -----------
73
- **login** | Authenticate your CLI to access Catalyst Details. *Requires access to a web browser*.
74
- **whoami** | Prints the current logged in user email Id.
75
- **token:generate** | Create a CLI token in order to use in CI systems.
76
- **token:revoke** | Revoke the token created from this CLI.
77
- **token:list** | List all the available tokens created from this CLI.
78
- **project:list** | List the Catalyst projects you have access to.
73
+ **login** | Log the CLI in to your Catalyst account. *Requires access to a web browser*.
74
+ **whoami** | Print the email address of the user currently logged in.
75
+ **token:generate** | Generate a token to authenticate accessing the CLI from a remote system.
76
+ **token:revoke** | Revoke a token generated in this CLI.
77
+ **token:list** | List all the available tokens generated in this CLI.
78
+ **project:list** | List all the Catalyst projects you have access to.
79
79
  **project:use** | Set an active Catalyst project for your working directory.
80
- **project:reset** | Clear an active selection of project and reset to base project.
81
- **init** | Initialize a Catalyst sample project in the current directory.
82
- **pull** | Pull an existing project from Catalyst.
83
- **apig:status** | Displays the status of Catalyst API Gateway and schedule progress.
84
- **apig:enable** | Enables API Gateway if not already enabled. *in both Console and Local*
85
- **apig:disable** | Disable API Gateway if not already disabled. *in both Console and Local*
86
- **ds:import** | Write bulk data to table in Catalyst datastore.
87
- **ds:export** | Read bulk data from table in Catalyst datastore.
88
- **ds:status** | Displays the status of Catalyst datastore bulk schedule progress.
89
- **client:setup** | Setup and configure Client files.
90
- **client:delete** | Removes the selected version of Client.
91
- **functions:setup** | Setup and configure function files for Catalyst functions.
92
- **functions:delete** | Removes the selected functions.
93
- **functions:add** | Add single function of desirable stack to catalyst functions.
94
- **functions:shell** | Launch a node shell with emulated functions for any stack pointing to production or local.
95
- **functions:config** | Configure the resources for the functions deployed to the Catalyst remote console.
96
- **event:generate \| generate:event** | Generate sample payloads from different event sources of Catalyst
97
- **event:generate:integ** | Generate sample payload for testing your integration functions in local.
98
- **serve** | Serve your code for local testing without affecting the production.
99
- **deploy** | Deploy your code from working directory to your Catalyst Project.
100
- **help** | Display help information.
101
- **run-script \| run** | Run a particular command script.
102
- **logout** | Log the CLI out of your Zoho Catalyst account.
80
+ **project:reset** | Clear an active project selection and reset to the base project.
81
+ **init** | Initialize a Catalyst project, function, and client resources in the local directory.
82
+ **pull** | Pull resources of your project from the remote console to the local directory.
83
+ **apig:status** | Obtain the current status of API Gateway for your project and the schedule progress.
84
+ **apig:enable** | Enable API Gateway for your project. *In both Console and Local*.
85
+ **apig:disable** | Disable API Gateway for your project. *In both Console and Local*.
86
+ **ds:import** | Bulk write records to a table in the Catalyst Data Store.
87
+ **ds:export** | Bulk read records from a table in the Catalyst Data Store.
88
+ **ds:status** | Display the job status of a Data Store import or export operation.
89
+ **client:setup** | Set up and configure the client directory in your project directory.
90
+ **client:delete** | Delete a version of the client from the remote console or the local directory.
91
+ **functions:setup** | Set up and configure the function directory in your project directory.
92
+ **functions:add** | Add a function of the required stack to the function directory.
93
+ **functions:shell** | Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions.
94
+ **functions:config** | Perform advanced configurations such as memory allocation on a function in your project.
95
+ **functions:delete** | Delete a function from the remote console or the local directory.
96
+ **event:generate \| generate:event** | Generate sample payloads from different components or custom event sources to test Event functions.
97
+ **event:generate:integ** | Generate sample payloads for the required integration service to test Integration functions.
98
+ **serve** | Serve Basic I/O and Advanced I/O functions, and the client, to test them locally.
99
+ **deploy** | Deploy the Catalyst project and project resources to the remote console from the local directory.
100
+ **help** | Display the command reference or help for a specific command.
101
+ **run-script \| run** | Run a particular command script defined in *catalyst.json*.
102
+ **logout** | Log the CLI out of your Catalyst account.
103
103
 
104
104
  ---
105
105
 
@@ -22,3 +22,8 @@ link = 'https://www.zoho.com/catalyst/help/project-directory-structure.html#Clie
22
22
  context = '''Error when ${arg[0]} the Client with the ${arg[1]} plugin.'''
23
23
  aid = '''Please rectify the below error to continue. \n${arg[2]}'''
24
24
  link = ''
25
+
26
+ [CLIENT-UTILS-6]
27
+ context = '''Client Setup Skipped: Since the consent to overwrite the existing directory was not given.'''
28
+ aid = '''Existing directory: ${arg[0]}'''
29
+ link = ''
@@ -2,3 +2,8 @@
2
2
  context = '''Oops! It looks like you haven't logged in yet'''
3
3
  aid = '''Please use the ${arg[0]} command to log in, or provide auth token via ${arg[1]} param'''
4
4
  link = 'https://www.zoho.com/catalyst/help/cli-login.html'
5
+
6
+ [AUTH-2]
7
+ context = '''Oops! It looks like there is a scope missing for running this command'''
8
+ aid = '''Please use the ${arg[0]} command to re-login'''
9
+ link = 'https://www.zoho.com/catalyst/help/cli-login.html'
@@ -0,0 +1,4 @@
1
+ [PROJ-USE-1]
2
+ context = '''Oops! It looks like you haven't created your first Catalyst project yet'''
3
+ aid = '''Please visit the below link to get started with your first catalyst project'''
4
+ link = 'https://www.zoho.com/catalyst/help/catalyst-console.html#Projects'
@@ -0,0 +1,4 @@
1
+ [I-1]
2
+ context = '''No project template found in the zip provided.'''
3
+ aid = '''Project template should be placed at the root level of the zip.'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -0,0 +1,4 @@
1
+ [S-1]
2
+ context = '''The operation "${arg[0]}" provided by you is not supported.'''
3
+ aid = '''Supported operations are "import" and "export". Usage Example: "catalyst iac:status import"'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -7,3 +7,9 @@ link = 'https://www.zoho.com/catalyst/help/catalyst-console.html#Projects'
7
7
  context = '''The project ${arg[0]} does not exist in the Catalyst remote console.'''
8
8
  aid = '''Please specify only the projects from this list : \n${arg[1]}'''
9
9
  link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
10
+
11
+ [PROJ-USE-3]
12
+ context = '''The project ${arg[0]} is not live and is possibily still in import phase.'''
13
+ aid = '''Please specify only the projects from this list : \n${arg[1]}'''
14
+ link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
15
+
@@ -0,0 +1,4 @@
1
+ [B-1]
2
+ context = '''No export project available in server.'''
3
+ aid = '''To start exporting a project use "catalyst iac:export"'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -0,0 +1,4 @@
1
+ [PLG-LDR-1]
2
+ context = '''The ${arg[0]} plugin configured to ${arg[1]} the ${arg[2]} is not found.'''
3
+ aid = '''Please install the ${arg[0]} plugin either locally or globally to ${arg[1]} the ${arg[2]}.'''
4
+ link = ''
@@ -0,0 +1,4 @@
1
+ [SERVE-IDX-1]
2
+ context = '''Error when serving the ${arg[0]} with the ${arg[1]} plugin.'''
3
+ aid = '''Please rectify the below error to serve the ${arg[0]}: \n${arg[2]}'''
4
+ link = ''
@@ -0,0 +1,4 @@
1
+ [WEB-CLIENT-SERVER-1]
2
+ context = '''The file provided as homepage(${arg[0]}) for the web-client is not found inside the client source directory.'''
3
+ aid = '''Please provide a valid file as the web-client homepage'''
4
+ link = ''
@@ -0,0 +1,81 @@
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 events_1 = __importDefault(require("events"));
16
+ const error_1 = __importDefault(require("./error"));
17
+ class APITimer extends events_1.default {
18
+ constructor(apiFn, frequency, errorTolerance) {
19
+ super();
20
+ this.apiFn = apiFn;
21
+ this.frequency = frequency || 5000;
22
+ this.interval = null;
23
+ this.execCount = 0;
24
+ this.maxErrors = errorTolerance || 10;
25
+ this.errorCount = 0;
26
+ this.ended = false;
27
+ }
28
+ emit(eventName, ...args) {
29
+ if (this.ended || this.listenerCount(eventName) <= 0) {
30
+ return false;
31
+ }
32
+ return super.emit(eventName, ...args);
33
+ }
34
+ waitForEnd() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return new Promise((res, rej) => {
37
+ this.on('end', (e, data) => {
38
+ if (e) {
39
+ rej(e);
40
+ return;
41
+ }
42
+ res(data);
43
+ });
44
+ });
45
+ });
46
+ }
47
+ fire() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (this.ended) {
50
+ this.end();
51
+ }
52
+ try {
53
+ const data = yield this.apiFn();
54
+ this.emit('data', data, ++this.execCount);
55
+ }
56
+ catch (e) {
57
+ this.emit('error', e, ++this.errorCount);
58
+ const err = error_1.default.getErrorInstance(e);
59
+ if (this.errorCount >= this.maxErrors) {
60
+ this.end(err);
61
+ }
62
+ }
63
+ });
64
+ }
65
+ start() {
66
+ this.fire();
67
+ this.interval = setInterval(this.fire.bind(this), this.frequency);
68
+ return this;
69
+ }
70
+ end(e, data) {
71
+ if (this.interval) {
72
+ clearInterval(this.interval);
73
+ this.execCount = 0;
74
+ this.errorCount = 0;
75
+ this.interval = null;
76
+ }
77
+ this.emit('end', e, data);
78
+ this.ended = true;
79
+ }
80
+ }
81
+ exports.default = APITimer;
package/lib/apig-utils.js CHANGED
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.apigUtils = void 0;
27
27
  const ansi_colors_1 = require("ansi-colors");
28
+ const util_1 = require("util");
28
29
  const client_utils_1 = require("./client-utils");
29
30
  const error_1 = __importDefault(require("./error"));
30
31
  const execute_script_1 = __importDefault(require("./execute-script"));
@@ -64,14 +65,14 @@ exports.apigUtils = {
64
65
  yield client_utils_1.clientUtils.validate();
65
66
  const homepage = runtime_store_1.default.get('context.client.homepage', 'index.html');
66
67
  const loginRedirect = runtime_store_1.default.get('context.client.login_redirect', homepage);
67
- if (loginRedirect) {
68
+ if (typeof loginRedirect === 'string') {
68
69
  redirectPath = loginRedirect.startsWith('/')
69
70
  ? loginRedirect
70
71
  : '/app/' + loginRedirect;
71
72
  }
72
73
  }
73
74
  catch (e) {
74
- logger_1.debug(e.message);
75
+ logger_1.debug(error_1.default.getErrorInstance(e).message);
75
76
  }
76
77
  let redirectIdx = -1;
77
78
  const namesArr = [];
@@ -197,19 +198,21 @@ exports.apigUtils = {
197
198
  rule.name, new RegExp(regexParts[1]);
198
199
  }
199
200
  catch (regexError) {
200
- throw new error_1.default('source_endpoint provided for apig rule "' +
201
- rule.name +
202
- '" is not valid', {
203
- exit: 1,
204
- original: regexError,
205
- errorId: 'APIG-UTILS-9',
206
- arg: [
207
- ansi_colors_1.bold('source_endpoint'),
208
- ansi_colors_1.bold(rule.name),
209
- ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
210
- ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(regexError)
211
- ]
201
+ const err = error_1.default.getErrorInstance(regexError, {
202
+ message: 'source_endpoint provided for apig rule "' +
203
+ rule.name +
204
+ '" is not valid',
205
+ skipHelp: false,
206
+ fileName: __filename
212
207
  });
208
+ err.errorId = 'APIG-UTILS-9';
209
+ err.arg = [
210
+ ansi_colors_1.bold('source_endpoint'),
211
+ ansi_colors_1.bold(rule.name),
212
+ ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
213
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(util_1.inspect(regexError))
214
+ ];
215
+ throw err;
213
216
  }
214
217
  if (regexParts[1].includes('^') || regexParts[1].includes('$')) {
215
218
  throw new error_1.default('source_endpoint provided for apig rule "' +
package/lib/archiver.js CHANGED
@@ -43,27 +43,38 @@ class Archiver {
43
43
  this.promiseArr = [];
44
44
  }
45
45
  load(content, { createFolders = true } = {}) {
46
- if (Buffer.isBuffer(content) || js_1.JS.isString(content)) {
47
- this.content = content;
48
- }
49
- else {
46
+ if (!Buffer.isBuffer(content) && !js_1.JS.isString(content)) {
50
47
  throw new error_1.default('Unable to parse zip content, content should be either a string or buffer', { exit: 2 });
51
48
  }
49
+ this.content = content;
52
50
  this.jszip = jszip_1.loadAsync(content, { createFolders });
53
51
  return this;
54
52
  }
55
- _writeFolder(folder, to) {
53
+ _writeFolder(folder, to, recursive = false, ignoreInitial = false) {
56
54
  return __awaiter(this, void 0, void 0, function* () {
57
- const allFilePromise = [];
58
- folder.forEach((relPath, file) => {
59
- if (!file.dir) {
60
- const relDir = path_1.dirname(relPath);
61
- allFilePromise.push(fs_1.ASYNC.ensureDir(path_1.join(to, relDir)).then(() => {
62
- return this._writeFile(file, path_1.join(to, relDir));
63
- }));
64
- }
65
- });
66
- return Promise.all(allFilePromise);
55
+ return this._writeAllFile(folder.filter((_relPath, file) => !file.dir), to, recursive, ignoreInitial);
56
+ });
57
+ }
58
+ _writeAllFile(files, to, recursive = false, ignoreInitial = false) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ while (files.length > 0) {
61
+ const limit = files.length < Archiver.maxWriteLimit ? files.length : Archiver.maxWriteLimit;
62
+ yield Promise.all(files.splice(0, limit).map((file) => __awaiter(this, void 0, void 0, function* () {
63
+ const filePath = path_1.join(to, path_1.dirname(ignoreInitial ? file.name.substr(file.name.indexOf('/') + 1) : file.name));
64
+ yield fs_1.ASYNC.ensureDir(filePath);
65
+ if (file.name.endsWith('.zip') && recursive) {
66
+ const zipContent = yield file.async('nodebuffer');
67
+ return new Archiver()
68
+ .load(zipContent)
69
+ .extract(path_1.join(filePath, path_1.basename(file.name).replace('.zip', '')), '/', {
70
+ recursive,
71
+ ignoreInitial
72
+ })
73
+ .finalize();
74
+ }
75
+ return this._writeFile(file, filePath);
76
+ })));
77
+ }
67
78
  });
68
79
  }
69
80
  _writeFile(file, to) {
@@ -76,35 +87,51 @@ class Archiver {
76
87
  });
77
88
  });
78
89
  }
79
- extract(from, to, { isFolder = false }) {
80
- this.promiseArr.push(this.jszip.then((zip) => __awaiter(this, void 0, void 0, function* () {
90
+ readFile(relPath) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const actualZip = yield this.jszip;
93
+ const fileObjArr = [];
94
+ if (typeof relPath === 'string') {
95
+ const fileObj = actualZip.file(relPath);
96
+ if (fileObj) {
97
+ fileObjArr.push(fileObj);
98
+ }
99
+ }
100
+ else {
101
+ fileObjArr.push(...actualZip.file(relPath));
102
+ }
103
+ if (fileObjArr.length === 0) {
104
+ return;
105
+ }
106
+ return fileObjArr[0].async('string');
107
+ });
108
+ }
109
+ extract(to, from = '/', { isFolder = true, recursive = false, ignoreInitial = false } = {}) {
110
+ const extractPromise = this.jszip.then((zip) => __awaiter(this, void 0, void 0, function* () {
81
111
  if (isFolder) {
82
- const fromFolderObj = [];
112
+ let folder = null;
83
113
  if (typeof from === 'string') {
84
- if (from === '/') {
85
- fromFolderObj.push(zip);
86
- }
87
- else {
88
- const folder = zip.folder(from);
89
- if (folder) {
90
- fromFolderObj.push(folder);
91
- }
92
- }
114
+ folder = from === '/' ? zip : zip.folder(from);
93
115
  }
94
116
  else {
95
117
  const folderObjects = zip.folder(from);
96
- folderObjects.forEach((folder) => {
97
- if (folder) {
98
- fromFolderObj.push(zip.folder(folder.name));
118
+ if (folderObjects.length > 0) {
119
+ folder = zip.folder(folderObjects[0].name);
120
+ if (folderObjects.length > 1) {
121
+ folderObjects.forEach((folderObj) => {
122
+ if (folder !== null && folderObj.name.length > folder.name.length) {
123
+ folder = zip.folder(folderObj.name);
124
+ }
125
+ });
99
126
  }
100
- });
127
+ }
101
128
  }
102
- if (fromFolderObj.length === 0) {
129
+ if (!folder) {
103
130
  throw new error_1.default('Unable to extract zip, FolderObj is null', {
104
131
  exit: 2
105
132
  });
106
133
  }
107
- yield Promise.all(fromFolderObj.map((obj) => this._writeFolder(obj, to)));
134
+ yield this._writeFolder(folder, to, recursive, ignoreInitial);
108
135
  return true;
109
136
  }
110
137
  const fromFileObj = [];
@@ -115,28 +142,21 @@ class Archiver {
115
142
  }
116
143
  }
117
144
  else {
118
- fromFileObj.push(...zip.file(from).filter((fileObj) => {
119
- if (fileObj) {
120
- return true;
121
- }
122
- return false;
123
- }));
145
+ fromFileObj.concat(zip.file(from));
124
146
  }
125
147
  if (fromFileObj.length === 0) {
126
148
  throw new error_1.default('Unable to extract zip, FileObj is null', {
127
149
  exit: 2
128
150
  });
129
151
  }
130
- while (fromFileObj.length > 0) {
131
- const limit = fromFileObj.length < 20 ? fromFileObj.length : 20;
132
- yield Promise.all(fromFileObj.splice(0, limit).map((obj) => this._writeFile(obj, to)));
133
- }
152
+ yield this._writeAllFile(fromFileObj, to, recursive, ignoreInitial);
134
153
  return true;
135
- })));
154
+ }));
155
+ this.promiseArr.push(extractPromise);
136
156
  return this;
137
157
  }
138
158
  getUnixPath(pth) {
139
- return js_1.JS.join(js_1.JS.split(pth, path_1.sep), '/');
159
+ return pth.split(path_1.sep).join('/');
140
160
  }
141
161
  add(pth, content, { createFolders = true } = {}) {
142
162
  this.promiseArr.push(this.jszip.then((zip) => {
@@ -189,6 +209,23 @@ class Archiver {
189
209
  });
190
210
  yield fs_1.ASYNC.writeFile(tempFilePath, content);
191
211
  return fs_1.SYNC.getReadStream(tempFilePath);
212
+ }),
213
+ writeZip: (pth) => __awaiter(this, void 0, void 0, function* () {
214
+ const zip = yield this.jszip;
215
+ const content = yield zip.generateAsync({
216
+ type: 'nodebuffer',
217
+ compression: 'DEFLATE',
218
+ compressionOptions: {
219
+ level: 9
220
+ }
221
+ });
222
+ if (pth.endsWith('.zip')) {
223
+ pth = path_1.join(path_1.dirname(pth), this.name + '.zip');
224
+ }
225
+ if (path_1.parse(pth).ext === '') {
226
+ pth = path_1.join(pth, this.name + '.zip');
227
+ }
228
+ yield fs_1.ASYNC.writeFile(pth, content);
192
229
  })
193
230
  };
194
231
  }
@@ -199,4 +236,5 @@ class Archiver {
199
236
  });
200
237
  }
201
238
  }
239
+ Archiver.maxWriteLimit = 50;
202
240
  exports.default = Archiver;
@@ -287,9 +287,11 @@ class Login {
287
287
  processReq = false;
288
288
  res.writeHead(404);
289
289
  res.end();
290
+ return;
290
291
  }
291
292
  reqCount += 1;
292
- const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`).searchParams;
293
+ const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`)
294
+ .searchParams;
293
295
  const code = queryParamsObj !== undefined && queryParamsObj.get('code');
294
296
  const location = queryParamsObj !== undefined && queryParamsObj.get('location');
295
297
  if (processReq && typeof code === 'string') {
@@ -335,7 +337,7 @@ class Login {
335
337
  server.close();
336
338
  reject(new error_1.default('Server crashed with error.\n', {
337
339
  exit: 2,
338
- original: e
340
+ original: error_1.default.getErrorInstance(e)
339
341
  }));
340
342
  }
341
343
  }));
@@ -82,7 +82,6 @@ process.on('exit', (code) => {
82
82
  pkg,
83
83
  updateCheckInterval: 1000 * 60 * 15
84
84
  }).notify({ defer: false, isGlobal: true });
85
- errorOut_1.default();
86
85
  });
87
86
  process.on('uncaughtException', (err) => {
88
87
  errorOut_1.default(err);
@@ -27,9 +27,10 @@ const js_1 = require("./util_modules/js");
27
27
  const logger_1 = require("./util_modules/logger");
28
28
  const option_1 = require("./util_modules/option");
29
29
  const project_1 = require("./util_modules/project");
30
+ const prompt_1 = __importDefault(require("./prompt"));
30
31
  exports.clientUtils = {
31
- validate: () => __awaiter(void 0, void 0, void 0, function* () {
32
- const sourceDir = project_1.resolveProjectPath(config_1.clientConfig.source());
32
+ validate: (source) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const sourceDir = source || project_1.resolveProjectPath(config_1.clientConfig.source());
33
34
  const packageJsonFile = path_1.join(sourceDir, constants_1.FILENAME.client.package_json);
34
35
  const sourceDirExists = yield fs_1.ASYNC.dirExists(sourceDir);
35
36
  if (!sourceDirExists) {
@@ -71,8 +72,8 @@ exports.clientUtils = {
71
72
  runtime_store_1.default.set('context.client.source', sourceDir);
72
73
  runtime_store_1.default.set('context.client.login_redirect', loginRedirect || homepage);
73
74
  runtime_store_1.default.set('context.client.package_json', packageJsonFile);
74
- const validatePlugin = yield plugin_loader_1.default('client', 'validate');
75
- if (validatePlugin === undefined) {
75
+ const validatePlugin = yield plugin_loader_1.default('client', 'validate').catch((err) => logger_1.debug(err));
76
+ if (typeof validatePlugin !== 'function') {
76
77
  runtime_store_1.default.set('context.client.valid', true);
77
78
  return packageJson;
78
79
  }
@@ -80,16 +81,17 @@ exports.clientUtils = {
80
81
  yield validatePlugin(option_1.getCurrentCommand(), sourceDir, runtime_store_1.default, packageJson);
81
82
  }
82
83
  catch (e) {
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
- ]
84
+ const err = error_1.default.getErrorInstance(e, {
85
+ skipHelp: false,
86
+ fileName: __filename
92
87
  });
88
+ err.errorId = 'CLIENT-UTILS-5';
89
+ err.arg = [
90
+ 'validating',
91
+ ansi_colors_1.bold(config_1.clientConfig.plugin('validate') || 'unknown'),
92
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
93
+ ];
94
+ throw err;
93
95
  }
94
96
  runtime_store_1.default.set('context.client.valid', true);
95
97
  return packageJson;
@@ -107,8 +109,8 @@ exports.clientUtils = {
107
109
  },
108
110
  pack: () => __awaiter(void 0, void 0, void 0, function* () {
109
111
  let source = project_1.resolveProjectPath(config_1.clientConfig.source());
110
- const buildPlugin = yield plugin_loader_1.default('client', 'build');
111
- if (buildPlugin !== undefined) {
112
+ const buildPlugin = yield plugin_loader_1.default('client', 'build').catch((err) => logger_1.debug(err));
113
+ if (typeof buildPlugin === 'function') {
112
114
  try {
113
115
  logger_1.message(`Plugin : "${runtime_store_1.default.get(`context.client.plugins.build`)}" is used for client deploy`);
114
116
  const outputDir = yield buildPlugin(source, runtime_store_1.default);
@@ -118,20 +120,21 @@ exports.clientUtils = {
118
120
  source = outputDir;
119
121
  }
120
122
  catch (e) {
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
- ]
123
+ const err = error_1.default.getErrorInstance(e, {
124
+ skipHelp: false,
125
+ fileName: __filename
130
126
  });
127
+ err.errorId = 'CLIENT-UTILS-5';
128
+ err.arg = [
129
+ 'building',
130
+ ansi_colors_1.bold(config_1.clientConfig.plugin('build') || 'unknown'),
131
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
132
+ ];
133
+ throw err;
131
134
  }
132
135
  }
133
- const ignore = config_1.clientConfig.ignore(source);
134
- const files = yield fs_1.ASYNC.walk(source, ignore);
136
+ const exclude = config_1.clientConfig.ignore(source);
137
+ const files = yield fs_1.ASYNC.walk(source, { exclude });
135
138
  const zip = new archiver_1.default();
136
139
  files.forEach((file) => {
137
140
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
@@ -147,5 +150,31 @@ exports.clientUtils = {
147
150
  }
148
151
  conf.unset('client');
149
152
  yield conf.save();
153
+ }),
154
+ directoryOverridePrompt: (dir) => __awaiter(void 0, void 0, void 0, function* () {
155
+ const foldeExists = yield fs_1.ASYNC.dirExists(dir);
156
+ if (foldeExists) {
157
+ const overwriteAns = yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' + ansi_colors_1.underline(dir) + ' already exists. Overwrite ?', {
158
+ type: 'confirm',
159
+ defaultAns: false
160
+ }));
161
+ if (!overwriteAns.overwrite) {
162
+ throw new error_1.default('Skipping client setup since unable to override the already existing client', { exit: 0, errorId: 'CLIENT-UTILS-6', arg: [ansi_colors_1.italic.red(dir)] });
163
+ }
164
+ yield fs_1.ASYNC.deleteDir(dir);
165
+ }
166
+ }),
167
+ clientNamePrompt: (question, defaultAns) => __awaiter(void 0, void 0, void 0, function* () {
168
+ const namePrompt = yield prompt_1.default.ask(prompt_1.default.question('name', question, {
169
+ type: 'input',
170
+ defaultAns,
171
+ validate: (ans) => {
172
+ if (ans.match(constants_1.REGEX.client.package_name)) {
173
+ return true;
174
+ }
175
+ return 'Invalid client name';
176
+ }
177
+ }));
178
+ return namePrompt.name;
150
179
  })
151
180
  };
package/lib/client.js CHANGED
@@ -46,8 +46,5 @@ class Client {
46
46
  return cmd.name();
47
47
  });
48
48
  }
49
- onUnknownCommand(actionFn) {
50
- this.cli.action(actionFn);
51
- }
52
49
  }
53
50
  exports.Client = Client;