zcatalyst-cli 1.26.0 → 1.26.2

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.
@@ -1,3 +1,3 @@
1
1
  import { TAppSailDetails } from './util_modules/config/lib/appsail';
2
2
  export declare function filterTargets(allTargets: Array<TAppSailDetails>): Array<TAppSailDetails>;
3
- export declare function validateAppSail(targDetails: Array<TAppSailDetails>): Promise<Array<TAppSailDetails>>;
3
+ export declare function validateAppSail(targDetails: Array<TAppSailDetails>, resolveLocalRuntime?: boolean): [Promise<Array<TAppSailDetails>>, Record<string, string>];
@@ -24,6 +24,10 @@ const container_1 = require("./util_modules/container");
24
24
  const image_1 = require("@zcatalyst/container-plugin/out/endpoints/image");
25
25
  const fs_1 = require("./util_modules/fs");
26
26
  const util_1 = require("util");
27
+ const node_1 = require("./fn-utils/lib/node");
28
+ const java_1 = require("./fn-utils/lib/java");
29
+ const ensure_python_1 = require("./init/dependencies/python/ensure-python");
30
+ const path_1 = require("path");
27
31
  const OCI_IMAGE_INDEX_MEDIA_TYPES = [
28
32
  'application/vnd.oci.image.index.v1+json',
29
33
  'application/vnd.docker.distribution.manifest.list.v2+json'
@@ -98,158 +102,195 @@ function filterTargets(allTargets) {
98
102
  }
99
103
  return allTargets;
100
104
  }
101
- function validateAppSail(targDetails) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- let isSocket;
104
- const getImageInfo = (target) => __awaiter(this, void 0, void 0, function* () {
105
- switch (true) {
106
- case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker): {
107
- const imgTag = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker, '');
108
- return (0, image_1.inspectImage)(imgTag);
105
+ function validateAppSail(targDetails, resolveLocalRuntime = true) {
106
+ let isSocket;
107
+ const binPathMap = {};
108
+ const getImageInfo = (target) => __awaiter(this, void 0, void 0, function* () {
109
+ switch (true) {
110
+ case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker): {
111
+ const imgTag = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker, '');
112
+ return (0, image_1.inspectImage)(imgTag);
113
+ }
114
+ case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive): {
115
+ const imgTar = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive, '');
116
+ const isFile = yield fs_1.ASYNC.fileExists(imgTar);
117
+ if (!isFile) {
118
+ throw new error_1.default('Invalid image tar path: ' + imgTar, { exit: 1 });
109
119
  }
110
- case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive): {
111
- const imgTar = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive, '');
112
- const isFile = yield fs_1.ASYNC.fileExists(imgTar);
113
- if (!isFile) {
114
- throw new error_1.default('Invalid image tar path: ' + imgTar, { exit: 1 });
115
- }
116
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
117
- var _a;
118
- try {
119
- const manifestJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'manifest.json');
120
- const repositoriesStream = yield (0, image_1.getTarEntry)(imgTar, 'repositories');
121
- const indexJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'index.json');
122
- if (!indexJsonStream) {
123
- if (manifestJsonStream || repositoriesStream) {
124
- throw new error_1.default('Legacy docker-archive format is not supported. Only OCI-compliant docker-archive formats (pure OCI or hybrid OCI) are supported.', { exit: 1 });
125
- }
126
- throw new error_1.default('Corrupted image tar :: required OCI metadata index.json not found in the tar', { exit: 1 });
127
- }
128
- const indexJson = yield fs_1.ASYNC.readStreamAsJSON(indexJsonStream);
129
- if (indexJson.schemaVersion !== 2) {
130
- throw new error_1.default('Corrupted image tar :: invalid index.json file. Unsupported schemaVersion', { exit: 1 });
120
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
121
+ var _a;
122
+ try {
123
+ const manifestJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'manifest.json');
124
+ const repositoriesStream = yield (0, image_1.getTarEntry)(imgTar, 'repositories');
125
+ const indexJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'index.json');
126
+ if (!indexJsonStream) {
127
+ if (manifestJsonStream || repositoriesStream) {
128
+ throw new error_1.default('Legacy docker-archive format is not supported. Only OCI-compliant docker-archive formats (pure OCI or hybrid OCI) are supported.', { exit: 1 });
131
129
  }
132
- const traversedDigests = new Set();
133
- const resolveImageManifestPath = (manifestIndex, sourceFile) => __awaiter(this, void 0, void 0, function* () {
134
- var _a;
135
- const imageDescriptor = (_a = manifestIndex.manifests) === null || _a === void 0 ? void 0 : _a.find((manifest) => {
136
- if (!(manifest === null || manifest === void 0 ? void 0 : manifest.digest)) {
137
- return false;
138
- }
139
- if (!manifest.mediaType) {
140
- return true;
141
- }
142
- return (OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(manifest.mediaType) ||
143
- OCI_IMAGE_INDEX_MEDIA_TYPES.includes(manifest.mediaType));
144
- });
145
- if (!(imageDescriptor === null || imageDescriptor === void 0 ? void 0 : imageDescriptor.digest)) {
146
- throw new error_1.default(`Corrupted image tar :: invalid ${sourceFile} file. Unable to identify image manifest`, { exit: 1 });
147
- }
148
- if (traversedDigests.has(imageDescriptor.digest)) {
149
- throw new error_1.default(`Corrupted image tar :: circular descriptor reference found for digest ${imageDescriptor.digest}`, { exit: 1 });
150
- }
151
- if (!imageDescriptor.mediaType ||
152
- OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(imageDescriptor.mediaType)) {
153
- return getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
154
- }
155
- traversedDigests.add(imageDescriptor.digest);
156
- const nestedIndexPath = getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
157
- const nestedIndexStream = yield (0, image_1.getTarEntry)(imgTar, nestedIndexPath);
158
- if (!nestedIndexStream) {
159
- throw new error_1.default(`Corrupted image tar :: nested image index ${nestedIndexPath} not found in the tar`, { exit: 1 });
130
+ throw new error_1.default('Corrupted image tar :: required OCI metadata index.json not found in the tar', { exit: 1 });
131
+ }
132
+ const indexJson = yield fs_1.ASYNC.readStreamAsJSON(indexJsonStream);
133
+ if (indexJson.schemaVersion !== 2) {
134
+ throw new error_1.default('Corrupted image tar :: invalid index.json file. Unsupported schemaVersion', { exit: 1 });
135
+ }
136
+ const traversedDigests = new Set();
137
+ const resolveImageManifestPath = (manifestIndex, sourceFile) => __awaiter(this, void 0, void 0, function* () {
138
+ var _a;
139
+ const imageDescriptor = (_a = manifestIndex.manifests) === null || _a === void 0 ? void 0 : _a.find((manifest) => {
140
+ if (!(manifest === null || manifest === void 0 ? void 0 : manifest.digest)) {
141
+ return false;
160
142
  }
161
- const nestedIndex = yield fs_1.ASYNC.readStreamAsJSON(nestedIndexStream);
162
- if (nestedIndex.schemaVersion !== 2) {
163
- throw new error_1.default(`Corrupted image tar :: invalid nested image index ${nestedIndexPath}. Unsupported schemaVersion`, { exit: 1 });
143
+ if (!manifest.mediaType) {
144
+ return true;
164
145
  }
165
- return resolveImageManifestPath(nestedIndex, nestedIndexPath);
146
+ return (OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(manifest.mediaType) ||
147
+ OCI_IMAGE_INDEX_MEDIA_TYPES.includes(manifest.mediaType));
166
148
  });
167
- const imageManifestPath = yield resolveImageManifestPath(indexJson, 'index.json');
168
- const imageManifestStream = yield (0, image_1.getTarEntry)(imgTar, imageManifestPath);
169
- if (!imageManifestStream) {
170
- throw new error_1.default(`Corrupted image tar :: image manifest ${imageManifestPath} not found in the tar`, { exit: 1 });
149
+ if (!(imageDescriptor === null || imageDescriptor === void 0 ? void 0 : imageDescriptor.digest)) {
150
+ throw new error_1.default(`Corrupted image tar :: invalid ${sourceFile} file. Unable to identify image manifest`, { exit: 1 });
151
+ }
152
+ if (traversedDigests.has(imageDescriptor.digest)) {
153
+ throw new error_1.default(`Corrupted image tar :: circular descriptor reference found for digest ${imageDescriptor.digest}`, { exit: 1 });
171
154
  }
172
- const imageManifest = yield fs_1.ASYNC.readStreamAsJSON(imageManifestStream);
173
- if (imageManifest.schemaVersion !== 2) {
174
- throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unsupported schemaVersion', { exit: 1 });
155
+ if (!imageDescriptor.mediaType ||
156
+ OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(imageDescriptor.mediaType)) {
157
+ return getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
175
158
  }
176
- const configDigest = (_a = imageManifest.config) === null || _a === void 0 ? void 0 : _a.digest;
177
- if (!configDigest) {
178
- throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unable to identify the config blob', { exit: 1 });
159
+ traversedDigests.add(imageDescriptor.digest);
160
+ const nestedIndexPath = getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
161
+ const nestedIndexStream = yield (0, image_1.getTarEntry)(imgTar, nestedIndexPath);
162
+ if (!nestedIndexStream) {
163
+ throw new error_1.default(`Corrupted image tar :: nested image index ${nestedIndexPath} not found in the tar`, { exit: 1 });
179
164
  }
180
- const configBlobPath = getBlobPathFromDigest(configDigest, imageManifestPath);
181
- const configFileStream = yield (0, image_1.getTarEntry)(imgTar, configBlobPath);
182
- if (!configFileStream) {
183
- throw new error_1.default(`Corrupted image tar :: config blob ${configBlobPath} not found in the tar`, { exit: 1 });
165
+ const nestedIndex = yield fs_1.ASYNC.readStreamAsJSON(nestedIndexStream);
166
+ if (nestedIndex.schemaVersion !== 2) {
167
+ throw new error_1.default(`Corrupted image tar :: invalid nested image index ${nestedIndexPath}. Unsupported schemaVersion`, { exit: 1 });
184
168
  }
185
- const configFile = yield fs_1.ASYNC.readStreamAsJSON(configFileStream);
186
- resolve(configFile);
169
+ return resolveImageManifestPath(nestedIndex, nestedIndexPath);
170
+ });
171
+ const imageManifestPath = yield resolveImageManifestPath(indexJson, 'index.json');
172
+ const imageManifestStream = yield (0, image_1.getTarEntry)(imgTar, imageManifestPath);
173
+ if (!imageManifestStream) {
174
+ throw new error_1.default(`Corrupted image tar :: image manifest ${imageManifestPath} not found in the tar`, { exit: 1 });
187
175
  }
188
- catch (er) {
189
- er instanceof error_1.default
190
- ? reject(er)
191
- : reject(error_1.default.getErrorInstance(er));
176
+ const imageManifest = yield fs_1.ASYNC.readStreamAsJSON(imageManifestStream);
177
+ if (imageManifest.schemaVersion !== 2) {
178
+ throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unsupported schemaVersion', { exit: 1 });
192
179
  }
193
- }));
194
- }
195
- default: {
196
- throw new error_1.default('Unsupported image source: ' + target.source, { exit: 1 });
197
- }
198
- }
199
- });
200
- const _details = targDetails.map((targ) => __awaiter(this, void 0, void 0, function* () {
201
- var _a, _b;
202
- if (targ.validity.valid) {
203
- if (targ.runtime === 'custom') {
204
- if (isSocket === undefined) {
205
- isSocket = yield (0, container_1.isSocketAccessible)(false);
206
- }
207
- if (isSocket === false) {
208
- targ.validity = {
209
- valid: false,
210
- reason: 'ZCatalyst-CLI is unable to communicate with the Container runtime'
211
- };
212
- return targ;
213
- }
214
- try {
215
- const imgInfo = (yield getImageInfo(targ));
216
- const os = 'os' in imgInfo ? imgInfo.os : imgInfo.Os;
217
- if ((os === null || os === void 0 ? void 0 : os.toLowerCase()) !== 'linux') {
218
- targ.validity = {
219
- valid: false,
220
- reason: 'container image should be Linux based'
221
- };
222
- return targ;
180
+ const configDigest = (_a = imageManifest.config) === null || _a === void 0 ? void 0 : _a.digest;
181
+ if (!configDigest) {
182
+ throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unable to identify the config blob', { exit: 1 });
223
183
  }
224
- const arch = 'architecture' in imgInfo
225
- ? imgInfo.architecture
226
- : imgInfo.Architecture;
227
- if ((arch === null || arch === void 0 ? void 0 : arch.toLowerCase()) !== 'amd64') {
228
- targ.validity = {
229
- valid: false,
230
- reason: 'container image should be amd64 based'
231
- };
232
- return targ;
184
+ const configBlobPath = getBlobPathFromDigest(configDigest, imageManifestPath);
185
+ const configFileStream = yield (0, image_1.getTarEntry)(imgTar, configBlobPath);
186
+ if (!configFileStream) {
187
+ throw new error_1.default(`Corrupted image tar :: config blob ${configBlobPath} not found in the tar`, { exit: 1 });
233
188
  }
189
+ const configFile = yield fs_1.ASYNC.readStreamAsJSON(configFileStream);
190
+ resolve(configFile);
234
191
  }
235
192
  catch (er) {
236
- targ.validity = {
237
- valid: false,
238
- reason: er instanceof error_1.default ? er.message : (0, util_1.inspect)(er)
239
- };
193
+ er instanceof error_1.default
194
+ ? reject(er)
195
+ : reject(error_1.default.getErrorInstance(er));
240
196
  }
197
+ }));
198
+ }
199
+ default: {
200
+ throw new error_1.default('Unsupported image source: ' + target.source, { exit: 1 });
201
+ }
202
+ }
203
+ });
204
+ const _details = targDetails.map((targ) => __awaiter(this, void 0, void 0, function* () {
205
+ var _a, _b, _c;
206
+ if (!targ.validity.valid) {
207
+ return targ;
208
+ }
209
+ if (targ.runtime === 'custom') {
210
+ if (isSocket === undefined) {
211
+ isSocket = yield (0, container_1.isSocketAccessible)(false);
212
+ }
213
+ if (isSocket === false) {
214
+ targ.validity = {
215
+ valid: false,
216
+ reason: 'ZCatalyst-CLI is unable to communicate with the Container runtime'
217
+ };
218
+ return targ;
219
+ }
220
+ try {
221
+ const imgInfo = (yield getImageInfo(targ));
222
+ const os = 'os' in imgInfo ? imgInfo.os : imgInfo.Os;
223
+ if ((os === null || os === void 0 ? void 0 : os.toLowerCase()) !== 'linux') {
224
+ targ.validity = {
225
+ valid: false,
226
+ reason: 'container image should be Linux based'
227
+ };
241
228
  return targ;
242
229
  }
243
- if (((_a = targ.config) === null || _a === void 0 ? void 0 : _a.platform) !== 'war' && !((_b = targ.config) === null || _b === void 0 ? void 0 : _b.command)) {
230
+ const arch = 'architecture' in imgInfo
231
+ ? imgInfo.architecture
232
+ : imgInfo.Architecture;
233
+ if ((arch === null || arch === void 0 ? void 0 : arch.toLowerCase()) !== 'amd64') {
244
234
  targ.validity = {
245
235
  valid: false,
246
- reason: 'Start-up command missing'
236
+ reason: 'container image should be amd64 based'
247
237
  };
248
238
  return targ;
249
239
  }
250
240
  }
241
+ catch (er) {
242
+ targ.validity = {
243
+ valid: false,
244
+ reason: er instanceof error_1.default ? er.message : (0, util_1.inspect)(er)
245
+ };
246
+ }
251
247
  return targ;
252
- }));
253
- return Promise.all(_details);
254
- });
248
+ }
249
+ try {
250
+ const stack = (_a = targ.config) === null || _a === void 0 ? void 0 : _a.stack;
251
+ if (!stack) {
252
+ throw new error_1.default(`Stack is not defined for AppSail target ${targ.name}`, {
253
+ exit: 2
254
+ });
255
+ }
256
+ if (((_b = targ.config) === null || _b === void 0 ? void 0 : _b.platform) !== 'war' && !((_c = targ.config) === null || _c === void 0 ? void 0 : _c.command)) {
257
+ throw new error_1.default(`Start-up command missing for AppSail target ${targ.name}`, {
258
+ exit: 2
259
+ });
260
+ }
261
+ if (resolveLocalRuntime === false) {
262
+ return targ;
263
+ }
264
+ if (binPathMap[stack]) {
265
+ return targ;
266
+ }
267
+ switch (true) {
268
+ case stack.startsWith('node'): {
269
+ binPathMap[stack] = yield (0, node_1.ensureNodeVersion)(stack, true);
270
+ break;
271
+ }
272
+ case stack.startsWith('java'): {
273
+ const javaBinPath = yield (0, java_1.ensureJava)(stack);
274
+ if (!javaBinPath) {
275
+ throw new error_1.default(`Invalid bin path for ${stack}`, { exit: 1 });
276
+ }
277
+ binPathMap[stack] = javaBinPath;
278
+ break;
279
+ }
280
+ case stack.startsWith('python'): {
281
+ const stackVersion = stack.replace('python_', '');
282
+ const pyExe = yield (0, ensure_python_1.ensurePython)(stackVersion.replace('_', '.'), false, true);
283
+ binPathMap[stack] = (0, path_1.dirname)(pyExe);
284
+ break;
285
+ }
286
+ }
287
+ }
288
+ catch (err) {
289
+ const error = error_1.default.getErrorInstance(err);
290
+ targ.validity.valid = false;
291
+ targ.validity.reason = error.message;
292
+ }
293
+ return targ;
294
+ }));
295
+ return [Promise.all(_details), binPathMap];
255
296
  }
@@ -43,7 +43,8 @@ exports.default = (...args_1) => __awaiter(void 0, [...args_1], void 0, function
43
43
  throw new error_1.default('No targets found');
44
44
  }
45
45
  const filtered = (0, appsail_utils_1.filterTargets)(targets);
46
- const validTargets = (yield (0, appsail_utils_1.validateAppSail)(filtered)).filter((targ) => {
46
+ const [_validatePromise] = (0, appsail_utils_1.validateAppSail)(filtered, false);
47
+ const validTargets = (yield _validatePromise).filter((targ) => {
47
48
  if (targ.validity.valid) {
48
49
  return targ;
49
50
  }
@@ -27,7 +27,7 @@ const urls_1 = __importDefault(require("../../util_modules/constants/lib/urls"))
27
27
  const project_1 = require("../../util_modules/project");
28
28
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
29
29
  const env = getEnvironmentType();
30
- const targets = yield config_1.slateConfig.getAllTargetDetails(false);
30
+ const targets = yield config_1.slateConfig.getAllTargetDetails(false, false);
31
31
  if (!targets || targets.length === 0) {
32
32
  throw new error_1.default('No targets found');
33
33
  }
@@ -50,7 +50,6 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
50
50
  const slateAppConfigs = yield (yield (0, endpoints_1.slateAPI)({ env })).getAllApps();
51
51
  const throbber = throbber_1.default.getInstance();
52
52
  const deployRes = yield validTargets.reduce((result, _targ) => __awaiter(void 0, void 0, void 0, function* () {
53
- var _a;
54
53
  const targ = _targ;
55
54
  const prevRes = yield result;
56
55
  try {
@@ -59,9 +58,14 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
59
58
  text: `Preparing Slate[${targ.name}]`
60
59
  });
61
60
  const isAppExists = slateAppConfigs.find((app) => app.name === targ.name && app.app_type === 'cli');
62
- const configDetails = !isAppExists
63
- ? (_a = (yield config_1.slateConfig.getTargetDetails(targ))) === null || _a === void 0 ? void 0 : _a.config
64
- : undefined;
61
+ let configDetails;
62
+ if (!isAppExists) {
63
+ const targetWithConfig = yield config_1.slateConfig.getTargetDetails(targ);
64
+ if (!targetWithConfig.config) {
65
+ throw new error_1.default('Unable to read slate configuration for deploy');
66
+ }
67
+ configDetails = targetWithConfig.config;
68
+ }
65
69
  const deploymentName = configDetails === null || configDetails === void 0 ? void 0 : configDetails.deployment_name;
66
70
  deploymentName ? configDetails === null || configDetails === void 0 ? true : delete configDetails.deployment_name : null;
67
71
  const readStream = yield slate_utils_1.slateUtils.pack(targ.source);
@@ -13,3 +13,8 @@ context = '''Error when installing the dependencies.'''
13
13
  aid = '''Please install the necessary packages before running the command ${arg[0]}'''
14
14
  link = 'https://docs.catalyst.zoho.com/en/cli/v1/serve-resources/serve-all-resources/#serve-a-slate-app'
15
15
 
16
+ [SERVE-SLATE-4]
17
+ context = '''The cli-config.json file was not found in the slate source directory ${arg[0]}.'''
18
+ aid = '''Please ensure cli-config.json exists in the slate source directory with a valid dev_command using ZC_SLATE_PORT.'''
19
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/serve-resources/serve-all-resources/#serve-a-slate-app'
20
+
@@ -202,9 +202,11 @@ function addExistingSlate(existingSlates) {
202
202
  return __awaiter(this, void 0, void 0, function* () {
203
203
  const projectRoot = (0, project_1.getProjectRoot)();
204
204
  const sourceOpt = (0, option_1.getOptionValue)('source');
205
+ const isDuplicate = (candidateAbs) => existingSlates.findIndex((targ) => (0, path_1.resolve)(projectRoot, targ.source) === candidateAbs) !==
206
+ -1;
205
207
  if (sourceOpt) {
206
208
  const buildPath = (0, path_1.resolve)(projectRoot, sourceOpt);
207
- if (existingSlates.findIndex((targ) => targ.source === buildPath) !== -1) {
209
+ if (isDuplicate(buildPath)) {
208
210
  throw new error_1.default(`Path ${(0, ansi_colors_1.bold)(buildPath)} is already linked to a Slate app.`, {
209
211
  exit: 1
210
212
  });
@@ -221,7 +223,7 @@ function addExistingSlate(existingSlates) {
221
223
  type: 'file-path',
222
224
  validate: (pth) => __awaiter(this, void 0, void 0, function* () {
223
225
  const buildPath = (0, path_1.resolve)(projectRoot, pth.value);
224
- if (existingSlates.findIndex((targ) => targ.source === buildPath) !== -1)
226
+ if (isDuplicate(buildPath))
225
227
  return 'Path is already linked.';
226
228
  if (yield fs_1.ASYNC.dirExists(buildPath)) {
227
229
  return true;
@@ -12,12 +12,8 @@ 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
- const path_1 = require("path");
16
15
  const appsail_utils_1 = require("../../appsail-utils");
17
16
  const error_1 = __importDefault(require("../../error"));
18
- const java_1 = require("../../fn-utils/lib/java");
19
- const node_1 = require("../../fn-utils/lib/node");
20
- const ensure_python_1 = require("../../init/dependencies/python/ensure-python");
21
17
  const port_resolver_1 = __importDefault(require("../../port-resolver"));
22
18
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
23
19
  const config_1 = require("../../util_modules/config");
@@ -30,47 +26,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
30
26
  (0, index_1.debug)('AppSail targets are empty');
31
27
  return [];
32
28
  }
33
- const validated = yield (0, appsail_utils_1.validateAppSail)(optionTargets);
34
- const binPathMap = {};
35
- yield Promise.all(validated.map((target) => __awaiter(void 0, void 0, void 0, function* () {
36
- var _a;
37
- try {
38
- const stack = (_a = target.config) === null || _a === void 0 ? void 0 : _a.stack;
39
- if (!stack) {
40
- throw new error_1.default(`Stack is not defined for AppSail target ${target.name}`, {
41
- exit: 2
42
- });
43
- }
44
- if (binPathMap[stack]) {
45
- return;
46
- }
47
- switch (true) {
48
- case stack.startsWith('node'): {
49
- binPathMap[stack] = yield (0, node_1.ensureNodeVersion)(stack, true);
50
- break;
51
- }
52
- case stack.startsWith('java'): {
53
- const javaBinPath = yield (0, java_1.ensureJava)(stack);
54
- if (!javaBinPath) {
55
- throw new error_1.default(`Invalid bin path for ${stack}`, { exit: 1 });
56
- }
57
- binPathMap[stack] = javaBinPath;
58
- break;
59
- }
60
- case stack.startsWith('python'): {
61
- const stackVersion = stack.replace('python_', '');
62
- const pyExe = yield (0, ensure_python_1.ensurePython)(stackVersion.replace('_', '.'), false, true);
63
- binPathMap[stack] = (0, path_1.dirname)(pyExe);
64
- break;
65
- }
66
- }
67
- }
68
- catch (err) {
69
- const error = error_1.default.getErrorInstance(err);
70
- target.validity.valid = false;
71
- target.validity.reason = error.message;
72
- }
73
- })));
29
+ const [_validatePromise, binPathMap] = (0, appsail_utils_1.validateAppSail)(optionTargets);
30
+ const validated = yield _validatePromise;
74
31
  const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () {
75
32
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
76
33
  if (!targ.validity.valid) {
@@ -4,7 +4,8 @@
4
4
  // exit codes
5
5
  // 150 - start up command failure
6
6
 
7
- const { spawn } = require('cross-spawn');
7
+ const EXEC = require('child_process').exec;
8
+
8
9
  const WAR = 'war';
9
10
  const JAVASE = 'javase';
10
11
  const NODEJS = 'nodejs';
@@ -61,12 +62,7 @@ function main() {
61
62
  throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
62
63
  }
63
64
 
64
- const _process = spawn('sh', ['-c', command.toString()], {
65
- cwd,
66
- env: process.env,
67
- stdio: 'pipe',
68
- detached: true
69
- });
65
+ const _process = EXEC(command.toString(), { cwd });
70
66
 
71
67
  _process.on('error', (error) => {
72
68
  // eslint-disable-next-line no-console
@@ -77,11 +73,8 @@ function main() {
77
73
  _process.stdout.pipe(process.stdout);
78
74
  _process.stderr.pipe(process.stderr);
79
75
 
80
- ['SIGINT', 'SIGTERM'].forEach((signal) => {
81
- process.on(signal, () => {
82
- process.kill(-_process.pid, signal);
83
- process.exit();
84
- });
76
+ process.once('SIGINT', () => {
77
+ _process.kill('SIGINT');
85
78
  });
86
79
  }
87
80
 
@@ -51,6 +51,13 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
51
51
  }
52
52
  else {
53
53
  const configFile = (0, path_1.join)(targetSlate.source, file_names_1.default.cli_config);
54
+ if (!(yield (0, async_1.fileExists)(configFile))) {
55
+ throw new error_1.default('cli-config.json file not found in source directory', {
56
+ exit: 1,
57
+ errorId: 'SERVE-SLATE-4',
58
+ arg: [targetSlate.source]
59
+ });
60
+ }
54
61
  const configJson = yield (0, async_1.readJSONFile)(configFile);
55
62
  const installDeps = (0, shell_1.spawn)('npm', ['install'], {
56
63
  cwd: targetSlate.source
@@ -18,12 +18,13 @@ const ansi_colors_1 = require("ansi-colors");
18
18
  const path_1 = require("path");
19
19
  const archiver_1 = __importDefault(require("./archiver"));
20
20
  const error_1 = __importDefault(require("./error"));
21
- const runtime_store_1 = __importDefault(require("./runtime-store"));
22
21
  const fs_1 = require("./util_modules/fs");
23
22
  const option_1 = require("./util_modules/option");
24
23
  const constants_1 = require("./util_modules/constants");
25
24
  const logger_1 = require("./util_modules/logger");
26
25
  const minimatch_1 = __importDefault(require("minimatch"));
26
+ const sync_1 = require("./util_modules/fs/lib/sync");
27
+ const project_1 = require("./util_modules/project");
27
28
  exports.slateUtils = {
28
29
  validate: (source) => __awaiter(void 0, void 0, void 0, function* () {
29
30
  const sourceDirExists = yield fs_1.ASYNC.dirExists(source);
@@ -92,11 +93,10 @@ exports.slateUtils = {
92
93
  }
93
94
  return refined.matched;
94
95
  }
95
- const refinedTargets = allTargets.filter((app) => app.source.includes(runtime_store_1.default.get('cwd')));
96
- if (refinedTargets.length === 0 || !refinedTargets) {
97
- throw new error_1.default('You are not in a catalyst app directory.');
98
- }
99
- return refinedTargets;
96
+ return allTargets.filter((app) => {
97
+ const rel = (0, path_1.relative)((0, project_1.getProjectRoot)(), app.source);
98
+ return rel === '' || (!rel.startsWith('..') && !rel.startsWith(path_1.sep + '..'));
99
+ });
100
100
  },
101
101
  pack: (source) => __awaiter(void 0, void 0, void 0, function* () {
102
102
  const excludePatterns = [
@@ -135,18 +135,27 @@ function validateServeCommand(targDetails) {
135
135
  targDetails.forEach((targ) => {
136
136
  var _a, _b, _c;
137
137
  if (((_a = targ.config) === null || _a === void 0 ? void 0 : _a.framework) !== 'static') {
138
- const serveConfig = fs_1.SYNC.readJSONFile((0, path_1.join)(targ.source, constants_1.FILENAME.cli_config));
139
- if (targ.validity.valid && !((_b = serveConfig === null || serveConfig === void 0 ? void 0 : serveConfig.slate) === null || _b === void 0 ? void 0 : _b.dev_command)) {
138
+ const configPath = (0, path_1.join)(targ.source, constants_1.FILENAME.cli_config);
139
+ if (!(0, sync_1.fileExists)(configPath)) {
140
140
  targ.validity = {
141
141
  valid: false,
142
- reason: 'Development command missing'
142
+ reason: 'Missing cli-config.json file in source directory'
143
143
  };
144
144
  }
145
- if (!((_c = serveConfig === null || serveConfig === void 0 ? void 0 : serveConfig.slate) === null || _c === void 0 ? void 0 : _c.dev_command).includes('ZC_SLATE_PORT')) {
146
- targ.validity = {
147
- valid: false,
148
- reason: `Port configuration is missing. Please set the ${(0, ansi_colors_1.bold)('ZC_SLATE_PORT')} as the port value in ${(0, ansi_colors_1.bold)('cli-config.json')} under your development command.`
149
- };
145
+ else {
146
+ const serveConfig = fs_1.SYNC.readJSONFile(configPath);
147
+ if (targ.validity.valid && !((_b = serveConfig === null || serveConfig === void 0 ? void 0 : serveConfig.slate) === null || _b === void 0 ? void 0 : _b.dev_command)) {
148
+ targ.validity = {
149
+ valid: false,
150
+ reason: 'Development command missing'
151
+ };
152
+ }
153
+ if (!((_c = serveConfig === null || serveConfig === void 0 ? void 0 : serveConfig.slate) === null || _c === void 0 ? void 0 : _c.dev_command).includes('ZC_SLATE_PORT')) {
154
+ targ.validity = {
155
+ valid: false,
156
+ reason: `Port configuration is missing. Please set the ${(0, ansi_colors_1.bold)('ZC_SLATE_PORT')} as the port value in ${(0, ansi_colors_1.bold)('cli-config.json')} under your development command.`
157
+ };
158
+ }
150
159
  }
151
160
  }
152
161
  });
@@ -27,7 +27,7 @@ exports.CONTAINER_IMAGE_PROTOCOLS = {
27
27
  docker: 'docker://',
28
28
  dockerArchive: 'docker-archive://'
29
29
  };
30
- function validateConfig(source, configJson) {
30
+ function validateManagedAppConfig(source, configJson) {
31
31
  if (!configJson) {
32
32
  return {
33
33
  valid: false,
@@ -73,6 +73,19 @@ function validateConfig(source, configJson) {
73
73
  };
74
74
  }
75
75
  }
76
+ if (!configJson.stack || configJson.stack.length === 0) {
77
+ return {
78
+ valid: false,
79
+ reason: 'Stack is not defined'
80
+ };
81
+ }
82
+ if (!configJson.command &&
83
+ !(configJson.stack.startsWith('java') && configJson.platform === 'war')) {
84
+ return {
85
+ valid: false,
86
+ reason: 'Start-up command is missing'
87
+ };
88
+ }
76
89
  return {
77
90
  valid: true
78
91
  };
@@ -177,7 +190,7 @@ function getAllTargetDetails() {
177
190
  try {
178
191
  const configJson = yield fs_1.ASYNC.readJSONFile(catalystConfigPth);
179
192
  configJson && (configJson.raw = {});
180
- target.validity = validateConfig(target.source, configJson);
193
+ target.validity = validateManagedAppConfig(target.source, configJson);
181
194
  target.config = configJson;
182
195
  return res(target);
183
196
  }
@@ -95,6 +95,7 @@ export interface ISlateConfig {
95
95
  config?: ISlateConfigDetails;
96
96
  details?: ISlateUploadResponse;
97
97
  source: string;
98
+ originalSource?: string;
98
99
  name: string;
99
100
  validity: {
100
101
  valid?: boolean;
@@ -103,4 +104,4 @@ export interface ISlateConfig {
103
104
  }
104
105
  export declare function raw(throwError?: boolean): Array<ISlateConfig> | undefined;
105
106
  export declare function getTargetDetails(targ: ISlateConfig): Promise<ISlateConfig>;
106
- export declare function getAllTargetDetails(throwErr?: boolean): Promise<Array<ISlateConfig> | undefined>;
107
+ export declare function getAllTargetDetails(throwErr?: boolean, loadConfig?: boolean): Promise<Array<ISlateConfig> | undefined>;
@@ -33,6 +33,11 @@ function raw(throwError = false) {
33
33
  }
34
34
  return config.get('slate');
35
35
  }
36
+ function normalizeTarget(target) {
37
+ const originalSource = target.source;
38
+ const resolvedSource = (0, project_1.resolveProjectPath)(originalSource);
39
+ return Object.assign(Object.assign({}, target), { source: resolvedSource, originalSource });
40
+ }
36
41
  function getTargetDetails(targ) {
37
42
  return __awaiter(this, void 0, void 0, function* () {
38
43
  const rawTargets = raw();
@@ -40,18 +45,22 @@ function getTargetDetails(targ) {
40
45
  if (!target) {
41
46
  return Object.assign(Object.assign({}, targ), { validity: { valid: false, reason: 'Slate not found' } });
42
47
  }
43
- const slateConfigPth = (0, project_1.resolveProjectPath)((0, path_1.join)(targ.source, '.catalyst', constants_1.FILENAME.slate_config));
48
+ const normalized = normalizeTarget(target);
49
+ const slateConfigPth = (0, path_1.join)(normalized.source, '.catalyst', constants_1.FILENAME.slate_config);
50
+ if (!fs_1.SYNC.fileExists(slateConfigPth)) {
51
+ return Object.assign(Object.assign({}, normalized), { validity: { valid: false, reason: 'Config file not present' } });
52
+ }
44
53
  const slateConfigJson = fs_1.SYNC.readFile(slateConfigPth);
45
54
  const slateConfig = (0, toml_1.parseTOML)(slateConfigJson);
46
55
  if (!slateConfig) {
47
- return Object.assign(Object.assign({}, targ), { validity: { valid: false, reason: 'Config file is empty' } });
56
+ return Object.assign(Object.assign({}, normalized), { validity: { valid: false, reason: 'Config file is empty' } });
48
57
  }
49
- target.config = slateConfig;
50
- return Object.assign({}, target);
58
+ normalized.config = slateConfig;
59
+ return Object.assign({}, normalized);
51
60
  });
52
61
  }
53
62
  function getAllTargetDetails() {
54
- return __awaiter(this, arguments, void 0, function* (throwErr = true) {
63
+ return __awaiter(this, arguments, void 0, function* (throwErr = true, loadConfig = true) {
55
64
  const rawTargets = raw();
56
65
  if (!rawTargets) {
57
66
  if (throwErr) {
@@ -59,16 +68,22 @@ function getAllTargetDetails() {
59
68
  }
60
69
  return;
61
70
  }
62
- return Promise.all(rawTargets.reduce((resArr, target) => {
71
+ return Promise.all(rawTargets.reduce((resArr, rawTarget) => {
72
+ var _a;
73
+ const target = normalizeTarget(rawTarget);
63
74
  const isPath = fs_1.SYNC.dirExists(target.source);
64
75
  if (!isPath) {
65
76
  resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: {
66
77
  valid: false,
67
- reason: `Invalid source path: (${(0, ansi_colors_1.bold)(target.source)}) directory not found`
78
+ reason: `Invalid source path: (${(0, ansi_colors_1.bold)((_a = target.originalSource) !== null && _a !== void 0 ? _a : target.source)}) directory not found`
68
79
  } })));
69
80
  return resArr;
70
81
  }
71
- const slateConfigPth = (0, project_1.resolveProjectPath)((0, path_1.join)(target.source, '.catalyst', constants_1.FILENAME.slate_config));
82
+ if (!loadConfig) {
83
+ resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: { valid: true } })));
84
+ return resArr;
85
+ }
86
+ const slateConfigPth = (0, path_1.join)(target.source, '.catalyst', constants_1.FILENAME.slate_config);
72
87
  const isConfigPath = fs_1.SYNC.fileExists(slateConfigPth);
73
88
  if (!isConfigPath) {
74
89
  resArr.push(Promise.resolve(Object.assign(Object.assign({}, target), { validity: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {