@sitecore-content-sdk/content 1.5.0-canary.5
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/LICENSE.txt +202 -0
- package/README.md +7 -0
- package/client.d.ts +1 -0
- package/codegen.d.ts +1 -0
- package/config-cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/dist/cjs/client/edge-proxy.js +24 -0
- package/dist/cjs/client/index.js +14 -0
- package/dist/cjs/client/models.js +2 -0
- package/dist/cjs/client/sitecore-client.js +420 -0
- package/dist/cjs/client/utils.js +53 -0
- package/dist/cjs/config/define-config.js +195 -0
- package/dist/cjs/config/index.js +7 -0
- package/dist/cjs/config/models.js +12 -0
- package/dist/cjs/config-cli/define-cli-config.js +23 -0
- package/dist/cjs/config-cli/index.js +7 -0
- package/dist/cjs/config-cli/models.js +8 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/debug.js +21 -0
- package/dist/cjs/editing/codegen/index.js +14 -0
- package/dist/cjs/editing/codegen/preview.js +277 -0
- package/dist/cjs/editing/component-layout-service.js +62 -0
- package/dist/cjs/editing/design-library.js +184 -0
- package/dist/cjs/editing/editing-service.js +81 -0
- package/dist/cjs/editing/index.js +33 -0
- package/dist/cjs/editing/models.js +44 -0
- package/dist/cjs/editing/utils.js +105 -0
- package/dist/cjs/form/form.js +81 -0
- package/dist/cjs/form/index.js +7 -0
- package/dist/cjs/i18n/dictionary-service.js +144 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/i18n/utils.js +16 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/layout/content-styles.js +73 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +68 -0
- package/dist/cjs/layout/models.js +39 -0
- package/dist/cjs/layout/themes.js +77 -0
- package/dist/cjs/layout/utils.js +117 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +100 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/personalize/index.js +15 -0
- package/dist/cjs/personalize/layout-personalizer.js +98 -0
- package/dist/cjs/personalize/personalize-service.js +109 -0
- package/dist/cjs/personalize/utils.js +143 -0
- package/dist/cjs/site/error-pages-service.js +82 -0
- package/dist/cjs/site/index.js +26 -0
- package/dist/cjs/site/models.js +2 -0
- package/dist/cjs/site/redirects-service.js +109 -0
- package/dist/cjs/site/robots-service.js +74 -0
- package/dist/cjs/site/site-resolver.js +73 -0
- package/dist/cjs/site/siteinfo-service.js +94 -0
- package/dist/cjs/site/sitemap-xml-service.js +92 -0
- package/dist/cjs/site/sitepath-service.js +201 -0
- package/dist/cjs/site/utils.js +55 -0
- package/dist/cjs/sitecore-service-base.js +33 -0
- package/dist/cjs/tools/codegen/component-generation.js +49 -0
- package/dist/cjs/tools/codegen/extract-files.js +105 -0
- package/dist/cjs/tools/codegen/import-map.js +411 -0
- package/dist/cjs/tools/codegen/utils.js +418 -0
- package/dist/cjs/tools/generate-map.js +2 -0
- package/dist/cjs/tools/generateSites.js +59 -0
- package/dist/cjs/tools/index.js +30 -0
- package/dist/cjs/tools/scaffold.js +62 -0
- package/dist/cjs/tools/templating/components.js +96 -0
- package/dist/cjs/tools/templating/index.js +6 -0
- package/dist/esm/client/edge-proxy.js +19 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/models.js +1 -0
- package/dist/esm/client/sitecore-client.js +416 -0
- package/dist/esm/client/utils.js +49 -0
- package/dist/esm/config/define-config.js +189 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/models.js +9 -0
- package/dist/esm/config-cli/define-cli-config.js +19 -0
- package/dist/esm/config-cli/index.js +2 -0
- package/dist/esm/config-cli/models.js +5 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/debug.js +19 -0
- package/dist/esm/editing/codegen/index.js +1 -0
- package/dist/esm/editing/codegen/preview.js +263 -0
- package/dist/esm/editing/component-layout-service.js +55 -0
- package/dist/esm/editing/design-library.js +172 -0
- package/dist/esm/editing/editing-service.js +74 -0
- package/dist/esm/editing/index.js +6 -0
- package/dist/esm/editing/models.js +41 -0
- package/dist/esm/editing/utils.js +98 -0
- package/dist/esm/form/form.js +72 -0
- package/dist/esm/form/index.js +1 -0
- package/dist/esm/i18n/dictionary-service.js +137 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/i18n/utils.js +13 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/layout/content-styles.js +65 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +61 -0
- package/dist/esm/layout/models.js +36 -0
- package/dist/esm/layout/themes.js +72 -0
- package/dist/esm/layout/utils.js +109 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +90 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +93 -0
- package/dist/esm/personalize/personalize-service.js +102 -0
- package/dist/esm/personalize/utils.js +135 -0
- package/dist/esm/site/error-pages-service.js +75 -0
- package/dist/esm/site/index.js +8 -0
- package/dist/esm/site/models.js +1 -0
- package/dist/esm/site/redirects-service.js +102 -0
- package/dist/esm/site/robots-service.js +67 -0
- package/dist/esm/site/site-resolver.js +69 -0
- package/dist/esm/site/siteinfo-service.js +87 -0
- package/dist/esm/site/sitemap-xml-service.js +85 -0
- package/dist/esm/site/sitepath-service.js +193 -0
- package/dist/esm/site/utils.js +49 -0
- package/dist/esm/sitecore-service-base.js +29 -0
- package/dist/esm/tools/codegen/component-generation.js +44 -0
- package/dist/esm/tools/codegen/extract-files.js +99 -0
- package/dist/esm/tools/codegen/import-map.js +368 -0
- package/dist/esm/tools/codegen/utils.js +373 -0
- package/dist/esm/tools/generate-map.js +1 -0
- package/dist/esm/tools/generateSites.js +52 -0
- package/dist/esm/tools/index.js +6 -0
- package/dist/esm/tools/scaffold.js +54 -0
- package/dist/esm/tools/templating/components.js +59 -0
- package/dist/esm/tools/templating/index.js +1 -0
- package/editing.d.ts +1 -0
- package/i18n.d.ts +1 -0
- package/layout.d.ts +1 -0
- package/media.d.ts +1 -0
- package/package.json +157 -0
- package/personalize.d.ts +1 -0
- package/site.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/types/client/edge-proxy.d.ts +17 -0
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +7 -0
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -0
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -0
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -0
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -0
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -0
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -0
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -0
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -0
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -0
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +10 -0
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +19 -0
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -0
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -0
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -0
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -0
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +71 -0
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -0
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -0
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +82 -0
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -0
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -0
- package/types/form/index.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +133 -0
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -0
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -0
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -0
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -0
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -0
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -0
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -0
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -0
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -0
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +32 -0
- package/types/models.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -0
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -0
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +89 -0
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -0
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -0
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -0
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -0
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +91 -0
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -0
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -0
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +64 -0
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -0
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -0
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -0
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -0
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -0
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -0
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -0
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -0
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -0
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -0
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +8 -0
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -0
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -0
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +2 -0
- package/types/tools/templating/index.d.ts.map +1 -0
|
@@ -0,0 +1,418 @@
|
|
|
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
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.isNodeModuleImport = exports.getRelativeImportPath = exports.stripExtension = exports._xmCloudDeploy = exports.utils = exports.ExtractedFileType = exports.utilsUnitMocks = exports.sendCode = exports.readNamedExports = exports.resolveComponentImportFiles = void 0;
|
|
40
|
+
exports.validateDeployContext = validateDeployContext;
|
|
41
|
+
exports.toPosixPath = toPosixPath;
|
|
42
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
43
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
45
|
+
const fs_1 = __importDefault(require("fs"));
|
|
46
|
+
const ts = __importStar(require("typescript"));
|
|
47
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
48
|
+
const module_1 = require("module");
|
|
49
|
+
/**
|
|
50
|
+
* Parse the generated component-map file and return all referenced modules
|
|
51
|
+
* per map entry (handles both single identifiers and spread objects).
|
|
52
|
+
* @param {string} appRoot path to the JSS app root
|
|
53
|
+
* @param {string} componentMapPath path to the component map file
|
|
54
|
+
* @returns map of component names and their respective import strings
|
|
55
|
+
*/
|
|
56
|
+
exports.resolveComponentImportFiles = _resolveComponentImportFiles;
|
|
57
|
+
/**
|
|
58
|
+
* Reads the named exports from a TypeScript file.
|
|
59
|
+
* @param {ExtractedFile} filePath absolute path to a .ts/.tsx file
|
|
60
|
+
* @returns {string[]} list of named exports found in the file
|
|
61
|
+
*/
|
|
62
|
+
exports.readNamedExports = _readNamedExports;
|
|
63
|
+
/**
|
|
64
|
+
* Sends the extracted code to the specified target URL.
|
|
65
|
+
* @param {object} params - The parameters object.
|
|
66
|
+
* @param {ExtractedFile} params.file - The file to be sent.
|
|
67
|
+
* @param {string} params.token - The access token for authentication.
|
|
68
|
+
* @param {string} params.targetUrl - The target URL to send the file to.
|
|
69
|
+
* @param {Record<string, unknown>} [params.extraLabels] - Additional labels to include in the payload.
|
|
70
|
+
* @returns {Promise<string | null>} - The path of the sent file or null if sending failed.
|
|
71
|
+
*/
|
|
72
|
+
exports.sendCode = _sendCode;
|
|
73
|
+
exports.utilsUnitMocks = {
|
|
74
|
+
set xmCloudDeploy(mockImpl) {
|
|
75
|
+
exports.utils.xmCloudDeploy = mockImpl;
|
|
76
|
+
},
|
|
77
|
+
get xmCloudDeploy() {
|
|
78
|
+
return exports._xmCloudDeploy;
|
|
79
|
+
},
|
|
80
|
+
set resolveComponentImportFiles(mockImpl) {
|
|
81
|
+
exports.resolveComponentImportFiles = mockImpl;
|
|
82
|
+
},
|
|
83
|
+
get resolveComponentImportFiles() {
|
|
84
|
+
return _resolveComponentImportFiles;
|
|
85
|
+
},
|
|
86
|
+
set readNamedExports(mockImpl) {
|
|
87
|
+
exports.readNamedExports = mockImpl;
|
|
88
|
+
},
|
|
89
|
+
get readNamedExports() {
|
|
90
|
+
return _readNamedExports;
|
|
91
|
+
},
|
|
92
|
+
set sendCode(mockImpl) {
|
|
93
|
+
exports.sendCode = mockImpl;
|
|
94
|
+
},
|
|
95
|
+
get sendCode() {
|
|
96
|
+
return _sendCode;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Type of file to be sent to the mesh endpoint
|
|
101
|
+
*/
|
|
102
|
+
var ExtractedFileType;
|
|
103
|
+
(function (ExtractedFileType) {
|
|
104
|
+
ExtractedFileType["Component"] = "component";
|
|
105
|
+
ExtractedFileType["Variant"] = "variant";
|
|
106
|
+
ExtractedFileType["Json"] = "json";
|
|
107
|
+
ExtractedFileType["PackageJson"] = "package.json";
|
|
108
|
+
})(ExtractedFileType || (exports.ExtractedFileType = ExtractedFileType = {}));
|
|
109
|
+
exports.utils = {
|
|
110
|
+
xmCloudDeploy: (...args) => (0, exports._xmCloudDeploy)(...args),
|
|
111
|
+
};
|
|
112
|
+
const _xmCloudDeploy = () => !!process.env.SITECORE && !!process.env.SITECORE_BUILD;
|
|
113
|
+
exports._xmCloudDeploy = _xmCloudDeploy;
|
|
114
|
+
// workaround, Vercel does not have variables that are only accessible at build time
|
|
115
|
+
const vercelDeploy = () => !!process.env.VERCEL && !process.env.VERCEL_REGION;
|
|
116
|
+
const netlifyDeploy = () => !!process.env.NETLIFY && !!process.env.BUILD_ID;
|
|
117
|
+
/**
|
|
118
|
+
* Validates if the current operation is done in Vercel, Netlify or XMCloud
|
|
119
|
+
* deploy context
|
|
120
|
+
* @returns {boolean} - true if in deploy context, false otherwise
|
|
121
|
+
*/
|
|
122
|
+
function validateDeployContext() {
|
|
123
|
+
return (0, exports._xmCloudDeploy)() || vercelDeploy() || netlifyDeploy();
|
|
124
|
+
}
|
|
125
|
+
/*
|
|
126
|
+
* Load and parse the tsconfig.json file from the specified app path.
|
|
127
|
+
*/
|
|
128
|
+
function loadCompilerOptions(appPathAbs) {
|
|
129
|
+
const configPath = ts.findConfigFile(appPathAbs, ts.sys.fileExists, 'tsconfig.json');
|
|
130
|
+
if (!configPath) {
|
|
131
|
+
// Sane defaults if no tsconfig exists
|
|
132
|
+
return {
|
|
133
|
+
jsx: ts.JsxEmit.Preserve,
|
|
134
|
+
allowJs: true,
|
|
135
|
+
module: ts.ModuleKind.ESNext,
|
|
136
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
137
|
+
target: ts.ScriptTarget.ES2020,
|
|
138
|
+
baseUrl: appPathAbs,
|
|
139
|
+
noEmit: true,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
143
|
+
if (configFile.error) {
|
|
144
|
+
throw new Error(`Error reading tsconfig at ${configPath}: ${configFile.error.messageText}`);
|
|
145
|
+
}
|
|
146
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path_1.default.dirname(configPath));
|
|
147
|
+
// Merge with a few safe fallbacks/overrides
|
|
148
|
+
return Object.assign({ jsx: ts.JsxEmit.Preserve, allowJs: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.NodeNext, target: ts.ScriptTarget.ES2020, baseUrl: appPathAbs, noEmit: true }, parsed.options);
|
|
149
|
+
}
|
|
150
|
+
/*
|
|
151
|
+
* Resolve a module specifier using tsconfig options (fast, no Program needed).
|
|
152
|
+
*/
|
|
153
|
+
function resolveWithTs(spec, fromFile, options) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
const host = {
|
|
156
|
+
fileExists: ts.sys.fileExists,
|
|
157
|
+
readFile: ts.sys.readFile,
|
|
158
|
+
directoryExists: ts.sys.directoryExists,
|
|
159
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
160
|
+
getDirectories: ts.sys.getDirectories,
|
|
161
|
+
realpath: ts.sys.realpath,
|
|
162
|
+
};
|
|
163
|
+
const result = ts.resolveModuleName(spec, fromFile, options, host);
|
|
164
|
+
return (_b = (_a = result.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName) !== null && _b !== void 0 ? _b : null;
|
|
165
|
+
}
|
|
166
|
+
function _resolveComponentImportFiles(appRoot, componentMapPath = './.sitecore/component-map.ts') {
|
|
167
|
+
const appPath = path_1.default.isAbsolute(appRoot) ? appRoot : path_1.default.resolve(process.cwd(), appRoot);
|
|
168
|
+
const mapPath = path_1.default.isAbsolute(componentMapPath)
|
|
169
|
+
? componentMapPath
|
|
170
|
+
: path_1.default.resolve(appPath, componentMapPath);
|
|
171
|
+
if (!fs_1.default.existsSync(mapPath)) {
|
|
172
|
+
throw new ReferenceError(`Failed to find file ${mapPath}`);
|
|
173
|
+
}
|
|
174
|
+
// 1) Load tsconfig (simple + safe). Use appPath as baseUrl fallback.
|
|
175
|
+
const compilerOptions = loadCompilerOptions(appPath);
|
|
176
|
+
// Read & parse the map file to an AST (SourceFile)
|
|
177
|
+
const mapText = fs_1.default.readFileSync(mapPath, 'utf8');
|
|
178
|
+
const source = ts.createSourceFile(mapPath, mapText, ts.ScriptTarget.Latest, true);
|
|
179
|
+
const getFileType = (absPath) => {
|
|
180
|
+
const base = path_1.default.basename(absPath); // "PromoBlock.extra.tsx"
|
|
181
|
+
const name = base.replace(/\.[^.]+$/, ''); // "PromoBlock.extra"
|
|
182
|
+
return name.includes('.') ? ExtractedFileType.Variant : ExtractedFileType.Component;
|
|
183
|
+
};
|
|
184
|
+
// 1) Collect import (import %importString% from %importModule%) strings
|
|
185
|
+
const componentMapImports = new Map();
|
|
186
|
+
source.forEachChild((node) => {
|
|
187
|
+
if (ts.isImportDeclaration(node) && node.importClause) {
|
|
188
|
+
const importString = node.importClause.getText();
|
|
189
|
+
const importModule = node.moduleSpecifier.text;
|
|
190
|
+
componentMapImports.set(importString, importModule);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
// 2) Find the map literal: new Map([...]) and collect entries
|
|
194
|
+
// Also capture subsequent mutations: <mapIdent>.set('Key', Value)
|
|
195
|
+
const results = [];
|
|
196
|
+
const mapIdentifiers = new Set(); // all identifiers bound to the Map we care about
|
|
197
|
+
// Given an import and an expression (identifier or object literal with spreads),
|
|
198
|
+
// resolve the module(s) to absolute file paths and append normalized entries to `results`.
|
|
199
|
+
const resolveAndRecordEntry = (importStringsEntry, mapEntry) => {
|
|
200
|
+
// small guard to record a resolved path if valid
|
|
201
|
+
const recordIfValid = (spec) => {
|
|
202
|
+
// ignore Node built-ins and node: protocol up front
|
|
203
|
+
if ((0, module_1.isBuiltin)(spec) || isNodeProtocol(spec))
|
|
204
|
+
return;
|
|
205
|
+
const fileAbs = resolveWithTs(spec, mapPath, compilerOptions);
|
|
206
|
+
if (!fileAbs)
|
|
207
|
+
return;
|
|
208
|
+
// ignore node_modules and *.d.ts after resolution
|
|
209
|
+
if (inNodeModules(fileAbs) || isDeclarationFile(fileAbs))
|
|
210
|
+
return;
|
|
211
|
+
results.push({
|
|
212
|
+
componentKey: importStringsEntry,
|
|
213
|
+
filePath: toPosixPath(fileAbs),
|
|
214
|
+
fileType: getFileType(fileAbs),
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
// Helper to find the matching import statement for a given component/module name
|
|
218
|
+
const getImportPathForModule = (componentModuleName) => {
|
|
219
|
+
let result = componentMapImports.get(componentModuleName);
|
|
220
|
+
if (!result) {
|
|
221
|
+
for (const key of componentMapImports.keys()) {
|
|
222
|
+
const matcher = new RegExp(`\\b(${componentModuleName})\\b`);
|
|
223
|
+
if (key.match(matcher) !== null) {
|
|
224
|
+
return componentMapImports.get(key);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
};
|
|
231
|
+
// Case A: ['Key', Identifier]
|
|
232
|
+
if (ts.isIdentifier(mapEntry)) {
|
|
233
|
+
const componentEntryName = mapEntry.text;
|
|
234
|
+
const importPathString = getImportPathForModule(componentEntryName);
|
|
235
|
+
if (!importPathString)
|
|
236
|
+
return;
|
|
237
|
+
recordIfValid(importPathString);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
// Case B: ['Key', { ...A, ...B, ...C }]
|
|
241
|
+
if (ts.isObjectLiteralExpression(mapEntry)) {
|
|
242
|
+
mapEntry.properties.forEach((prop) => {
|
|
243
|
+
if (ts.isSpreadAssignment(prop) && ts.isIdentifier(prop.expression)) {
|
|
244
|
+
const componentEntryName = prop.expression.text;
|
|
245
|
+
const importPathString = getImportPathForModule(componentEntryName);
|
|
246
|
+
if (!importPathString)
|
|
247
|
+
return;
|
|
248
|
+
recordIfValid(importPathString);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
// Walk the `new Map([...])` array literal and feed each ['Key', Value] into
|
|
254
|
+
// `resolveAndRecordEntry` (only when the key is a string literal).
|
|
255
|
+
const collectArrayEntries = (arrayArg) => {
|
|
256
|
+
arrayArg.elements.forEach((el) => {
|
|
257
|
+
if (ts.isArrayLiteralExpression(el)) {
|
|
258
|
+
const [keyNode, valNode] = el.elements;
|
|
259
|
+
if (keyNode && valNode && ts.isStringLiteral(keyNode)) {
|
|
260
|
+
resolveAndRecordEntry(keyNode.text, valNode);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
// If this `new Map([...])` is bound to a variable (via decl or assignment),
|
|
266
|
+
// record the identifier name so we can catch later `<id>.set(...)` mutations.
|
|
267
|
+
const captureMapIdentifier = (node) => {
|
|
268
|
+
// const m = new Map([...])
|
|
269
|
+
const parent = node.parent;
|
|
270
|
+
// Variable declaration with initializer new Map(...)
|
|
271
|
+
if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
|
|
272
|
+
mapIdentifiers.add(parent.name.text);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
// Assignment: m = new Map([...])
|
|
276
|
+
if (parent &&
|
|
277
|
+
ts.isBinaryExpression(parent) &&
|
|
278
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
279
|
+
ts.isIdentifier(parent.left)) {
|
|
280
|
+
mapIdentifiers.add(parent.left.text);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
// Exported variable declaration: export const componentMap = new Map([...])
|
|
284
|
+
if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
|
|
285
|
+
mapIdentifiers.add(parent.name.text);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const traverseAst = (node) => {
|
|
290
|
+
var _a;
|
|
291
|
+
// A) Initial literal: new Map([...])
|
|
292
|
+
if (ts.isNewExpression(node) &&
|
|
293
|
+
node.expression.getText(source) === 'Map' &&
|
|
294
|
+
node.arguments &&
|
|
295
|
+
node.arguments.length > 0) {
|
|
296
|
+
const firstArg = node.arguments[0];
|
|
297
|
+
if (ts.isArrayLiteralExpression(firstArg)) {
|
|
298
|
+
collectArrayEntries(firstArg);
|
|
299
|
+
}
|
|
300
|
+
captureMapIdentifier(node);
|
|
301
|
+
}
|
|
302
|
+
// B) Mutations: <mapIdent>.set('Key', Value)
|
|
303
|
+
if (ts.isCallExpression(node) &&
|
|
304
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
305
|
+
node.expression.name.text === 'set') {
|
|
306
|
+
const target = node.expression.expression;
|
|
307
|
+
if (ts.isIdentifier(target) && mapIdentifiers.has(target.text)) {
|
|
308
|
+
const [keyArg, valArg] = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
|
|
309
|
+
if (keyArg && ts.isStringLiteral(keyArg) && valArg) {
|
|
310
|
+
resolveAndRecordEntry(keyArg.text, valArg);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
ts.forEachChild(node, traverseAst);
|
|
315
|
+
};
|
|
316
|
+
ts.forEachChild(source, traverseAst);
|
|
317
|
+
return results.filter((r) => !isDeclarationFile(r.filePath));
|
|
318
|
+
}
|
|
319
|
+
function _readNamedExports(filePath) {
|
|
320
|
+
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
321
|
+
const sf = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
|
|
322
|
+
const names = new Set();
|
|
323
|
+
const visit = (node) => {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
// export const X = ...
|
|
326
|
+
if (ts.isVariableStatement(node) &&
|
|
327
|
+
((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))) {
|
|
328
|
+
node.declarationList.declarations.forEach((d) => {
|
|
329
|
+
if (ts.isIdentifier(d.name))
|
|
330
|
+
names.add(d.name.text);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// export function X() {}
|
|
334
|
+
if (ts.isFunctionDeclaration(node) &&
|
|
335
|
+
((_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) &&
|
|
336
|
+
node.name) {
|
|
337
|
+
names.add(node.name.text);
|
|
338
|
+
}
|
|
339
|
+
// export { A, B as C }
|
|
340
|
+
if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) {
|
|
341
|
+
node.exportClause.elements.forEach((e) => names.add(e.name.text));
|
|
342
|
+
}
|
|
343
|
+
// export default ...
|
|
344
|
+
if (ts.isExportAssignment(node)) {
|
|
345
|
+
names.add('Default');
|
|
346
|
+
}
|
|
347
|
+
ts.forEachChild(node, visit);
|
|
348
|
+
};
|
|
349
|
+
ts.forEachChild(sf, visit);
|
|
350
|
+
return Array.from(names);
|
|
351
|
+
}
|
|
352
|
+
async function _sendCode({ file, token, targetUrl, }) {
|
|
353
|
+
const apiEndpoint = `${targetUrl}/mesh/push/api/v1/contentsdk/code/extracted`;
|
|
354
|
+
if (!fs_1.default.existsSync(file.path)) {
|
|
355
|
+
console.error(chalk_1.default.red(`File not found: ${file.path}`));
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const code = fs_1.default.readFileSync(file.path);
|
|
359
|
+
// Merge base labels with any extra labels (variants, componentName, etc.)
|
|
360
|
+
const labels = Object.assign({ type: file.type }, (file.labels || {}));
|
|
361
|
+
try {
|
|
362
|
+
const response = await fetch(apiEndpoint, {
|
|
363
|
+
method: 'POST',
|
|
364
|
+
headers: {
|
|
365
|
+
Authorization: `Bearer ${token}`,
|
|
366
|
+
'Content-Type': 'application/json',
|
|
367
|
+
},
|
|
368
|
+
body: JSON.stringify({
|
|
369
|
+
EnvironmentId: 'ContentSDK',
|
|
370
|
+
name: file.name,
|
|
371
|
+
content: code.toString(),
|
|
372
|
+
labels,
|
|
373
|
+
}),
|
|
374
|
+
});
|
|
375
|
+
if (!response.ok) {
|
|
376
|
+
console.error(chalk_1.default.red(`Failed to send extracted code from ${file.path}: ${response.statusText}`));
|
|
377
|
+
core_1.debug.http('Error details: %o', {
|
|
378
|
+
status: response.status,
|
|
379
|
+
text: await response.text(),
|
|
380
|
+
url: response.url,
|
|
381
|
+
headers: response.headers,
|
|
382
|
+
});
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
console.error(chalk_1.default.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
return file.path;
|
|
391
|
+
}
|
|
392
|
+
const NODE_PROTOCOL = 'node:';
|
|
393
|
+
function isNodeProtocol(specifier) {
|
|
394
|
+
return specifier.startsWith(NODE_PROTOCOL);
|
|
395
|
+
}
|
|
396
|
+
function isDeclarationFile(p) {
|
|
397
|
+
return p.endsWith('.d.ts');
|
|
398
|
+
}
|
|
399
|
+
function inNodeModules(p) {
|
|
400
|
+
return p.replace(/\\/g, '/').includes('/node_modules/');
|
|
401
|
+
}
|
|
402
|
+
// Normalize path separators to POSIX-style "/" for cross-platform consistency.
|
|
403
|
+
function toPosixPath(p) {
|
|
404
|
+
if (/^\\\\\?\\/.test(p))
|
|
405
|
+
return p;
|
|
406
|
+
return p.replace(/\\/g, '/');
|
|
407
|
+
}
|
|
408
|
+
const stripExtension = (p) => p.replace(/\.(tsx?|jsx?|mjs|cjs)$/, '');
|
|
409
|
+
exports.stripExtension = stripExtension;
|
|
410
|
+
// Convert an absolute file path into an relative module specifier (POSIX)
|
|
411
|
+
const getRelativeImportPath = (absFile, appPath) => {
|
|
412
|
+
let rel = toPosixPath(path_1.default.relative(appPath, absFile));
|
|
413
|
+
return (0, exports.stripExtension)(rel);
|
|
414
|
+
};
|
|
415
|
+
exports.getRelativeImportPath = getRelativeImportPath;
|
|
416
|
+
// Determine if a specifier is bare/aliased (i.e., not relative "./" or "../" and not absolute "/").
|
|
417
|
+
const isNodeModuleImport = (name) => !name.startsWith('./') && !name.startsWith('../') && !name.startsWith('/');
|
|
418
|
+
exports.isNodeModuleImport = isNodeModuleImport;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateSites = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
11
|
+
const site_1 = require("../site");
|
|
12
|
+
const client_1 = require("../client");
|
|
13
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
14
|
+
const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
|
|
15
|
+
/**
|
|
16
|
+
* Generates site information and writes it to a specified destination path.
|
|
17
|
+
* @param {GenerateSitesConfig} config - The configuration for generating site info.
|
|
18
|
+
* @returns {Promise<Function>} - A promise that resolves to an asynchronous function that fetches site information and writes it to a file.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
const generateSites = ({ scConfig: deprecatedScConfig, destinationPath, } = {}) => {
|
|
22
|
+
return async ({ scConfig } = {}) => {
|
|
23
|
+
const config = deprecatedScConfig !== null && deprecatedScConfig !== void 0 ? deprecatedScConfig : scConfig;
|
|
24
|
+
if (!config) {
|
|
25
|
+
throw new Error('Sitecore configuration is required to be provided');
|
|
26
|
+
}
|
|
27
|
+
let sites = [];
|
|
28
|
+
const sitesFilePath = path_1.default.resolve(destinationPath !== null && destinationPath !== void 0 ? destinationPath : DEFAULT_SITES_DIST_PATH);
|
|
29
|
+
debug_1.default.multisite(config.multisite.enabled
|
|
30
|
+
? 'Multisite Enabled: Generating site information'
|
|
31
|
+
: 'Multisite Disabled');
|
|
32
|
+
if (config.multisite.enabled) {
|
|
33
|
+
try {
|
|
34
|
+
const siteInfoService = new site_1.SiteInfoService({
|
|
35
|
+
clientFactory: (0, client_1.createGraphQLClientFactory)({
|
|
36
|
+
api: config.api,
|
|
37
|
+
retries: config.retries.count,
|
|
38
|
+
retryStrategy: config.retries.retryStrategy,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
sites = await siteInfoService.fetchSiteInfo();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error(chalk_1.default.red('Error fetching site information'));
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Add default site to the list
|
|
49
|
+
const defaultSite = {
|
|
50
|
+
name: config.defaultSite,
|
|
51
|
+
hostName: '*',
|
|
52
|
+
language: config.defaultLanguage,
|
|
53
|
+
};
|
|
54
|
+
sites.unshift(defaultSite);
|
|
55
|
+
(0, tools_1.ensurePathExists)(sitesFilePath);
|
|
56
|
+
fs_1.default.writeFileSync(sitesFilePath, JSON.stringify(sites, null, 2), { encoding: 'utf8' });
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.generateSites = generateSites;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getComponentSpecUrl = exports.getComponentSpec = exports.defaultImportMapTemplate = exports.writeImportMap = exports.extractFiles = exports.scaffoldComponent = exports.generateSites = void 0;
|
|
18
|
+
var generateSites_1 = require("./generateSites");
|
|
19
|
+
Object.defineProperty(exports, "generateSites", { enumerable: true, get: function () { return generateSites_1.generateSites; } });
|
|
20
|
+
var scaffold_1 = require("./scaffold");
|
|
21
|
+
Object.defineProperty(exports, "scaffoldComponent", { enumerable: true, get: function () { return scaffold_1.scaffoldComponent; } });
|
|
22
|
+
var extract_files_1 = require("./codegen/extract-files");
|
|
23
|
+
Object.defineProperty(exports, "extractFiles", { enumerable: true, get: function () { return extract_files_1.extractFiles; } });
|
|
24
|
+
var import_map_1 = require("./codegen/import-map");
|
|
25
|
+
Object.defineProperty(exports, "writeImportMap", { enumerable: true, get: function () { return import_map_1.writeImportMap; } });
|
|
26
|
+
Object.defineProperty(exports, "defaultImportMapTemplate", { enumerable: true, get: function () { return import_map_1.defaultMapTemplate; } });
|
|
27
|
+
var component_generation_1 = require("./codegen/component-generation");
|
|
28
|
+
Object.defineProperty(exports, "getComponentSpec", { enumerable: true, get: function () { return component_generation_1.getComponentSpec; } });
|
|
29
|
+
Object.defineProperty(exports, "getComponentSpecUrl", { enumerable: true, get: function () { return component_generation_1.getComponentSpecUrl; } });
|
|
30
|
+
__exportStar(require("./templating"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.editLineEndings = editLineEndings;
|
|
7
|
+
exports.scaffoldFile = scaffoldFile;
|
|
8
|
+
exports.scaffoldComponent = scaffoldComponent;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
/**
|
|
13
|
+
* Force to use `crlf` line endings, we are using `crlf` across the project.
|
|
14
|
+
* Replace: `lf` (\n), `cr` (\r)
|
|
15
|
+
* @param {string} content
|
|
16
|
+
*/
|
|
17
|
+
function editLineEndings(content) {
|
|
18
|
+
return content.replace(/\r|\n/gm, '\r\n');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a file relative to the specified path if the file doesn't exist.
|
|
22
|
+
* Creates directories as needed.
|
|
23
|
+
* Does not overwrite existing files.
|
|
24
|
+
* @param {string} filePath - the file path
|
|
25
|
+
* @param {string} fileContent - the file content
|
|
26
|
+
* @returns {string} the file path if the file was created, otherwise null
|
|
27
|
+
*/
|
|
28
|
+
function scaffoldFile(filePath, fileContent) {
|
|
29
|
+
const outputDir = path_1.default.dirname(filePath);
|
|
30
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
31
|
+
console.log(chalk_1.default.red(`Skipping creating ${filePath}; already exists.`));
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
35
|
+
fs_1.default.writeFileSync(filePath, editLineEndings(fileContent), 'utf8');
|
|
36
|
+
console.log(chalk_1.default.green(`File ${filePath} has been scaffolded.`));
|
|
37
|
+
return filePath;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Scaffolds a new component based on the provided template.
|
|
41
|
+
* @param {string} outputFolderPath - The file path where the component will be created.
|
|
42
|
+
* @param {string} componentName - The name of the component to be created.
|
|
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
|
+
* @param {ScaffoldTemplate[]} templates - An array of template objects, each containing a name, a template function, and a getNextSteps function.
|
|
45
|
+
* @throws Will throw an error if the specified template is not found.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function scaffoldComponent(outputFolderPath, componentName, templateName, templates) {
|
|
49
|
+
const template = templates.find((t) => t.name === templateName);
|
|
50
|
+
if (!template) {
|
|
51
|
+
throw new Error(`Template ${templateName} not found.`);
|
|
52
|
+
}
|
|
53
|
+
const outputFilePath = path_1.default.join(outputFolderPath, `${componentName}.${template.fileExtension}`);
|
|
54
|
+
const componentOutputPath = scaffoldFile(outputFilePath, template.generateTemplate(componentName));
|
|
55
|
+
if (componentOutputPath) {
|
|
56
|
+
const nextSteps = [];
|
|
57
|
+
nextSteps.push(chalk_1.default.green(`
|
|
58
|
+
Scaffolding of ${componentName} complete.
|
|
59
|
+
Next steps:`), ...(template.getNextSteps ? template.getNextSteps(componentOutputPath) : []));
|
|
60
|
+
console.log(nextSteps.join('\n'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.componentUnitMocks = exports.getComponentList = void 0;
|
|
37
|
+
exports.filterComponentsByType = filterComponentsByType;
|
|
38
|
+
const glob = __importStar(require("glob"));
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
exports.getComponentList = _getComponentList;
|
|
43
|
+
exports.componentUnitMocks = {
|
|
44
|
+
set getComponentList(mockImplementation) {
|
|
45
|
+
exports.getComponentList = mockImplementation;
|
|
46
|
+
},
|
|
47
|
+
get getComponentList() {
|
|
48
|
+
return _getComponentList;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
|
|
52
|
+
const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
|
|
53
|
+
/**
|
|
54
|
+
* Get list of components from @var path
|
|
55
|
+
* Returns a list of components in the following format:
|
|
56
|
+
* {
|
|
57
|
+
* path: 'path/to/component',
|
|
58
|
+
* componentName: 'ComponentName',
|
|
59
|
+
* moduleName: 'ComponentName'
|
|
60
|
+
* }
|
|
61
|
+
* @param {string[]} paths paths to search
|
|
62
|
+
* @param {string[]} [exclude] paths and glob patterns to exclude from final result
|
|
63
|
+
* @param {boolean} [includeVariants] whether to include variant components
|
|
64
|
+
*/
|
|
65
|
+
function _getComponentList(paths, exclude, includeVariants) {
|
|
66
|
+
const components = paths.reduce((result, path) => {
|
|
67
|
+
const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
|
|
68
|
+
? path
|
|
69
|
+
: path.replace(/\/$/, '').concat('/**/*.{js,jsx,ts,tsx}');
|
|
70
|
+
return result.concat(...glob
|
|
71
|
+
.sync(globPath, { ignore: exclude, nodir: true })
|
|
72
|
+
.filter((path) => path.match(componentNamePattern))
|
|
73
|
+
.map((filePath) => {
|
|
74
|
+
const name = filePath.match(componentNamePattern)[2];
|
|
75
|
+
return {
|
|
76
|
+
filePath,
|
|
77
|
+
importPath: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
|
|
78
|
+
componentName: name,
|
|
79
|
+
moduleName: name.replace(/[^\w]+/g, ''),
|
|
80
|
+
};
|
|
81
|
+
}));
|
|
82
|
+
}, []);
|
|
83
|
+
return includeVariants
|
|
84
|
+
? components
|
|
85
|
+
: components.filter((component) => !component.componentName.includes('.'));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Filters components by their detected type.
|
|
89
|
+
* @param {ComponentFileWithType[]} components - Array of components with types
|
|
90
|
+
* @param {ComponentType[]} allowedTypes - Array of allowed component types to filter by
|
|
91
|
+
* @returns {ComponentFileWithType[]} Filtered array containing only components matching allowed types
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
function filterComponentsByType(components, allowedTypes) {
|
|
95
|
+
return components.filter((component) => allowedTypes.includes(component.componentType));
|
|
96
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterComponentsByType = exports.getComponentList = void 0;
|
|
4
|
+
var components_1 = require("./components");
|
|
5
|
+
Object.defineProperty(exports, "getComponentList", { enumerable: true, get: function () { return components_1.getComponentList; } });
|
|
6
|
+
Object.defineProperty(exports, "filterComponentsByType", { enumerable: true, get: function () { return components_1.filterComponentsByType; } });
|