@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.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.
- package/README.md +7 -7
- package/dist/cjs/cache-client.js +55 -54
- package/dist/cjs/client/constants.js +7 -7
- package/dist/cjs/client/edge-proxy.js +24 -22
- package/dist/cjs/client/index.js +15 -15
- package/dist/cjs/client/models.js +2 -2
- package/dist/cjs/client/sitecore-client.js +421 -419
- package/dist/cjs/client/utils.js +47 -46
- package/dist/cjs/config/define-config.js +194 -193
- package/dist/cjs/config/index.js +7 -7
- package/dist/cjs/config/models.js +12 -11
- package/dist/cjs/config-cli/define-cli-config.js +23 -22
- package/dist/cjs/config-cli/index.js +7 -7
- package/dist/cjs/config-cli/models.js +8 -7
- package/dist/cjs/constants.js +49 -17
- package/dist/cjs/debug.js +48 -46
- package/dist/cjs/editing/codegen/index.js +14 -9
- package/dist/cjs/editing/codegen/preview.js +277 -193
- package/dist/cjs/editing/component-layout-service.js +62 -61
- package/dist/cjs/editing/design-library.js +183 -126
- package/dist/cjs/editing/editing-service.js +75 -74
- package/dist/cjs/editing/index.js +33 -27
- package/dist/cjs/editing/metadata.js +42 -42
- package/dist/cjs/editing/models.js +44 -38
- package/dist/cjs/editing/utils.js +108 -90
- package/dist/cjs/form/form.js +81 -78
- package/dist/cjs/form/index.js +7 -7
- package/dist/cjs/graphql-request-client.js +108 -107
- package/dist/cjs/i18n/dictionary-service.js +122 -121
- package/dist/cjs/i18n/index.js +7 -7
- package/dist/cjs/i18n/utils.js +16 -15
- package/dist/cjs/index.js +60 -60
- package/dist/cjs/layout/content-styles.js +72 -71
- package/dist/cjs/layout/index.js +24 -24
- package/dist/cjs/layout/layout-service.js +62 -57
- package/dist/cjs/layout/models.js +39 -34
- package/dist/cjs/layout/themes.js +76 -75
- package/dist/cjs/layout/utils.js +117 -110
- package/dist/cjs/media/index.js +38 -38
- package/dist/cjs/media/media-api.js +100 -96
- package/dist/cjs/models.js +2 -2
- package/dist/cjs/native-fetcher.js +194 -179
- package/dist/cjs/personalize/index.js +15 -15
- package/dist/cjs/personalize/layout-personalizer.js +98 -97
- package/dist/cjs/personalize/personalize-service.js +98 -94
- package/dist/cjs/personalize/utils.js +143 -136
- package/dist/cjs/retries.js +43 -42
- package/dist/cjs/site/error-pages-service.js +65 -64
- package/dist/cjs/site/index.js +26 -26
- package/dist/cjs/site/models.js +2 -2
- package/dist/cjs/site/redirects-service.js +94 -81
- package/dist/cjs/site/robots-service.js +66 -65
- package/dist/cjs/site/site-resolver.js +73 -72
- package/dist/cjs/site/siteinfo-service.js +84 -80
- package/dist/cjs/site/sitemap-xml-service.js +84 -83
- package/dist/cjs/site/sitepath-service.js +165 -164
- package/dist/cjs/site/utils.js +55 -47
- package/dist/cjs/sitecore-service-base.js +36 -36
- package/dist/cjs/tools/auth/flow.js +65 -64
- package/dist/cjs/tools/auth/index.js +5 -5
- package/dist/cjs/tools/auth/models.js +2 -2
- package/dist/cjs/tools/auth/tenant-store.js +38 -38
- package/dist/cjs/tools/codegen/component-generation.js +52 -50
- package/dist/cjs/tools/codegen/extract-files.js +105 -107
- package/dist/cjs/tools/codegen/import-map.js +401 -349
- package/dist/cjs/tools/codegen/utils.js +418 -418
- package/dist/cjs/tools/generate-map.js +2 -2
- package/dist/cjs/tools/generateMetadata.js +36 -35
- package/dist/cjs/tools/generateSites.js +59 -58
- package/dist/cjs/tools/index.js +75 -73
- package/dist/cjs/tools/scaffold.js +60 -59
- package/dist/cjs/tools/templating/components.js +96 -266
- package/dist/cjs/tools/templating/index.js +11 -14
- package/dist/cjs/tools/templating/plugins.js +80 -78
- package/dist/cjs/tools/templating/utils.js +67 -66
- package/dist/cjs/utils/ensurePath.js +20 -20
- package/dist/cjs/utils/env.js +28 -27
- package/dist/cjs/utils/globalCache.js +55 -0
- package/dist/cjs/utils/index.js +26 -21
- package/dist/cjs/utils/is-server.js +11 -10
- package/dist/cjs/utils/normalize-url.js +5 -5
- package/dist/cjs/utils/timeout-promise.js +31 -31
- package/dist/cjs/utils/utils.js +254 -229
- package/dist/esm/cache-client.js +51 -50
- package/dist/esm/client/constants.js +4 -4
- package/dist/esm/client/edge-proxy.js +19 -17
- package/dist/esm/client/index.js +5 -5
- package/dist/esm/client/models.js +1 -1
- package/dist/esm/client/sitecore-client.js +414 -412
- package/dist/esm/client/utils.js +43 -42
- package/dist/esm/config/define-config.js +188 -187
- package/dist/esm/config/index.js +2 -2
- package/dist/esm/config/models.js +9 -8
- package/dist/esm/config-cli/define-cli-config.js +19 -18
- package/dist/esm/config-cli/index.js +2 -2
- package/dist/esm/config-cli/models.js +5 -4
- package/dist/esm/constants.js +46 -14
- package/dist/esm/debug.js +41 -39
- package/dist/esm/editing/codegen/index.js +1 -1
- package/dist/esm/editing/codegen/preview.js +263 -185
- package/dist/esm/editing/component-layout-service.js +55 -54
- package/dist/esm/editing/design-library.js +171 -117
- package/dist/esm/editing/editing-service.js +68 -67
- package/dist/esm/editing/index.js +6 -5
- package/dist/esm/editing/metadata.js +39 -39
- package/dist/esm/editing/models.js +41 -35
- package/dist/esm/editing/utils.js +98 -80
- package/dist/esm/form/form.js +72 -69
- package/dist/esm/form/index.js +1 -1
- package/dist/esm/graphql-request-client.js +101 -100
- package/dist/esm/i18n/dictionary-service.js +115 -114
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/i18n/utils.js +13 -12
- package/dist/esm/index.js +13 -13
- package/dist/esm/layout/content-styles.js +64 -63
- package/dist/esm/layout/index.js +6 -6
- package/dist/esm/layout/layout-service.js +55 -50
- package/dist/esm/layout/models.js +36 -31
- package/dist/esm/layout/themes.js +71 -70
- package/dist/esm/layout/utils.js +109 -102
- package/dist/esm/media/index.js +2 -2
- package/dist/esm/media/media-api.js +90 -86
- package/dist/esm/models.js +1 -1
- package/dist/esm/native-fetcher.js +187 -172
- package/dist/esm/personalize/index.js +3 -3
- package/dist/esm/personalize/layout-personalizer.js +93 -92
- package/dist/esm/personalize/personalize-service.js +91 -87
- package/dist/esm/personalize/utils.js +135 -128
- package/dist/esm/retries.js +39 -38
- package/dist/esm/site/error-pages-service.js +58 -57
- package/dist/esm/site/index.js +8 -8
- package/dist/esm/site/models.js +1 -1
- package/dist/esm/site/redirects-service.js +87 -74
- package/dist/esm/site/robots-service.js +59 -58
- package/dist/esm/site/site-resolver.js +69 -68
- package/dist/esm/site/siteinfo-service.js +77 -73
- package/dist/esm/site/sitemap-xml-service.js +77 -76
- package/dist/esm/site/sitepath-service.js +157 -156
- package/dist/esm/site/utils.js +49 -41
- package/dist/esm/sitecore-service-base.js +29 -29
- package/dist/esm/tools/auth/flow.js +62 -61
- package/dist/esm/tools/auth/index.js +1 -1
- package/dist/esm/tools/auth/models.js +1 -1
- package/dist/esm/tools/auth/tenant-store.js +35 -35
- package/dist/esm/tools/codegen/component-generation.js +44 -42
- package/dist/esm/tools/codegen/extract-files.js +99 -101
- package/dist/esm/tools/codegen/import-map.js +358 -306
- package/dist/esm/tools/codegen/utils.js +373 -373
- package/dist/esm/tools/generate-map.js +1 -1
- package/dist/esm/tools/generateMetadata.js +29 -28
- package/dist/esm/tools/generateSites.js +52 -51
- package/dist/esm/tools/index.js +28 -27
- package/dist/esm/tools/scaffold.js +52 -51
- package/dist/esm/tools/templating/components.js +59 -223
- package/dist/esm/tools/templating/index.js +3 -3
- package/dist/esm/tools/templating/plugins.js +72 -70
- package/dist/esm/tools/templating/utils.js +59 -58
- package/dist/esm/utils/ensurePath.js +13 -13
- package/dist/esm/utils/env.js +24 -23
- package/dist/esm/utils/globalCache.js +49 -0
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/is-server.js +9 -8
- package/dist/esm/utils/normalize-url.js +1 -1
- package/dist/esm/utils/timeout-promise.js +28 -28
- package/dist/esm/utils/utils.js +238 -213
- package/package.json +73 -5
- package/types/cache-client.d.ts +68 -64
- package/types/cache-client.d.ts.map +1 -0
- package/types/client/constants.d.ts +5 -4
- package/types/client/constants.d.ts.map +1 -0
- package/types/client/edge-proxy.d.ts +18 -15
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +8 -7
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -19
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -327
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -9
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -18
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -2
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -268
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -7
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -2
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -4
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +44 -11
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +35 -28
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -1
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -195
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -80
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -63
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +72 -62
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -6
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/metadata.d.ts +8 -7
- package/types/editing/metadata.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -92
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +91 -74
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -21
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -1
- package/types/form/index.d.ts.map +1 -0
- package/types/graphql-request-client.d.ts +112 -105
- package/types/graphql-request-client.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +135 -131
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -2
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -7
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +13 -12
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -18
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -5
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -35
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -151
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -11
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -41
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -2
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -55
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +94 -84
- package/types/models.d.ts.map +1 -0
- package/types/native-fetcher.d.ts +124 -114
- package/types/native-fetcher.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -3
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -27
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +90 -80
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -69
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/retries.d.ts +26 -24
- package/types/retries.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -57
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -9
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -18
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +92 -69
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -50
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -26
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +65 -52
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -56
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -134
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -28
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -30
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/auth/flow.d.ts +29 -27
- package/types/tools/auth/flow.d.ts.map +1 -0
- package/types/tools/auth/index.d.ts +2 -1
- package/types/tools/auth/index.d.ts.map +1 -0
- package/types/tools/auth/models.d.ts +35 -33
- package/types/tools/auth/models.d.ts.map +1 -0
- package/types/tools/auth/tenant-store.d.ts +12 -11
- package/types/tools/auth/tenant-store.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -47
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -22
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -70
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -75
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -26
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateMetadata.d.ts +24 -22
- package/types/tools/generateMetadata.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -22
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +22 -20
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -25
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -103
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +4 -3
- package/types/tools/templating/index.d.ts.map +1 -0
- package/types/tools/templating/plugins.d.ts +71 -67
- package/types/tools/templating/plugins.d.ts.map +1 -0
- package/types/tools/templating/utils.d.ts +42 -40
- package/types/tools/templating/utils.d.ts.map +1 -0
- package/types/utils/ensurePath.d.ts +7 -6
- package/types/utils/ensurePath.d.ts.map +1 -0
- package/types/utils/env.d.ts +9 -7
- package/types/utils/env.d.ts.map +1 -0
- package/types/utils/globalCache.d.ts +37 -0
- package/types/utils/globalCache.d.ts.map +1 -0
- package/types/utils/index.d.ts +5 -3
- package/types/utils/index.d.ts.map +1 -0
- package/types/utils/is-server.d.ts +8 -6
- package/types/utils/is-server.d.ts.map +1 -0
- package/types/utils/normalize-url.d.ts +2 -1
- package/types/utils/normalize-url.d.ts.map +1 -0
- package/types/utils/timeout-promise.d.ts +18 -17
- package/types/utils/timeout-promise.d.ts.map +1 -0
- package/types/utils/utils.d.ts +104 -79
- package/types/utils/utils.d.ts.map +1 -0
- package/client.js +0 -1
- package/codegen.js +0 -1
- package/config-cli.js +0 -1
- package/config.js +0 -1
- package/editing.js +0 -1
- package/i18n.js +0 -1
- package/layout.js +0 -1
- package/media.js +0 -1
- package/personalize.js +0 -1
- package/site.js +0 -1
- package/tools.js +0 -1
- package/utils.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { getMetadata } from '../editing/metadata';
|
|
4
|
-
import { ensurePathExists } from '../utils/ensurePath';
|
|
5
|
-
/**
|
|
6
|
-
* Generate application metadata
|
|
7
|
-
* @param {GenerateMetadataConfig} config - Optional configuration for generating metadata.
|
|
8
|
-
* If not provided, the default '.sitecore/metadata.json' will be used and allowWorkspaces will be set to false.
|
|
9
|
-
* @returns {Promise<void>} A promise that resolves when the metadata generation is complete.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @param {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getMetadata } from '../editing/metadata';
|
|
4
|
+
import { ensurePathExists } from '../utils/ensurePath';
|
|
5
|
+
/**
|
|
6
|
+
* Generate application metadata
|
|
7
|
+
* @param {GenerateMetadataConfig} config - Optional configuration for generating metadata.
|
|
8
|
+
* If not provided, the default '.sitecore/metadata.json' will be used and allowWorkspaces will be set to false.
|
|
9
|
+
* @returns {Promise<void>} A promise that resolves when the metadata generation is complete.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const generateMetadata = (config) => {
|
|
13
|
+
return async () => {
|
|
14
|
+
var _a;
|
|
15
|
+
const metadata = getMetadata(!!(config === null || config === void 0 ? void 0 : config.allowWorkspaces));
|
|
16
|
+
writeMetadata(metadata, (_a = config === null || config === void 0 ? void 0 : config.destinationPath) !== null && _a !== void 0 ? _a : '.sitecore/metadata.json');
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Writes the metadata object to disk.
|
|
21
|
+
* @param {Metadata} metadata metadata to write.
|
|
22
|
+
* @param {string} destinationPath path to write the metadata to.
|
|
23
|
+
*/
|
|
24
|
+
function writeMetadata(metadata, destinationPath) {
|
|
25
|
+
const filePath = path.resolve(destinationPath);
|
|
26
|
+
ensurePathExists(filePath);
|
|
27
|
+
console.log(`Writing metadata to ${filePath}`);
|
|
28
|
+
fs.writeFileSync(filePath, JSON.stringify(metadata, null, 2), { encoding: 'utf8' });
|
|
29
|
+
}
|
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import debug from '../debug';
|
|
5
|
-
import { SiteInfoService } from '../site';
|
|
6
|
-
import { ensurePathExists } from '../utils/ensurePath';
|
|
7
|
-
import { createGraphQLClientFactory } from '../client';
|
|
8
|
-
const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
|
|
9
|
-
/**
|
|
10
|
-
* Generates site information and writes it to a specified destination path.
|
|
11
|
-
* @param {GenerateSitesConfig} config - The configuration for generating site info.
|
|
12
|
-
* @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import debug from '../debug';
|
|
5
|
+
import { SiteInfoService } from '../site';
|
|
6
|
+
import { ensurePathExists } from '../utils/ensurePath';
|
|
7
|
+
import { createGraphQLClientFactory } from '../client';
|
|
8
|
+
const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
|
|
9
|
+
/**
|
|
10
|
+
* Generates site information and writes it to a specified destination path.
|
|
11
|
+
* @param {GenerateSitesConfig} config - The configuration for generating site info.
|
|
12
|
+
* @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const generateSites = ({ scConfig: deprecatedScConfig, destinationPath, } = {}) => {
|
|
16
|
+
return async ({ scConfig } = {}) => {
|
|
17
|
+
const config = deprecatedScConfig !== null && deprecatedScConfig !== void 0 ? deprecatedScConfig : scConfig;
|
|
18
|
+
if (!config) {
|
|
19
|
+
throw new Error('Sitecore configuration is required to be provided');
|
|
20
|
+
}
|
|
21
|
+
let sites = [];
|
|
22
|
+
const sitesFilePath = path.resolve(destinationPath !== null && destinationPath !== void 0 ? destinationPath : DEFAULT_SITES_DIST_PATH);
|
|
23
|
+
debug.multisite(config.multisite.enabled
|
|
24
|
+
? 'Multisite Enabled: Generating site information'
|
|
25
|
+
: 'Multisite Disabled');
|
|
26
|
+
if (config.multisite.enabled) {
|
|
27
|
+
try {
|
|
28
|
+
const siteInfoService = new SiteInfoService({
|
|
29
|
+
clientFactory: createGraphQLClientFactory({
|
|
30
|
+
api: config.api,
|
|
31
|
+
retries: config.retries.count,
|
|
32
|
+
retryStrategy: config.retries.retryStrategy,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
sites = await siteInfoService.fetchSiteInfo();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(chalk.red('Error fetching site information'));
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Add default site to the list
|
|
43
|
+
const defaultSite = {
|
|
44
|
+
name: config.defaultSite,
|
|
45
|
+
hostName: '*',
|
|
46
|
+
language: config.defaultLanguage,
|
|
47
|
+
};
|
|
48
|
+
sites.unshift(defaultSite);
|
|
49
|
+
ensurePathExists(sitesFilePath);
|
|
50
|
+
fs.writeFileSync(sitesFilePath, JSON.stringify(sites, null, 2), { encoding: 'utf8' });
|
|
51
|
+
};
|
|
52
|
+
};
|
package/dist/esm/tools/index.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
export { generateSites } from './generateSites';
|
|
2
|
-
export { generateMetadata } from './generateMetadata';
|
|
3
|
-
export { scaffoldComponent } from './scaffold';
|
|
4
|
-
export { extractFiles } from './codegen/extract-files';
|
|
5
|
-
export { writeImportMap } from './codegen/import-map';
|
|
6
|
-
export { getComponentSpec, getComponentSpecUrl } from './codegen/component-generation';
|
|
7
|
-
export * from './templating';
|
|
8
|
-
export * from './auth/models';
|
|
9
|
-
import * as authModule from './auth';
|
|
10
|
-
/**
|
|
11
|
-
* Preserve "live binding" semantics similar to ES module imports: production
|
|
12
|
-
* code always sees the current implementation; tests can swap it safely and
|
|
13
|
-
* restore via `sandbox.restore()` with no hidden global state.
|
|
14
|
-
*
|
|
15
|
-
* Public surface consumed by the rest of the codebase.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
export { generateSites } from './generateSites';
|
|
2
|
+
export { generateMetadata } from './generateMetadata';
|
|
3
|
+
export { scaffoldComponent } from './scaffold';
|
|
4
|
+
export { extractFiles } from './codegen/extract-files';
|
|
5
|
+
export { writeImportMap, defaultMapTemplate as defaultImportMapTemplate, } from './codegen/import-map';
|
|
6
|
+
export { getComponentSpec, getComponentSpecUrl } from './codegen/component-generation';
|
|
7
|
+
export * from './templating';
|
|
8
|
+
export * from './auth/models';
|
|
9
|
+
import * as authModule from './auth';
|
|
10
|
+
/**
|
|
11
|
+
* Preserve "live binding" semantics similar to ES module imports: production
|
|
12
|
+
* code always sees the current implementation; tests can swap it safely and
|
|
13
|
+
* restore via `sandbox.restore()` with no hidden global state.
|
|
14
|
+
*
|
|
15
|
+
* Public surface consumed by the rest of the codebase.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const auth = {};
|
|
19
|
+
/*
|
|
20
|
+
* Define an accessor so reads are dynamic
|
|
21
|
+
* - Production: returns the real `authModule.clientCredentialsFlow`.
|
|
22
|
+
* - Tests: can be replaced with a stub via `sinon.replaceGetter` or `sandbox.replaceGetter`
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(auth, 'clientCredentialsFlow', {
|
|
25
|
+
get: () => authModule.clientCredentialsFlow,
|
|
26
|
+
configurable: true,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
});
|
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
/**
|
|
5
|
-
* Force to use `crlf` line endings, we are using `crlf` across the project.
|
|
6
|
-
* Replace: `lf` (\n), `cr` (\r)
|
|
7
|
-
* @param {string} content
|
|
8
|
-
*/
|
|
9
|
-
export function editLineEndings(content) {
|
|
10
|
-
return content.replace(/\r|\n/gm, '\r\n');
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Creates a file relative to the specified path if the file doesn't exist.
|
|
14
|
-
* Creates directories as needed.
|
|
15
|
-
* Does not overwrite existing files.
|
|
16
|
-
* @param {string} filePath - the file path
|
|
17
|
-
* @param {string} fileContent - the file content
|
|
18
|
-
* @returns {string} the file path if the file was created, otherwise null
|
|
19
|
-
*/
|
|
20
|
-
export function scaffoldFile(filePath, fileContent) {
|
|
21
|
-
const outputDir = path.dirname(filePath);
|
|
22
|
-
if (fs.existsSync(filePath)) {
|
|
23
|
-
console.log(chalk.red(`Skipping creating ${filePath}; already exists.`));
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
27
|
-
fs.writeFileSync(filePath, editLineEndings(fileContent), 'utf8');
|
|
28
|
-
console.log(chalk.green(`File ${filePath} has been scaffolded.`));
|
|
29
|
-
return filePath;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Scaffolds a new component based on the provided template.
|
|
33
|
-
* @param {string} outputFolderPath - The file path where the component will be created.
|
|
34
|
-
* @param {string} componentName - The name of the component to be created.
|
|
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
|
-
* @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
|
|
37
|
-
* @throws Will throw an error if the specified template is not found.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Force to use `crlf` line endings, we are using `crlf` across the project.
|
|
6
|
+
* Replace: `lf` (\n), `cr` (\r)
|
|
7
|
+
* @param {string} content
|
|
8
|
+
*/
|
|
9
|
+
export function editLineEndings(content) {
|
|
10
|
+
return content.replace(/\r|\n/gm, '\r\n');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a file relative to the specified path if the file doesn't exist.
|
|
14
|
+
* Creates directories as needed.
|
|
15
|
+
* Does not overwrite existing files.
|
|
16
|
+
* @param {string} filePath - the file path
|
|
17
|
+
* @param {string} fileContent - the file content
|
|
18
|
+
* @returns {string} the file path if the file was created, otherwise null
|
|
19
|
+
*/
|
|
20
|
+
export function scaffoldFile(filePath, fileContent) {
|
|
21
|
+
const outputDir = path.dirname(filePath);
|
|
22
|
+
if (fs.existsSync(filePath)) {
|
|
23
|
+
console.log(chalk.red(`Skipping creating ${filePath}; already exists.`));
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
27
|
+
fs.writeFileSync(filePath, editLineEndings(fileContent), 'utf8');
|
|
28
|
+
console.log(chalk.green(`File ${filePath} has been scaffolded.`));
|
|
29
|
+
return filePath;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Scaffolds a new component based on the provided template.
|
|
33
|
+
* @param {string} outputFolderPath - The file path where the component will be created.
|
|
34
|
+
* @param {string} componentName - The name of the component to be created.
|
|
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
|
+
* @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
|
|
37
|
+
* @throws Will throw an error if the specified template is not found.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export function scaffoldComponent(outputFolderPath, componentName, templateName, templates) {
|
|
41
|
+
const template = templates.find((t) => t.name === templateName);
|
|
42
|
+
if (!template) {
|
|
43
|
+
throw new Error(`Template ${templateName} not found.`);
|
|
44
|
+
}
|
|
45
|
+
const outputFilePath = path.join(outputFolderPath, `${componentName}.${template.fileExtension}`);
|
|
46
|
+
const componentOutputPath = scaffoldFile(outputFilePath, template.generateTemplate(componentName));
|
|
47
|
+
if (componentOutputPath) {
|
|
48
|
+
const nextSteps = [];
|
|
48
49
|
nextSteps.push(chalk.green(`
|
|
49
50
|
Scaffolding of ${componentName} complete.
|
|
50
|
-
Next steps:`), ...(template.getNextSteps ? template.getNextSteps(componentOutputPath) : []));
|
|
51
|
-
console.log(nextSteps.join('\n'));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
51
|
+
Next steps:`), ...(template.getNextSteps ? template.getNextSteps(componentOutputPath) : []));
|
|
52
|
+
console.log(nextSteps.join('\n'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,223 +1,59 @@
|
|
|
1
|
-
import * as glob from 'glob';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param {string[]}
|
|
25
|
-
* @param {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (pagesDirExists) {
|
|
61
|
-
return 'pages';
|
|
62
|
-
}
|
|
63
|
-
return 'pages';
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Detects the component type based on directives, imports, and router context.
|
|
67
|
-
* - Checks for 'use client' directive
|
|
68
|
-
* - Checks for explicit componentType export
|
|
69
|
-
* - Checks for server-only imports (next/headers, etc.)
|
|
70
|
-
* - Defaults to 'server' for App Router, 'universal' for Pages Router
|
|
71
|
-
* @param {string} filePath - Path to the component file
|
|
72
|
-
* @param {RouterType} [routerType] - Optional router type override. Auto-detected if not provided.
|
|
73
|
-
* @returns {ComponentType} 'server', 'client', or 'universal'
|
|
74
|
-
*/
|
|
75
|
-
export function detectComponentType(filePath, routerType) {
|
|
76
|
-
try {
|
|
77
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
78
|
-
// Parse using TypeScript AST (following patterns from import-map.ts and utils.ts)
|
|
79
|
-
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
80
|
-
let hasUseClientDirective = false;
|
|
81
|
-
let explicitComponentType = null;
|
|
82
|
-
let hasServerOnlyImports = false;
|
|
83
|
-
// Auto-detect router type if not provided
|
|
84
|
-
const detectedRouterType = routerType || detectRouterType();
|
|
85
|
-
// Track position to ensure directives come before imports/other statements
|
|
86
|
-
let foundFirstNonDirectiveStatement = false;
|
|
87
|
-
// Helper function to check if a node is a valid directive
|
|
88
|
-
const isValidDirective = (node) => {
|
|
89
|
-
return (ts.isExpressionStatement(node) &&
|
|
90
|
-
ts.isStringLiteral(node.expression) &&
|
|
91
|
-
!foundFirstNonDirectiveStatement);
|
|
92
|
-
};
|
|
93
|
-
// More comprehensive AST traversal (following patterns from import-map.ts and utils.ts)
|
|
94
|
-
const traverseNode = (node) => {
|
|
95
|
-
var _a;
|
|
96
|
-
// Check for 'use client'/'use server' directives (must be at top, before imports)
|
|
97
|
-
if (isValidDirective(node) &&
|
|
98
|
-
ts.isStringLiteral(node.expression)) {
|
|
99
|
-
const directiveText = node.expression
|
|
100
|
-
.text;
|
|
101
|
-
if (directiveText === 'use client') {
|
|
102
|
-
hasUseClientDirective = true;
|
|
103
|
-
return; // Don't mark as non-directive statement
|
|
104
|
-
}
|
|
105
|
-
if (directiveText === 'use server') {
|
|
106
|
-
explicitComponentType = 'server';
|
|
107
|
-
return; // Don't mark as non-directive statement
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Mark that we've seen a non-directive statement (imports, declarations, etc.)
|
|
111
|
-
if (ts.isImportDeclaration(node) ||
|
|
112
|
-
ts.isVariableStatement(node) ||
|
|
113
|
-
ts.isFunctionDeclaration(node) ||
|
|
114
|
-
ts.isExportDeclaration(node) ||
|
|
115
|
-
ts.isExportAssignment(node)) {
|
|
116
|
-
foundFirstNonDirectiveStatement = true;
|
|
117
|
-
}
|
|
118
|
-
// Check for import declarations with server-only modules
|
|
119
|
-
if (ts.isImportDeclaration(node)) {
|
|
120
|
-
const moduleSpecifier = node.moduleSpecifier;
|
|
121
|
-
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
122
|
-
const importPath = moduleSpecifier.text;
|
|
123
|
-
// Expand server-only module detection
|
|
124
|
-
if (importPath === 'next/headers' ||
|
|
125
|
-
importPath === 'server-only' ||
|
|
126
|
-
importPath === 'next/cache' ||
|
|
127
|
-
importPath === 'next/cookies' ||
|
|
128
|
-
importPath.startsWith('node:') ||
|
|
129
|
-
importPath === 'fs' ||
|
|
130
|
-
importPath === 'path') {
|
|
131
|
-
hasServerOnlyImports = true;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// Check for explicit componentType export (improved detection)
|
|
136
|
-
if (ts.isVariableStatement(node)) {
|
|
137
|
-
const hasExportModifier = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
138
|
-
if (hasExportModifier) {
|
|
139
|
-
node.declarationList.declarations.forEach((declaration) => {
|
|
140
|
-
if (ts.isIdentifier(declaration.name) &&
|
|
141
|
-
declaration.name.text === 'componentType' &&
|
|
142
|
-
declaration.initializer) {
|
|
143
|
-
// Handle string literal
|
|
144
|
-
if (ts.isStringLiteral(declaration.initializer)) {
|
|
145
|
-
const typeValue = declaration.initializer.text;
|
|
146
|
-
if (typeValue === 'server' || typeValue === 'client' || typeValue === 'universal') {
|
|
147
|
-
explicitComponentType = typeValue;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Handle template literal (e.g., `client`)
|
|
151
|
-
else if (ts.isNoSubstitutionTemplateLiteral(declaration.initializer)) {
|
|
152
|
-
const typeValue = declaration.initializer.text;
|
|
153
|
-
if (typeValue === 'server' || typeValue === 'client' || typeValue === 'universal') {
|
|
154
|
-
explicitComponentType = typeValue;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// Check for named export of componentType (export const componentType = ...)
|
|
162
|
-
if (ts.isExportDeclaration(node) &&
|
|
163
|
-
node.exportClause &&
|
|
164
|
-
ts.isNamedExports(node.exportClause)) {
|
|
165
|
-
node.exportClause.elements.forEach((exportSpecifier) => {
|
|
166
|
-
if (exportSpecifier.name.text === 'componentType') {
|
|
167
|
-
// This would need additional logic to resolve the actual value, but for now
|
|
168
|
-
// we'll rely on the variable declaration detection above
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
// Recursively traverse child nodes (following import-map.ts pattern)
|
|
173
|
-
ts.forEachChild(node, traverseNode);
|
|
174
|
-
};
|
|
175
|
-
// Start traversal from the source file (following utils.ts pattern)
|
|
176
|
-
ts.forEachChild(sourceFile, traverseNode);
|
|
177
|
-
// Priority: explicit componentType export > use client/server directives > server-only imports > universal default
|
|
178
|
-
if (explicitComponentType) {
|
|
179
|
-
return explicitComponentType;
|
|
180
|
-
}
|
|
181
|
-
if (hasUseClientDirective) {
|
|
182
|
-
return 'client';
|
|
183
|
-
}
|
|
184
|
-
if (hasServerOnlyImports) {
|
|
185
|
-
return 'server';
|
|
186
|
-
}
|
|
187
|
-
// Router-aware defaults:
|
|
188
|
-
// - App Router: defaults to server (RSC by default)
|
|
189
|
-
// - Pages Router: defaults to universal (isomorphic by default)
|
|
190
|
-
if (detectedRouterType === 'app') {
|
|
191
|
-
return 'server';
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return 'universal';
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
console.warn(`Failed to parse component file ${filePath}, defaulting to universal:`, error);
|
|
199
|
-
return 'universal';
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Get list of components with detected types (server, client, or universal).
|
|
204
|
-
* @param {string[]} paths - Paths to search for components
|
|
205
|
-
* @param {string[]} [exclude] - Paths and glob patterns to exclude from final result
|
|
206
|
-
* @param {boolean} includeVariants - Whether to include variant components
|
|
207
|
-
* @param {RouterType} [routerType] - Optional router type override for type detection. Auto-detected if not provided.
|
|
208
|
-
* @returns {ComponentFileWithType[]} Array of components with their detected types
|
|
209
|
-
*/
|
|
210
|
-
export function getComponentListWithTypes(paths, exclude, includeVariants, routerType) {
|
|
211
|
-
const components = getComponentList(paths, exclude, includeVariants);
|
|
212
|
-
const detectedRouterType = routerType || detectRouterType();
|
|
213
|
-
return components.map((component) => (Object.assign(Object.assign({}, component), { componentType: detectComponentType(component.filePath, detectedRouterType) })));
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Filters components by their detected type.
|
|
217
|
-
* @param {ComponentFileWithType[]} components - Array of components with types
|
|
218
|
-
* @param {ComponentType[]} allowedTypes - Array of allowed component types to filter by
|
|
219
|
-
* @returns {ComponentFileWithType[]} Filtered array containing only components matching allowed types
|
|
220
|
-
*/
|
|
221
|
-
export function filterComponentsByType(components, allowedTypes) {
|
|
222
|
-
return components.filter((component) => allowedTypes.includes(component.componentType));
|
|
223
|
-
}
|
|
1
|
+
import * as glob from 'glob';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export let getComponentList = _getComponentList;
|
|
6
|
+
export const componentUnitMocks = {
|
|
7
|
+
set getComponentList(mockImplementation) {
|
|
8
|
+
getComponentList = mockImplementation;
|
|
9
|
+
},
|
|
10
|
+
get getComponentList() {
|
|
11
|
+
return _getComponentList;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
|
|
15
|
+
const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
|
|
16
|
+
/**
|
|
17
|
+
* Get list of components from @var path
|
|
18
|
+
* Returns a list of components in the following format:
|
|
19
|
+
* {
|
|
20
|
+
* path: 'path/to/component',
|
|
21
|
+
* componentName: 'ComponentName',
|
|
22
|
+
* moduleName: 'ComponentName'
|
|
23
|
+
* }
|
|
24
|
+
* @param {string[]} paths paths to search
|
|
25
|
+
* @param {string[]} [exclude] paths and glob patterns to exclude from final result
|
|
26
|
+
* @param {boolean} [includeVariants] whether to include variant components
|
|
27
|
+
*/
|
|
28
|
+
function _getComponentList(paths, exclude, includeVariants) {
|
|
29
|
+
const components = paths.reduce((result, path) => {
|
|
30
|
+
const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
|
|
31
|
+
? path
|
|
32
|
+
: path.replace(/\/$/, '').concat('/**/*.{js,jsx,ts,tsx}');
|
|
33
|
+
return result.concat(...glob
|
|
34
|
+
.sync(globPath, { ignore: exclude, nodir: true })
|
|
35
|
+
.filter((path) => path.match(componentNamePattern))
|
|
36
|
+
.map((filePath) => {
|
|
37
|
+
const name = filePath.match(componentNamePattern)[2];
|
|
38
|
+
return {
|
|
39
|
+
filePath,
|
|
40
|
+
importPath: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
|
|
41
|
+
componentName: name,
|
|
42
|
+
moduleName: name.replace(/[^\w]+/g, ''),
|
|
43
|
+
};
|
|
44
|
+
}));
|
|
45
|
+
}, []);
|
|
46
|
+
return includeVariants
|
|
47
|
+
? components
|
|
48
|
+
: components.filter((component) => !component.componentName.includes('.'));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Filters components by their detected type.
|
|
52
|
+
* @param {ComponentFileWithType[]} components - Array of components with types
|
|
53
|
+
* @param {ComponentType[]} allowedTypes - Array of allowed component types to filter by
|
|
54
|
+
* @returns {ComponentFileWithType[]} Filtered array containing only components matching allowed types
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export function filterComponentsByType(components, allowedTypes) {
|
|
58
|
+
return components.filter((component) => allowedTypes.includes(component.componentType));
|
|
59
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getComponentList,
|
|
2
|
-
export { generatePlugins, ModuleType } from './plugins';
|
|
3
|
-
export { matchPath } from './utils';
|
|
1
|
+
export { getComponentList, filterComponentsByType, } from './components';
|
|
2
|
+
export { generatePlugins, ModuleType } from './plugins';
|
|
3
|
+
export { matchPath } from './utils';
|