zcatalyst-cli 1.18.0-beta.11 → 1.18.0-beta.12

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 (55) hide show
  1. package/docs/commands/slate/unlink.toml +9 -0
  2. package/docs/endpoints/lib/env.toml +3 -1
  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/authentication/login.js +3 -2
  7. package/lib/command_needs/auth.js +1 -1
  8. package/lib/command_needs/rc.js +40 -3
  9. package/lib/commands/deploy/index.js +6 -1
  10. package/lib/commands/deploy/slate.js +58 -0
  11. package/lib/commands/index.js +3 -0
  12. package/lib/commands/init.js +4 -10
  13. package/lib/commands/slate/create.js +59 -0
  14. package/lib/commands/slate/link.js +59 -0
  15. package/lib/commands/slate/unlink.js +75 -0
  16. package/lib/config-store.js +2 -1
  17. package/lib/deploy/features/index.js +3 -0
  18. package/lib/deploy/features/slate.js +123 -0
  19. package/lib/endpoints/index.js +8 -1
  20. package/lib/endpoints/lib/env.js +2 -1
  21. package/lib/endpoints/lib/slate.js +91 -0
  22. package/lib/fn-utils/lib/common.js +1 -1
  23. package/lib/init/features/appsail/index.js +1 -1
  24. package/lib/init/features/index.js +15 -2
  25. package/lib/init/features/project.js +1 -1
  26. package/lib/init/features/slate/index.js +313 -0
  27. package/lib/internal/api.js +1 -1
  28. package/lib/internal/command.js +9 -5
  29. package/lib/option-filter.js +8 -2
  30. package/lib/port-resolver.js +7 -0
  31. package/lib/prompt/index.js +22 -6
  32. package/lib/prompt/types/file-path.js +10 -7
  33. package/lib/serve/features/index.js +8 -1
  34. package/lib/serve/features/slate.js +47 -0
  35. package/lib/serve/index.js +19 -0
  36. package/lib/serve/server/index.js +61 -1
  37. package/lib/serve/server/lib/appsail/index.js +1 -1
  38. package/lib/serve/server/lib/master/index.js +25 -21
  39. package/lib/serve/server/lib/master/slate.js +45 -0
  40. package/lib/serve/server/lib/master/utils.js +2 -2
  41. package/lib/serve/server/lib/slate/index.js +115 -0
  42. package/lib/serve/server/lib/slate/static-server.js +193 -0
  43. package/lib/slate-utils.js +212 -0
  44. package/lib/util_modules/config/index.js +3 -1
  45. package/lib/util_modules/config/lib/slate.js +94 -0
  46. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  47. package/lib/util_modules/constants/lib/default.js +4 -0
  48. package/lib/util_modules/constants/lib/file-names.js +7 -1
  49. package/lib/util_modules/constants/lib/folder-names.js +1 -0
  50. package/lib/util_modules/constants/lib/scopes.js +3 -1
  51. package/lib/util_modules/context-help.js +2 -2
  52. package/lib/util_modules/fs/lib/async.js +14 -3
  53. package/lib/util_modules/fs/lib/sync.js +6 -1
  54. package/lib/util_modules/parser/toml.js +20 -5
  55. package/package.json +2 -2
@@ -0,0 +1,193 @@
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
+ const server_js_1 = require("../../../../util_modules/server.js");
27
+ function prepareScriptFile(dir, port) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const scriptFile = yield index_js_2.ASYNC.readFile(index_js_1.TEMPLATE.client.basic.socket);
30
+ if (!scriptFile) {
31
+ throw new error_js_1.default('Unable to read the script file', { exit: 2 });
32
+ }
33
+ const scriptReady = scriptFile.replace(new RegExp(index_js_1.PLACEHOLDER.client.port, 'g'), port + '');
34
+ yield index_js_2.ASYNC.ensureDir(dir);
35
+ const scriptFilePath = (0, path_1.join)(dir, 'reload-script.js');
36
+ yield index_js_2.ASYNC.writeFile(scriptFilePath, scriptReady);
37
+ return scriptFilePath;
38
+ });
39
+ }
40
+ function stringInjector(source, anchorIdx, marker, inject) {
41
+ const headLastIdx = anchorIdx + marker.length;
42
+ const scriptPrefix = source.slice(0, headLastIdx);
43
+ const scriptSuffix = source.slice(headLastIdx);
44
+ return scriptPrefix + inject + scriptSuffix;
45
+ }
46
+ function injectScript(scriptLocale, indexHtml) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const headIdx = indexHtml.search(/<head>/gi);
49
+ const scriptTag = `\n<!-- Catalyst web client reload script -->\n<script type="text/javascript" src="${scriptLocale}"></script>\n`;
50
+ if (headIdx !== -1) {
51
+ return stringInjector(indexHtml, headIdx, '<head>', scriptTag);
52
+ }
53
+ const htmlIdx = indexHtml.search(/<html>/gi);
54
+ const headTag = `\n<head>${scriptTag}</head>\n`;
55
+ return stringInjector(indexHtml, htmlIdx, '<html>', headTag);
56
+ });
57
+ }
58
+ function reloadApp(event, path, liveSockets) {
59
+ (0, logger_js_1.info)((0, ansi_colors_1.cyan)(`${event} detected in ${path} of the Web-Client.`));
60
+ liveSockets.forEach((socket) => socket.send('reload'));
61
+ }
62
+ function slateServer(httpPort, source, { homepage = '/index.html', enableWatch = true, notFoundPage } = {}) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const eventListener = new events_1.EventEmitter();
65
+ const catalystTempDir = (0, path_1.join)(source, '.catalyst');
66
+ const socketServerPort = yield port_resolver_js_1.default.getFreePort(httpPort, 20, true);
67
+ const reloadScriptSrc = enableWatch
68
+ ? (0, path_1.relative)(source, yield prepareScriptFile(catalystTempDir, socketServerPort))
69
+ : undefined;
70
+ if (reloadScriptSrc) {
71
+ const clientWatcher = (0, chokidar_1.watch)(source, {
72
+ ignoreInitial: true,
73
+ ignored: ['node_modules/**/*']
74
+ });
75
+ const liveSockets = [];
76
+ let watcherReady = false;
77
+ clientWatcher.on('error', (err) => {
78
+ watcherReady = false;
79
+ eventListener.emit('error', new error_js_1.default('client watcher error', {
80
+ original: err,
81
+ exit: 1,
82
+ skipHelp: true
83
+ }));
84
+ });
85
+ clientWatcher.on('ready', () => {
86
+ watcherReady = true;
87
+ const socketServer = new ws_1.WebSocketServer({
88
+ port: socketServerPort,
89
+ path: '/client-reload'
90
+ })
91
+ .on('connection', (clientSocket) => {
92
+ if (!watcherReady) {
93
+ clientSocket.send('watcher not ready');
94
+ clientSocket.close();
95
+ return;
96
+ }
97
+ clientSocket.on('close', () => {
98
+ const socketIdx = liveSockets.findIndex((socket) => socket === clientSocket);
99
+ liveSockets.splice(socketIdx, 1);
100
+ });
101
+ liveSockets.push(clientSocket);
102
+ clientSocket.send('connected');
103
+ })
104
+ .on('error', (err) => (0, logger_js_1.debug)(err));
105
+ setTimeout(() => {
106
+ clientWatcher.on('change', (path) => {
107
+ reloadApp('Change(s) is', (0, path_1.relative)(source, path), liveSockets);
108
+ });
109
+ clientWatcher.on('add', (path) => {
110
+ reloadApp('Addition of file(s) is', (0, path_1.relative)(source, path), liveSockets);
111
+ });
112
+ clientWatcher.on('unlink', (path) => {
113
+ reloadApp('Deletion of file(s) is', (0, path_1.relative)(source, path), liveSockets);
114
+ });
115
+ }, 1000);
116
+ eventListener.addListener('close', () => socketServer === null || socketServer === void 0 ? void 0 : socketServer.close());
117
+ });
118
+ eventListener.addListener('close', () => {
119
+ if (clientWatcher) {
120
+ clientWatcher.close();
121
+ }
122
+ liveSockets.forEach((socket) => socket.close());
123
+ index_js_2.SYNC.deleteDir(reloadScriptSrc);
124
+ });
125
+ }
126
+ const app = (0, express_1.default)();
127
+ app.use('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
128
+ const requestedFile = req.url === '/' ? homepage : decodeURIComponent(req.path);
129
+ if (enableWatch && (requestedFile.includes('.html') || requestedFile.includes('.htm'))) {
130
+ const htmlFile = yield index_js_2.ASYNC.readFile((0, path_1.join)(source, requestedFile));
131
+ if (!htmlFile) {
132
+ res.contentType('text/html');
133
+ res.status(404);
134
+ res.end();
135
+ eventListener.emit('error', new error_js_1.default('Unable to read the html file', {
136
+ exit: 1,
137
+ errorId: 'SL-SERVER-1',
138
+ arg: [ansi_colors_1.red.italic(requestedFile)]
139
+ }));
140
+ return;
141
+ }
142
+ const injectedHtml = reloadScriptSrc
143
+ ? yield injectScript(encodeURIComponent(reloadScriptSrc), htmlFile)
144
+ : undefined;
145
+ res.contentType('text/html');
146
+ res.status(200);
147
+ res.send(injectedHtml || htmlFile);
148
+ return;
149
+ }
150
+ res.sendFile((0, path_1.join)(source, requestedFile), (err) => {
151
+ if (!err) {
152
+ return;
153
+ }
154
+ if (err.code && err.code === 'ENOENT') {
155
+ (0, logger_js_1.error)((0, ansi_colors_1.red)('[404 - Resource not found]: ') + (0, ansi_colors_1.bold)(requestedFile));
156
+ (0, logger_js_1.info)();
157
+ (0, logger_js_1.debug)(err.stack || err.message);
158
+ res.status(404);
159
+ notFoundPage
160
+ ? res.sendFile(notFoundPage, (e) => {
161
+ if (!e) {
162
+ return;
163
+ }
164
+ (0, logger_js_1.debug)('Unable to send the 404 page to server: ', e);
165
+ res.status(500);
166
+ res.send('Error sending 404 page to server: ' + e.stack);
167
+ })
168
+ : res.send('Resource not found');
169
+ return;
170
+ }
171
+ (0, logger_js_1.error)('Error fetching the resource: ' + err);
172
+ (0, logger_js_1.debug)(err.stack);
173
+ res.status(500);
174
+ res.send('Error fetching the resource');
175
+ });
176
+ }));
177
+ const server = app.listen(httpPort, '127.0.0.1').on('error', (err) => {
178
+ eventListener.emit('error', err);
179
+ });
180
+ const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
181
+ eventListener.on('error', (err) => {
182
+ (0, logger_js_1.error)('Error when serving the web-client: ' + err.message);
183
+ (0, logger_js_1.info)('Please exit the command to get more info');
184
+ eventListener.emit('close');
185
+ });
186
+ eventListener.on('close', () => __awaiter(this, void 0, void 0, function* () {
187
+ yield expressDestroyer.destroy();
188
+ (0, logger_js_1.debug)('client server closed');
189
+ }));
190
+ return new Promise((res) => server.on('listening', () => res(eventListener)));
191
+ });
192
+ }
193
+ exports.default = slateServer;
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.validateServeCommand = exports.slateUtils = void 0;
16
+ const ansi_colors_1 = require("ansi-colors");
17
+ const fs_extra_1 = require("fs-extra");
18
+ const path_1 = require("path");
19
+ const archiver_1 = __importDefault(require("./archiver"));
20
+ const error_1 = __importDefault(require("./error"));
21
+ const runtime_store_1 = __importDefault(require("./runtime-store"));
22
+ const fs_1 = require("./util_modules/fs");
23
+ const option_1 = require("./util_modules/option");
24
+ const constants_1 = require("./util_modules/constants");
25
+ const logger_1 = require("./util_modules/logger");
26
+ const minimatch_1 = __importDefault(require("minimatch"));
27
+ const env_1 = require("./util_modules/env");
28
+ const async_1 = require("./util_modules/fs/lib/async");
29
+ exports.slateUtils = {
30
+ validate: (source) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const sourceDirExists = yield fs_1.ASYNC.dirExists(source);
32
+ if (!sourceDirExists) {
33
+ throw new error_1.default('source directory does not exist', {
34
+ exit: 1,
35
+ errorId: 'SLATE-UTILS-1',
36
+ arg: [ansi_colors_1.italic.red(source)]
37
+ });
38
+ }
39
+ }),
40
+ getSlateFilters(targetStr) {
41
+ return targetStr.split(',').reduce((filterArr, target) => {
42
+ const opts = target.split(':');
43
+ if (opts[0] === 'slate' && opts[1]) {
44
+ filterArr.push(opts[1]);
45
+ return filterArr;
46
+ }
47
+ return filterArr;
48
+ }, []);
49
+ },
50
+ filterTargets(allTargets) {
51
+ const only = (0, option_1.getOptionValue)('only');
52
+ if (only !== undefined) {
53
+ const onlyTargs = this.getSlateFilters(only);
54
+ if (onlyTargs.length === 0) {
55
+ return allTargets;
56
+ }
57
+ const refined = onlyTargs.reduce((filtered, filter) => {
58
+ const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
59
+ if (targDetailsIdx === -1) {
60
+ filtered.unmatched.push(filter);
61
+ }
62
+ else {
63
+ const targDetails = allTargets.splice(targDetailsIdx, 1);
64
+ filtered.matched.push(targDetails[0]);
65
+ }
66
+ return filtered;
67
+ }, {
68
+ matched: [],
69
+ unmatched: []
70
+ });
71
+ if (refined.unmatched.length > 0) {
72
+ throw new error_1.default(`The filters ${(0, ansi_colors_1.bold)(refined.unmatched.join(', '))} provided with --only option does not match with any Slate service in ${constants_1.FILENAME.config}.`);
73
+ }
74
+ return refined.matched;
75
+ }
76
+ const except = (0, option_1.getOptionValue)('except');
77
+ if (except !== undefined) {
78
+ const exceptTargs = this.getSlateFilters(except);
79
+ const refined = exceptTargs.reduce((filtered, filter) => {
80
+ const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
81
+ if (targDetailsIdx === -1) {
82
+ filtered.unmatched.push(filter);
83
+ }
84
+ else {
85
+ filtered.matched.splice(targDetailsIdx, 1);
86
+ }
87
+ return filtered;
88
+ }, {
89
+ matched: allTargets,
90
+ unmatched: []
91
+ });
92
+ if (refined.unmatched.length > 0) {
93
+ (0, logger_1.message)(`The filters ${(0, ansi_colors_1.bold)(refined.unmatched.join(', '))} provided with --except option does not match with any Slate service in ${constants_1.FILENAME.config}, hence ignored.`);
94
+ }
95
+ return refined.matched;
96
+ }
97
+ const refinedTargets = allTargets.filter((app) => app.source.includes(runtime_store_1.default.get('cwd')));
98
+ if (refinedTargets.length === 0 || !refinedTargets) {
99
+ throw new error_1.default('You are not in a catalyst app directory.');
100
+ }
101
+ return refinedTargets;
102
+ },
103
+ pack: (source) => __awaiter(void 0, void 0, void 0, function* () {
104
+ if (env_1.isCI) {
105
+ source = source !== null && source !== void 0 ? source : runtime_store_1.default.get('cwd');
106
+ const tempDir = (0, path_1.resolve)(constants_1.FOLDERNAME.slate);
107
+ if (!(yield (0, async_1.dirExists)(tempDir))) {
108
+ (0, fs_extra_1.mkdir)(tempDir);
109
+ const excludePatterns = [
110
+ '**/.catalyst',
111
+ `**/${constants_1.FILENAME.log}`,
112
+ `**/${constants_1.FILENAME.config}`,
113
+ `**/${constants_1.FILENAME.rc}`,
114
+ `**/${constants_1.FILENAME.app_config}`,
115
+ `**/${constants_1.FILENAME.catalyst_ignore}`
116
+ ];
117
+ const files = yield fs_1.ASYNC.walk(source, {
118
+ filter: {
119
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
120
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(source + path_1.sep, ''), glob, {
121
+ dot: true
122
+ }));
123
+ }),
124
+ excludeDir: true
125
+ }
126
+ });
127
+ const zip = new archiver_1.default('static');
128
+ const fileArr = [];
129
+ files.forEach((file) => {
130
+ fileArr.push({
131
+ path: (0, path_1.relative)(source, file.path),
132
+ type: (0, path_1.extname)(file.path).replace('.', '').toUpperCase() || '',
133
+ size: file.stats.size
134
+ });
135
+ zip.add(file.path.replace(source + path_1.sep, ''), file.stats.isSymbolicLink()
136
+ ? fs_1.SYNC.readSymLink(file.path)
137
+ : fs_1.SYNC.getReadStream(file.path), {
138
+ mode: file.stats.mode
139
+ });
140
+ });
141
+ const zipFinalizer = yield zip.finalize();
142
+ const staticZip = (0, path_1.join)(tempDir, constants_1.FILENAME.slate.static_zip);
143
+ yield zipFinalizer.writeZip(staticZip);
144
+ const content = {
145
+ version: '',
146
+ framework: process.env.ZC_FRAMEWORK,
147
+ runtime: '',
148
+ static: fileArr
149
+ };
150
+ const configJson = (0, path_1.join)(tempDir, constants_1.FILENAME.slate.config_json);
151
+ fs_1.SYNC.writeFile(configJson, JSON.stringify(content, null, 2) + '\n');
152
+ }
153
+ const slateZip = yield fs_1.ASYNC.walk(tempDir, { includeDirPaths: false });
154
+ const zipWithJson = new archiver_1.default();
155
+ slateZip.forEach((file) => {
156
+ zipWithJson.add(file.path.replace(tempDir + path_1.sep, ''), file.stats.isSymbolicLink()
157
+ ? fs_1.SYNC.readSymLink(file.path)
158
+ : fs_1.SYNC.getReadStream(file.path), {
159
+ mode: file.stats.mode
160
+ });
161
+ });
162
+ const zipFinalizerWithJson = yield zipWithJson.finalize();
163
+ yield fs_1.ASYNC.deleteDir(tempDir);
164
+ return yield zipFinalizerWithJson.fsStream();
165
+ }
166
+ const excludePatterns = [
167
+ '**/.DS_Store',
168
+ '**/.catalyst',
169
+ '**/.vscode/**/*',
170
+ '**/node_modules',
171
+ `**/${constants_1.FILENAME.log}`,
172
+ `**/${constants_1.FILENAME.config}`,
173
+ `**/${constants_1.FILENAME.rc}`,
174
+ `**/${constants_1.FILENAME.app_config}`,
175
+ `**/${constants_1.FILENAME.catalyst_ignore}`
176
+ ];
177
+ const slateZip = yield fs_1.ASYNC.walk(source, {
178
+ filter: {
179
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
180
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(source + path_1.sep, ''), glob, { dot: true }));
181
+ }),
182
+ excludeDir: true
183
+ }
184
+ });
185
+ const zipWithJson = new archiver_1.default();
186
+ slateZip.forEach((file) => {
187
+ zipWithJson.add(file.path.replace(source + path_1.sep, ''), file.stats.isSymbolicLink()
188
+ ? fs_1.SYNC.readSymLink(file.path)
189
+ : fs_1.SYNC.getReadStream(file.path), {
190
+ mode: file.stats.mode
191
+ });
192
+ });
193
+ const zipFinalizerWithJson = yield zipWithJson.finalize();
194
+ return yield zipFinalizerWithJson.fsStream();
195
+ })
196
+ };
197
+ function validateServeCommand(targDetails) {
198
+ targDetails.forEach((targ) => {
199
+ var _a, _b;
200
+ if (((_a = targ.config) === null || _a === void 0 ? void 0 : _a.framework) !== 'static') {
201
+ const serveConfig = fs_1.SYNC.readJSONFile((0, path_1.join)(targ.source, constants_1.FILENAME.cli_config));
202
+ if (targ.validity.valid && !((_b = serveConfig === null || serveConfig === void 0 ? void 0 : serveConfig.slate) === null || _b === void 0 ? void 0 : _b.dev_command)) {
203
+ targ.validity = {
204
+ valid: false,
205
+ reason: 'Development command missing'
206
+ };
207
+ }
208
+ }
209
+ });
210
+ return targDetails;
211
+ }
212
+ exports.validateServeCommand = validateServeCommand;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.appSailConfig = exports.apigConfig = exports.functionsConfig = exports.clientConfig = void 0;
26
+ exports.slateConfig = exports.appSailConfig = exports.apigConfig = exports.functionsConfig = exports.clientConfig = void 0;
27
27
  const apigConfig = __importStar(require("./lib/apig"));
28
28
  exports.apigConfig = apigConfig;
29
29
  const clientConfig = __importStar(require("./lib/client"));
@@ -32,3 +32,5 @@ const functionsConfig = __importStar(require("./lib/functions"));
32
32
  exports.functionsConfig = functionsConfig;
33
33
  const appSailConfig = __importStar(require("./lib/appsail"));
34
34
  exports.appSailConfig = appSailConfig;
35
+ const slateConfig = __importStar(require("./lib/slate.js"));
36
+ exports.slateConfig = slateConfig;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAllTargetDetails = exports.getTargetDetails = exports.raw = void 0;
16
+ const ansi_colors_1 = require("ansi-colors");
17
+ const error_1 = __importDefault(require("../../../error"));
18
+ const runtime_store_1 = __importDefault(require("../../../runtime-store"));
19
+ const constants_1 = require("../../constants");
20
+ const fs_1 = require("../../fs");
21
+ const toml_1 = require("../../parser/toml");
22
+ const project_1 = require("../../project");
23
+ const path_1 = require("path");
24
+ function raw(throwError = false) {
25
+ const config = runtime_store_1.default.get('config', null);
26
+ if (config === null) {
27
+ if (throwError) {
28
+ throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 2 });
29
+ }
30
+ return;
31
+ }
32
+ return config.get('slate');
33
+ }
34
+ exports.raw = raw;
35
+ function getTargetDetails(targ) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const rawTargets = raw();
38
+ const target = rawTargets === null || rawTargets === void 0 ? void 0 : rawTargets.find((tar) => tar.name === targ.name);
39
+ if (!target) {
40
+ return Object.assign(Object.assign({}, targ), { validity: { valid: false, reason: 'Slate not found' } });
41
+ }
42
+ const slateConfigPth = (0, project_1.resolveProjectPath)((0, path_1.join)(targ.source, '.catalyst', constants_1.FILENAME.slate_config));
43
+ const slateConfigJson = fs_1.SYNC.readFile(slateConfigPth);
44
+ const slateConfig = (0, toml_1.parseTOML)(slateConfigJson);
45
+ if (!slateConfig) {
46
+ return Object.assign(Object.assign({}, targ), { validity: { valid: false, reason: 'Config file is empty' } });
47
+ }
48
+ target.config = slateConfig;
49
+ return Object.assign({}, target);
50
+ });
51
+ }
52
+ exports.getTargetDetails = getTargetDetails;
53
+ function getAllTargetDetails(throwErr = true) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const rawTargets = raw();
56
+ if (!rawTargets) {
57
+ if (throwErr) {
58
+ throw new error_1.default('No Slate targets found');
59
+ }
60
+ return;
61
+ }
62
+ return Promise.all(rawTargets.reduce((resArr, target) => {
63
+ const isPath = fs_1.SYNC.dirExists(target.source);
64
+ if (!isPath) {
65
+ resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: {
66
+ valid: false,
67
+ reason: `Invalid source path: (${(0, ansi_colors_1.bold)(target.source)}) directory not found`
68
+ } })));
69
+ return resArr;
70
+ }
71
+ const slateConfigPth = (0, project_1.resolveProjectPath)((0, path_1.join)(target.source, '.catalyst', constants_1.FILENAME.slate_config));
72
+ const isConfigPath = fs_1.SYNC.fileExists(slateConfigPth);
73
+ if (!isConfigPath) {
74
+ resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: {
75
+ valid: false,
76
+ reason: 'Config file not present'
77
+ } })));
78
+ return resArr;
79
+ }
80
+ const slateConfigJson = fs_1.SYNC.readFile(slateConfigPth);
81
+ const slateConfig = (0, toml_1.parseTOML)(slateConfigJson);
82
+ if (!slateConfig) {
83
+ resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: { valid: false, reason: 'Config file is empty' } })));
84
+ return resArr;
85
+ }
86
+ target.config = slateConfig;
87
+ resArr.push(new Promise((res) => __awaiter(this, void 0, void 0, function* () {
88
+ return res(Object.assign(Object.assign({}, target), { validity: { valid: true } }));
89
+ })));
90
+ return resArr;
91
+ }, []));
92
+ });
93
+ }
94
+ exports.getAllTargetDetails = getAllTargetDetails;
@@ -48,5 +48,13 @@ exports.default = Object.freeze({
48
48
  w_auth: 'us',
49
49
  m_auth: 'us',
50
50
  ext: '.sa'
51
+ },
52
+ jp: {
53
+ loc: 'Japan',
54
+ ref: 'jp',
55
+ value: 'jp',
56
+ w_auth: 'us',
57
+ m_auth: 'us',
58
+ ext: '.jp'
51
59
  }
52
60
  });
@@ -19,6 +19,10 @@ exports.default = Object.freeze({
19
19
  master: 3000,
20
20
  service: 4600
21
21
  },
22
+ slate: {
23
+ master: 3000,
24
+ service: 4800
25
+ },
22
26
  client: 5000
23
27
  },
24
28
  debug: {
@@ -5,6 +5,10 @@ exports.default = Object.freeze({
5
5
  http_log: 'catalyst-http-log.json',
6
6
  rc: '.catalystrc',
7
7
  config: 'catalyst.json',
8
+ slate: {
9
+ config_json: 'files.json',
10
+ static_zip: 'static.zip'
11
+ },
8
12
  client: {
9
13
  package_json: 'client-package.json',
10
14
  notFoundPage: '404.html'
@@ -23,9 +27,11 @@ exports.default = Object.freeze({
23
27
  system_rules: 'catalyst-system-rules.json'
24
28
  },
25
29
  catalyst_config: 'catalyst-config.json',
30
+ slate_config: 'slate-config.toml',
26
31
  command_log: '.command.log',
27
32
  node_modules: 'node_modules',
28
33
  app_config: 'app-config.json',
29
34
  package_json: 'package.json',
30
- catalyst_ignore: '.catalystignore'
35
+ catalyst_ignore: '.catalystignore',
36
+ cli_config: 'cli-config.json'
31
37
  });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = Object.freeze({
4
4
  client: 'client',
5
5
  functions: 'functions',
6
+ slate: '.slate',
6
7
  java_fn_lib: 'lib',
7
8
  build: '.build',
8
9
  output: '.output'
@@ -80,5 +80,7 @@ exports.default = Object.freeze({
80
80
  zest_spec_read: 'ZohoZEST.specifications.READ',
81
81
  zest_spec_all: 'ZohoZEST.specifications.ALL',
82
82
  zest_spec_src_action: 'ZohoZEST.specifications.sources.CREATE',
83
- zest_schedule_job_read: 'ZohoZEST.scheduled_jobs.READ'
83
+ zest_schedule_job_read: 'ZohoZEST.scheduled_jobs.READ',
84
+ slate_read: 'ZohoCatalyst.Slate.app.READ',
85
+ slate_create: 'ZohoCatalyst.Slate.app.CREATE'
84
86
  });
@@ -8,7 +8,7 @@ const runtime_store_1 = __importDefault(require("../runtime-store"));
8
8
  const ansi_colors_1 = require("ansi-colors");
9
9
  const fs_1 = require("./fs");
10
10
  const logger_1 = require("./logger");
11
- const toml_1 = __importDefault(require("./parser/toml"));
11
+ const toml_1 = require("./parser/toml");
12
12
  function help() {
13
13
  let exitCode = 0;
14
14
  const logs = runtime_store_1.default.get('log');
@@ -40,7 +40,7 @@ function help() {
40
40
  }
41
41
  const docPath = ((_a = errQueue[0].fileName) === null || _a === void 0 ? void 0 : _a.replace((0, path_1.join)(__dirname, '../../lib'), (0, path_1.join)(__dirname, '../../docs'))) + '.toml';
42
42
  const doc = fs_1.SYNC.readFile(docPath) || '';
43
- const catHelp = (0, toml_1.default)(doc);
43
+ const catHelp = (0, toml_1.parseTOML)(doc);
44
44
  errQueue.forEach((err) => {
45
45
  exitCode = err.exit > exitCode ? err.exit : exitCode;
46
46
  if (err.errorId === undefined ||
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.chmod = exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.findAndReplace = exports.rename = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteDir = exports.deleteFile = exports.ensureDir = exports.ensureFile = exports.walk = exports.dirList = exports.writeFile = exports.tempFile = exports.readFile = exports.fileExists = exports.dirExists = exports.isPathExists = void 0;
15
+ exports.isDirEmpty = exports.chmod = exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.findAndReplace = exports.rename = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteDir = exports.deleteFile = exports.ensureDir = exports.ensureFile = exports.walk = exports.dirList = exports.writeFile = exports.tempFile = exports.readFile = exports.fileExists = exports.dirExists = exports.isPathExists = void 0;
16
16
  const fs_extra_1 = __importDefault(require("fs-extra"));
17
17
  const minimatch_1 = __importDefault(require("minimatch"));
18
18
  const os_1 = __importDefault(require("os"));
@@ -84,7 +84,8 @@ function dirList(dir) {
84
84
  exports.dirList = dirList;
85
85
  function walk(dir, { filter = {
86
86
  exclude: [],
87
- excludeDir: true
87
+ excludeDir: true,
88
+ ignoreFiles: false
88
89
  }, depth = -1, includeDirPaths = false } = {}) {
89
90
  return __awaiter(this, void 0, void 0, function* () {
90
91
  const stats = yield fs_extra_1.default.lstat(dir);
@@ -98,7 +99,7 @@ function walk(dir, { filter = {
98
99
  const entryPathStats = yield fs_extra_1.default.lstat(entryPath);
99
100
  const isEntryPthDir = entryPathStats.isDirectory() && !entryPathStats.isSymbolicLink();
100
101
  let excludeMatch = false;
101
- if (!(isEntryPthDir && !filter.excludeDir)) {
102
+ if (!isEntryPthDir || filter.excludeDir) {
102
103
  if (typeof filter.exclude === 'function') {
103
104
  excludeMatch = excludeMatch || (yield filter.exclude(entryPath));
104
105
  }
@@ -108,6 +109,9 @@ function walk(dir, { filter = {
108
109
  }
109
110
  }
110
111
  }
112
+ if (!isEntryPthDir && filter.ignoreFiles && !excludeMatch) {
113
+ excludeMatch = true;
114
+ }
111
115
  if (excludeMatch) {
112
116
  return [];
113
117
  }
@@ -249,3 +253,10 @@ function chmod(path, mode, { checkPath = true, recursive = false } = {}) {
249
253
  });
250
254
  }
251
255
  exports.chmod = chmod;
256
+ function isDirEmpty(pth) {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ const files = yield fs_extra_1.default.readdir(pth);
259
+ return files.length === 0;
260
+ });
261
+ }
262
+ exports.isDirEmpty = isDirEmpty;