@sitecore-content-sdk/core 0.1.0-beta.22 → 0.1.0-beta.24

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}`);
@@ -38,17 +38,18 @@ function scaffoldFile(filePath, fileContent) {
38
38
  }
39
39
  /**
40
40
  * Scaffolds a new component based on the provided template.
41
- * @param {string} outputFilePath - The file path where the component will be created.
41
+ * @param {string} outputFolderPath - The file path where the component will be created.
42
42
  * @param {string} componentName - The name of the component to be created.
43
43
  * @param {string} templateName - The name of the template to use for scaffolding. If not provided, defaults to 'byoc' if `byoc` is true, otherwise 'default'.
44
44
  * @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
45
45
  * @throws Will throw an error if the specified template is not found.
46
46
  */
47
- function scaffoldComponent(outputFilePath, componentName, templateName, templates) {
47
+ function scaffoldComponent(outputFolderPath, componentName, templateName, templates) {
48
48
  const template = templates.find((t) => t.name === templateName);
49
49
  if (!template) {
50
50
  throw new Error(`Template ${templateName} not found.`);
51
51
  }
52
+ const outputFilePath = path_1.default.join(outputFolderPath, `${componentName}.${template.fileExtension}`);
52
53
  const componentOutputPath = scaffoldFile(outputFilePath, template.generateTemplate(componentName));
53
54
  if (componentOutputPath) {
54
55
  const nextSteps = [];
@@ -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}`);
@@ -30,17 +30,18 @@ export function scaffoldFile(filePath, fileContent) {
30
30
  }
31
31
  /**
32
32
  * Scaffolds a new component based on the provided template.
33
- * @param {string} outputFilePath - The file path where the component will be created.
33
+ * @param {string} outputFolderPath - The file path where the component will be created.
34
34
  * @param {string} componentName - The name of the component to be created.
35
35
  * @param {string} templateName - The name of the template to use for scaffolding. If not provided, defaults to 'byoc' if `byoc` is true, otherwise 'default'.
36
36
  * @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
37
37
  * @throws Will throw an error if the specified template is not found.
38
38
  */
39
- export function scaffoldComponent(outputFilePath, componentName, templateName, templates) {
39
+ export function scaffoldComponent(outputFolderPath, componentName, templateName, templates) {
40
40
  const template = templates.find((t) => t.name === templateName);
41
41
  if (!template) {
42
42
  throw new Error(`Template ${templateName} not found.`);
43
43
  }
44
+ const outputFilePath = path.join(outputFolderPath, `${componentName}.${template.fileExtension}`);
44
45
  const componentOutputPath = scaffoldFile(outputFilePath, template.generateTemplate(componentName));
45
46
  if (componentOutputPath) {
46
47
  const nextSteps = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.1.0-beta.22",
3
+ "version": "0.1.0-beta.24",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "description": "",
70
70
  "types": "types/index.d.ts",
71
- "gitHead": "5d08aecb15836849a90a2f93f15c6d8ec915f667",
71
+ "gitHead": "68d52610f8306266df0e0ddba6dc6c4d0f284ba5",
72
72
  "files": [
73
73
  "dist",
74
74
  "types",
@@ -214,6 +214,10 @@ export type ScaffoldTemplate = {
214
214
  * Name of the template.
215
215
  */
216
216
  name: string;
217
+ /**
218
+ * File extension for the generated component.
219
+ */
220
+ fileExtension: string;
217
221
  /**
218
222
  * Function to generate the component file contents based on the component name.
219
223
  * @param componentName - The name of the component.
@@ -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>);
@@ -16,10 +16,10 @@ export declare function editLineEndings(content: string): string;
16
16
  export declare function scaffoldFile(filePath: string, fileContent: string): string | null;
17
17
  /**
18
18
  * Scaffolds a new component based on the provided template.
19
- * @param {string} outputFilePath - The file path where the component will be created.
19
+ * @param {string} outputFolderPath - The file path where the component will be created.
20
20
  * @param {string} componentName - The name of the component to be created.
21
21
  * @param {string} templateName - The name of the template to use for scaffolding. If not provided, defaults to 'byoc' if `byoc` is true, otherwise 'default'.
22
22
  * @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
23
23
  * @throws Will throw an error if the specified template is not found.
24
24
  */
25
- export declare function scaffoldComponent(outputFilePath: string, componentName: string, templateName: string, templates: ScaffoldTemplate[]): void;
25
+ export declare function scaffoldComponent(outputFolderPath: string, componentName: string, templateName: string, templates: ScaffoldTemplate[]): void;