@sitecore-content-sdk/core 0.1.0-beta.21 → 0.1.0-beta.23

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.
@@ -7,21 +7,30 @@ exports.generateSites = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
+ const site_1 = require("../site");
10
11
  const ensurePath_1 = require("../utils/ensurePath");
12
+ const client_1 = require("../client");
11
13
  const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
12
14
  /**
13
15
  * Generates site information and writes it to a specified destination path.
14
16
  * @param {GenerateSitesConfig} config - The configuration for generating site info.
15
- * @param {GraphQLSiteInfoService} config.siteInfoService - The service used to fetch site information.
17
+ * @param {GraphQLSiteInfoService} config.scConfig - The Sitecore configuration used at build and run time.
16
18
  * @param {string} config.destinationPath - The optional path where the generated sites file will be written. Defaults to '.sitecore/sites.json'.
17
19
  * @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
18
20
  */
19
- const generateSites = ({ multisiteEnabled, defaultSite, siteInfoService, destinationPath, }) => {
21
+ const generateSites = ({ scConfig, destinationPath, }) => {
20
22
  return async () => {
21
23
  let sites = [];
22
24
  const sitesFilePath = path_1.default.resolve(destinationPath !== null && destinationPath !== void 0 ? destinationPath : DEFAULT_SITES_DIST_PATH);
23
- if (multisiteEnabled) {
25
+ if (scConfig.multisite.enabled) {
24
26
  try {
27
+ const siteInfoService = new site_1.GraphQLSiteInfoService({
28
+ clientFactory: (0, client_1.createGraphQLClientFactory)({
29
+ api: scConfig.api,
30
+ retries: scConfig.retries.count,
31
+ retryStrategy: scConfig.retries.retryStrategy,
32
+ }),
33
+ });
25
34
  console.log('Fetching site information');
26
35
  sites = await siteInfoService.fetchSiteInfo();
27
36
  }
@@ -30,6 +39,12 @@ const generateSites = ({ multisiteEnabled, defaultSite, siteInfoService, destina
30
39
  console.error(error);
31
40
  }
32
41
  }
42
+ // Add default site to the list
43
+ const defaultSite = {
44
+ name: scConfig.defaultSite,
45
+ hostName: scConfig.multisite.defaultHostname,
46
+ language: scConfig.defaultLanguage,
47
+ };
33
48
  sites.unshift(defaultSite);
34
49
  (0, ensurePath_1.ensurePathExists)(sitesFilePath);
35
50
  console.log(`Writing site info to ${sitesFilePath}`);
@@ -1,21 +1,30 @@
1
1
  import path from 'path';
2
2
  import chalk from 'chalk';
3
3
  import fs from 'fs';
4
+ import { GraphQLSiteInfoService } from '../site';
4
5
  import { ensurePathExists } from '../utils/ensurePath';
6
+ import { createGraphQLClientFactory } from '../client';
5
7
  const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
6
8
  /**
7
9
  * Generates site information and writes it to a specified destination path.
8
10
  * @param {GenerateSitesConfig} config - The configuration for generating site info.
9
- * @param {GraphQLSiteInfoService} config.siteInfoService - The service used to fetch site information.
11
+ * @param {GraphQLSiteInfoService} config.scConfig - The Sitecore configuration used at build and run time.
10
12
  * @param {string} config.destinationPath - The optional path where the generated sites file will be written. Defaults to '.sitecore/sites.json'.
11
13
  * @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
12
14
  */
13
- export const generateSites = ({ multisiteEnabled, defaultSite, siteInfoService, destinationPath, }) => {
15
+ export const generateSites = ({ scConfig, destinationPath, }) => {
14
16
  return async () => {
15
17
  let sites = [];
16
18
  const sitesFilePath = path.resolve(destinationPath !== null && destinationPath !== void 0 ? destinationPath : DEFAULT_SITES_DIST_PATH);
17
- if (multisiteEnabled) {
19
+ if (scConfig.multisite.enabled) {
18
20
  try {
21
+ const siteInfoService = new GraphQLSiteInfoService({
22
+ clientFactory: createGraphQLClientFactory({
23
+ api: scConfig.api,
24
+ retries: scConfig.retries.count,
25
+ retryStrategy: scConfig.retries.retryStrategy,
26
+ }),
27
+ });
19
28
  console.log('Fetching site information');
20
29
  sites = await siteInfoService.fetchSiteInfo();
21
30
  }
@@ -24,6 +33,12 @@ export const generateSites = ({ multisiteEnabled, defaultSite, siteInfoService,
24
33
  console.error(error);
25
34
  }
26
35
  }
36
+ // Add default site to the list
37
+ const defaultSite = {
38
+ name: scConfig.defaultSite,
39
+ hostName: scConfig.multisite.defaultHostname,
40
+ language: scConfig.defaultLanguage,
41
+ };
27
42
  sites.unshift(defaultSite);
28
43
  ensurePathExists(sitesFilePath);
29
44
  console.log(`Writing site info to ${sitesFilePath}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.1.0-beta.21",
3
+ "version": "0.1.0-beta.23",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -59,7 +59,7 @@
59
59
  "typescript": "~5.7.3"
60
60
  },
61
61
  "dependencies": {
62
- "chalk": "^5.4.1",
62
+ "chalk": "^4.1.2",
63
63
  "debug": "^4.4.0",
64
64
  "graphql": "^16.10.0",
65
65
  "graphql-request": "^6.1.0",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "description": "",
70
70
  "types": "types/index.d.ts",
71
- "gitHead": "3693d2408fb12a96c1195a95281188e1c0c1a05a",
71
+ "gitHead": "e51a9eb11fceedefb6f378a5e8427cac40f05784",
72
72
  "files": [
73
73
  "dist",
74
74
  "types",
@@ -1,20 +1,12 @@
1
- import { SiteInfo, GraphQLSiteInfoService } from '../site';
1
+ import { SitecoreConfig } from '../config';
2
2
  /**
3
3
  * Configuration object for generating sites.
4
4
  */
5
5
  export type GenerateSitesConfig = {
6
6
  /**
7
- * Indicates if multisite support is enabled.
7
+ * The Sitecore configuration used at build and run time.
8
8
  */
9
- multisiteEnabled: boolean;
10
- /**
11
- * The default site name.
12
- */
13
- defaultSite: SiteInfo;
14
- /**
15
- * The SiteInfo service.
16
- */
17
- siteInfoService: GraphQLSiteInfoService;
9
+ scConfig: SitecoreConfig;
18
10
  /**
19
11
  * Optional path where the generated sites will be saved.
20
12
  * If not provided, the default '.sitecore/sites.json' will be used.
@@ -24,8 +16,8 @@ export type GenerateSitesConfig = {
24
16
  /**
25
17
  * Generates site information and writes it to a specified destination path.
26
18
  * @param {GenerateSitesConfig} config - The configuration for generating site info.
27
- * @param {GraphQLSiteInfoService} config.siteInfoService - The service used to fetch site information.
19
+ * @param {GraphQLSiteInfoService} config.scConfig - The Sitecore configuration used at build and run time.
28
20
  * @param {string} config.destinationPath - The optional path where the generated sites file will be written. Defaults to '.sitecore/sites.json'.
29
21
  * @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
30
22
  */
31
- export declare const generateSites: ({ multisiteEnabled, defaultSite, siteInfoService, destinationPath, }: GenerateSitesConfig) => (() => Promise<void>);
23
+ export declare const generateSites: ({ scConfig, destinationPath, }: GenerateSitesConfig) => (() => Promise<void>);