@ng-shangjc/cli 1.0.5-beta → 1.0.7-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -170,13 +170,13 @@ async function setupTailwind() {
170
170
  if (fs.existsSync(stylesPath)) {
171
171
  existingContent = await fs.readFile(stylesPath, 'utf8');
172
172
  }
173
- // Check if Tailwind import already exists
174
- const hasTailwindImport = existingContent.includes("@import 'tailwindcss';");
175
- let newContent = '';
176
- // Add Tailwind import if not present
177
- if (!hasTailwindImport) {
178
- newContent += "@import 'tailwindcss';\n";
179
- }
173
+ // Remove existing Tailwind import and clean up extra blank lines
174
+ const cleanedContent = existingContent
175
+ .replace(/@import\s+['"]tailwindcss['"];?\s*\n?/gi, '')
176
+ .replace(/\n\s*\n\s*\n/g, '\n\n')
177
+ .trim();
178
+ // Always start with Tailwind import
179
+ let newContent = "@import 'tailwindcss';\n";
180
180
  // Add dark mode custom variant if user wants dark mode
181
181
  const config = await fs.readJson('shangjc.config.json');
182
182
  if (config.theme === 'dark' || config.theme === 'both') {
@@ -278,42 +278,44 @@ async function setupTailwind() {
278
278
  }
279
279
  `;
280
280
  // Preserve existing styles after the theme
281
- if (existingContent && !hasTailwindImport) {
282
- // If file existed but didn't have tailwind import, keep existing content
283
- const existingWithoutTailwind = existingContent;
284
- if (existingWithoutTailwind.trim()) {
285
- newContent += '\n\n' + existingWithoutTailwind;
286
- }
287
- }
288
- else if (existingContent && hasTailwindImport) {
289
- // If file had tailwind import, remove the old theme and keep other styles
290
- const lines = existingContent.split('\n');
291
- const afterThemeLines = [];
292
- let inThemeBlock = false;
293
- let foundTheme = false;
294
- for (const line of lines) {
295
- if (line.includes('@theme {') || line.includes(':root {') || line.includes('.dark {') || line.includes('@layer base {')) {
296
- inThemeBlock = true;
297
- foundTheme = true;
281
+ if (cleanedContent) {
282
+ // Remove any existing theme blocks from the preserved content
283
+ const lines = cleanedContent.split('\n');
284
+ const preservedLines = [];
285
+ let inThemeSection = false;
286
+ for (let i = 0; i < lines.length; i++) {
287
+ const line = lines[i];
288
+ const trimmedLine = line.trim();
289
+ // Skip theme-related blocks but preserve everything else
290
+ if (trimmedLine.startsWith('@theme {') ||
291
+ trimmedLine.startsWith(':root {') ||
292
+ trimmedLine.startsWith('.dark {') ||
293
+ trimmedLine.startsWith('@custom-variant dark')) {
294
+ inThemeSection = true;
298
295
  continue;
299
296
  }
300
- if (inThemeBlock && line.includes('}') && !line.includes('@layer')) {
301
- inThemeBlock = false;
297
+ if (inThemeSection && trimmedLine === '}' &&
298
+ !lines[i + 1]?.trim().startsWith('@layer')) {
299
+ inThemeSection = false;
302
300
  continue;
303
301
  }
304
- if (inThemeBlock && line.includes('@layer base {')) {
305
- // Skip the old @layer base content
302
+ if (trimmedLine.startsWith('@layer base {')) {
303
+ inThemeSection = true;
306
304
  continue;
307
305
  }
308
- if (inThemeBlock) {
306
+ if (inThemeSection && trimmedLine === '}' &&
307
+ lines[i - 1]?.trim().startsWith('@layer base')) {
308
+ inThemeSection = false;
309
309
  continue;
310
310
  }
311
- if (foundTheme && line.trim()) {
312
- afterThemeLines.push(line);
311
+ if (inThemeSection) {
312
+ continue;
313
313
  }
314
+ // Preserve this line
315
+ preservedLines.push(line);
314
316
  }
315
- if (afterThemeLines.length > 0) {
316
- newContent += '\n\n' + afterThemeLines.join('\n');
317
+ if (preservedLines.length > 0) {
318
+ newContent += '\n\n' + preservedLines.join('\n');
317
319
  }
318
320
  }
319
321
  // Write the updated content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-shangjc/cli",
3
- "version": "1.0.5-beta",
3
+ "version": "1.0.7-beta",
4
4
  "bin": {
5
5
  "ng-shangjc": "./dist/index.js"
6
6
  },
@@ -143,15 +143,14 @@ async function setupTailwind() {
143
143
  existingContent = await fs.readFile(stylesPath, 'utf8');
144
144
  }
145
145
 
146
- // Check if Tailwind import already exists
147
- const hasTailwindImport = existingContent.includes("@import 'tailwindcss';");
148
-
149
- let newContent = '';
150
-
151
- // Add Tailwind import if not present
152
- if (!hasTailwindImport) {
153
- newContent += "@import 'tailwindcss';\n";
154
- }
146
+ // Remove existing Tailwind import and clean up extra blank lines
147
+ const cleanedContent = existingContent
148
+ .replace(/@import\s+['"]tailwindcss['"];?\s*\n?/gi, '')
149
+ .replace(/\n\s*\n\s*\n/g, '\n\n')
150
+ .trim();
151
+
152
+ // Always start with Tailwind import
153
+ let newContent = "@import 'tailwindcss';\n";
155
154
 
156
155
  // Add dark mode custom variant if user wants dark mode
157
156
  const config = await fs.readJson('shangjc.config.json');
@@ -256,43 +255,52 @@ async function setupTailwind() {
256
255
  `;
257
256
 
258
257
  // Preserve existing styles after the theme
259
- if (existingContent && !hasTailwindImport) {
260
- // If file existed but didn't have tailwind import, keep existing content
261
- const existingWithoutTailwind = existingContent;
262
- if (existingWithoutTailwind.trim()) {
263
- newContent += '\n\n' + existingWithoutTailwind;
264
- }
265
- } else if (existingContent && hasTailwindImport) {
266
- // If file had tailwind import, remove the old theme and keep other styles
267
- const lines = existingContent.split('\n');
268
- const afterThemeLines = [];
269
- let inThemeBlock = false;
270
- let foundTheme = false;
258
+ if (cleanedContent) {
259
+ // Remove any existing theme blocks from the preserved content
260
+ const lines = cleanedContent.split('\n');
261
+ const preservedLines = [];
262
+ let inThemeSection = false;
271
263
 
272
- for (const line of lines) {
273
- if (line.includes('@theme {') || line.includes(':root {') || line.includes('.dark {') || line.includes('@layer base {')) {
274
- inThemeBlock = true;
275
- foundTheme = true;
264
+ for (let i = 0; i < lines.length; i++) {
265
+ const line = lines[i];
266
+ const trimmedLine = line.trim();
267
+
268
+ // Skip theme-related blocks but preserve everything else
269
+ if (trimmedLine.startsWith('@theme {') ||
270
+ trimmedLine.startsWith(':root {') ||
271
+ trimmedLine.startsWith('.dark {') ||
272
+ trimmedLine.startsWith('@custom-variant dark')) {
273
+ inThemeSection = true;
276
274
  continue;
277
275
  }
278
- if (inThemeBlock && line.includes('}') && !line.includes('@layer')) {
279
- inThemeBlock = false;
276
+
277
+ if (inThemeSection && trimmedLine === '}' &&
278
+ !lines[i + 1]?.trim().startsWith('@layer')) {
279
+ inThemeSection = false;
280
280
  continue;
281
281
  }
282
- if (inThemeBlock && line.includes('@layer base {')) {
283
- // Skip the old @layer base content
282
+
283
+ if (trimmedLine.startsWith('@layer base {')) {
284
+ inThemeSection = true;
284
285
  continue;
285
286
  }
286
- if (inThemeBlock) {
287
+
288
+ if (inThemeSection && trimmedLine === '}' &&
289
+ lines[i - 1]?.trim().startsWith('@layer base')) {
290
+ inThemeSection = false;
287
291
  continue;
288
292
  }
289
- if (foundTheme && line.trim()) {
290
- afterThemeLines.push(line);
293
+
294
+ if (inThemeSection) {
295
+ continue;
291
296
  }
297
+
298
+ // Preserve this line
299
+ preservedLines.push(line);
292
300
  }
293
301
 
294
- if (afterThemeLines.length > 0) {
295
- newContent += '\n\n' + afterThemeLines.join('\n');
302
+ if (preservedLines.length > 0) {
303
+ newContent += '\n\n' + preservedLines.join('\n');
296
304
  }
297
305
  }
298
306