@sitecore-content-sdk/core 0.3.0-canary.13 → 0.3.0-canary.14

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.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineCliConfig = void 0;
4
+ var define_cli_config_1 = require("./define-cli-config");
5
+ Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineCliConfig = exports.defineConfig = exports.ComponentTemplateType = void 0;
3
+ exports.defineConfig = exports.ComponentTemplateType = void 0;
4
4
  var models_1 = require("./models");
5
5
  Object.defineProperty(exports, "ComponentTemplateType", { enumerable: true, get: function () { return models_1.ComponentTemplateType; } });
6
6
  var define_config_1 = require("./define-config");
7
7
  Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return define_config_1.defineConfig; } });
8
- var define_cli_config_1 = require("./define-cli-config");
9
- Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.getComponentList = getComponentList;
4
- const utils_1 = require("./utils");
37
+ const glob = __importStar(require("glob"));
38
+ const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
39
+ const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
5
40
  /**
6
41
  * Get list of components from @var path
7
42
  * Returns a list of components in the following format:
@@ -10,17 +45,23 @@ const utils_1 = require("./utils");
10
45
  * componentName: 'ComponentName',
11
46
  * moduleName: 'ComponentName'
12
47
  * }
13
- * @param {string} path path to search
48
+ * @param {string[]} paths paths to search
49
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
14
50
  */
15
- function getComponentList(path) {
16
- const components = (0, utils_1.getItems)({
17
- path,
18
- resolveItem: (path, name) => ({
19
- path: `${path}/${name}`,
20
- componentName: name,
21
- moduleName: name.replace(/[^\w]+/g, ''),
22
- }),
23
- cb: (name) => console.debug(`Registering Content SDK component ${name}`),
24
- });
51
+ function getComponentList(paths, exclude) {
52
+ const components = paths.reduce((result, path) => {
53
+ const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
54
+ ? path
55
+ : path.replace(/\/$/, '').concat('/*.{js,jsx,ts,tsx}');
56
+ return result.concat(...glob.sync(globPath, { ignore: exclude }).map((filePath) => {
57
+ const name = filePath.match(componentNamePattern)[2];
58
+ console.debug(`Registering Content SDK component ${name}`);
59
+ return {
60
+ path: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
61
+ componentName: name,
62
+ moduleName: name.replace(/[^\w]+/g, ''),
63
+ };
64
+ }));
65
+ }, []);
25
66
  return components;
26
67
  }
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModuleType = exports.generatePlugins = exports.getComponentList = void 0;
3
+ exports.matchPath = exports.ModuleType = exports.generatePlugins = exports.getComponentList = void 0;
4
4
  var components_1 = require("./components");
5
5
  Object.defineProperty(exports, "getComponentList", { enumerable: true, get: function () { return components_1.getComponentList; } });
6
6
  var plugins_1 = require("./plugins");
7
7
  Object.defineProperty(exports, "generatePlugins", { enumerable: true, get: function () { return plugins_1.generatePlugins; } });
8
8
  Object.defineProperty(exports, "ModuleType", { enumerable: true, get: function () { return plugins_1.ModuleType; } });
9
+ var utils_1 = require("./utils");
10
+ Object.defineProperty(exports, "matchPath", { enumerable: true, get: function () { return utils_1.matchPath; } });
@@ -3,8 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.matchPath = void 0;
6
7
  exports.getItems = getItems;
7
8
  const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Compares two paths to determine if they match.
12
+ * @param {string} itemPath base path to compare against, can be absolute or relative
13
+ * @param {string} compare comparer, can be relate, absolute or regex string
14
+ * @returns true if paths match, false otherwise
15
+ */
16
+ const matchPath = (itemPath, compare) => {
17
+ if (compare === itemPath ||
18
+ path_1.default.join(process.cwd(), itemPath) === compare ||
19
+ itemPath === path_1.default.join(process.cwd(), compare) ||
20
+ new RegExp(compare).test(itemPath)) {
21
+ return true;
22
+ }
23
+ return false;
24
+ };
25
+ exports.matchPath = matchPath;
8
26
  /**
9
27
  * Using @var path find all files and generate output using @var resolveItem function for each file
10
28
  * Can be used to generate list of components, templates, etc.
@@ -12,11 +30,17 @@ const fs_1 = __importDefault(require("fs"));
12
30
  * @returns {Item[]} list of items
13
31
  */
14
32
  function getItems(settings) {
15
- const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), } = settings;
33
+ const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), exclude, } = settings;
16
34
  const items = [];
17
35
  const folders = [];
18
36
  if (!fs_1.default.existsSync(path))
19
37
  return [];
38
+ if (exclude) {
39
+ for (const exclusion of exclude) {
40
+ if ((0, exports.matchPath)(path, exclusion))
41
+ return [];
42
+ }
43
+ }
20
44
  fs_1.default.readdirSync(path, { withFileTypes: true }).forEach((item) => {
21
45
  if (item.isDirectory()) {
22
46
  folders.push(item);
@@ -0,0 +1 @@
1
+ export { defineCliConfig } from './define-cli-config';
@@ -1,3 +1,2 @@
1
1
  export { ComponentTemplateType, } from './models';
2
2
  export { defineConfig } from './define-config';
3
- export { defineCliConfig } from './define-cli-config';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,6 @@
1
- import { getItems } from './utils';
1
+ import * as glob from 'glob';
2
+ const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
3
+ const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
2
4
  /**
3
5
  * Get list of components from @var path
4
6
  * Returns a list of components in the following format:
@@ -7,17 +9,23 @@ import { getItems } from './utils';
7
9
  * componentName: 'ComponentName',
8
10
  * moduleName: 'ComponentName'
9
11
  * }
10
- * @param {string} path path to search
12
+ * @param {string[]} paths paths to search
13
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
11
14
  */
12
- export function getComponentList(path) {
13
- const components = getItems({
14
- path,
15
- resolveItem: (path, name) => ({
16
- path: `${path}/${name}`,
17
- componentName: name,
18
- moduleName: name.replace(/[^\w]+/g, ''),
19
- }),
20
- cb: (name) => console.debug(`Registering Content SDK component ${name}`),
21
- });
15
+ export function getComponentList(paths, exclude) {
16
+ const components = paths.reduce((result, path) => {
17
+ const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
18
+ ? path
19
+ : path.replace(/\/$/, '').concat('/*.{js,jsx,ts,tsx}');
20
+ return result.concat(...glob.sync(globPath, { ignore: exclude }).map((filePath) => {
21
+ const name = filePath.match(componentNamePattern)[2];
22
+ console.debug(`Registering Content SDK component ${name}`);
23
+ return {
24
+ path: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
25
+ componentName: name,
26
+ moduleName: name.replace(/[^\w]+/g, ''),
27
+ };
28
+ }));
29
+ }, []);
22
30
  return components;
23
31
  }
@@ -1,2 +1,3 @@
1
1
  export { getComponentList } from './components';
2
2
  export { generatePlugins, ModuleType } from './plugins';
3
+ export { matchPath } from './utils';
@@ -1,4 +1,20 @@
1
1
  import fs from 'fs';
2
+ import path from 'path';
3
+ /**
4
+ * Compares two paths to determine if they match.
5
+ * @param {string} itemPath base path to compare against, can be absolute or relative
6
+ * @param {string} compare comparer, can be relate, absolute or regex string
7
+ * @returns true if paths match, false otherwise
8
+ */
9
+ export const matchPath = (itemPath, compare) => {
10
+ if (compare === itemPath ||
11
+ path.join(process.cwd(), itemPath) === compare ||
12
+ itemPath === path.join(process.cwd(), compare) ||
13
+ new RegExp(compare).test(itemPath)) {
14
+ return true;
15
+ }
16
+ return false;
17
+ };
2
18
  /**
3
19
  * Using @var path find all files and generate output using @var resolveItem function for each file
4
20
  * Can be used to generate list of components, templates, etc.
@@ -6,11 +22,17 @@ import fs from 'fs';
6
22
  * @returns {Item[]} list of items
7
23
  */
8
24
  export function getItems(settings) {
9
- const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), } = settings;
25
+ const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), exclude, } = settings;
10
26
  const items = [];
11
27
  const folders = [];
12
28
  if (!fs.existsSync(path))
13
29
  return [];
30
+ if (exclude) {
31
+ for (const exclusion of exclude) {
32
+ if (matchPath(path, exclusion))
33
+ return [];
34
+ }
35
+ }
14
36
  fs.readdirSync(path, { withFileTypes: true }).forEach((item) => {
15
37
  if (item.isDirectory()) {
16
38
  folders.push(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.3.0-canary.13",
3
+ "version": "0.3.0-canary.14",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -69,6 +69,7 @@
69
69
  "dependencies": {
70
70
  "chalk": "^4.1.2",
71
71
  "debug": "^4.4.0",
72
+ "glob": "^11.0.2",
72
73
  "graphql": "^16.11.0",
73
74
  "graphql-request": "^6.1.0",
74
75
  "memory-cache": "^0.2.0",
@@ -77,7 +78,7 @@
77
78
  },
78
79
  "description": "",
79
80
  "types": "types/index.d.ts",
80
- "gitHead": "60ee93b0b1dd958cd163cb2b157630d091a7bc70",
81
+ "gitHead": "62a8c4708e0be2ed7000f1dad2864500e8df7e40",
81
82
  "files": [
82
83
  "dist",
83
84
  "types",
@@ -1,4 +1,4 @@
1
- import { SitecoreCliConfig, SitecoreCliConfigInput } from './models';
1
+ import { SitecoreCliConfig, SitecoreCliConfigInput } from '../models';
2
2
  /**
3
3
  * Accepts a `SitecoreCliConfigInput` object and returns Sitecore Content SDK CLI configuration, updated with required default values
4
4
  * @param {SitecoreCliConfigInput} cliConfig the cli configuration provided by the application
@@ -0,0 +1 @@
1
+ export { defineCliConfig } from './define-cli-config';
@@ -1,3 +1,2 @@
1
1
  export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, DeepRequired, } from './models';
2
2
  export { defineConfig } from './define-config';
3
- export { defineCliConfig } from './define-cli-config';
@@ -1,4 +1,5 @@
1
1
  import { RetryStrategy } from '../models';
2
+ import { GenerateMapFunction, GenerateMapArgs } from '../tools';
2
3
  /**
3
4
  * Utility type to make every property in a type required
4
5
  */
@@ -205,6 +206,15 @@ export type SitecoreCliConfigInput = {
205
206
  */
206
207
  templates?: ScaffoldTemplate[];
207
208
  };
209
+ /**
210
+ * Configuration for the `sitecore-tools component generate-map` cli command
211
+ */
212
+ componentMap?: GenerateMapArgs & {
213
+ /**
214
+ * Function implementationt for generating a component map.
215
+ */
216
+ generator?: GenerateMapFunction;
217
+ };
208
218
  };
209
219
  /**
210
220
  * Final sitecore cli config type used required by the cli
@@ -0,0 +1,18 @@
1
+ import { ComponentFile, ComponentImport } from './templating';
2
+ export type GenerateMapFunction = (args: GenerateMapArgs) => void;
3
+ /**
4
+ * Arguments for the generateMap function.
5
+ * @typedef GenerateMapArgs
6
+ * @property {string[]} paths - Array of component paths to include in component map.
7
+ * @property {string} [destination='src/.sitecore'] - Destination folder path for the generated map.
8
+ * @property {ComponentImport[]} [componentImports] - Optional array of package definitions for component imports to include in the map.
9
+ * @property {string[]} [exclude] - Optional array of glob paths to exclude from the map.
10
+ * @property {function} [mapTemplate] - Optional custom template function to generate the component map content.
11
+ */
12
+ export type GenerateMapArgs = {
13
+ paths: string[];
14
+ destination?: string;
15
+ componentImports?: ComponentImport[];
16
+ exclude?: string[];
17
+ mapTemplate?: (components: ComponentFile[], componentImports?: ComponentImport[]) => string;
18
+ };
@@ -1,4 +1,5 @@
1
1
  export { generateSites, GenerateSitesConfig } from './generateSites';
2
2
  export { generateMetadata } from './generateMetadata';
3
3
  export { scaffoldComponent } from './scaffold';
4
+ export { GenerateMapFunction, GenerateMapArgs } from './generate-map';
4
5
  export * from './templating';
@@ -7,14 +7,20 @@ export interface ComponentFile {
7
7
  componentName: string;
8
8
  }
9
9
  /**
10
- * Describes a package and components to be imported
10
+ * Definition for custom components to be included in component map.
11
+ * Use this to define components imported from modules/dependencies/packages
12
+ * @typedef ComponentImport
13
+ * @property {string} importName - Name of the import.
14
+ * @property {object} importInfo - Information about how to import the package.
15
+ * @property {string} importInfo.importFrom - The path from which to import the component(s).
16
+ * @property {string[]} [importInfo.namedImports] - The specific named components to import from the package. Leave empty to have whole package be imported as wildcard and allow SXA variants support for component.
11
17
  */
12
- export interface PackageDefinition {
13
- name: string;
14
- components: {
15
- moduleName: string;
16
- componentName: string;
17
- }[];
18
+ export interface ComponentImport {
19
+ importName: string;
20
+ importInfo: {
21
+ importFrom: string;
22
+ namedImports?: string[];
23
+ };
18
24
  }
19
25
  /**
20
26
  * Get list of components from @var path
@@ -24,6 +30,7 @@ export interface PackageDefinition {
24
30
  * componentName: 'ComponentName',
25
31
  * moduleName: 'ComponentName'
26
32
  * }
27
- * @param {string} path path to search
33
+ * @param {string[]} paths paths to search
34
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
28
35
  */
29
- export declare function getComponentList(path: string): ComponentFile[];
36
+ export declare function getComponentList(paths: string[], exclude?: string[]): ComponentFile[];
@@ -1,2 +1,3 @@
1
- export { ComponentFile, PackageDefinition, getComponentList } from './components';
1
+ export { ComponentFile, ComponentImport, getComponentList } from './components';
2
2
  export { PluginDefinition, generatePlugins, ModuleType } from './plugins';
3
+ export { matchPath } from './utils';
@@ -14,6 +14,7 @@ export type GetItemsSettings<Item> = {
14
14
  * Will be called when new file is found
15
15
  */
16
16
  cb?: (name: string) => void;
17
+ exclude?: string[];
17
18
  /**
18
19
  * Matches specific files format
19
20
  */
@@ -23,6 +24,13 @@ export type GetItemsSettings<Item> = {
23
24
  */
24
25
  recursive?: boolean;
25
26
  };
27
+ /**
28
+ * Compares two paths to determine if they match.
29
+ * @param {string} itemPath base path to compare against, can be absolute or relative
30
+ * @param {string} compare comparer, can be relate, absolute or regex string
31
+ * @returns true if paths match, false otherwise
32
+ */
33
+ export declare const matchPath: (itemPath: string, compare: string) => boolean;
26
34
  /**
27
35
  * Using @var path find all files and generate output using @var resolveItem function for each file
28
36
  * Can be used to generate list of components, templates, etc.