in src/app/shared/stack-blitz/stack-blitz-writer.ts [158:211]
private _replaceExamplePlaceholders(data: ExampleData, fileName: string,
fileContent: string, isTest: boolean): string {
// Replaces the version placeholder in the `index.html` and `package.json` file.
// Technically we invalidate the `package-lock.json` file for the StackBlitz boilerplate
// by dynamically changing the version in the `package.json`, but the Turbo package manager
// seems to be able to partially re-use the lock file to speed up the module tree computation,
// so providing a lock file is still reasonable while modifying the `package.json`.
if (fileName === 'src/index.html' || fileName === 'package.json') {
fileContent = fileContent.replace(/\${version}/g, MAT_VERSION.full);
}
if (fileName === 'src/index.html') {
// Replace the component selector in `index,html`.
// For example, <material-docs-example></material-docs-example> will be replaced as
// <button-demo></button-demo>
fileContent = fileContent
.replace(/material-docs-example/g, data.selectorName)
.replace(/\${title}/g, data.description);
} else if (fileName === '.stackblitzrc') {
fileContent = fileContent
.replace(/\${startCommand}/, isTest ? 'turbo test' : 'turbo start');
} else if (fileName === 'src/app/app.module.ts') {
const joinedComponentNames = data.componentNames.join(', ');
// Replace the component name in `main.ts`.
// Replace `import {MaterialDocsExample} from 'material-docs-example'`
// will be replaced as `import {ButtonDemo} from './button-demo'`
fileContent = fileContent.replace(/{MaterialDocsExample}/g, `{${joinedComponentNames}}`);
// Replace `declarations: [MaterialDocsExample]`
// will be replaced as `declarations: [ButtonDemo]`
fileContent = fileContent.
replace(/declarations: \[MaterialDocsExample]/g,
`declarations: [${joinedComponentNames}]`);
// Replace `entryComponents: [MaterialDocsExample]`
// will be replaced as `entryComponents: [DialogContent]`
fileContent = fileContent.
replace(/entryComponents: \[MaterialDocsExample]/g,
`entryComponents: [${joinedComponentNames}]`);
// Replace `bootstrap: [MaterialDocsExample]`
// will be replaced as `bootstrap: [ButtonDemo]`
// This assumes the first component listed in the main component
fileContent = fileContent.
replace(/bootstrap: \[MaterialDocsExample]/g,
`bootstrap: [${data.componentNames[0]}]`);
const dotIndex = data.indexFilename.lastIndexOf('.');
const importFileName = data.indexFilename.slice(0, dotIndex === -1 ? undefined : dotIndex);
fileContent = fileContent.replace(/material-docs-example/g, importFileName);
}
return fileContent;
}