zcatalyst-cli 1.13.3 → 1.14.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 (159) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +175 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/master.js +18 -5
  72. package/lib/serve/server/lib/node.mjs +41 -0
  73. package/lib/serve/server/lib/web_client/index.js +7 -3
  74. package/lib/serve/server/lib/web_client/server.js +31 -15
  75. package/lib/shell/dependencies/http-functions.js +57 -21
  76. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  77. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  78. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  79. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  80. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  81. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  82. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  83. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  84. package/lib/shell/dependencies/local-function.js +74 -22
  85. package/lib/shell/index.js +11 -2
  86. package/lib/shell/prepare/index.js +21 -0
  87. package/lib/shell/prepare/languages/index.js +8 -2
  88. package/lib/shell/prepare/languages/java.js +39 -2
  89. package/lib/shell/prepare/languages/node.js +21 -2
  90. package/lib/shell/prepare/languages/python.js +65 -0
  91. package/lib/throbber/index.js +3 -1
  92. package/lib/userConfig.js +48 -0
  93. package/lib/util_modules/constants/index.js +3 -1
  94. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  95. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  96. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  97. package/lib/util_modules/constants/lib/default.js +2 -2
  98. package/lib/util_modules/constants/lib/env-path.js +12 -0
  99. package/lib/util_modules/constants/lib/file-names.js +4 -1
  100. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  101. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  102. package/lib/util_modules/constants/lib/runtime.js +2 -1
  103. package/lib/util_modules/constants/lib/scopes.js +1 -0
  104. package/lib/util_modules/constants/lib/template.js +9 -0
  105. package/lib/util_modules/constants/lib/urls.js +2 -6
  106. package/lib/util_modules/context-help.js +2 -0
  107. package/lib/util_modules/fs/lib/async.js +35 -11
  108. package/lib/util_modules/project.js +20 -1
  109. package/package.json +2 -1
  110. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  111. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  112. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  113. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  115. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  116. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  117. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  118. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  120. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  121. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  122. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  123. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  124. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  125. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  128. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  129. package/templates/init/functions/python/aio/requirements.txt +1 -0
  130. package/templates/init/functions/python/aio/sample.py +26 -0
  131. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/bio/requirements.txt +1 -0
  133. package/templates/init/functions/python/bio/sample.py +6 -0
  134. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/cron/requirements.txt +1 -0
  136. package/templates/init/functions/python/cron/sample.py +18 -0
  137. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/event/requirements.txt +1 -0
  139. package/templates/init/functions/python/event/sample.py +21 -0
  140. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  142. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  143. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  148. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  149. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  150. package/lib/serve/server/lib/node.js +0 -62
  151. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  152. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  153. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  154. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  155. package/templates/.DS_Store +0 -0
  156. package/templates/init/.DS_Store +0 -0
  157. package/templates/init/client/.DS_Store +0 -0
  158. package/templates/init/client/react/.DS_Store +0 -0
  159. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -1,267 +1,302 @@
1
- "use strict";
2
1
  const stringWidth = require('string-width');
2
+
3
3
  function codeRegex(capture) {
4
- return capture ? /\u001b\[((?:\d*;){0,5}\d*)m/g : /\u001b\[(?:\d*;){0,5}\d*m/g;
4
+ return capture ? /\u001b\[((?:\d*;){0,5}\d*)m/g : /\u001b\[(?:\d*;){0,5}\d*m/g;
5
5
  }
6
+
6
7
  function strlen(str) {
7
- const code = codeRegex();
8
- const stripped = ('' + str).replace(code, '');
9
- const split = stripped.split('\n');
10
- return split.reduce((memo, s) => {
11
- return stringWidth(s) > memo ? stringWidth(s) : memo;
12
- }, 0);
8
+ const code = codeRegex();
9
+ const stripped = ('' + str).replace(code, '');
10
+ const split = stripped.split('\n');
11
+ return split.reduce((memo, s) => {
12
+ return stringWidth(s) > memo ? stringWidth(s) : memo;
13
+ }, 0);
13
14
  }
15
+
14
16
  function repeat(str, times) {
15
- return Array(times + 1).join(str);
17
+ return Array(times + 1).join(str);
16
18
  }
19
+
17
20
  function pad(str, len, pad, dir) {
18
- const length = strlen(str);
19
- if (len + 1 >= length) {
20
- const padlen = len - length;
21
- switch (dir) {
22
- case 'right': {
23
- str = repeat(pad, padlen) + str;
24
- break;
25
- }
26
- case 'center': {
27
- const right = Math.ceil(padlen / 2);
28
- const left = padlen - right;
29
- str = repeat(pad, left) + str + repeat(pad, right);
30
- break;
31
- }
32
- default: {
33
- str = str + repeat(pad, padlen);
34
- break;
35
- }
36
- }
37
- }
38
- return str;
21
+ const length = strlen(str);
22
+ if (len + 1 >= length) {
23
+ const padlen = len - length;
24
+ switch (dir) {
25
+ case 'right': {
26
+ str = repeat(pad, padlen) + str;
27
+ break;
28
+ }
29
+ case 'center': {
30
+ const right = Math.ceil(padlen / 2);
31
+ const left = padlen - right;
32
+ str = repeat(pad, left) + str + repeat(pad, right);
33
+ break;
34
+ }
35
+ default: {
36
+ str = str + repeat(pad, padlen);
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ return str;
39
42
  }
43
+
40
44
  const codeCache = {};
45
+
41
46
  function addToCodeCache(name, on, off) {
42
- on = '\u001b[' + on + 'm';
43
- off = '\u001b[' + off + 'm';
44
- codeCache[on] = { set: name, to: true };
45
- codeCache[off] = { set: name, to: false };
46
- codeCache[name] = { on: on, off: off };
47
+ on = '\u001b[' + on + 'm';
48
+ off = '\u001b[' + off + 'm';
49
+ codeCache[on] = { set: name, to: true };
50
+ codeCache[off] = { set: name, to: false };
51
+ codeCache[name] = { on: on, off: off };
47
52
  }
53
+
54
+ // https://github.com/Marak/colors.js/blob/master/lib/styles.js
48
55
  addToCodeCache('bold', 1, 22);
49
56
  addToCodeCache('italics', 3, 23);
50
57
  addToCodeCache('underline', 4, 24);
51
58
  addToCodeCache('inverse', 7, 27);
52
59
  addToCodeCache('strikethrough', 9, 29);
60
+
53
61
  function updateState(state, controlChars) {
54
- const controlCode = controlChars[1] ? parseInt(controlChars[1].split(';')[0]) : 0;
55
- if ((controlCode >= 30 && controlCode <= 39) || (controlCode >= 90 && controlCode <= 97)) {
56
- state.lastForegroundAdded = controlChars[0];
57
- return;
58
- }
59
- if ((controlCode >= 40 && controlCode <= 49) || (controlCode >= 100 && controlCode <= 107)) {
60
- state.lastBackgroundAdded = controlChars[0];
61
- return;
62
- }
63
- if (controlCode === 0) {
64
- for (const i in state) {
65
- if (Object.prototype.hasOwnProperty.call(state, i)) {
66
- delete state[i];
67
- }
68
- }
69
- return;
70
- }
71
- const info = codeCache[controlChars[0]];
72
- if (info) {
73
- state[info.set] = info.to;
74
- }
62
+ const controlCode = controlChars[1] ? parseInt(controlChars[1].split(';')[0]) : 0;
63
+ if ((controlCode >= 30 && controlCode <= 39) || (controlCode >= 90 && controlCode <= 97)) {
64
+ state.lastForegroundAdded = controlChars[0];
65
+ return;
66
+ }
67
+ if ((controlCode >= 40 && controlCode <= 49) || (controlCode >= 100 && controlCode <= 107)) {
68
+ state.lastBackgroundAdded = controlChars[0];
69
+ return;
70
+ }
71
+ if (controlCode === 0) {
72
+ for (const i in state) {
73
+ /* istanbul ignore else */
74
+ if (Object.prototype.hasOwnProperty.call(state, i)) {
75
+ delete state[i];
76
+ }
77
+ }
78
+ return;
79
+ }
80
+ const info = codeCache[controlChars[0]];
81
+ if (info) {
82
+ state[info.set] = info.to;
83
+ }
75
84
  }
85
+
76
86
  function readState(line) {
77
- const code = codeRegex(true);
78
- let controlChars = code.exec(line);
79
- const state = {};
80
- while (controlChars !== null) {
81
- updateState(state, controlChars);
82
- controlChars = code.exec(line);
83
- }
84
- return state;
87
+ const code = codeRegex(true);
88
+ let controlChars = code.exec(line);
89
+ const state = {};
90
+ while (controlChars !== null) {
91
+ updateState(state, controlChars);
92
+ controlChars = code.exec(line);
93
+ }
94
+ return state;
85
95
  }
96
+
86
97
  function unwindState(state, ret) {
87
- const lastBackgroundAdded = state.lastBackgroundAdded;
88
- const lastForegroundAdded = state.lastForegroundAdded;
89
- delete state.lastBackgroundAdded;
90
- delete state.lastForegroundAdded;
91
- Object.keys(state).forEach((key) => {
92
- if (state[key]) {
93
- ret += codeCache[key].off;
94
- }
95
- });
96
- if (lastBackgroundAdded && lastBackgroundAdded != '\u001b[49m') {
97
- ret += '\u001b[49m';
98
- }
99
- if (lastForegroundAdded && lastForegroundAdded != '\u001b[39m') {
100
- ret += '\u001b[39m';
101
- }
102
- return ret;
98
+ const lastBackgroundAdded = state.lastBackgroundAdded;
99
+ const lastForegroundAdded = state.lastForegroundAdded;
100
+
101
+ delete state.lastBackgroundAdded;
102
+ delete state.lastForegroundAdded;
103
+
104
+ Object.keys(state).forEach((key) => {
105
+ if (state[key]) {
106
+ ret += codeCache[key].off;
107
+ }
108
+ });
109
+
110
+ if (lastBackgroundAdded && lastBackgroundAdded != '\u001b[49m') {
111
+ ret += '\u001b[49m';
112
+ }
113
+ if (lastForegroundAdded && lastForegroundAdded != '\u001b[39m') {
114
+ ret += '\u001b[39m';
115
+ }
116
+
117
+ return ret;
103
118
  }
119
+
104
120
  function rewindState(state, ret) {
105
- const lastBackgroundAdded = state.lastBackgroundAdded;
106
- const lastForegroundAdded = state.lastForegroundAdded;
107
- delete state.lastBackgroundAdded;
108
- delete state.lastForegroundAdded;
109
- Object.keys(state).forEach((key) => {
110
- if (state[key]) {
111
- ret = codeCache[key].on + ret;
112
- }
113
- });
114
- if (lastBackgroundAdded && lastBackgroundAdded != '\u001b[49m') {
115
- ret = lastBackgroundAdded + ret;
116
- }
117
- if (lastForegroundAdded && lastForegroundAdded != '\u001b[39m') {
118
- ret = lastForegroundAdded + ret;
119
- }
120
- return ret;
121
+ const lastBackgroundAdded = state.lastBackgroundAdded;
122
+ const lastForegroundAdded = state.lastForegroundAdded;
123
+
124
+ delete state.lastBackgroundAdded;
125
+ delete state.lastForegroundAdded;
126
+
127
+ Object.keys(state).forEach((key) => {
128
+ if (state[key]) {
129
+ ret = codeCache[key].on + ret;
130
+ }
131
+ });
132
+
133
+ if (lastBackgroundAdded && lastBackgroundAdded != '\u001b[49m') {
134
+ ret = lastBackgroundAdded + ret;
135
+ }
136
+ if (lastForegroundAdded && lastForegroundAdded != '\u001b[39m') {
137
+ ret = lastForegroundAdded + ret;
138
+ }
139
+
140
+ return ret;
121
141
  }
142
+
122
143
  function truncateWidth(str, desiredLength) {
123
- if (str.length === strlen(str)) {
124
- return str.substr(0, desiredLength);
125
- }
126
- while (strlen(str) > desiredLength) {
127
- str = str.slice(0, -1);
128
- }
129
- return str;
144
+ if (str.length === strlen(str)) {
145
+ return str.substr(0, desiredLength);
146
+ }
147
+
148
+ while (strlen(str) > desiredLength) {
149
+ str = str.slice(0, -1);
150
+ }
151
+
152
+ return str;
130
153
  }
154
+
131
155
  function truncateWidthWithAnsi(str, desiredLength) {
132
- const code = codeRegex(true);
133
- const split = str.split(codeRegex());
134
- let splitIndex = 0;
135
- let retLen = 0;
136
- let ret = '';
137
- let myArray;
138
- const state = {};
139
- while (retLen < desiredLength) {
140
- myArray = code.exec(str);
141
- let toAdd = split[splitIndex];
142
- splitIndex++;
143
- if (retLen + strlen(toAdd) > desiredLength) {
144
- toAdd = truncateWidth(toAdd, desiredLength - retLen);
145
- }
146
- ret += toAdd;
147
- retLen += strlen(toAdd);
148
- if (retLen < desiredLength) {
149
- if (!myArray) {
150
- break;
151
- }
152
- ret += myArray[0];
153
- updateState(state, myArray);
154
- }
155
- }
156
- return unwindState(state, ret);
156
+ const code = codeRegex(true);
157
+ const split = str.split(codeRegex());
158
+ let splitIndex = 0;
159
+ let retLen = 0;
160
+ let ret = '';
161
+ let myArray;
162
+ const state = {};
163
+
164
+ while (retLen < desiredLength) {
165
+ myArray = code.exec(str);
166
+ let toAdd = split[splitIndex];
167
+ splitIndex++;
168
+ if (retLen + strlen(toAdd) > desiredLength) {
169
+ toAdd = truncateWidth(toAdd, desiredLength - retLen);
170
+ }
171
+ ret += toAdd;
172
+ retLen += strlen(toAdd);
173
+
174
+ if (retLen < desiredLength) {
175
+ if (!myArray) {
176
+ break;
177
+ } // full-width chars may cause a whitespace which cannot be filled
178
+ ret += myArray[0];
179
+ updateState(state, myArray);
180
+ }
181
+ }
182
+
183
+ return unwindState(state, ret);
157
184
  }
185
+
158
186
  function truncate(str, desiredLength, truncateChar) {
159
- truncateChar = truncateChar || '…';
160
- const lengthOfStr = strlen(str);
161
- if (lengthOfStr <= desiredLength) {
162
- return str;
163
- }
164
- desiredLength -= strlen(truncateChar);
165
- const ret = truncateWidthWithAnsi(str, desiredLength);
166
- return ret + truncateChar;
187
+ truncateChar = truncateChar || '…';
188
+ const lengthOfStr = strlen(str);
189
+ if (lengthOfStr <= desiredLength) {
190
+ return str;
191
+ }
192
+ desiredLength -= strlen(truncateChar);
193
+
194
+ const ret = truncateWidthWithAnsi(str, desiredLength);
195
+
196
+ return ret + truncateChar;
167
197
  }
198
+
168
199
  function defaultOptions() {
169
- return {
170
- chars: {
171
- top: '─',
172
- 'top-mid': '┬',
173
- 'top-left': '┌',
174
- 'top-right': '┐',
175
- bottom: '─',
176
- 'bottom-mid': '┴',
177
- 'bottom-left': '└',
178
- 'bottom-right': '┘',
179
- left: '│',
180
- 'left-mid': '├',
181
- mid: '─',
182
- 'mid-mid': '┼',
183
- right: '│',
184
- 'right-mid': '┤',
185
- middle: '│'
186
- },
187
- truncate: '…',
188
- colWidths: [],
189
- rowHeights: [],
190
- colAligns: [],
191
- rowAligns: [],
192
- style: {
193
- 'padding-left': 1,
194
- 'padding-right': 1,
195
- head: ['red'],
196
- border: ['grey'],
197
- compact: false
198
- },
199
- head: []
200
- };
200
+ return {
201
+ chars: {
202
+ top: '─',
203
+ 'top-mid': '┬',
204
+ 'top-left': '┌',
205
+ 'top-right': '┐',
206
+ bottom: '─',
207
+ 'bottom-mid': '┴',
208
+ 'bottom-left': '└',
209
+ 'bottom-right': '┘',
210
+ left: '│',
211
+ 'left-mid': '├',
212
+ mid: '─',
213
+ 'mid-mid': '┼',
214
+ right: '│',
215
+ 'right-mid': '┤',
216
+ middle: '│'
217
+ },
218
+ truncate: '…',
219
+ colWidths: [],
220
+ rowHeights: [],
221
+ colAligns: [],
222
+ rowAligns: [],
223
+ style: {
224
+ 'padding-left': 1,
225
+ 'padding-right': 1,
226
+ head: ['red'],
227
+ border: ['grey'],
228
+ compact: false
229
+ },
230
+ head: []
231
+ };
201
232
  }
233
+
202
234
  function mergeOptions(options, defaults) {
203
- options = options || {};
204
- defaults = defaults || defaultOptions();
205
- const ret = Object.assign({}, defaults, options);
206
- ret.chars = Object.assign({}, defaults.chars, options.chars);
207
- ret.style = Object.assign({}, defaults.style, options.style);
208
- return ret;
235
+ options = options || {};
236
+ defaults = defaults || defaultOptions();
237
+ const ret = Object.assign({}, defaults, options);
238
+ ret.chars = Object.assign({}, defaults.chars, options.chars);
239
+ ret.style = Object.assign({}, defaults.style, options.style);
240
+ return ret;
209
241
  }
242
+
210
243
  function wordWrap(maxLength, input) {
211
- const lines = [];
212
- const split = input.split(/(\s+)/g);
213
- let line = [];
214
- let lineLength = 0;
215
- let whitespace;
216
- for (let i = 0; i < split.length; i += 2) {
217
- const word = split[i];
218
- let newLength = lineLength + strlen(word);
219
- if (lineLength > 0 && whitespace) {
220
- newLength += whitespace.length;
221
- }
222
- if (newLength > maxLength) {
223
- if (lineLength !== 0) {
224
- lines.push(line.join(''));
225
- }
226
- line = [word];
227
- lineLength = strlen(word);
228
- }
229
- else {
230
- line.push(whitespace || '', word);
231
- lineLength = newLength;
232
- }
233
- whitespace = split[i + 1];
234
- }
235
- if (lineLength) {
236
- lines.push(line.join(''));
237
- }
238
- return lines;
244
+ const lines = [];
245
+ const split = input.split(/(\s+)/g);
246
+ let line = [];
247
+ let lineLength = 0;
248
+ let whitespace;
249
+ for (let i = 0; i < split.length; i += 2) {
250
+ const word = split[i];
251
+ let newLength = lineLength + strlen(word);
252
+ if (lineLength > 0 && whitespace) {
253
+ newLength += whitespace.length;
254
+ }
255
+ if (newLength > maxLength) {
256
+ if (lineLength !== 0) {
257
+ lines.push(line.join(''));
258
+ }
259
+ line = [word];
260
+ lineLength = strlen(word);
261
+ } else {
262
+ line.push(whitespace || '', word);
263
+ lineLength = newLength;
264
+ }
265
+ whitespace = split[i + 1];
266
+ }
267
+ if (lineLength) {
268
+ lines.push(line.join(''));
269
+ }
270
+ return lines;
239
271
  }
272
+
240
273
  function multiLineWordWrap(maxLength, input) {
241
- const output = [];
242
- input = input.split('\n');
243
- for (let i = 0; i < input.length; i++) {
244
- output.push.apply(output, wordWrap(maxLength, input[i]));
245
- }
246
- return output;
274
+ const output = [];
275
+ input = input.split('\n');
276
+ for (let i = 0; i < input.length; i++) {
277
+ output.push.apply(output, wordWrap(maxLength, input[i]));
278
+ }
279
+ return output;
247
280
  }
281
+
248
282
  function colorizeLines(input) {
249
- let state = {};
250
- const output = [];
251
- for (let i = 0; i < input.length; i++) {
252
- const line = rewindState(state, input[i]);
253
- state = readState(line);
254
- const temp = Object.assign({}, state);
255
- output.push(unwindState(temp, line));
256
- }
257
- return output;
283
+ let state = {};
284
+ const output = [];
285
+ for (let i = 0; i < input.length; i++) {
286
+ const line = rewindState(state, input[i]);
287
+ state = readState(line);
288
+ const temp = Object.assign({}, state);
289
+ output.push(unwindState(temp, line));
290
+ }
291
+ return output;
258
292
  }
293
+
259
294
  module.exports = {
260
- strlen: strlen,
261
- repeat: repeat,
262
- pad: pad,
263
- truncate: truncate,
264
- mergeOptions: mergeOptions,
265
- wordWrap: multiLineWordWrap,
266
- colorizeLines: colorizeLines
295
+ strlen: strlen,
296
+ repeat: repeat,
297
+ pad: pad,
298
+ truncate: truncate,
299
+ mergeOptions: mergeOptions,
300
+ wordWrap: multiLineWordWrap,
301
+ colorizeLines: colorizeLines
267
302
  };
@@ -58,13 +58,25 @@ exports.clientUtils = {
58
58
  });
59
59
  }
60
60
  const name = js_1.JS.get(packageJson, 'name', null);
61
- const homepage = js_1.JS.get(packageJson, 'homepage', null);
61
+ const homepage = js_1.JS.get(packageJson, 'homepage', 'index.html');
62
+ const notFoundPagePath = js_1.JS.get(packageJson, '404', '404.html');
63
+ if (homepage === notFoundPagePath) {
64
+ throw new error_1.default('404 page and homepage cannot be the same', {
65
+ exit: 1,
66
+ errorId: 'CLIENT-UTILS-7',
67
+ arg: [(0, ansi_colors_1.bold)('404'), (0, ansi_colors_1.bold)('HOME'), ansi_colors_1.italic.red(homepage)]
68
+ });
69
+ }
70
+ const notFoundPage = notFoundPagePath && (yield fs_1.ASYNC.fileExists((0, path_1.resolve)(sourceDir, notFoundPagePath)))
71
+ ? (0, path_1.resolve)(sourceDir, notFoundPagePath)
72
+ : (yield fs_1.ASYNC.fileExists((0, path_1.join)(sourceDir, constants_1.FILENAME.client.notFoundPage))) &&
73
+ (0, path_1.join)(sourceDir, constants_1.FILENAME.client.notFoundPage);
62
74
  const loginRedirect = runtime_store_1.default.get('context.client.login_redirect', packageJson.login_redirect);
63
- if (js_1.JS.isNull(name) || js_1.JS.isNull(homepage)) {
75
+ if (js_1.JS.isNull(name)) {
64
76
  throw new error_1.default(constants_1.FILENAME.client.package_json + ' file is corrupted.', {
65
77
  exit: 1,
66
78
  errorId: 'CLIENT-UTILS-4',
67
- arg: [(0, ansi_colors_1.bold)(packageJsonFile), (0, ansi_colors_1.bold)('name'), (0, ansi_colors_1.bold)('homepage')]
79
+ arg: [(0, ansi_colors_1.bold)(packageJsonFile), (0, ansi_colors_1.bold)('name')]
68
80
  });
69
81
  }
70
82
  runtime_store_1.default.set('context.client.name', name);
@@ -72,6 +84,7 @@ exports.clientUtils = {
72
84
  runtime_store_1.default.set('context.client.source', sourceDir);
73
85
  runtime_store_1.default.set('context.client.login_redirect', loginRedirect || homepage);
74
86
  runtime_store_1.default.set('context.client.package_json', packageJsonFile);
87
+ runtime_store_1.default.set('context.client.notFoundPage', notFoundPage);
75
88
  const validatePlugin = yield (0, plugin_loader_1.default)('client', 'validate').catch((err) => (0, logger_1.debug)(err));
76
89
  if (typeof validatePlugin !== 'function') {
77
90
  runtime_store_1.default.set('context.client.valid', true);
@@ -120,6 +133,7 @@ exports.clientUtils = {
120
133
  let source = (0, project_1.resolveProjectPath)(config_1.clientConfig.source());
121
134
  const buildPlugin = yield (0, plugin_loader_1.default)('client', 'build').catch((err) => (0, logger_1.debug)(err));
122
135
  if (typeof buildPlugin === 'function') {
136
+ process.env.X_CATALYST_WEBAPP_PATH = source;
123
137
  const logStreamPlugin = yield (0, plugin_loader_1.default)('client', 'logs').catch((err) => (0, logger_1.debug)(err));
124
138
  let stream;
125
139
  const streamLogFn = (chunk) => (0, logger_1.log)('info', chunk.toString(), true);
@@ -154,7 +168,7 @@ exports.clientUtils = {
154
168
  }
155
169
  }
156
170
  const exclude = config_1.clientConfig.ignore(source);
157
- const files = yield fs_1.ASYNC.walk(source, { exclude });
171
+ const files = yield fs_1.ASYNC.walk(source, { filter: { exclude, excludeDir: true } });
158
172
  const zip = new archiver_1.default();
159
173
  files.forEach((file) => {
160
174
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));