@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
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/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
1
|
/**
|
|
4
2
|
* Export variant functionality to add extra files like package.json, tsconfig, etc.
|
|
5
3
|
* Users can pass configuration options that vary the output here.
|
|
@@ -15,21 +13,16 @@ import { mergeCodeMetadata, extractCodeMetadata } from "../pipeline/loadCodeVari
|
|
|
15
13
|
* Similar to mergeExternals but for file structures.
|
|
16
14
|
* Automatically adds metadata: false to files that don't have a metadata property.
|
|
17
15
|
*/
|
|
18
|
-
function mergeFiles() {
|
|
19
|
-
|
|
20
|
-
for (
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
for (var _i = 0, _fileSets = fileSets; _i < _fileSets.length; _i++) {
|
|
24
|
-
var fileSet = _fileSets[_i];
|
|
25
|
-
for (var _i2 = 0, _Object$entries = Object.entries(fileSet); _i2 < _Object$entries.length; _i2++) {
|
|
26
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
27
|
-
fileName = _Object$entries$_i[0],
|
|
28
|
-
fileData = _Object$entries$_i[1];
|
|
16
|
+
function mergeFiles(...fileSets) {
|
|
17
|
+
const merged = {};
|
|
18
|
+
for (const fileSet of fileSets) {
|
|
19
|
+
for (const [fileName, fileData] of Object.entries(fileSet)) {
|
|
29
20
|
// Later files override earlier ones (similar to Object.assign behavior)
|
|
30
|
-
|
|
21
|
+
const normalizedData = typeof fileData === 'string' ? {
|
|
31
22
|
source: fileData
|
|
32
|
-
} :
|
|
23
|
+
} : {
|
|
24
|
+
...fileData
|
|
25
|
+
};
|
|
33
26
|
// Add metadata: false if not already set (source files default to false)
|
|
34
27
|
if (!('metadata' in normalizedData)) {
|
|
35
28
|
normalizedData.metadata = false;
|
|
@@ -48,8 +41,9 @@ export function getFilenameFromVariant(variantCode) {
|
|
|
48
41
|
return variantCode.fileName;
|
|
49
42
|
}
|
|
50
43
|
if (variantCode.url) {
|
|
51
|
-
|
|
52
|
-
fileName
|
|
44
|
+
const {
|
|
45
|
+
fileName
|
|
46
|
+
} = getFileNameFromUrl(variantCode.url);
|
|
53
47
|
return fileName || undefined;
|
|
54
48
|
}
|
|
55
49
|
return undefined;
|
|
@@ -58,26 +52,24 @@ export function getFilenameFromVariant(variantCode) {
|
|
|
58
52
|
/**
|
|
59
53
|
* Generate a unique entrypoint filename that doesn't conflict with existing files
|
|
60
54
|
*/
|
|
61
|
-
export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var candidates = ["".concat(pathPrefix, "App.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
|
|
55
|
+
export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript, pathPrefix = '') {
|
|
56
|
+
const ext = useTypescript ? 'tsx' : 'jsx';
|
|
57
|
+
const candidates = [`${pathPrefix}App.${ext}`, `${pathPrefix}entrypoint.${ext}`, `${pathPrefix}main.${ext}`];
|
|
65
58
|
|
|
66
59
|
// If we have a source filename, also try variations
|
|
67
60
|
if (sourceFilename) {
|
|
68
|
-
|
|
69
|
-
candidates.push(
|
|
61
|
+
const baseName = sourceFilename.replace(/\.[^.]*$/, '');
|
|
62
|
+
candidates.push(`${pathPrefix}${baseName}-entry.${ext}`);
|
|
70
63
|
}
|
|
71
|
-
for (
|
|
72
|
-
|
|
73
|
-
if (candidate !== "".concat(pathPrefix).concat(sourceFilename) && !existingFiles[candidate]) {
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
if (candidate !== `${pathPrefix}${sourceFilename}` && !existingFiles[candidate]) {
|
|
74
66
|
return candidate;
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
|
|
78
70
|
// Generate with hash if all candidates are taken
|
|
79
|
-
|
|
80
|
-
return
|
|
71
|
+
const hash = Math.random().toString(36).substring(2, 8);
|
|
72
|
+
return `${pathPrefix}entrypoint-${hash}.${ext}`;
|
|
81
73
|
}
|
|
82
74
|
|
|
83
75
|
/**
|
|
@@ -89,100 +81,99 @@ export function getRelativeImportPath(sourceFilename) {
|
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
// Remove extension for import
|
|
92
|
-
|
|
93
|
-
return
|
|
84
|
+
const baseName = sourceFilename.replace(/\.[^.]*$/, '');
|
|
85
|
+
return `./${baseName}`;
|
|
94
86
|
}
|
|
95
87
|
|
|
96
88
|
/**
|
|
97
89
|
* Default HTML template function for Vite-based demos
|
|
98
90
|
*/
|
|
99
|
-
export function defaultHtmlTemplate(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
export function defaultHtmlTemplate({
|
|
92
|
+
language,
|
|
93
|
+
title,
|
|
94
|
+
description,
|
|
95
|
+
head,
|
|
96
|
+
entrypoint
|
|
97
|
+
}) {
|
|
98
|
+
return `<!DOCTYPE html>
|
|
99
|
+
<html lang="${language}">
|
|
100
|
+
<head>
|
|
101
|
+
<meta charset="utf-8" />
|
|
102
|
+
<title>${title}</title>
|
|
103
|
+
${description ? `<meta name="description" content="${description}" />` : ''}
|
|
104
|
+
<meta name="viewport" content="initial-scale=1, width=device-width" />${head ? `\n ${head.split('\n').join('\n ')}` : ''}
|
|
105
|
+
</head>
|
|
106
|
+
<body>
|
|
107
|
+
<div id="root"></div>${entrypoint ? `\n <script type="module" src="${entrypoint}"></script>` : ''}
|
|
108
|
+
</body>
|
|
109
|
+
</html>
|
|
110
|
+
`;
|
|
106
111
|
}
|
|
107
112
|
/**
|
|
108
113
|
* Export a variant as a standalone project with metadata files properly scoped
|
|
109
114
|
*/
|
|
110
|
-
export function exportVariant(variantCode) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
scripts = _config$scripts === void 0 ? {} : _config$scripts,
|
|
143
|
-
packageType = config.packageType,
|
|
144
|
-
_config$packageJsonFi = config.packageJsonFields,
|
|
145
|
-
packageJsonFields = _config$packageJsonFi === void 0 ? {} : _config$packageJsonFi,
|
|
146
|
-
_config$tsconfigOptio = config.tsconfigOptions,
|
|
147
|
-
tsconfigOptions = _config$tsconfigOptio === void 0 ? {} : _config$tsconfigOptio,
|
|
148
|
-
_config$viteConfig = config.viteConfig,
|
|
149
|
-
viteConfig = _config$viteConfig === void 0 ? {} : _config$viteConfig,
|
|
150
|
-
_config$useTypescript = config.useTypescript,
|
|
151
|
-
useTypescript = _config$useTypescript === void 0 ? false : _config$useTypescript,
|
|
152
|
-
_config$extraMetadata = config.extraMetadataFiles,
|
|
153
|
-
extraMetadataFiles = _config$extraMetadata === void 0 ? {} : _config$extraMetadata,
|
|
154
|
-
_config$frameworkFile = config.frameworkFiles,
|
|
155
|
-
frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile,
|
|
156
|
-
transformVariant = config.transformVariant,
|
|
157
|
-
_config$versions = config.versions,
|
|
158
|
-
versions = _config$versions === void 0 ? {} : _config$versions,
|
|
159
|
-
resolveDependencies = config.resolveDependencies;
|
|
115
|
+
export function exportVariant(variantCode, config = {}) {
|
|
116
|
+
const {
|
|
117
|
+
title = 'Demo',
|
|
118
|
+
titlePrefix,
|
|
119
|
+
titleSuffix,
|
|
120
|
+
description = 'Demo created with Vite',
|
|
121
|
+
descriptionPrefix,
|
|
122
|
+
descriptionSuffix,
|
|
123
|
+
variantName,
|
|
124
|
+
language = 'en',
|
|
125
|
+
htmlPrefix = '',
|
|
126
|
+
sourcePrefix = 'src/',
|
|
127
|
+
assetPrefix = '',
|
|
128
|
+
frameworkHandlesEntrypoint = false,
|
|
129
|
+
htmlSkipJsLink = false,
|
|
130
|
+
htmlTemplate,
|
|
131
|
+
headTemplate,
|
|
132
|
+
rootIndexTemplate,
|
|
133
|
+
dependencies = {},
|
|
134
|
+
devDependencies = {},
|
|
135
|
+
scripts = {},
|
|
136
|
+
packageType,
|
|
137
|
+
packageJsonFields = {},
|
|
138
|
+
tsconfigOptions = {},
|
|
139
|
+
viteConfig = {},
|
|
140
|
+
useTypescript = false,
|
|
141
|
+
extraMetadataFiles = {},
|
|
142
|
+
frameworkFiles = {},
|
|
143
|
+
transformVariant,
|
|
144
|
+
versions = {},
|
|
145
|
+
resolveDependencies
|
|
146
|
+
} = config;
|
|
160
147
|
|
|
161
148
|
// Build final title and description with prefixes and suffixes
|
|
162
|
-
|
|
163
|
-
|
|
149
|
+
const finalTitle = [titlePrefix, title, titleSuffix].filter(Boolean).join('');
|
|
150
|
+
const finalDescription = [descriptionPrefix, description, descriptionSuffix].filter(Boolean).join('');
|
|
164
151
|
|
|
165
152
|
// Use extractCodeMetadata to properly separate metadata and non-metadata files
|
|
166
|
-
|
|
167
|
-
processedVariantCode
|
|
168
|
-
processedGlobals
|
|
153
|
+
let {
|
|
154
|
+
variant: processedVariantCode,
|
|
155
|
+
metadata: processedGlobals
|
|
156
|
+
} = extractCodeMetadata(variantCode);
|
|
169
157
|
|
|
170
158
|
// Run optional transform hook to modify variant and globals before processing
|
|
171
159
|
if (transformVariant) {
|
|
172
|
-
|
|
160
|
+
const transformed = transformVariant(processedVariantCode, variantName, processedGlobals);
|
|
173
161
|
if (transformed) {
|
|
174
162
|
// Re-extract metadata after transformation
|
|
175
|
-
|
|
176
|
-
processedVariantCode =
|
|
163
|
+
const result = transformed.variant && extractCodeMetadata(transformed.variant);
|
|
164
|
+
processedVariantCode = result?.variant || processedVariantCode;
|
|
177
165
|
|
|
178
166
|
// Start fresh with only the new metadata and explicitly transformed globals
|
|
179
167
|
// Do NOT merge with the original processedGlobals to avoid duplication
|
|
180
|
-
processedGlobals =
|
|
168
|
+
processedGlobals = {
|
|
169
|
+
...result?.metadata,
|
|
170
|
+
...transformed.globals
|
|
171
|
+
};
|
|
181
172
|
}
|
|
182
173
|
}
|
|
183
174
|
|
|
184
175
|
// If packageType is explicitly provided (even as undefined), use that value
|
|
185
|
-
|
|
176
|
+
let finalPackageType;
|
|
186
177
|
if ('packageType' in config) {
|
|
187
178
|
finalPackageType = packageType;
|
|
188
179
|
} else {
|
|
@@ -190,51 +181,51 @@ export function exportVariant(variantCode) {
|
|
|
190
181
|
}
|
|
191
182
|
|
|
192
183
|
// Get existing extraFiles and source filename
|
|
193
|
-
|
|
184
|
+
const sourceFilename = getFilenameFromVariant(processedVariantCode);
|
|
194
185
|
|
|
195
186
|
// Get path context to understand navigation
|
|
196
|
-
|
|
187
|
+
const pathContext = examineCodeVariant(variantCode);
|
|
197
188
|
|
|
198
189
|
// Determine if we need to rename the source file
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
190
|
+
const ext = useTypescript ? 'tsx' : 'jsx';
|
|
191
|
+
const isSourceFileIndex = sourceFilename === `index.${ext}`;
|
|
192
|
+
const hasBackNavigation = pathContext.maxSourceBackNavigation > 0;
|
|
193
|
+
let actualSourceFilename = sourceFilename;
|
|
203
194
|
|
|
204
195
|
// Use urlDirectory to construct the full path from src root
|
|
205
|
-
|
|
206
|
-
|
|
196
|
+
const directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
|
|
197
|
+
let actualRootFile = directoryPath ? `${sourcePrefix}${directoryPath}/${sourceFilename}` : `${sourcePrefix}${sourceFilename}`;
|
|
207
198
|
|
|
208
199
|
// If the source file is index.tsx and it's in the src root, we need to rename it
|
|
209
200
|
if (isSourceFileIndex && !hasBackNavigation) {
|
|
210
201
|
actualSourceFilename = generateEntrypointFilename(processedVariantCode.extraFiles || {}, sourceFilename, useTypescript);
|
|
211
202
|
// When renaming due to conflicts, place the file in src root regardless of original location
|
|
212
|
-
actualRootFile =
|
|
203
|
+
actualRootFile = `${sourcePrefix}${actualSourceFilename}`;
|
|
213
204
|
}
|
|
214
205
|
|
|
215
206
|
// The main entrypoint is always src/index.tsx (or .jsx)
|
|
216
|
-
|
|
217
|
-
|
|
207
|
+
const mainEntrypointFilename = `index.${ext}`;
|
|
208
|
+
const entrypoint = !htmlSkipJsLink ? `${sourcePrefix}${mainEntrypointFilename}` : undefined;
|
|
218
209
|
|
|
219
210
|
// Get relative import path for the main component
|
|
220
|
-
|
|
211
|
+
let importPath;
|
|
221
212
|
if (!hasBackNavigation) {
|
|
222
213
|
// Component is in src root - import directly
|
|
223
214
|
importPath = getRelativeImportPath(actualSourceFilename);
|
|
224
215
|
} else {
|
|
225
216
|
// Component is in a subdirectory - import with full path from src root
|
|
226
|
-
|
|
227
|
-
importPath =
|
|
217
|
+
const componentPath = directoryPath ? `${directoryPath}/${actualSourceFilename}` : actualSourceFilename;
|
|
218
|
+
importPath = `./${(componentPath || '').replace(/\.[^.]*$/, '')}`; // Remove extension
|
|
228
219
|
}
|
|
229
220
|
|
|
230
221
|
// Strip /index from the end of import paths since module resolution handles it automatically
|
|
231
222
|
if (importPath.endsWith('/index')) {
|
|
232
223
|
importPath = importPath.slice(0, -6); // Remove '/index'
|
|
233
224
|
}
|
|
234
|
-
|
|
225
|
+
const importString = processedVariantCode.namedExport ? `import { ${processedVariantCode.namedExport} as App } from '${importPath}';` : `import App from '${importPath}';`;
|
|
235
226
|
|
|
236
227
|
// Collect all files that will be generated
|
|
237
|
-
|
|
228
|
+
const generatedFiles = {};
|
|
238
229
|
|
|
239
230
|
// Update the variant's fileName if we renamed it
|
|
240
231
|
if (isSourceFileIndex && !hasBackNavigation && actualSourceFilename && actualSourceFilename !== sourceFilename) {
|
|
@@ -242,14 +233,14 @@ export function exportVariant(variantCode) {
|
|
|
242
233
|
}
|
|
243
234
|
|
|
244
235
|
// Check if they're providing their own framework
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
236
|
+
const isFramework = 'frameworkFiles' in config;
|
|
237
|
+
const externalPackages = externalsToPackages(processedVariantCode.externals || []);
|
|
238
|
+
const variantDeps = Object.keys(externalPackages).reduce((acc, pkg) => {
|
|
248
239
|
// Check if we have a specific version for this package first
|
|
249
240
|
if (versions[pkg]) {
|
|
250
241
|
acc[pkg] = versions[pkg];
|
|
251
242
|
} else if (resolveDependencies) {
|
|
252
|
-
|
|
243
|
+
const resolvedDeps = resolveDependencies(pkg);
|
|
253
244
|
Object.assign(acc, resolvedDeps);
|
|
254
245
|
} else {
|
|
255
246
|
// Simple fallback: just use 'latest' for each package
|
|
@@ -259,47 +250,66 @@ export function exportVariant(variantCode) {
|
|
|
259
250
|
}, {});
|
|
260
251
|
|
|
261
252
|
// Collect metadata files to be generated
|
|
262
|
-
|
|
253
|
+
const metadataFiles = {};
|
|
263
254
|
|
|
264
255
|
// Generate package.json
|
|
265
|
-
|
|
266
|
-
|
|
256
|
+
const packageJson = {
|
|
257
|
+
private: true,
|
|
267
258
|
name: finalTitle.toLowerCase().replace(/[^a-z0-9]/g, '-'),
|
|
268
259
|
version: '0.0.0',
|
|
269
|
-
description: finalDescription
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
260
|
+
description: finalDescription,
|
|
261
|
+
...(finalPackageType && {
|
|
262
|
+
type: finalPackageType
|
|
263
|
+
}),
|
|
273
264
|
// Add type if specified
|
|
274
|
-
scripts:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
265
|
+
scripts: {
|
|
266
|
+
...(!isFramework && {
|
|
267
|
+
dev: 'vite',
|
|
268
|
+
build: 'vite build',
|
|
269
|
+
preview: 'vite preview'
|
|
270
|
+
}),
|
|
271
|
+
...scripts
|
|
272
|
+
},
|
|
273
|
+
dependencies: {
|
|
280
274
|
react: versions.react || 'latest',
|
|
281
|
-
'react-dom': versions['react-dom'] || 'latest'
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
275
|
+
'react-dom': versions['react-dom'] || 'latest',
|
|
276
|
+
...variantDeps,
|
|
277
|
+
...dependencies
|
|
278
|
+
},
|
|
279
|
+
devDependencies: {
|
|
280
|
+
...(!isFramework && {
|
|
281
|
+
'@vitejs/plugin-react': 'latest',
|
|
282
|
+
vite: 'latest'
|
|
283
|
+
}),
|
|
284
|
+
...(useTypescript && {
|
|
285
|
+
typescript: 'latest',
|
|
286
|
+
'@types/react': versions['@types/react'] || 'latest',
|
|
287
|
+
'@types/react-dom': versions['@types/react-dom'] || 'latest'
|
|
288
|
+
}),
|
|
289
|
+
...devDependencies
|
|
290
|
+
},
|
|
291
|
+
...packageJsonFields
|
|
292
|
+
};
|
|
292
293
|
metadataFiles['package.json'] = {
|
|
293
|
-
source:
|
|
294
|
+
source: `${JSON.stringify(packageJson, null, 2)}\n`
|
|
294
295
|
};
|
|
295
296
|
|
|
296
297
|
// Generate entrypoint and HTML files unless framework handles them
|
|
297
298
|
if (!frameworkHandlesEntrypoint) {
|
|
298
299
|
// Create entrypoint file that imports the main component
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
300
|
+
const defaultEntrypointContent = `import * as React from 'react';
|
|
301
|
+
import * as ReactDOM from 'react-dom/client';
|
|
302
|
+
${importString}
|
|
303
|
+
|
|
304
|
+
ReactDOM.createRoot(document.getElementById('root')${useTypescript ? '!' : ''}).render(
|
|
305
|
+
<React.StrictMode>
|
|
306
|
+
<App />
|
|
307
|
+
</React.StrictMode>
|
|
308
|
+
);
|
|
309
|
+
`;
|
|
310
|
+
const entrypointContent = rootIndexTemplate ? rootIndexTemplate({
|
|
311
|
+
importString,
|
|
312
|
+
useTypescript
|
|
303
313
|
}) : defaultEntrypointContent;
|
|
304
314
|
generatedFiles[mainEntrypointFilename] = {
|
|
305
315
|
source: entrypointContent
|
|
@@ -308,8 +318,17 @@ export function exportVariant(variantCode) {
|
|
|
308
318
|
|
|
309
319
|
// Add Vite config file only if no framework files (Vite-specific)
|
|
310
320
|
if (!isFramework) {
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
const viteConfigContent = `import { defineConfig } from 'vite';
|
|
322
|
+
import react from '@vitejs/plugin-react';
|
|
323
|
+
|
|
324
|
+
// https://vitejs.dev/config/
|
|
325
|
+
export default defineConfig({
|
|
326
|
+
plugins: [react()],
|
|
327
|
+
define: { 'process.env': {} },
|
|
328
|
+
...${JSON.stringify(viteConfig, null, 2).split('\n').join('\n ')}
|
|
329
|
+
});
|
|
330
|
+
`;
|
|
331
|
+
metadataFiles[`vite.config.${useTypescript ? 'ts' : 'js'}`] = {
|
|
313
332
|
source: viteConfigContent
|
|
314
333
|
};
|
|
315
334
|
}
|
|
@@ -317,13 +336,11 @@ export function exportVariant(variantCode) {
|
|
|
317
336
|
// Add TypeScript configuration if requested
|
|
318
337
|
if (useTypescript) {
|
|
319
338
|
// Check if frameworkFiles already includes a tsconfig
|
|
320
|
-
|
|
321
|
-
return fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json');
|
|
322
|
-
});
|
|
339
|
+
const hasFrameworkTsConfig = frameworkFiles?.globals && Object.keys(frameworkFiles.globals).some(fileName => fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json'));
|
|
323
340
|
if (!hasFrameworkTsConfig) {
|
|
324
341
|
// Main tsconfig.json (default Vite config)
|
|
325
|
-
|
|
326
|
-
compilerOptions:
|
|
342
|
+
const defaultTsConfig = {
|
|
343
|
+
compilerOptions: {
|
|
327
344
|
target: 'ES2020',
|
|
328
345
|
useDefineForClassFields: true,
|
|
329
346
|
lib: ['ES2020', 'DOM', 'DOM.Iterable'],
|
|
@@ -338,23 +355,25 @@ export function exportVariant(variantCode) {
|
|
|
338
355
|
strict: true,
|
|
339
356
|
noUnusedLocals: true,
|
|
340
357
|
noUnusedParameters: true,
|
|
341
|
-
noFallthroughCasesInSwitch: true
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
358
|
+
noFallthroughCasesInSwitch: true,
|
|
359
|
+
...tsconfigOptions
|
|
360
|
+
},
|
|
361
|
+
include: ['src'],
|
|
362
|
+
...(!isFramework && {
|
|
363
|
+
references: [{
|
|
364
|
+
path: './tsconfig.node.json'
|
|
365
|
+
}]
|
|
366
|
+
})
|
|
367
|
+
};
|
|
349
368
|
metadataFiles['tsconfig.json'] = {
|
|
350
|
-
source:
|
|
369
|
+
source: `${JSON.stringify(defaultTsConfig, null, 2)}\n`
|
|
351
370
|
};
|
|
352
371
|
}
|
|
353
372
|
|
|
354
373
|
// Only add tsconfig.node.json for Vite (not for framework files)
|
|
355
374
|
if (!isFramework) {
|
|
356
375
|
// Node tsconfig for Vite config
|
|
357
|
-
|
|
376
|
+
const nodeTsConfig = {
|
|
358
377
|
compilerOptions: {
|
|
359
378
|
composite: true,
|
|
360
379
|
skipLibCheck: true,
|
|
@@ -365,7 +384,7 @@ export function exportVariant(variantCode) {
|
|
|
365
384
|
include: ['vite.config.ts']
|
|
366
385
|
};
|
|
367
386
|
metadataFiles['tsconfig.node.json'] = {
|
|
368
|
-
source:
|
|
387
|
+
source: `${JSON.stringify(nodeTsConfig, null, 2)}\n`
|
|
369
388
|
};
|
|
370
389
|
}
|
|
371
390
|
}
|
|
@@ -373,46 +392,47 @@ export function exportVariant(variantCode) {
|
|
|
373
392
|
// Generate HTML file after all files are ready
|
|
374
393
|
if (!frameworkHandlesEntrypoint) {
|
|
375
394
|
// Add index.html
|
|
376
|
-
|
|
377
|
-
sourcePrefix
|
|
378
|
-
assetPrefix
|
|
395
|
+
const headContent = headTemplate ? headTemplate({
|
|
396
|
+
sourcePrefix,
|
|
397
|
+
assetPrefix,
|
|
379
398
|
variant: processedVariantCode,
|
|
380
|
-
variantName
|
|
399
|
+
variantName
|
|
381
400
|
}) : undefined;
|
|
382
|
-
|
|
383
|
-
language
|
|
401
|
+
const htmlContent = htmlTemplate ? htmlTemplate({
|
|
402
|
+
language,
|
|
384
403
|
title: finalTitle,
|
|
385
404
|
description: finalDescription,
|
|
386
405
|
head: headContent,
|
|
387
|
-
entrypoint
|
|
406
|
+
entrypoint,
|
|
388
407
|
variant: processedVariantCode,
|
|
389
|
-
variantName
|
|
408
|
+
variantName
|
|
390
409
|
}) : defaultHtmlTemplate({
|
|
391
|
-
language
|
|
410
|
+
language,
|
|
392
411
|
title: finalTitle,
|
|
393
412
|
description: finalDescription,
|
|
394
413
|
head: headContent,
|
|
395
|
-
entrypoint
|
|
414
|
+
entrypoint
|
|
396
415
|
});
|
|
397
|
-
|
|
416
|
+
const htmlFileName = htmlPrefix ? `${htmlPrefix}index.html` : 'index.html';
|
|
398
417
|
metadataFiles[htmlFileName] = {
|
|
399
418
|
source: htmlContent
|
|
400
419
|
};
|
|
401
420
|
}
|
|
402
421
|
|
|
403
422
|
// Merge all metadata files including framework metadata and globals
|
|
404
|
-
|
|
423
|
+
const allMetadataFiles = mergeFiles(processedGlobals || {}, metadataFiles, extraMetadataFiles, frameworkFiles.globals || {});
|
|
405
424
|
|
|
406
425
|
// Merge all files using mergeCodeMetadata to properly position everything with 'src/' (sourcePrefix opt) prefix
|
|
407
|
-
|
|
426
|
+
const allSourceFilesWithFramework = mergeFiles(processedVariantCode.extraFiles || {}, generatedFiles, frameworkFiles.variant?.extraFiles || {});
|
|
408
427
|
|
|
409
428
|
// Update the variant with all source files including framework source files
|
|
410
|
-
|
|
429
|
+
const finalVariantWithSources = {
|
|
430
|
+
...processedVariantCode,
|
|
411
431
|
extraFiles: allSourceFilesWithFramework
|
|
412
|
-
}
|
|
432
|
+
};
|
|
413
433
|
|
|
414
434
|
// Use mergeCodeMetadata to position everything correctly
|
|
415
|
-
|
|
435
|
+
const finalVariant = mergeCodeMetadata(finalVariantWithSources, allMetadataFiles, {
|
|
416
436
|
metadataPrefix: sourcePrefix
|
|
417
437
|
});
|
|
418
438
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["title", "description", "scripts", "devDependencies"];
|
|
4
1
|
/**
|
|
5
2
|
* Export VariantCode as Create React App template using exportVariant
|
|
6
3
|
* This is a general-purpose wrapper that creates CRA-compatible templates
|
|
@@ -13,35 +10,34 @@ import { exportVariant } from "./exportVariant.js";
|
|
|
13
10
|
* Export a VariantCode as a Create React App template
|
|
14
11
|
* Returns an object with the exported VariantCode and entrypoint path
|
|
15
12
|
*/
|
|
16
|
-
export function exportVariantAsCra(variantCode) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_config$devDependenci = config.devDependencies,
|
|
25
|
-
devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
|
|
26
|
-
otherConfig = _objectWithoutPropertiesLoose(config, _excluded);
|
|
13
|
+
export function exportVariantAsCra(variantCode, config = {}) {
|
|
14
|
+
const {
|
|
15
|
+
title = 'Demo',
|
|
16
|
+
description = 'Demo created with Create React App',
|
|
17
|
+
scripts = {},
|
|
18
|
+
devDependencies = {},
|
|
19
|
+
...otherConfig
|
|
20
|
+
} = config;
|
|
27
21
|
|
|
28
22
|
// Default CRA scripts
|
|
29
|
-
|
|
23
|
+
const craScripts = {
|
|
30
24
|
start: 'react-scripts start',
|
|
31
25
|
build: 'react-scripts build',
|
|
32
26
|
test: 'react-scripts test',
|
|
33
|
-
eject: 'react-scripts eject'
|
|
34
|
-
|
|
27
|
+
eject: 'react-scripts eject',
|
|
28
|
+
...scripts
|
|
29
|
+
};
|
|
35
30
|
|
|
36
31
|
// CRA only needs react-scripts, other deps are handled by exportVariant
|
|
37
|
-
|
|
38
|
-
'react-scripts': 'latest'
|
|
39
|
-
|
|
32
|
+
const craDevDependencies = {
|
|
33
|
+
'react-scripts': 'latest',
|
|
34
|
+
...devDependencies
|
|
35
|
+
};
|
|
40
36
|
|
|
41
37
|
// Create export configuration for CRA
|
|
42
|
-
|
|
43
|
-
title
|
|
44
|
-
description
|
|
38
|
+
const exportConfig = {
|
|
39
|
+
title,
|
|
40
|
+
description,
|
|
45
41
|
htmlPrefix: 'public/',
|
|
46
42
|
packageType: undefined,
|
|
47
43
|
// CRA should not have 'type: module'
|
|
@@ -49,8 +45,9 @@ export function exportVariantAsCra(variantCode) {
|
|
|
49
45
|
frameworkFiles: {},
|
|
50
46
|
// Prevent Vite-specific files from being generated
|
|
51
47
|
devDependencies: craDevDependencies,
|
|
52
|
-
scripts: craScripts
|
|
53
|
-
|
|
48
|
+
scripts: craScripts,
|
|
49
|
+
...otherConfig
|
|
50
|
+
};
|
|
54
51
|
|
|
55
52
|
// Use exportVariant to generate the final result
|
|
56
53
|
return exportVariant(variantCode, exportConfig);
|