@@ -19,6 +19,7 @@ const { generateLiveEditing } = require('igniteui-live-editing');
1919const argv = yargs ( hideBin ( process . argv ) ) . parse ( ) ;
2020
2121const submodule = "igniteui-live-editing-samples" ;
22+ const mainPkgDevDeps = JSON . parse ( fs . readFileSync ( path . join ( __dirname , 'package.json' ) , 'utf8' ) ) . devDependencies ;
2223
2324gulp . task ( "generate-live-editing" , async ( ) => {
2425 var appDv = argv . appDv !== undefined && argv . appDv . toLowerCase ( ) . trim ( ) === "true" ;
@@ -53,7 +54,38 @@ gulp.task("generate-live-editing", async () => {
5354 } ,
5455 additionalSharedStyles : [ "_variables.scss" , "_app-layout.scss" ]
5556 } )
57+ const samplesDir = path . resolve ( liveEditingOptions . samplesDir , 'samples' ) ;
5658 await generateLiveEditing ( liveEditingOptions ) ;
59+
60+ const sharedJsonPath = path . join ( samplesDir , 'shared.json' ) ;
61+ const sharedJson = JSON . parse ( fs . readFileSync ( sharedJsonPath , 'utf8' ) ) ;
62+ const stylesFile = sharedJson . files && sharedJson . files . find ( f => f . path === 'src/styles.scss' ) ;
63+ if ( stylesFile ) {
64+ const tailwindImportRegex = / @ i m p o r t \s + [ " ' ] t a i l w i n d c s s [ " ' ] \s * ; ? \r ? \n ? / g;
65+ const stylesWithTailwind = tailwindImportRegex . test ( stylesFile . content )
66+ ? stylesFile . content
67+ : stylesFile . content . replace ( / ( (?: @ u s e [ ^ \n ] + \n ) + ) / , '$1@import "tailwindcss";\n' ) ;
68+ stylesFile . content = stylesFile . content . replace ( tailwindImportRegex , '' ) ;
69+ fs . writeFileSync ( sharedJsonPath , JSON . stringify ( sharedJson ) ) ;
70+
71+ fs . readdirSync ( samplesDir )
72+ . filter ( f => f . endsWith ( '.json' ) && f !== 'shared.json' && f !== 'meta.json' )
73+ . forEach ( f => {
74+ const samplePath = path . join ( samplesDir , f ) ;
75+ const sample = JSON . parse ( fs . readFileSync ( samplePath , 'utf8' ) ) ;
76+ const deps = JSON . parse ( sample . sampleDependencies || '{}' ) ;
77+ if ( deps [ 'tailwindcss' ] ) {
78+ const existing = sample . sampleFiles . findIndex ( sf => sf . path === 'src/styles.scss' ) ;
79+ const styleEntry = { path : 'src/styles.scss' , hasRelativeAssetsUrls : false , content : stylesWithTailwind } ;
80+ if ( existing !== - 1 ) {
81+ sample . sampleFiles [ existing ] = styleEntry ;
82+ } else {
83+ sample . sampleFiles . push ( styleEntry ) ;
84+ }
85+ fs . writeFileSync ( samplePath , JSON . stringify ( sample ) ) ;
86+ }
87+ } ) ;
88+ }
5789} ) ;
5890
5991gulp . task ( "overwrite-package-json" , ( done ) => {
@@ -116,8 +148,15 @@ const processApp = (projectPath, dest, directoriesToExclude) => {
116148 "path" : "package.json" ,
117149 "hasRelativeAssetsUrls" : false ,
118150 "content" : JSON . stringify ( {
119- "dependencies" : JSON . parse ( jsonObj . sampleDependencies ) ,
120- "devDependencies" : sharedJson . devDependencies
151+ "name" : "example-app" ,
152+ "version" : "0.0.0" ,
153+ "scripts" : {
154+ "ng" : "ng" ,
155+ "start" : "node --max_old_space_size=12192 node_modules/@angular/cli/bin/ng serve" ,
156+ "build" : "node --max_old_space_size=12192 node_modules/@angular/cli/bin/ng build"
157+ } ,
158+ "dependencies" : Object . fromEntries ( Object . entries ( JSON . parse ( jsonObj . sampleDependencies ) ) . map ( ( [ pkg , ver ] ) => [ pkg , / ^ [ \^ ~ > < = * ] / . test ( ver ) ? ver : '^' + ver ] ) ) ,
159+ "devDependencies" : Object . fromEntries ( Object . keys ( sharedJson . devDependencies ) . map ( pkg => [ pkg , mainPkgDevDeps [ pkg ] || sharedJson . devDependencies [ pkg ] ] ) )
121160 } , null , 2 )
122161 }
123162 additionals . push ( packageJson ) ;
@@ -153,6 +192,16 @@ const processApp = (projectPath, dest, directoriesToExclude) => {
153192 } else {
154193 sampleContent = sampleFile . content ;
155194 }
195+ if ( sampleFile . path === 'src/styles.scss' ) {
196+ const deps = JSON . parse ( jsonObj . sampleDependencies ) ;
197+ const tailwindImportRegex = / @ i m p o r t \s + [ " ' ] t a i l w i n d c s s [ " ' ] ; ? / ;
198+ const tailwindImportStripRegex = / @ i m p o r t \s + [ " ' ] t a i l w i n d c s s [ " ' ] ; ? \r ? \n ? / g;
199+ if ( deps [ 'tailwindcss' ] && ! tailwindImportRegex . test ( sampleContent ) ) {
200+ sampleContent = sampleContent . replace ( / ( (?: @ u s e [ ^ \n ] + \n ) + ) / , '$1@import "tailwindcss";\n' ) ;
201+ } else if ( ! deps [ 'tailwindcss' ] ) {
202+ sampleContent = sampleContent . replace ( tailwindImportStripRegex , '' ) ;
203+ }
204+ }
156205 const paths = sampleFile . path . replace ( "./" , "" ) . split ( "/" ) ;
157206 let tempPath = "" ;
158207 paths . forEach ( p => {
0 commit comments