zcatalyst-cli 1.10.0 → 1.12.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 (137) hide show
  1. package/docs/.DS_Store +0 -0
  2. package/docs/client-utils.toml +5 -0
  3. package/docs/command_needs/auth.toml +1 -1
  4. package/docs/optional-import.toml +10 -0
  5. package/docs/plugin-loader.toml +4 -0
  6. package/docs/serve/server/index.toml +4 -0
  7. package/docs/serve/server/lib/web_client/server.toml +4 -0
  8. package/lib/apig-utils.js +2 -1
  9. package/lib/archiver.js +3 -3
  10. package/lib/client-utils.js +8 -6
  11. package/lib/command_needs/auth.js +2 -2
  12. package/lib/commands/client/delete.js +1 -0
  13. package/lib/commands/event/generate/index.js +4 -13
  14. package/lib/commands/functions/shell.js +5 -2
  15. package/lib/commands/iac/import.js +29 -6
  16. package/lib/commands/init.js +1 -1
  17. package/lib/commands/pull.js +1 -1
  18. package/lib/commands/serve.js +2 -1
  19. package/lib/endpoints/lib/sdk.js +2 -2
  20. package/lib/error.js +16 -13
  21. package/lib/errorOut.js +2 -2
  22. package/lib/fn-utils/lib/common.js +6 -5
  23. package/lib/fn-utils/lib/java.js +1 -1
  24. package/lib/fn-utils/lib/node.js +2 -2
  25. package/lib/init/dependencies/npm-install.js +10 -10
  26. package/lib/init/features/client/index.js +47 -0
  27. package/lib/init/features/client/initializers/angular.js +104 -0
  28. package/lib/init/features/client/initializers/basic.js +50 -0
  29. package/lib/init/features/client/initializers/lyte.js +56 -0
  30. package/lib/init/features/client/initializers/react.js +78 -0
  31. package/lib/init/features/functions/languages/node.js +3 -1
  32. package/lib/init/features/index.js +10 -3
  33. package/lib/init/features/project.js +2 -1
  34. package/lib/init/util/client.js +89 -4
  35. package/lib/internal/command.js +4 -1
  36. package/lib/internal/config.js +2 -1
  37. package/lib/optional-import.js +27 -26
  38. package/lib/plugin-loader.js +27 -10
  39. package/lib/port-resolver.js +4 -2
  40. package/lib/serve/index.js +6 -1
  41. package/lib/serve/server/index.js +52 -8
  42. package/lib/serve/server/lib/master.js +24 -12
  43. package/lib/serve/server/lib/web_client/index.js +30 -0
  44. package/lib/serve/server/lib/web_client/server.js +171 -0
  45. package/lib/shell/index.js +10 -6
  46. package/lib/util_modules/char.js +1 -1
  47. package/lib/util_modules/config/lib/apig.js +2 -1
  48. package/lib/util_modules/config/lib/client.js +18 -21
  49. package/lib/util_modules/constants/index.js +3 -1
  50. package/lib/util_modules/constants/lib/placeholders.js +1 -0
  51. package/lib/util_modules/constants/lib/plugin.js +28 -0
  52. package/lib/util_modules/constants/lib/template.js +11 -1
  53. package/lib/util_modules/constants/lib/urls.js +29 -13
  54. package/lib/util_modules/{contextHelp.js → context-help.js} +0 -0
  55. package/lib/util_modules/env.js +13 -12
  56. package/lib/util_modules/fs/index.js +1 -9
  57. package/lib/util_modules/fs/lib/async.js +3 -3
  58. package/lib/util_modules/fs/utils.js +8 -0
  59. package/lib/util_modules/global-space.js +2 -0
  60. package/lib/util_modules/option.js +5 -1
  61. package/lib/util_modules/shell.js +10 -6
  62. package/lib/winston.js +1 -1
  63. package/package.json +7 -4
  64. package/templates/.DS_Store +0 -0
  65. package/templates/init/.DS_Store +0 -0
  66. package/templates/init/client/.DS_Store +0 -0
  67. package/templates/init/client/{client-package.json → basic/client-package.json} +0 -0
  68. package/templates/init/client/{index.html → basic/index.html} +0 -0
  69. package/templates/init/client/{main.css → basic/main.css} +0 -0
  70. package/templates/init/client/{main.js → basic/main.js} +0 -0
  71. package/templates/init/client/lyte/build/build.js +301 -0
  72. package/templates/init/client/lyte/build/scripts/cliDownloadScript.js +54 -0
  73. package/templates/init/client/lyte/client-package.json +5 -0
  74. package/templates/init/client/lyte/components/javascript/welcome-comp.js +13 -0
  75. package/templates/init/client/lyte/components/styles/welcome-comp.css +0 -0
  76. package/templates/init/client/lyte/components/templates/welcome-comp.html +8 -0
  77. package/templates/init/client/lyte/data-store/adapters/.gitkeep +0 -0
  78. package/templates/init/client/lyte/data-store/models/.gitkeep +0 -0
  79. package/templates/init/client/lyte/data-store/serializers/.gitkeep +0 -0
  80. package/templates/init/client/lyte/index.html +17 -0
  81. package/templates/init/client/lyte/package.json +12 -0
  82. package/templates/init/client/lyte/router.js +14 -0
  83. package/templates/init/client/lyte/routes/index.js +54 -0
  84. package/templates/init/client/react/.DS_Store +0 -0
  85. package/templates/init/client/react/react_js/package.json +11 -0
  86. package/templates/init/client/react/react_js/template/README.md +70 -0
  87. package/templates/init/client/react/react_js/template/client-package.json +5 -0
  88. package/templates/init/client/react/react_js/template/gitignore +23 -0
  89. package/templates/init/client/react/react_js/template/public/favicon.ico +0 -0
  90. package/templates/init/client/react/react_js/template/public/index.html +43 -0
  91. package/templates/init/client/react/react_js/template/public/logo192.png +0 -0
  92. package/templates/init/client/react/react_js/template/public/logo512.png +0 -0
  93. package/templates/init/client/react/react_js/template/public/manifest.json +25 -0
  94. package/templates/init/client/react/react_js/template/public/robots.txt +3 -0
  95. package/templates/init/client/react/react_js/template/src/App.css +38 -0
  96. package/templates/init/client/react/react_js/template/src/App.js +25 -0
  97. package/templates/init/client/react/react_js/template/src/App.test.js +8 -0
  98. package/templates/init/client/react/react_js/template/src/index.css +13 -0
  99. package/templates/init/client/react/react_js/template/src/index.js +17 -0
  100. package/templates/init/client/react/react_js/template/src/logo.svg +1 -0
  101. package/templates/init/client/react/react_js/template/src/reportWebVitals.js +13 -0
  102. package/templates/init/client/react/react_js/template/src/setupTests.js +5 -0
  103. package/templates/init/client/react/react_js/template.json +13 -0
  104. package/templates/init/client/react/react_ts/package.json +11 -0
  105. package/templates/init/client/react/react_ts/template/README.md +46 -0
  106. package/templates/init/client/react/react_ts/template/client-package.json +5 -0
  107. package/templates/init/client/react/react_ts/template/gitignore +23 -0
  108. package/templates/init/client/react/react_ts/template/public/favicon.ico +0 -0
  109. package/templates/init/client/react/react_ts/template/public/index.html +43 -0
  110. package/templates/init/client/react/react_ts/template/public/logo192.png +0 -0
  111. package/templates/init/client/react/react_ts/template/public/logo512.png +0 -0
  112. package/templates/init/client/react/react_ts/template/public/manifest.json +25 -0
  113. package/templates/init/client/react/react_ts/template/public/robots.txt +3 -0
  114. package/templates/init/client/react/react_ts/template/src/App.css +38 -0
  115. package/templates/init/client/react/react_ts/template/src/App.test.tsx +9 -0
  116. package/templates/init/client/react/react_ts/template/src/App.tsx +26 -0
  117. package/templates/init/client/react/react_ts/template/src/index.css +13 -0
  118. package/templates/init/client/react/react_ts/template/src/index.tsx +17 -0
  119. package/templates/init/client/react/react_ts/template/src/logo.svg +1 -0
  120. package/templates/init/client/react/react_ts/template/src/reportWebVitals.ts +15 -0
  121. package/templates/init/client/react/react_ts/template/src/setupTests.ts +5 -0
  122. package/templates/init/client/react/react_ts/template.json +18 -0
  123. package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +96 -111
  124. package/templates/init/functions/java/integ/cliq/com/handlers/CommandHandler.java +20 -27
  125. package/templates/init/functions/java/integ/cliq/com/handlers/FunctionHandler.java +143 -112
  126. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationHandler.java +4 -7
  127. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationValidator.java +4 -7
  128. package/templates/init/functions/java/integ/cliq/com/handlers/MessageActionHandler.java +10 -12
  129. package/templates/init/functions/java/integ/cliq/com/handlers/WidgetHandler.java +100 -66
  130. package/templates/init/functions/java/integ/cliq/sample.java +5 -7
  131. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -3
  132. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +0 -1
  133. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +46 -0
  134. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +31 -0
  135. package/templates/web-socket.txt +21 -0
  136. package/lib/init/features/client.js +0 -50
  137. package/lib/serve/server/lib/client.js +0 -30
@@ -54,7 +54,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
54
54
  runtime_store_1.default.set('context.port.http.master', masterPort);
55
55
  yield Promise.all(serveTargets.map((target) => features[target]()));
56
56
  const rawTargets = runtime_store_1.default.get('context.functions.targets', []);
57
- if (option_1.getOptionValue('watch', false)) {
57
+ const watchOpt = option_1.getOptionValue('watch', false);
58
+ if (watchOpt) {
58
59
  yield Promise.all(rawTargets.map((target) => __awaiter(void 0, void 0, void 0, function* () { return (target.valid ? fn_watcher_1.default(target) : undefined); })));
59
60
  }
60
61
  const funtionTargets = rawTargets.filter((target) => {
@@ -73,6 +74,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
73
74
  if (serveTargets.includes('client')) {
74
75
  const client = runtime_store_1.default.get('context.client', false);
75
76
  if (client && client.valid) {
77
+ client.opts = {
78
+ open: option_1.getOptionValue('open', false),
79
+ watch: watchOpt
80
+ };
76
81
  advancedServer.add('client', client);
77
82
  }
78
83
  else {
@@ -1,4 +1,23 @@
1
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
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,6 +54,7 @@ const js_1 = require("../../util_modules/js");
35
54
  const logger_1 = require("../../util_modules/logger");
36
55
  const shell_1 = require("../../util_modules/shell");
37
56
  const master_1 = __importDefault(require("./lib/master"));
57
+ const ansi_colors_1 = require("ansi-colors");
38
58
  class Server {
39
59
  constructor() {
40
60
  this.targetDetailsArr = [];
@@ -85,8 +105,8 @@ class Server {
85
105
  opts.push(details.httpPort + '');
86
106
  const targetSource = (_c = details.target) === null || _c === void 0 ? void 0 : _c.source;
87
107
  const configType = details.type === 'server' ? 'functions' : details.type;
88
- const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource);
89
- if (servePlugin !== undefined) {
108
+ const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource).catch((err) => logger_1.debug(err));
109
+ if (typeof servePlugin === 'function') {
90
110
  const event = servePlugin(details, masterPort);
91
111
  logger_1.labeled(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
92
112
  return event;
@@ -111,7 +131,7 @@ class Server {
111
131
  const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
112
132
  const _d = details.target, { ['watcher']: _ } = _d, serialisableTarget = __rest(_d, ['watcher']);
113
133
  const opts = [
114
- path_1.join(__dirname, 'lib', details.type === 'client' ? 'client.js' : 'node.js'),
134
+ path_1.join(__dirname, 'lib', 'node.js'),
115
135
  details.httpPort + '',
116
136
  JSON.stringify(serialisableTarget)
117
137
  ];
@@ -121,12 +141,28 @@ class Server {
121
141
  }
122
142
  const targetSource = (_b = details.target) === null || _b === void 0 ? void 0 : _b.source;
123
143
  const configType = details.type === 'server' ? 'functions' : details.type;
124
- const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource);
125
- if (servePlugin !== undefined) {
126
- const event = servePlugin(details, masterPort);
144
+ const servePlugin = yield plugin_loader_1.default(configType, 'start', targetSource).catch((err) => logger_1.debug(err));
145
+ if (typeof servePlugin === 'function') {
146
+ const event = servePlugin(details, masterPort).catch((e) => {
147
+ var _a, _b;
148
+ const err = error_1.default.getErrorInstance(e, {
149
+ fileName: __filename,
150
+ skipHelp: false
151
+ });
152
+ err.errorId = 'SERVE-IDX-1';
153
+ err.arg = [
154
+ configType,
155
+ ansi_colors_1.bold(((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.start)[targetSource] || 'start'),
156
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
157
+ ];
158
+ throw err;
159
+ });
127
160
  logger_1.labeled(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
128
161
  return event;
129
162
  }
163
+ if (details.type === 'client') {
164
+ return yield (yield Promise.resolve().then(() => __importStar(require('./lib/web_client/index.js')))).default(details, masterPort);
165
+ }
130
166
  const child = shell_1.spawn('node', opts, {
131
167
  cwd: targetSource,
132
168
  stdio: 'pipe',
@@ -136,7 +172,7 @@ class Server {
136
172
  X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
137
173
  }
138
174
  }).RAW();
139
- logger_1.labeled(label, `URL : http://localhost:${masterPort}/${details.type === 'client' ? 'app/' : 'server/' + ((_c = details.target) === null || _c === void 0 ? void 0 : _c.name) + '/'}`).MESSAGE();
175
+ logger_1.labeled(label, `URL : http://localhost:${masterPort}/server/${(_c = details.target) === null || _c === void 0 ? void 0 : _c.name}/`).MESSAGE();
140
176
  logger_1.info();
141
177
  return child;
142
178
  });
@@ -196,7 +232,15 @@ class Server {
196
232
  this.masterServer = server;
197
233
  return new Promise((res) => {
198
234
  server.on('listening', () => {
199
- this.targetDetailsArr.forEach((targetDetails) => { var _a; return (_a = targetDetails.process) === null || _a === void 0 ? void 0 : _a.emit('start'); });
235
+ this.targetDetailsArr.forEach((targetDetails) => {
236
+ var _a;
237
+ if (targetDetails.process &&
238
+ 'send' in targetDetails.process) {
239
+ targetDetails.process.send('start');
240
+ return;
241
+ }
242
+ (_a = targetDetails.process) === null || _a === void 0 ? void 0 : _a.emit('start');
243
+ });
200
244
  res();
201
245
  });
202
246
  });
@@ -122,26 +122,36 @@ function spinUpMaster(listenPort, otherServerDetails) {
122
122
  app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
123
123
  }
124
124
  const proxy = http_proxy_1.createProxyServer()
125
- .on('error', (err, req) => {
125
+ .on('error', (err, req, res) => {
126
+ res.writeHead(503, { 'Content-Type': 'json' });
127
+ res.write(JSON.stringify({ error: 'unable to proxy request' }));
128
+ res.end();
126
129
  console.log('unable to proxy request ', req.url);
127
130
  console.error(err);
128
131
  })
129
- .on('proxyRes', proxyResponseHandler(systemRoutes));
132
+ .on('proxyRes', proxyResponseHandler(systemRoutes))
133
+ .on('proxyReq', (proxyReq) => {
134
+ const id = js_1.JS.randomNumber(4) + '';
135
+ connections[id] = proxyReq;
136
+ proxyReq.on('finish', () => {
137
+ delete connections[id];
138
+ });
139
+ })
140
+ .on('close', () => logger_2.debug('proxy closed'));
130
141
  otherServerDetails.forEach((serverDetail) => {
131
142
  var _a, _b, _c, _d, _e, _f;
132
143
  switch (serverDetail.type) {
133
144
  case 'client':
134
145
  const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
135
146
  app.use('/app', (req, res) => {
136
- var _a;
137
- if (req.url.startsWith('/local-redirect') &&
138
- ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.login_redirect)) {
139
- const isUrl = serverDetail.target.login_redirect.startsWith('/');
147
+ const target = serverDetail.target;
148
+ if (req.url.startsWith('/local-redirect') && target.login_redirect) {
149
+ const isUrl = target.login_redirect.startsWith('/');
140
150
  if (isUrl) {
141
- res.redirect(serverDetail.target.login_redirect);
151
+ res.redirect(target.login_redirect);
142
152
  }
143
153
  else {
144
- res.redirect('/app/' + serverDetail.target.login_redirect);
154
+ res.redirect('/app/' + target.login_redirect);
145
155
  }
146
156
  }
147
157
  else {
@@ -192,7 +202,8 @@ function spinUpMaster(listenPort, otherServerDetails) {
192
202
  ws: true
193
203
  });
194
204
  });
195
- app.use('/baas/v1/project/:projectId/function/' + ((_f = serverDetail.target) === null || _f === void 0 ? void 0 : _f.id), (req, res) => {
205
+ app.use('/baas/v1/project/:projectId/function/' +
206
+ ((_f = serverDetail.target) === null || _f === void 0 ? void 0 : _f.id), (req, res) => {
196
207
  var _a;
197
208
  proxy.web(req, res, {
198
209
  target: `http://127.0.0.1:${serverDetail.httpPort}/server/${(_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.id}`,
@@ -216,10 +227,11 @@ function spinUpMaster(listenPort, otherServerDetails) {
216
227
  console.error(err);
217
228
  });
218
229
  expressServer.maxConnections = 100;
219
- process.once('SIGINT', () => Object.keys(connections).forEach((sokcetId) => { var _a; return (_a = connections[sokcetId]) === null || _a === void 0 ? void 0 : _a.destroy(); }));
230
+ process.on('SIGINT', () => Object.keys(connections).forEach((connectionId) => {
231
+ connections[connectionId].destroy();
232
+ }));
220
233
  expressServer.on('connection', (socket) => {
221
- const offset = Math.floor(Math.random() * 10);
222
- const id = Date.now() + offset + '';
234
+ const id = js_1.JS.randomNumber(4) + '';
223
235
  connections[id] = socket;
224
236
  socket.on('close', () => {
225
237
  delete connections[id];
@@ -0,0 +1,30 @@
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 open_1 = __importDefault(require("open"));
16
+ const logger_1 = require("../../../../util_modules/logger");
17
+ const server_js_1 = __importDefault(require("./server.js"));
18
+ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a;
20
+ const target = details.target;
21
+ const clientListner = yield server_js_1.default(details.httpPort, target.source, target.homepage, ((_a = target.opts) === null || _a === void 0 ? void 0 : _a.watch) || false);
22
+ clientListner.addListener('start', () => {
23
+ var _a, _b;
24
+ const appUrl = 'http://localhost:' + masterPort;
25
+ const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
26
+ logger_1.labeled(label, `URL : ${appUrl}/app/`).MESSAGE();
27
+ ((_b = details.target.opts) === null || _b === void 0 ? void 0 : _b.open) && open_1.default(appUrl).catch();
28
+ });
29
+ return clientListner;
30
+ });
@@ -0,0 +1,171 @@
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 express_1 = __importDefault(require("express"));
16
+ const events_1 = require("events");
17
+ const chokidar_1 = require("chokidar");
18
+ const logger_js_1 = require("../../../../util_modules/logger.js");
19
+ const index_js_1 = require("../../../../util_modules/constants/index.js");
20
+ const error_js_1 = __importDefault(require("../../../../error.js"));
21
+ const index_js_2 = require("../../../../util_modules/fs/index.js");
22
+ const path_1 = require("path");
23
+ const ws_1 = require("ws");
24
+ const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
25
+ const ansi_colors_1 = require("ansi-colors");
26
+ function prepareScriptFile(dir, port) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const scriptFile = yield index_js_2.ASYNC.readFile(index_js_1.TEMPLATE.client.basic.socket);
29
+ if (!scriptFile) {
30
+ throw new error_js_1.default('Unable to read the script file', { exit: 2 });
31
+ }
32
+ const scriptReady = scriptFile.replace(new RegExp(index_js_1.PLACEHOLDER.client.port, 'g'), port + '');
33
+ yield index_js_2.ASYNC.ensureDir(dir);
34
+ const scriptFilePath = path_1.join(dir, 'reload-script.js');
35
+ yield index_js_2.ASYNC.writeFile(scriptFilePath, scriptReady);
36
+ return scriptFilePath;
37
+ });
38
+ }
39
+ function stringInjector(source, anchorIdx, marker, inject) {
40
+ const headLastIdx = anchorIdx + marker.length;
41
+ const scriptPrefix = source.slice(0, headLastIdx);
42
+ const scriptSuffix = source.slice(headLastIdx);
43
+ return scriptPrefix + inject + scriptSuffix;
44
+ }
45
+ function injectScript(scriptLocale, indexHtml) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const headIdx = indexHtml.search(/<head>/gi);
48
+ const scriptTag = `\n<!-- Catalyst web client reload script -->\n<script type="text/javascript" src="${scriptLocale}"></script>\n`;
49
+ if (headIdx !== -1) {
50
+ return stringInjector(indexHtml, headIdx, '<head>', scriptTag);
51
+ }
52
+ const htmlIdx = indexHtml.search(/<html>/gi);
53
+ const headTag = `\n<head>${scriptTag}</head>\n`;
54
+ return stringInjector(indexHtml, htmlIdx, '<html>', headTag);
55
+ });
56
+ }
57
+ function reloadApp(event, path, liveSockets) {
58
+ logger_js_1.info(ansi_colors_1.cyan(`${event} detected in ${path} of the Web-Client.`));
59
+ liveSockets.forEach((socket) => socket.send('reload'));
60
+ }
61
+ function webClientServer(httpPort, source, homepage, enableWatch) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const eventListener = new events_1.EventEmitter();
64
+ const catalystTempDir = path_1.join(source, '.catalyst');
65
+ const socketServerPort = yield port_resolver_js_1.default.getFreePort(httpPort, 20, true);
66
+ const reloadScriptSrc = enableWatch
67
+ ? path_1.relative(source, yield prepareScriptFile(catalystTempDir, socketServerPort))
68
+ : undefined;
69
+ if (reloadScriptSrc) {
70
+ const clientWatcher = chokidar_1.watch(source, {
71
+ ignoreInitial: true,
72
+ ignored: ['node_modules/**/*']
73
+ });
74
+ const liveSockets = [];
75
+ let watcherReady = false;
76
+ clientWatcher.on('error', (err) => {
77
+ watcherReady = false;
78
+ eventListener.emit('error', new error_js_1.default('client watcher error', {
79
+ original: err,
80
+ exit: 1,
81
+ skipHelp: true
82
+ }));
83
+ });
84
+ clientWatcher.on('ready', () => {
85
+ watcherReady = true;
86
+ const socketServer = new ws_1.WebSocketServer({
87
+ port: socketServerPort,
88
+ path: '/client-reload'
89
+ })
90
+ .on('connection', (clientSocket) => {
91
+ if (!watcherReady) {
92
+ clientSocket.send('watcher not ready');
93
+ clientSocket.close();
94
+ return;
95
+ }
96
+ clientSocket.on('close', () => {
97
+ const socketIdx = liveSockets.findIndex((socket) => socket === clientSocket);
98
+ liveSockets.splice(socketIdx, 1);
99
+ });
100
+ liveSockets.push(clientSocket);
101
+ clientSocket.send('connected');
102
+ })
103
+ .on('error', (err) => logger_js_1.debug(err));
104
+ setTimeout(() => {
105
+ clientWatcher.on('change', (path) => {
106
+ reloadApp('Change(s) is', path_1.relative(source, path), liveSockets);
107
+ });
108
+ clientWatcher.on('add', (path) => {
109
+ reloadApp('Addition of file(s) is', path_1.relative(source, path), liveSockets);
110
+ });
111
+ clientWatcher.on('unlink', (path) => {
112
+ reloadApp('Deletion of file(s) is', path_1.relative(source, path), liveSockets);
113
+ });
114
+ }, 1000);
115
+ eventListener.addListener('close', () => socketServer === null || socketServer === void 0 ? void 0 : socketServer.close());
116
+ });
117
+ eventListener.addListener('close', () => {
118
+ if (clientWatcher) {
119
+ clientWatcher.close();
120
+ }
121
+ liveSockets.forEach((socket) => socket.close());
122
+ index_js_2.SYNC.deleteDir(catalystTempDir);
123
+ });
124
+ }
125
+ const app = express_1.default();
126
+ app.use('/app', (req, res) => __awaiter(this, void 0, void 0, function* () {
127
+ const requestedFile = req.url === '/' ? homepage : decodeURIComponent(req.path);
128
+ if (enableWatch &&
129
+ requestedFile === homepage &&
130
+ (requestedFile.includes('.html') || requestedFile.includes('.htm'))) {
131
+ const homepageFile = yield index_js_2.ASYNC.readFile(path_1.join(source, homepage));
132
+ if (!homepageFile) {
133
+ eventListener.emit('error', new error_js_1.default('Unable to read the homepage file', {
134
+ exit: 1,
135
+ errorId: 'WEB-CLIENT-SERVER-1',
136
+ arg: [ansi_colors_1.red.italic(homepage)]
137
+ }));
138
+ return;
139
+ }
140
+ const injectedHomePage = reloadScriptSrc
141
+ ? yield injectScript(encodeURIComponent(reloadScriptSrc), homepageFile)
142
+ : undefined;
143
+ res.contentType('text/html');
144
+ res.status(200);
145
+ res.send(injectedHomePage || homepageFile);
146
+ return;
147
+ }
148
+ res.sendFile(path_1.join(source, requestedFile), (err) => {
149
+ if (err) {
150
+ logger_js_1.error('Unable to serve the requested file: ' + path_1.join(source, requestedFile));
151
+ logger_js_1.debug(err.stack || err.message);
152
+ res.status(404);
153
+ res.send('Resource not found');
154
+ }
155
+ });
156
+ }));
157
+ const server = app.listen(httpPort).on('error', (err) => {
158
+ eventListener.emit('error', err);
159
+ });
160
+ eventListener.on('error', (err) => {
161
+ logger_js_1.error('Error when serving the web-client: ' + err.message);
162
+ logger_js_1.info('Please exit the command to get more info');
163
+ eventListener.emit('close');
164
+ });
165
+ eventListener.on('close', () => {
166
+ server.close(() => logger_js_1.debug('client server closed'));
167
+ });
168
+ return new Promise((res) => server.on('listening', () => res(eventListener)));
169
+ });
170
+ }
171
+ exports.default = webClientServer;
@@ -21,7 +21,7 @@ const fn_utils_1 = require("../fn-utils");
21
21
  const runtime_store_1 = __importDefault(require("../runtime-store"));
22
22
  const constants_1 = require("../util_modules/constants");
23
23
  const fs_1 = require("../util_modules/fs");
24
- const logger_1 = require("../util_modules/logger");
24
+ const logger_js_1 = require("../util_modules/logger.js");
25
25
  const option_1 = require("../util_modules/option");
26
26
  const http_functions_1 = __importDefault(require("./dependencies/http-functions"));
27
27
  const local_function_1 = __importDefault(require("./dependencies/local-function"));
@@ -50,7 +50,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
50
50
  .get('context.functions.targets', [])
51
51
  .filter((target) => {
52
52
  if (!target.valid) {
53
- logger_1.warning('target [' +
53
+ logger_js_1.warning('target [' +
54
54
  target.name +
55
55
  '] is not a valid one reason : ' +
56
56
  target.failure_reason);
@@ -64,9 +64,13 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
64
64
  });
65
65
  }
66
66
  replServer.start();
67
- const watchOpt = option_1.getOptionValue('watch', false);
67
+ const watchOpt = option_1.getOptionValue('watch');
68
+ if (watchOpt === true) {
69
+ logger_js_1.info();
70
+ logger_js_1.labeled('DEPRECATED', `The ${ansi_colors_1.italic.bold('--watch')} option is deprecated. \nThe watch mode will be enabled by default. If you wish to disable it use the ${ansi_colors_1.italic.bold('--no-watch')} option. \nPlease execute ${ansi_colors_1.bold('catalyst functions:shell ' + ansi_colors_1.italic('--help'))} command for more usage details.`).WARN();
71
+ }
68
72
  yield Promise.all(targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
69
- if (watchOpt) {
73
+ if (watchOpt !== false) {
70
74
  yield fn_watcher_1.default(target);
71
75
  }
72
76
  const localFn = new local_function_1.default(replServer, target);
@@ -85,8 +89,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
85
89
  })));
86
90
  yield fs_1.ASYNC.deleteDir(path_1.join(runtime_store_1.default.get('cwd'), '.build')).catch();
87
91
  fn_utils_1.fnUtils.common.executeHook({ prefix: 'post', command: 'serve' });
88
- logger_1.info();
89
- logger_1.success('shell complete');
92
+ logger_js_1.info();
93
+ logger_js_1.success('shell complete');
90
94
  }
91
95
  catch (e) {
92
96
  yield Promise.all([
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CHAR = void 0;
4
4
  const ansi_colors_1 = require("ansi-colors");
5
5
  const env_1 = require("./env");
6
- const isSupported = !env_1.isWindows() || process.env.CI || process.env.TERM === 'xterm-256color';
6
+ const isSupported = !env_1.isWindows || process.env.CI || process.env.TERM === 'xterm-256color';
7
7
  exports.CHAR = {
8
8
  success: isSupported ? ansi_colors_1.bold.green('✔') : ansi_colors_1.bold.green('√'),
9
9
  warning: isSupported ? ansi_colors_1.bold.yellow('⚠') : ansi_colors_1.bold.yellow('‼'),
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.script = exports.enabled = exports.rules = exports.raw = void 0;
6
+ exports.source = exports.script = exports.enabled = exports.rules = exports.raw = void 0;
7
7
  const error_1 = __importDefault(require("../../../error"));
8
8
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
9
9
  const constants_1 = require("../../constants");
@@ -43,3 +43,4 @@ function script(name, fallback) {
43
43
  return (rawScripts && rawScripts[name]) || fallback;
44
44
  }
45
45
  exports.script = script;
46
+ exports.source = rules;
@@ -5,16 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.script = exports.ignore = exports.plugin = exports.source = exports.raw = void 0;
7
7
  const path_1 = require("path");
8
- const error_1 = __importDefault(require("../../../error"));
9
- const runtime_store_1 = __importDefault(require("../../../runtime-store"));
10
- const constants_1 = require("../../constants");
11
- const js_1 = require("../../js");
12
- const logger_1 = require("../../logger");
8
+ const error_js_1 = __importDefault(require("../../../error.js"));
9
+ const runtime_store_js_1 = __importDefault(require("../../../runtime-store.js"));
10
+ const file_names_js_1 = __importDefault(require("../../constants/lib/file-names.js"));
11
+ const folder_names_js_1 = __importDefault(require("../../constants/lib/folder-names.js"));
12
+ const js_js_1 = require("../../js.js");
13
13
  function raw(throwError = false) {
14
- const config = runtime_store_1.default.get('config', null);
14
+ const config = runtime_store_js_1.default.get('config', null);
15
15
  if (config === null) {
16
16
  if (throwError) {
17
- throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 2 });
17
+ throw new error_js_1.default(file_names_js_1.default.config + ' file is required', { exit: 2 });
18
18
  }
19
19
  return;
20
20
  }
@@ -23,13 +23,10 @@ function raw(throwError = false) {
23
23
  exports.raw = raw;
24
24
  function source() {
25
25
  const clientConfig = raw();
26
- return (clientConfig && clientConfig.source) || constants_1.FOLDERNAME.client;
26
+ return (clientConfig && clientConfig.source) || folder_names_js_1.default.client;
27
27
  }
28
28
  exports.source = source;
29
- function plugin(name, source) {
30
- if (source) {
31
- logger_1.debug('Source config not supported for client');
32
- }
29
+ function plugin(name) {
33
30
  const clientConfig = raw();
34
31
  const rawPlugins = clientConfig && clientConfig.plugin;
35
32
  if (!rawPlugins) {
@@ -55,17 +52,17 @@ function ignore(sourcePath) {
55
52
  const clientConfig = raw();
56
53
  const ignoreArr = (clientConfig && clientConfig.ignore) || [];
57
54
  return ignoreArr.map((value) => {
58
- if (js_1.JS.indexOf(value, path_1.sep) === js_1.JS.size(value) - 1) {
59
- return '**' + path_1.sep + js_1.JS.initial(value).join('');
55
+ if (js_js_1.JS.indexOf(value, path_1.sep) === js_js_1.JS.size(value) - 1) {
56
+ return '**' + path_1.sep + js_js_1.JS.initial(value).join('');
60
57
  }
61
58
  else {
62
- if (js_1.JS.startsWith(value, path_1.sep)) {
63
- return js_1.JS.endsWith(value, path_1.sep)
64
- ? sourcePath + js_1.JS.initial(value).join('')
59
+ if (js_js_1.JS.startsWith(value, path_1.sep)) {
60
+ return js_js_1.JS.endsWith(value, path_1.sep)
61
+ ? sourcePath + js_js_1.JS.initial(value).join('')
65
62
  : sourcePath + value;
66
63
  }
67
- return js_1.JS.endsWith(value, path_1.sep)
68
- ? sourcePath + path_1.sep + js_1.JS.initial(value).join('')
64
+ return js_js_1.JS.endsWith(value, path_1.sep)
65
+ ? sourcePath + path_1.sep + js_js_1.JS.initial(value).join('')
69
66
  : sourcePath + path_1.sep + value;
70
67
  }
71
68
  });
@@ -75,13 +72,13 @@ function script(name, fallback) {
75
72
  const clientConfig = raw();
76
73
  const rawScripts = clientConfig && (clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.scripts);
77
74
  if (rawScripts === undefined && fallback === undefined) {
78
- throw new error_1.default('Scripts not found', { exit: 2 });
75
+ throw new error_js_1.default('Scripts not found', { exit: 2 });
79
76
  }
80
77
  if (name === undefined) {
81
78
  return rawScripts || fallback;
82
79
  }
83
80
  if (rawScripts && rawScripts[name] === undefined && fallback === undefined) {
84
- throw new error_1.default('Scripts not found', { exit: 2 });
81
+ throw new error_js_1.default('Scripts not found', { exit: 2 });
85
82
  }
86
83
  return (rawScripts && rawScripts[name]) || fallback;
87
84
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IAC = exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
6
+ exports.IAC = exports.PLUGIN = exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
7
7
  var apig_rules_1 = require("./lib/apig-rules");
8
8
  Object.defineProperty(exports, "APIG_RULES", { enumerable: true, get: function () { return __importDefault(apig_rules_1).default; } });
9
9
  var auth_1 = require("./lib/auth");
@@ -40,5 +40,7 @@ var template_1 = require("./lib/template");
40
40
  Object.defineProperty(exports, "TEMPLATE", { enumerable: true, get: function () { return __importDefault(template_1).default; } });
41
41
  var urls_1 = require("./lib/urls");
42
42
  Object.defineProperty(exports, "ORIGIN", { enumerable: true, get: function () { return __importDefault(urls_1).default; } });
43
+ var plugin_1 = require("./lib/plugin");
44
+ Object.defineProperty(exports, "PLUGIN", { enumerable: true, get: function () { return __importDefault(plugin_1).default; } });
43
45
  var iac_1 = require("./lib/iac");
44
46
  Object.defineProperty(exports, "IAC", { enumerable: true, get: function () { return __importDefault(iac_1).default; } });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = Object.freeze({
4
4
  client: {
5
+ port: '{{_PORT_}}',
5
6
  package: {
6
7
  name: '{{_NAME_}}'
7
8
  }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = Object.freeze({
4
+ mangaer: {
5
+ npm: {
6
+ command: 'npm',
7
+ opts: ['config', 'get', 'prefix', '--json']
8
+ },
9
+ yarn: {
10
+ command: 'yarn',
11
+ opts: ['global', 'dir']
12
+ }
13
+ },
14
+ client: ['Angular', 'React', 'Basic'],
15
+ react: {
16
+ plugin: 'zcatalyst-cli-plugin-react',
17
+ runner_command: ['create-react-app']
18
+ },
19
+ lyte: {
20
+ plugin: 'zcatalyst-cli-plugin-lyte'
21
+ },
22
+ angular: {
23
+ plugin: 'zcatalyst-cli-plugin-angular',
24
+ runner_command: ['ng', 'new'],
25
+ collection_name: 'zcatalyst-angular-schematics',
26
+ runner_package: '@angular/cli@v12-lts'
27
+ }
28
+ });
@@ -7,7 +7,17 @@ exports.default = Object.freeze({
7
7
  banner: path_1.join(TEMPLATE_ROOT, 'banner.txt'),
8
8
  login_success: path_1.join(TEMPLATE_ROOT, 'loginSuccess.html'),
9
9
  login_fail: path_1.join(TEMPLATE_ROOT, 'loginFailure.html'),
10
- client: path_1.join(TEMPLATE_ROOT, 'init/client'),
10
+ client: {
11
+ basic: {
12
+ new: path_1.join(TEMPLATE_ROOT, 'init', 'client', 'basic'),
13
+ socket: path_1.join(TEMPLATE_ROOT, 'web-socket.txt')
14
+ },
15
+ lyte: path_1.join(TEMPLATE_ROOT, 'init', 'client', 'lyte'),
16
+ react: {
17
+ js: path_1.join(TEMPLATE_ROOT, 'init', 'client', 'react', 'react_js'),
18
+ ts: path_1.join(TEMPLATE_ROOT, 'init', 'client', 'react', 'react_ts')
19
+ }
20
+ },
11
21
  applogic: {
12
22
  node: path_1.join(TEMPLATE_ROOT, 'init', 'applogic', 'node')
13
23
  },