diff --git a/gulpfile.js b/gulpfile.js index 7d6d5d1f8..ec7718e0a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,6 +19,7 @@ const { generateLiveEditing } = require('igniteui-live-editing'); const argv = yargs(hideBin(process.argv)).parse(); const submodule = "igniteui-live-editing-samples"; +const mainPkgDevDeps = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')).devDependencies; gulp.task("generate-live-editing", async () => { var appDv = argv.appDv !== undefined && argv.appDv.toLowerCase().trim() === "true"; @@ -53,7 +54,38 @@ gulp.task("generate-live-editing", async () => { }, additionalSharedStyles: ["_variables.scss", "_app-layout.scss"] }) + const samplesDir = path.resolve(liveEditingOptions.samplesDir, 'samples'); await generateLiveEditing(liveEditingOptions); + + const sharedJsonPath = path.join(samplesDir, 'shared.json'); + const sharedJson = JSON.parse(fs.readFileSync(sharedJsonPath, 'utf8')); + const stylesFile = sharedJson.files && sharedJson.files.find(f => f.path === 'src/styles.scss'); + if (stylesFile) { + const tailwindImportRegex = /@import\s+["']tailwindcss["']\s*;?\r?\n?/g; + const stylesWithTailwind = tailwindImportRegex.test(stylesFile.content) + ? stylesFile.content + : stylesFile.content.replace(/((?:@use [^\n]+\n)+)/, '$1@import "tailwindcss";\n'); + stylesFile.content = stylesFile.content.replace(tailwindImportRegex, ''); + fs.writeFileSync(sharedJsonPath, JSON.stringify(sharedJson)); + + fs.readdirSync(samplesDir) + .filter(f => f.endsWith('.json') && f !== 'shared.json' && f !== 'meta.json') + .forEach(f => { + const samplePath = path.join(samplesDir, f); + const sample = JSON.parse(fs.readFileSync(samplePath, 'utf8')); + const deps = JSON.parse(sample.sampleDependencies || '{}'); + if (deps['tailwindcss']) { + const existing = sample.sampleFiles.findIndex(sf => sf.path === 'src/styles.scss'); + const styleEntry = { path: 'src/styles.scss', hasRelativeAssetsUrls: false, content: stylesWithTailwind }; + if (existing !== -1) { + sample.sampleFiles[existing] = styleEntry; + } else { + sample.sampleFiles.push(styleEntry); + } + fs.writeFileSync(samplePath, JSON.stringify(sample)); + } + }); + } }); gulp.task("overwrite-package-json", (done) => { @@ -116,8 +148,15 @@ const processApp = (projectPath, dest, directoriesToExclude) => { "path": "package.json", "hasRelativeAssetsUrls": false, "content": JSON.stringify({ - "dependencies": JSON.parse(jsonObj.sampleDependencies), - "devDependencies": sharedJson.devDependencies + "name": "example-app", + "version": "0.0.0", + "scripts": { + "ng": "ng", + "start": "node --max_old_space_size=12192 node_modules/@angular/cli/bin/ng serve", + "build": "node --max_old_space_size=12192 node_modules/@angular/cli/bin/ng build" + }, + "dependencies": Object.fromEntries(Object.entries(JSON.parse(jsonObj.sampleDependencies)).map(([pkg, ver]) => [pkg, /^[\^~><=*]/.test(ver) ? ver : '^' + ver])), + "devDependencies": Object.fromEntries(Object.keys(sharedJson.devDependencies).map(pkg => [pkg, mainPkgDevDeps[pkg] || sharedJson.devDependencies[pkg]])) }, null, 2) } additionals.push(packageJson); @@ -153,6 +192,16 @@ const processApp = (projectPath, dest, directoriesToExclude) => { } else { sampleContent = sampleFile.content; } + if (sampleFile.path === 'src/styles.scss') { + const deps = JSON.parse(jsonObj.sampleDependencies); + const tailwindImportRegex = /@import\s+["']tailwindcss["'];?/; + const tailwindImportStripRegex = /@import\s+["']tailwindcss["'];?\r?\n?/g; + if (deps['tailwindcss'] && !tailwindImportRegex.test(sampleContent)) { + sampleContent = sampleContent.replace(/((?:@use [^\n]+\n)+)/, '$1@import "tailwindcss";\n'); + } else if (!deps['tailwindcss']) { + sampleContent = sampleContent.replace(tailwindImportStripRegex, ''); + } + } const paths = sampleFile.path.replace("./", "").split("/"); let tempPath = ""; paths.forEach(p => { diff --git a/package-lock.json b/package-lock.json index 0305d1a5a..7dfc37bb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -693,6 +693,18 @@ } } }, + "node_modules/@angular/build/node_modules/@types/node": { + "version": "25.6.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz", + "integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "undici-types": "~7.19.0" + } + }, "node_modules/@angular/build/node_modules/@vitejs/plugin-basic-ssl": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-2.1.4.tgz", @@ -706,6 +718,15 @@ "vite": "^6.0.0 || ^7.0.0" } }, + "node_modules/@angular/build/node_modules/undici-types": { + "version": "7.19.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz", + "integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true + }, "node_modules/@angular/build/node_modules/vite": { "version": "7.3.2", "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.2.tgz", @@ -4569,9 +4590,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4589,9 +4607,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4609,9 +4624,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4629,9 +4641,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4808,9 +4817,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4825,9 +4831,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4842,9 +4845,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4859,9 +4859,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4876,9 +4873,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4893,9 +4887,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4910,9 +4901,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4927,9 +4915,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4944,9 +4929,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4961,9 +4943,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4978,9 +4957,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4995,9 +4971,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -5012,9 +4985,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [