@@ -66,26 +66,32 @@ export class StackBlitzWriter {
66
66
constructor ( private _http : HttpClient , private _ngZone : NgZone ) { }
67
67
68
68
/** Opens a StackBlitz for the specified example. */
69
- async createStackBlitzForExample ( exampleId : string , data : ExampleData ,
70
- isTest : boolean ) : Promise < ( ) => void > {
71
- // Run outside the zone since this form doesn't interact with Angular
69
+ createStackBlitzForExample ( exampleId : string , data : ExampleData ,
70
+ isTest : boolean ) : Promise < ( ) => void > {
71
+ // Run outside the zone since the creation doesn't interact with Angular
72
72
// and the file requests can cause excessive change detections.
73
- return await this . _ngZone . runOutsideAngular ( async ( ) => {
73
+ return this . _ngZone . runOutsideAngular ( async ( ) => {
74
74
const files = await this . _buildInMemoryFileDictionary ( data , exampleId , isTest ) ;
75
75
const exampleMainFile = `src/app/${ data . indexFilename } ` ;
76
76
77
77
return ( ) => {
78
- this . _openStackBlitz ( `Angular Components - ${ exampleId } example` , exampleMainFile , files ) ;
78
+ this . _openStackBlitz ( {
79
+ files,
80
+ title : `Angular Components - ${ data . description } ` ,
81
+ description : `${ data . description } \n\nAuto-generated from: https://material.angular.io` ,
82
+ openFile : exampleMainFile ,
83
+ } ) ;
79
84
} ;
80
85
} ) ;
81
86
}
82
87
83
- /** Opens a new WebContainer-based StackBlitz with the given files. */
84
- private _openStackBlitz ( title : string , openFile : string , files : FileDictionary ) : void {
88
+ /** Opens a new WebContainer-based StackBlitz for the given files. */
89
+ private _openStackBlitz ( { title, description, openFile, files} :
90
+ { title : string , description : string , openFile : string , files : FileDictionary } ) : void {
85
91
stackblitz . openProject ( {
86
92
title,
87
93
files,
88
- description : title ,
94
+ description,
89
95
template : PROJECT_TEMPLATE ,
90
96
tags : PROJECT_TAGS ,
91
97
} , { openFile} ) ;
@@ -147,15 +153,22 @@ export class StackBlitzWriter {
147
153
*/
148
154
private _replaceExamplePlaceholders ( data : ExampleData , fileName : string ,
149
155
fileContent : string , isTest : boolean ) : string {
156
+ // Replaces the version placeholder in the `index.html` and `package.json` file.
157
+ // Technically we invalidate the `package-lock.json` file for the StackBlitz boilerplate
158
+ // by dynamically changing the version in the `package.json`, but the Turbo package manager
159
+ // seems to be able to partially re-use the lock file to speed up the module tree computation,
160
+ // so providing a lock file is still reasonable while modifying the `package.json`.
161
+ if ( fileName === 'src/index.html' || fileName === 'package.json' ) {
162
+ fileContent = fileContent . replace ( / \$ { version} / g, MAT_VERSION . full ) ;
163
+ }
150
164
151
165
if ( fileName === 'src/index.html' ) {
152
166
// Replace the component selector in `index,html`.
153
167
// For example, <material-docs-example></material-docs-example> will be replaced as
154
168
// <button-demo></button-demo>
155
169
fileContent = fileContent
156
170
. replace ( / m a t e r i a l - d o c s - e x a m p l e / g, data . selectorName )
157
- . replace ( / \$ { title} / g, data . description )
158
- . replace ( / \$ { version} / g, MAT_VERSION . full ) ;
171
+ . replace ( / \$ { title} / g, data . description ) ;
159
172
} else if ( fileName === '.stackblitzrc' ) {
160
173
fileContent = fileContent
161
174
. replace ( / \$ { startCommand} / , isTest ? 'turbo test' : 'turbo start' ) ;
0 commit comments