@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
32 lines (31 loc) • 802 B
JavaScript
/**
* Utility function for creating StackBlitz demos
* Returns the configuration that can be used with openWithForm
*/
/**
* Create StackBlitz configuration for use with openWithForm
*/
export function createStackBlitz({
title,
description,
flattenedFiles,
rootFile
}) {
// Convert flattened files to string format
const files = {};
Object.entries(flattenedFiles).forEach(([filePath, fileData]) => {
files[filePath] = fileData.source;
});
const formData = {
'project[template]': 'node',
'project[title]': title,
'project[description]': `# ${title}\n${description}`
};
Object.entries(files).forEach(([key, value]) => {
formData[`project[files][${key}]`] = value;
});
return {
url: `https://stackblitz.com/run?file=${rootFile}`,
formData
};
}