@@ -185,6 +185,25 @@ if (argv.watch) {
185185// START OR BUILD DEMO PROJECT
186186//
187187if ( argv . demo ) {
188+ const injectStorySourceCodeAndCopyCode = ( ) => {
189+ shell . echo ( chalk . blue ( '>> reading demo story source files' ) ) ;
190+ const files = fs . readdirSync ( relativePath ( './src/demo/stories/' ) ) ;
191+ if ( files !== undefined && files !== null && files . length > 0 ) {
192+ let storySource = '' ;
193+ for ( let i = 0 ; i < files . length ; i ++ ) {
194+ const storyName = files [ i ] ;
195+ let fileContent = fs . readFileSync ( relativePath ( './src/demo/stories/' + storyName ) ) ;
196+ fileContent = `${ fileContent } ` . replace ( / ` / g, '\\`' ) ;
197+ storySource = storySource + `
198+ case '${ storyName } ': { return \`${ fileContent } \`; }
199+ ` ;
200+ }
201+ shell . cp ( '-r' , `./src/*` , `./dist-demo/src/` ) ;
202+ let storiesIndex = fs . readFileSync ( relativePath ( './src/demo/story-index.ts' ) ) ;
203+ storiesIndex = `${ storiesIndex } ` . replace ( / [ / ] [ * ] _ _ _ I N J E C T _ S O U R C E _ _ _ [ * ] [ / ] / , storySource ) ;
204+ fs . writeFileSync ( relativePath ( './dist-demo/src/demo/story-index.ts' ) , storiesIndex ) ;
205+ }
206+ } ;
188207 const packageJson = JSON . parse ( shell . cat ( relativePath ( './package.json' ) ) . stdout ) ;
189208 shell . echo ( chalk . blue ( '>> creating dist-demo' ) ) ;
190209 if ( shell . test ( '-d' , relativePath ( './dist-demo' ) ) ) {
@@ -198,7 +217,7 @@ if (argv.demo) {
198217 if ( shell . test ( '-d' , relativePath ( './_dist_demo_node_modules' ) ) ) {
199218 shell . mv ( relativePath ( '_dist_demo_node_modules' ) , relativePath ( './dist-demo/node_modules' ) ) ;
200219 }
201- shell . cp ( '-r' , `./src/*` , `./dist-demo/src/` ) ;
220+ injectStorySourceCodeAndCopyCode ( ) ;
202221 shell . cd ( relativePath ( './dist-demo/' ) ) ;
203222 if ( argv . install ) {
204223 shell . echo ( chalk . blue ( '>> injecting package.json dependencies into dist-demo/package.json' ) ) ;
@@ -215,7 +234,7 @@ if (argv.demo) {
215234 gaze . on ( 'all' , ( event , filepath ) => {
216235 try {
217236 shell . echo ( chalk . blue ( `>> ${ filepath } has changed. copying it to ./dist-demo/src/` ) ) ;
218- shell . cp ( '-r' , relativePath ( `./src` ) + '/*' , relativePath ( `./dist-demo/src/` ) ) ;
237+ injectStorySourceCodeAndCopyCode ( ) ;
219238 } catch ( err ) {
220239 console . log ( err ) ;
221240 }
0 commit comments