@sitecore-jss/sitecore-jss-dev-tools 22.5.0-beta.15 → 22.5.0-beta.16

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.
@@ -17,6 +17,7 @@ const utils_1 = require("./utils");
17
17
  const fetch_bearer_token_1 = require("../auth/fetch-bearer-token");
18
18
  const chalk_1 = __importDefault(require("chalk"));
19
19
  const path_1 = __importDefault(require("path"));
20
+ const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
20
21
  /**
21
22
  * Handler for the extract-component API command
22
23
  * Reads imports from the componentBuilder.ts file and posts the code to the mesh endpoint
@@ -25,15 +26,16 @@ const path_1 = __importDefault(require("path"));
25
26
  */
26
27
  function extractFiles() {
27
28
  return __awaiter(this, arguments, void 0, function* (args = {}) {
28
- if (!validateDeployContext()) {
29
- console.log(chalk_1.default.yellow('Skipping code extraction, not in deploy context'));
29
+ if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
30
+ !(0, utils_1.validateDeployContext)()) {
31
+ sitecore_jss_1.debug.common('Skipping code extraction, not in deploy context');
30
32
  return;
31
33
  }
32
- // TODO: add alternative consent procedure
33
- if (!process.env.EXTRACT_CONSENT) {
34
- console.log(chalk_1.default.yellow('Skipping code extraction, EXTRACT_CONSENT is not set'));
34
+ if (!(0, utils_1.validateConsent)()) {
35
+ console.log(chalk_1.default.yellow('Skipping code extraction, consent not given'));
35
36
  return;
36
37
  }
38
+ console.log(chalk_1.default.green('Code extraction started'));
37
39
  const basePath = process.cwd();
38
40
  try {
39
41
  const token = yield (0, fetch_bearer_token_1.fetchBearerToken)();
@@ -52,23 +54,13 @@ function extractFiles() {
52
54
  path: path_1.default.resolve(basePath, './package.json'),
53
55
  type: utils_1.ExtractedFileType.PackageJson,
54
56
  }, token));
55
- yield Promise.all(fileDispatches);
57
+ const files = yield Promise.all(fileDispatches);
58
+ console.log(chalk_1.default.green(`Code extraction completed successfully, files extracted:\r\n${files
59
+ .filter((file) => file !== null)
60
+ .join('\r\n')}`));
56
61
  }
57
62
  catch (error) {
58
- console.error(chalk_1.default.red('Error during component extraction:', error));
63
+ console.error(chalk_1.default.red('Error during code extraction:', error));
59
64
  }
60
65
  });
61
66
  }
62
- const validateDeployContext = () => {
63
- if (process.env.NETLIFY && process.env.BUILD_ID) {
64
- return true;
65
- }
66
- // workaround, Vercel does not have variables that are only accessible at build time
67
- if (process.env.VERCEL && !process.env.VERCEL_REGION) {
68
- return true;
69
- }
70
- if (process.env.SITECORE && process.env.BuildMetadata_BuildId) {
71
- return true;
72
- }
73
- return false;
74
- };
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.sendCode = exports.resolveComponentImportFiles = exports.ExtractedFileType = void 0;
38
+ exports.sendCode = exports.resolveComponentImportFiles = exports.validateDeployContext = exports.validateConsent = exports.ExtractedFileType = void 0;
39
39
  const chalk_1 = __importDefault(require("chalk"));
40
40
  const path_1 = __importDefault(require("path"));
41
41
  const fs_1 = __importDefault(require("fs"));
@@ -54,6 +54,37 @@ var ExtractedFileType;
54
54
  ExtractedFileType["Json"] = "json";
55
55
  ExtractedFileType["PackageJson"] = "package.json";
56
56
  })(ExtractedFileType || (exports.ExtractedFileType = ExtractedFileType = {}));
57
+ /**
58
+ * Validates consent for code extraction procedures
59
+ * @returns {boolean} - true if consent is given, false otherwise
60
+ */
61
+ const validateConsent = () => {
62
+ var _a;
63
+ if (((_a = process.env.EXTRACT_CONSENT) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'true') {
64
+ return false;
65
+ }
66
+ return true;
67
+ };
68
+ exports.validateConsent = validateConsent;
69
+ /**
70
+ * Validates if the current operation is done in Vercel, Netlify or XMCloud
71
+ * deploy context
72
+ * @returns {boolean} - true if in deploy context, false otherwise
73
+ */
74
+ const validateDeployContext = () => {
75
+ if (process.env.NETLIFY && process.env.BUILD_ID) {
76
+ return true;
77
+ }
78
+ // workaround, Vercel does not have variables that are only accessible at build time
79
+ if (process.env.VERCEL && !process.env.VERCEL_REGION) {
80
+ return true;
81
+ }
82
+ if (process.env.SITECORE && process.env.SITECORE_BUILD) {
83
+ return true;
84
+ }
85
+ return false;
86
+ };
87
+ exports.validateDeployContext = validateDeployContext;
57
88
  /**
58
89
  * Parses the componentBuilder.ts file and returns a map of component names
59
90
  * and their respective import strings
@@ -180,13 +211,13 @@ const sendCode = (file, token) => __awaiter(void 0, void 0, void 0, function* ()
180
211
  url: response.url,
181
212
  headers: response.headers,
182
213
  });
183
- return;
214
+ return null;
184
215
  }
185
216
  }
186
217
  catch (error) {
187
218
  console.error(chalk_1.default.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
188
- return;
219
+ return null;
189
220
  }
190
- console.log(chalk_1.default.green(`Code from ${file.path} extracted and sent to mesh endpoint`));
221
+ return file.path;
191
222
  });
192
223
  exports.sendCode = sendCode;
@@ -7,10 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { ExtractedFileType, resolveComponentImportFiles, sendCode } from './utils';
10
+ import { validateDeployContext, validateConsent, ExtractedFileType, resolveComponentImportFiles, sendCode, } from './utils';
11
11
  import { fetchBearerToken } from '../auth/fetch-bearer-token';
12
12
  import chalk from 'chalk';
13
13
  import path from 'path';
14
+ import { debug } from '@sitecore-jss/sitecore-jss';
14
15
  /**
15
16
  * Handler for the extract-component API command
16
17
  * Reads imports from the componentBuilder.ts file and posts the code to the mesh endpoint
@@ -19,15 +20,16 @@ import path from 'path';
19
20
  */
20
21
  export function extractFiles() {
21
22
  return __awaiter(this, arguments, void 0, function* (args = {}) {
22
- if (!validateDeployContext()) {
23
- console.log(chalk.yellow('Skipping code extraction, not in deploy context'));
23
+ if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
24
+ !validateDeployContext()) {
25
+ debug.common('Skipping code extraction, not in deploy context');
24
26
  return;
25
27
  }
26
- // TODO: add alternative consent procedure
27
- if (!process.env.EXTRACT_CONSENT) {
28
- console.log(chalk.yellow('Skipping code extraction, EXTRACT_CONSENT is not set'));
28
+ if (!validateConsent()) {
29
+ console.log(chalk.yellow('Skipping code extraction, consent not given'));
29
30
  return;
30
31
  }
32
+ console.log(chalk.green('Code extraction started'));
31
33
  const basePath = process.cwd();
32
34
  try {
33
35
  const token = yield fetchBearerToken();
@@ -46,23 +48,13 @@ export function extractFiles() {
46
48
  path: path.resolve(basePath, './package.json'),
47
49
  type: ExtractedFileType.PackageJson,
48
50
  }, token));
49
- yield Promise.all(fileDispatches);
51
+ const files = yield Promise.all(fileDispatches);
52
+ console.log(chalk.green(`Code extraction completed successfully, files extracted:\r\n${files
53
+ .filter((file) => file !== null)
54
+ .join('\r\n')}`));
50
55
  }
51
56
  catch (error) {
52
- console.error(chalk.red('Error during component extraction:', error));
57
+ console.error(chalk.red('Error during code extraction:', error));
53
58
  }
54
59
  });
55
60
  }
56
- const validateDeployContext = () => {
57
- if (process.env.NETLIFY && process.env.BUILD_ID) {
58
- return true;
59
- }
60
- // workaround, Vercel does not have variables that are only accessible at build time
61
- if (process.env.VERCEL && !process.env.VERCEL_REGION) {
62
- return true;
63
- }
64
- if (process.env.SITECORE && process.env.BuildMetadata_BuildId) {
65
- return true;
66
- }
67
- return false;
68
- };
@@ -25,6 +25,35 @@ export var ExtractedFileType;
25
25
  ExtractedFileType["Json"] = "json";
26
26
  ExtractedFileType["PackageJson"] = "package.json";
27
27
  })(ExtractedFileType || (ExtractedFileType = {}));
28
+ /**
29
+ * Validates consent for code extraction procedures
30
+ * @returns {boolean} - true if consent is given, false otherwise
31
+ */
32
+ export const validateConsent = () => {
33
+ var _a;
34
+ if (((_a = process.env.EXTRACT_CONSENT) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'true') {
35
+ return false;
36
+ }
37
+ return true;
38
+ };
39
+ /**
40
+ * Validates if the current operation is done in Vercel, Netlify or XMCloud
41
+ * deploy context
42
+ * @returns {boolean} - true if in deploy context, false otherwise
43
+ */
44
+ export const validateDeployContext = () => {
45
+ if (process.env.NETLIFY && process.env.BUILD_ID) {
46
+ return true;
47
+ }
48
+ // workaround, Vercel does not have variables that are only accessible at build time
49
+ if (process.env.VERCEL && !process.env.VERCEL_REGION) {
50
+ return true;
51
+ }
52
+ if (process.env.SITECORE && process.env.SITECORE_BUILD) {
53
+ return true;
54
+ }
55
+ return false;
56
+ };
28
57
  /**
29
58
  * Parses the componentBuilder.ts file and returns a map of component names
30
59
  * and their respective import strings
@@ -150,12 +179,12 @@ export const sendCode = (file, token) => __awaiter(void 0, void 0, void 0, funct
150
179
  url: response.url,
151
180
  headers: response.headers,
152
181
  });
153
- return;
182
+ return null;
154
183
  }
155
184
  }
156
185
  catch (error) {
157
186
  console.error(chalk.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
158
- return;
187
+ return null;
159
188
  }
160
- console.log(chalk.green(`Code from ${file.path} extracted and sent to mesh endpoint`));
189
+ return file.path;
161
190
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-dev-tools",
3
- "version": "22.5.0-beta.15",
3
+ "version": "22.5.0-beta.16",
4
4
  "description": "Utilities to assist in the development and deployment of Sitecore JSS apps.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/parser": "^7.24.0",
36
- "@sitecore-jss/sitecore-jss": "22.5.0-beta.15",
36
+ "@sitecore-jss/sitecore-jss": "22.5.0-beta.16",
37
37
  "chalk": "^4.1.2",
38
38
  "chokidar": "^3.6.0",
39
39
  "del": "^6.0.0",
@@ -85,7 +85,7 @@
85
85
  "typescript": "~5.6.3"
86
86
  },
87
87
  "types": "types/index.d.ts",
88
- "gitHead": "c9ac450559f169083ee682bbdb562da14d948468",
88
+ "gitHead": "a99edf7bd6bfc0fd0724f7abfb1838d2b42d315a",
89
89
  "files": [
90
90
  "dist",
91
91
  "types",
@@ -1,5 +1,6 @@
1
1
  type ExtracFilesOptions = {
2
2
  componentBuilderPath?: string;
3
+ customValidateDeployContext?: () => boolean;
3
4
  };
4
5
  /**
5
6
  * Handler for the extract-component API command
@@ -14,6 +14,17 @@ export declare enum ExtractedFileType {
14
14
  Json = "json",
15
15
  PackageJson = "package.json"
16
16
  }
17
+ /**
18
+ * Validates consent for code extraction procedures
19
+ * @returns {boolean} - true if consent is given, false otherwise
20
+ */
21
+ export declare const validateConsent: () => boolean;
22
+ /**
23
+ * Validates if the current operation is done in Vercel, Netlify or XMCloud
24
+ * deploy context
25
+ * @returns {boolean} - true if in deploy context, false otherwise
26
+ */
27
+ export declare const validateDeployContext: () => boolean;
17
28
  /**
18
29
  * Parses the componentBuilder.ts file and returns a map of component names
19
30
  * and their respective import strings
@@ -27,4 +38,4 @@ export declare const resolveComponentImportFiles: (appPath: string, componentBui
27
38
  * @param {ExcractedFile} file properties of the file to be sent
28
39
  * @param {string} token bearer token for authentication into mesh endpoint
29
40
  */
30
- export declare const sendCode: (file: ExtractedFile, token: string) => Promise<void>;
41
+ export declare const sendCode: (file: ExtractedFile, token: string) => Promise<string | null | undefined>;