zcatalyst-cli 1.18.0-beta.10 → 1.18.0-beta.11-slate

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 (100) hide show
  1. package/docs/commands/slate/unlink.toml +9 -0
  2. package/docs/option-filter.toml +5 -0
  3. package/docs/serve/server/lib/slate/index.toml +14 -0
  4. package/docs/slate-utils.toml +4 -0
  5. package/lib/archiver.js +18 -9
  6. package/lib/command_needs/auth.js +1 -1
  7. package/lib/command_needs/rc.js +40 -3
  8. package/lib/commands/deploy/index.js +6 -1
  9. package/lib/commands/deploy/slate.js +58 -0
  10. package/lib/commands/index.js +3 -0
  11. package/lib/commands/init.js +4 -0
  12. package/lib/commands/slate/create.js +60 -0
  13. package/lib/commands/slate/link.js +60 -0
  14. package/lib/commands/slate/unlink.js +74 -0
  15. package/lib/deploy/features/index.js +3 -0
  16. package/lib/deploy/features/slate.js +123 -0
  17. package/lib/endpoints/index.js +8 -1
  18. package/lib/endpoints/lib/slate.js +91 -0
  19. package/lib/fn-utils/lib/common.js +1 -1
  20. package/lib/init/features/appsail/index.js +1 -1
  21. package/lib/init/features/index.js +15 -2
  22. package/lib/init/features/project.js +1 -1
  23. package/lib/init/features/slate/index.js +308 -0
  24. package/lib/internal/api.js +1 -1
  25. package/lib/internal/command.js +9 -5
  26. package/lib/option-filter.js +8 -2
  27. package/lib/port-resolver.js +7 -0
  28. package/lib/prompt/types/file-path.js +8 -5
  29. package/lib/serve/features/index.js +8 -1
  30. package/lib/serve/features/slate.js +47 -0
  31. package/lib/serve/index.js +19 -0
  32. package/lib/serve/server/index.js +61 -1
  33. package/lib/serve/server/lib/appsail/index.js +1 -1
  34. package/lib/serve/server/lib/master/index.js +25 -21
  35. package/lib/serve/server/lib/master/slate.js +45 -0
  36. package/lib/serve/server/lib/master/utils.js +2 -2
  37. package/lib/serve/server/lib/slate/index.js +144 -0
  38. package/lib/serve/server/lib/slate/static-server.js +193 -0
  39. package/lib/slate-utils.js +212 -0
  40. package/lib/util_modules/config/index.js +3 -1
  41. package/lib/util_modules/config/lib/slate.js +94 -0
  42. package/lib/util_modules/constants/lib/cliq-handlers.js +18 -10
  43. package/lib/util_modules/constants/lib/default.js +4 -0
  44. package/lib/util_modules/constants/lib/file-names.js +7 -1
  45. package/lib/util_modules/constants/lib/folder-names.js +1 -0
  46. package/lib/util_modules/constants/lib/scopes.js +3 -1
  47. package/lib/util_modules/context-help.js +2 -2
  48. package/lib/util_modules/fs/lib/async.js +8 -1
  49. package/lib/util_modules/fs/lib/sync.js +6 -1
  50. package/lib/util_modules/parser/toml.js +20 -5
  51. package/package.json +2 -2
  52. package/templates/event/integ/cliq/bot/action_handler.json +13 -4
  53. package/templates/event/integ/cliq/bot/call_handler.json +41 -0
  54. package/templates/event/integ/cliq/bot/context_handler.json +11 -3
  55. package/templates/event/integ/cliq/bot/incomingwebhook_handler.json +11 -3
  56. package/templates/event/integ/cliq/bot/mention_handler.json +12 -4
  57. package/templates/event/integ/cliq/bot/message_handler.json +13 -4
  58. package/templates/event/integ/cliq/bot/participation_handler.json +13 -3
  59. package/templates/event/integ/cliq/bot/welcome_handler.json +12 -8
  60. package/templates/event/integ/cliq/command/execution_handler.json +12 -3
  61. package/templates/event/integ/cliq/command/suggestion_handler.json +18 -4
  62. package/templates/event/integ/cliq/{installation → extension}/installation_handler.json +13 -4
  63. package/templates/event/integ/cliq/{installation → extension}/installation_validator.json +13 -5
  64. package/templates/event/integ/cliq/extension/uninstallation_handler.json +37 -0
  65. package/templates/event/integ/cliq/function/button_handler.json +13 -5
  66. package/templates/event/integ/cliq/function/form_change_handler.json +9 -3
  67. package/templates/event/integ/cliq/function/form_handler.json +11 -3
  68. package/templates/event/integ/cliq/function/form_values_handler.json +9 -3
  69. package/templates/event/integ/cliq/function/form_view_handler.json +26 -0
  70. package/templates/event/integ/cliq/function/widget_button_handler.json +14 -5
  71. package/templates/event/integ/cliq/link_preview/action_handler.json +54 -0
  72. package/templates/event/integ/cliq/link_preview/after_send_handler.json +47 -0
  73. package/templates/event/integ/cliq/link_preview/menu_handler.json +47 -0
  74. package/templates/event/integ/cliq/link_preview/preview_handler.json +47 -0
  75. package/templates/event/integ/cliq/messageaction/execution_handler.json +11 -3
  76. package/templates/event/integ/cliq/widget/view_handler.json +12 -4
  77. package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +29 -23
  78. package/templates/init/functions/java/integ/cliq/com/handlers/CommandHandler.java +14 -17
  79. package/templates/init/functions/java/integ/cliq/com/handlers/ExtensionHandler.java +41 -0
  80. package/templates/init/functions/java/integ/cliq/com/handlers/FunctionHandler.java +74 -22
  81. package/templates/init/functions/java/integ/cliq/com/handlers/LinkPreviewHandler.java +108 -0
  82. package/templates/init/functions/java/integ/cliq/com/handlers/MessageActionHandler.java +6 -8
  83. package/templates/init/functions/java/integ/cliq/sample.java +10 -0
  84. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +4 -0
  85. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +3 -5
  86. package/templates/init/functions/node/integ/cliq/handlers/{installation-validator.js → extension-handler.js} +20 -3
  87. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +42 -0
  88. package/templates/init/functions/node/integ/cliq/handlers/link-preview-handler.js +73 -0
  89. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +13 -3
  90. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +7 -7
  91. package/templates/init/functions/python/integ/cliq/handlers/extension_handler.py +25 -0
  92. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +54 -10
  93. package/templates/init/functions/python/integ/cliq/handlers/link_preview_handler.py +76 -0
  94. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +10 -9
  95. package/templates/init/functions/python/integ/cliq/sample.py +2 -2
  96. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationHandler.java +0 -20
  97. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationValidator.java +0 -22
  98. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +0 -15
  99. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +0 -12
  100. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +0 -16
@@ -0,0 +1,47 @@
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 error_1 = __importDefault(require("../../error"));
16
+ const port_resolver_1 = __importDefault(require("../../port-resolver"));
17
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
+ const slate_utils_1 = require("../../slate-utils");
19
+ const config_1 = require("../../util_modules/config");
20
+ const logger_1 = require("../../util_modules/logger");
21
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
22
+ const allTargets = yield config_1.slateConfig.getAllTargetDetails();
23
+ const optionTargets = slate_utils_1.slateUtils.filterTargets(allTargets || []);
24
+ if (optionTargets.length === 0) {
25
+ (0, logger_1.debug)('Slate targets are empty');
26
+ return;
27
+ }
28
+ const validated = (0, slate_utils_1.validateServeCommand)(optionTargets);
29
+ const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () {
30
+ if (!targ.validity.valid) {
31
+ return targ;
32
+ }
33
+ const proxyPort = yield port_resolver_1.default.getPort('slate', 'http', {
34
+ name: targ.name + '_proxy',
35
+ searchSpan: 10,
36
+ server: 'master'
37
+ }).catch((err) => {
38
+ throw new error_1.default('No free ports between 3000 and 3010. Slate needs the ports within this range to function properly', { original: err });
39
+ });
40
+ const slatePort = yield port_resolver_1.default.getPort('slate', 'http', {
41
+ name: targ.name + '_proxy',
42
+ server: 'service'
43
+ });
44
+ return Object.assign(Object.assign({}, targ), { port: { slate: slatePort, proxy: proxyPort }, trigger: { kill: false } });
45
+ })));
46
+ runtime_store_1.default.set('context.slate.targets', filledTargets);
47
+ });
@@ -124,6 +124,25 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
124
124
  runtime_store_1.default.set('context.targets', serveTargets);
125
125
  }
126
126
  }
127
+ if (serveTargets.includes('slate')) {
128
+ const slates = runtime_store_1.default.get('context.slate.targets', []);
129
+ const validSlates = slates.filter((slate) => {
130
+ if (!slate.validity.valid) {
131
+ (0, logger_1.warning)('skipping serve of Slate service [' +
132
+ slate.name +
133
+ '] since ' +
134
+ slate.validity.reason);
135
+ return false;
136
+ }
137
+ advancedServer.add('slate', slate);
138
+ return true;
139
+ });
140
+ if (validSlates.length === 0) {
141
+ (0, logger_1.labeled)('Slate', 'No targets are ready to be served in local').WARN();
142
+ serveTargets.splice(serveTargets.indexOf('slate'), 1);
143
+ runtime_store_1.default.set('context.targets', serveTargets);
144
+ }
145
+ }
127
146
  if (serveTargets.includes('client')) {
128
147
  const client = runtime_store_1.default.get('context.client', false);
129
148
  if (client && client.valid) {
@@ -24,6 +24,7 @@ const index_js_2 = __importDefault(require("./lib/node/index.js"));
24
24
  const index_js_3 = __importDefault(require("./lib/python/index.js"));
25
25
  const index_js_4 = __importDefault(require("./lib/web_client/index.js"));
26
26
  const index_js_5 = __importDefault(require("./lib/appsail/index.js"));
27
+ const index_js_6 = __importDefault(require("./lib/slate/index.js"));
27
28
  const cli_table_1 = require("../../cli_table");
28
29
  const ansi_colors_1 = require("ansi-colors");
29
30
  const bioLogUrl = (details, masterPort, addSpaces) => {
@@ -50,7 +51,8 @@ class Server {
50
51
  functions: [],
51
52
  server: [],
52
53
  client: [],
53
- appSail: []
54
+ appSail: [],
55
+ slate: []
54
56
  };
55
57
  }
56
58
  _addBasicFnDetails(bioUrlLogs) {
@@ -95,6 +97,15 @@ class Server {
95
97
  });
96
98
  return;
97
99
  }
100
+ if (type === 'slate') {
101
+ this.targetsMap.slate.push({
102
+ type,
103
+ target: target,
104
+ httpPort: -1,
105
+ debugPort: -1
106
+ });
107
+ return;
108
+ }
98
109
  const httpPort = runtime_store_1.default.get(`context.port.http.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
99
110
  const debugPort = runtime_store_1.default.get(`context.port.debug.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
100
111
  if (httpPort === -1) {
@@ -129,6 +140,10 @@ class Server {
129
140
  currentProcess = yield (0, index_js_5.default)(details);
130
141
  break;
131
142
  }
143
+ case 'slate': {
144
+ currentProcess = yield (0, index_js_6.default)(details);
145
+ break;
146
+ }
132
147
  case 'client': {
133
148
  currentProcess = yield (0, index_js_4.default)(details, masterPort);
134
149
  break;
@@ -177,6 +192,11 @@ class Server {
177
192
  target.valid = false;
178
193
  (0, logger_1.labeled)(`WebClient[${details.target}]`, error).ERROR();
179
194
  }
195
+ else if (details.type === 'slate') {
196
+ const target = details.target;
197
+ target.validity.valid = false;
198
+ (0, logger_1.labeled)(`Slate[${target.name}]`, error).ERROR();
199
+ }
180
200
  else {
181
201
  const target = details.target;
182
202
  target.valid = false;
@@ -195,6 +215,7 @@ class Server {
195
215
  browserlogic: { targs: [], nameMaxLength: 0 }
196
216
  },
197
217
  appsail: { targs: [], nameMaxLength: 0 },
218
+ slate: { targs: [], nameMaxLength: 0 },
198
219
  client: {}
199
220
  };
200
221
  this._addBasicFnDetails(logUrls.functions.bio);
@@ -297,6 +318,21 @@ class Server {
297
318
  : logUrls.appsail.nameMaxLength;
298
319
  })));
299
320
  }
321
+ if (this.targetsMap.slate.length > 0) {
322
+ yield Promise.all(this.targetsMap.slate.map((targSlate) => this.startServer(targSlate, -1).then((details) => {
323
+ var _a, _b, _c, _d;
324
+ const serverDetails = details;
325
+ if (!((_a = serverDetails.target) === null || _a === void 0 ? void 0 : _a.validity.valid)) {
326
+ return;
327
+ }
328
+ logUrls.slate.targs.push(targSlate);
329
+ logUrls.slate.nameMaxLength =
330
+ ((_b = targSlate.target) === null || _b === void 0 ? void 0 : _b.name) &&
331
+ ((_c = targSlate.target) === null || _c === void 0 ? void 0 : _c.name.length) > logUrls.slate.nameMaxLength
332
+ ? (_d = targSlate.target) === null || _d === void 0 ? void 0 : _d.name.length
333
+ : logUrls.slate.nameMaxLength;
334
+ })));
335
+ }
300
336
  let loggedEntries = 0;
301
337
  Object.entries(logUrls).forEach(([targType, logTarg]) => {
302
338
  var _a;
@@ -422,6 +458,30 @@ class Server {
422
458
  (0, logger_1.info)();
423
459
  break;
424
460
  }
461
+ case 'slate': {
462
+ const _logTarg = logTarg;
463
+ if (_logTarg.targs.length === 0) {
464
+ return;
465
+ }
466
+ loggedEntries++;
467
+ let isHeaderDisplayed = false;
468
+ _logTarg.targs.forEach((t) => {
469
+ const targetSlate = t.target;
470
+ if (!targetSlate.validity.valid) {
471
+ return;
472
+ }
473
+ if (isHeaderDisplayed === false) {
474
+ (0, logger_1.info)();
475
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> Slate <<<<<<<<<<<<<< '));
476
+ isHeaderDisplayed = true;
477
+ }
478
+ const targName = targetSlate.name + '';
479
+ (0, logger_1.labeled)(targName +
480
+ ' '.repeat((_logTarg.nameMaxLength || targName.length) - targName.length), `http://localhost:${targetSlate.port.proxy}`).MESSAGE();
481
+ });
482
+ (0, logger_1.info)();
483
+ break;
484
+ }
425
485
  }
426
486
  });
427
487
  return loggedEntries > 0
@@ -114,7 +114,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
114
114
  const zip = new archiver_1.default();
115
115
  zip.load(jettyZip);
116
116
  zip.extract(jettyPath, '/', {
117
- ignoreInitial: false,
117
+ ignoreLevel: 0,
118
118
  isFolder: true
119
119
  });
120
120
  yield zip.finalize();
@@ -34,10 +34,12 @@ const utils_1 = require("./utils");
34
34
  const appsail_1 = require("./appsail");
35
35
  const web_client_1 = require("./web-client");
36
36
  const functions_1 = require("./functions");
37
- function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
37
+ const slate_1 = require("./slate");
38
+ function spinUpMaster(listenPort, { otherServerDetails, appSailDetails, slateDetails }) {
38
39
  var _a, _b;
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
- if ((otherServerDetails && appSailDetails) || (!otherServerDetails && !appSailDetails)) {
41
+ if ((otherServerDetails && appSailDetails && slateDetails) ||
42
+ (!otherServerDetails && !appSailDetails && !slateDetails)) {
41
43
  throw new error_1.default('Either functions/client or AppSail is need to start the master server. But both cannot use the same master', { exit: 2 });
42
44
  }
43
45
  const projectDetails = {
@@ -56,12 +58,11 @@ function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
56
58
  app.use(cookie_parser_1.default);
57
59
  app.use((0, project_1.default)(projectDetails));
58
60
  app.use(authenticator_1.default);
59
- !appSailDetails &&
61
+ if (!appSailDetails && !slateDetails) {
60
62
  app.use(nonApigURL, (req, res) => {
61
63
  req.url = req.originalUrl;
62
64
  unknownProxy(req, res);
63
65
  });
64
- !appSailDetails &&
65
66
  app.use('*/.catalyst%2Freload-script.js', (req, res) => {
66
67
  var _a;
67
68
  req.url = '/.catalyst%2Freload-script.js';
@@ -73,33 +74,35 @@ function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
73
74
  });
74
75
  });
75
76
  });
76
- if (rules !== -1 && !appSailDetails) {
77
- for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
78
- const router = app.route(sourceURL);
79
- for (const [method, config] of Object.entries(methodByConfig)) {
80
- if (config.system) {
81
- if (systemRoutes === undefined) {
82
- systemRoutes = {};
77
+ if (rules !== -1) {
78
+ for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
79
+ const router = app.route(sourceURL);
80
+ for (const [method, config] of Object.entries(methodByConfig)) {
81
+ if (config.system) {
82
+ if (systemRoutes === undefined) {
83
+ systemRoutes = {};
84
+ }
85
+ js_1.JS.set(systemRoutes, [sourceURL, method], config);
83
86
  }
84
- js_1.JS.set(systemRoutes, [sourceURL, method], config);
87
+ router[method]((req, res, next) => {
88
+ if (res.locals.apigRules === undefined) {
89
+ res.locals.apigRules = [];
90
+ }
91
+ res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
92
+ next();
93
+ });
85
94
  }
86
- router[method]((req, res, next) => {
87
- if (res.locals.apigRules === undefined) {
88
- res.locals.apigRules = [];
89
- }
90
- res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
91
- next();
92
- });
93
95
  }
96
+ app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
94
97
  }
95
- app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
96
98
  }
97
99
  const proxy = (0, utils_1.createProxyServer)(listenPort);
100
+ const signRedirectUrl = slateDetails ? undefined : '/app/local-redirect';
98
101
  appSailDetails && ((_b = (_a = appSailDetails.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true
99
102
  ? proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({
100
103
  signInRedirect: appSailDetails.target.config.login_redirect || '/'
101
104
  }))
102
- : proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({ systemRoutes }));
105
+ : proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({ systemRoutes, signInRedirect: signRedirectUrl }));
103
106
  const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
104
107
  const unknownProxy = (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl);
105
108
  otherServerDetails &&
@@ -132,6 +135,7 @@ function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
132
135
  }
133
136
  });
134
137
  appSailDetails && (0, appsail_1.addAppSailRoutes)(app, appSailDetails, proxy, unknownProxy);
138
+ slateDetails && (0, slate_1.addSlateRoutes)(app, slateDetails, proxy, unknownProxy);
135
139
  app.use('/', (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl));
136
140
  app.use(error_handler_1.default);
137
141
  const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
@@ -0,0 +1,45 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addSlateRoutes = void 0;
13
+ function addSlateRoutes(app, details, proxy, unknownProxy) {
14
+ app.use('/__catalyst/sdk/init', (req, res) => __awaiter(this, void 0, void 0, function* () {
15
+ req.url = req.originalUrl;
16
+ unknownProxy(req, res);
17
+ }));
18
+ app.use(['/accounts', '/oauthorize'], (req, res) => {
19
+ req.url = req.originalUrl;
20
+ unknownProxy(req, res);
21
+ });
22
+ app.use('/__catalyst', (req, res) => {
23
+ req.url = req.originalUrl;
24
+ if (req.url.includes('redirect_url')) {
25
+ res.redirect(req.url.split('redirect_url=')[1]);
26
+ }
27
+ else if (req.url.includes('service_url')) {
28
+ res.redirect(req.url.split('service_url=')[1]);
29
+ }
30
+ else {
31
+ unknownProxy(req, res);
32
+ }
33
+ });
34
+ app.use('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
35
+ if (req.header('catalyst-component') === 'true') {
36
+ unknownProxy(req, res);
37
+ return;
38
+ }
39
+ proxy.web(req, res, {
40
+ target: `http://127.0.0.1:${details.target.port.slate}`,
41
+ ws: true
42
+ });
43
+ }));
44
+ }
45
+ exports.addSlateRoutes = addSlateRoutes;
@@ -78,7 +78,7 @@ const createProxyServer = (port) => {
78
78
  return proxy;
79
79
  };
80
80
  exports.createProxyServer = createProxyServer;
81
- const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redirect' }) => (proxyRes, req, res) => {
81
+ const proxyResponseHandler = ({ systemRoutes, signInRedirect }) => (proxyRes, req, res) => {
82
82
  var _a, _b;
83
83
  if (!req.url) {
84
84
  return;
@@ -89,7 +89,7 @@ const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redir
89
89
  return cookie;
90
90
  });
91
91
  if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
92
- if (req.url.includes('/signin-redirect')) {
92
+ if (req.url.includes('/signin-redirect') && signInRedirect) {
93
93
  if (systemRoutes === undefined) {
94
94
  (0, exports.redirectByAuth)(req, res, signInRedirect);
95
95
  return;
@@ -0,0 +1,144 @@
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 path_1 = require("path");
16
+ const error_1 = __importDefault(require("../../../../error"));
17
+ const fs_1 = require("../../../../util_modules/fs");
18
+ const logger_1 = require("../../../../util_modules/logger");
19
+ const shell_1 = require("../../../../util_modules/shell");
20
+ const master_1 = __importDefault(require("../master"));
21
+ const ansi_colors_1 = require("ansi-colors");
22
+ const file_names_1 = __importDefault(require("../../../../util_modules/constants/lib/file-names"));
23
+ const static_server_1 = __importDefault(require("./static-server"));
24
+ const open_1 = __importDefault(require("open"));
25
+ const async_1 = require("../../../../util_modules/fs/lib/async");
26
+ const startSlate = (port, opts) => {
27
+ const child = (0, shell_1.spawn)(opts.command, [], {
28
+ cwd: opts.target,
29
+ shell: true,
30
+ env: {
31
+ ZC_SLATE_PORT: port + ''
32
+ }
33
+ }).RAW();
34
+ return new Promise((_res, _rej) => {
35
+ child.on('spawn', () => _res(child));
36
+ child.on('error', (reason) => _rej(reason));
37
+ });
38
+ };
39
+ const installPackages = (opts) => {
40
+ const child = (0, shell_1.spawn)(opts.command, [], {
41
+ cwd: opts.target,
42
+ shell: true
43
+ }).RAW();
44
+ return new Promise((_res, _rej) => {
45
+ child.on('spawn', () => _res(child));
46
+ child.on('error', (reason) => _rej(reason));
47
+ });
48
+ };
49
+ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
50
+ var _a, _b, _c;
51
+ const targetSlate = serverDetails.target;
52
+ if (!targetSlate || !targetSlate.config) {
53
+ throw new error_1.default('Slate details not found');
54
+ }
55
+ let child;
56
+ if (targetSlate.config.framework === 'static') {
57
+ child = yield (0, static_server_1.default)(targetSlate.port.slate, targetSlate.source, {
58
+ enableWatch: true
59
+ });
60
+ child.addListener('start', () => {
61
+ (0, open_1.default)('http://localhost:' + targetSlate.port.slate).catch();
62
+ });
63
+ }
64
+ else {
65
+ const configFile = (0, path_1.join)(targetSlate.source, file_names_1.default.cli_config);
66
+ if (!fs_1.ASYNC.fileExists(configFile)) {
67
+ throw new error_1.default('Unable to find the development command.', {
68
+ exit: 1,
69
+ errorId: 'SERVE-SLATE-1',
70
+ arg: ['catalyst slate:create']
71
+ });
72
+ }
73
+ if (!(yield fs_1.ASYNC.isPathExists(targetSlate.source))) {
74
+ throw new error_1.default('The given Slate source path does not exists', {
75
+ exit: 1,
76
+ errorId: 'SERVE-SlATE-1',
77
+ arg: [ansi_colors_1.italic.underline.red(targetSlate.source), (0, ansi_colors_1.bold)(targetSlate.name)]
78
+ });
79
+ }
80
+ const configJson = yield (0, async_1.readJSONFile)(configFile);
81
+ if (!configJson) {
82
+ throw new error_1.default('Development command not found', {
83
+ exit: 1,
84
+ errorId: 'SERVE-SLATE-1',
85
+ arg: ['catalyst slate:create']
86
+ });
87
+ }
88
+ if ((_a = targetSlate.config) === null || _a === void 0 ? void 0 : _a.install_command) {
89
+ const spwnProcess = yield installPackages({
90
+ target: targetSlate.source,
91
+ command: (_b = targetSlate.config) === null || _b === void 0 ? void 0 : _b.install_command
92
+ });
93
+ spwnProcess.once('exit', (code) => {
94
+ if (code === 150) {
95
+ targetSlate.validity = {
96
+ valid: false,
97
+ reason: 'Unable to install the dependencies'
98
+ };
99
+ throw new error_1.default('Unable to start the Slate', {
100
+ exit: 1,
101
+ errorId: 'SERVE-SLATE-3',
102
+ arg: [(0, ansi_colors_1.bold)('catalyst serve')]
103
+ });
104
+ }
105
+ });
106
+ }
107
+ child = yield startSlate(targetSlate.port.slate, {
108
+ target: targetSlate.source,
109
+ command: (_c = configJson === null || configJson === void 0 ? void 0 : configJson.slate) === null || _c === void 0 ? void 0 : _c.dev_command
110
+ });
111
+ child.once('exit', (code) => {
112
+ if (code === 150) {
113
+ targetSlate.validity = {
114
+ valid: false,
115
+ reason: 'Unable to start the Slate'
116
+ };
117
+ throw new error_1.default('Unable to start the Slate', {
118
+ exit: 1,
119
+ errorId: 'SERVE-SLATE-2',
120
+ arg: [(0, ansi_colors_1.bold)(targetSlate.name), (0, ansi_colors_1.underline)((configJson === null || configJson === void 0 ? void 0 : configJson.dev_command) || '')]
121
+ });
122
+ }
123
+ });
124
+ }
125
+ const masterServe = yield (0, master_1.default)(targetSlate.port.proxy, {
126
+ slateDetails: serverDetails
127
+ });
128
+ child.once('exit', () => {
129
+ masterServe.close((err) => {
130
+ if (err) {
131
+ (0, logger_1.debug)('Error stopping the Slate proxy server: ', err);
132
+ }
133
+ });
134
+ });
135
+ process.on('SIGINT', () => {
136
+ masterServe.close((err) => {
137
+ if (err) {
138
+ (0, logger_1.debug)('Error stopping the Slate proxy server: ', err);
139
+ }
140
+ });
141
+ targetSlate.trigger.kill = true;
142
+ });
143
+ return child;
144
+ });