scss-variable-extractor 1.6.5 → 1.9.1

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.
@@ -0,0 +1,262 @@
1
+ # Multi-App Dependency Analysis Guide
2
+
3
+ ## Your Scenario: Cafe Library Submodule + Unified App
4
+
5
+ This guide shows how to use the new `analyze-dependencies` command for your specific setup with:
6
+
7
+ - Multiple apps (unified, customer, admin, etc.)
8
+ - Git submodule: fluffySubby library
9
+ - Apps that reference each other's styles
10
+
11
+ ## Step 1: Create Configuration File
12
+
13
+ Create `multi-app-config.json` in your workspace root:
14
+
15
+ ```json
16
+ {
17
+ "workspaceRoot": ".",
18
+ "apps": [
19
+ {
20
+ "name": "unified-app",
21
+ "path": "./apps/unified/src",
22
+ "type": "app",
23
+ "description": "Unified app that references other apps"
24
+ },
25
+ {
26
+ "name": "customer-app",
27
+ "path": "./apps/customer/src",
28
+ "type": "app",
29
+ "description": "Customer-facing app"
30
+ },
31
+ {
32
+ "name": "admin-app",
33
+ "path": "./apps/admin/src",
34
+ "type": "app",
35
+ "description": "Admin dashboard"
36
+ }
37
+ ],
38
+ "sharedLibraries": [
39
+ {
40
+ "name": "fluffySubby-lib",
41
+ "path": "./libs/fluffySubby",
42
+ "type": "library",
43
+ "isSubmodule": true,
44
+ "description": "Git submodule fluffySubby library - shared across apps"
45
+ }
46
+ ]
47
+ }
48
+ ```
49
+
50
+ ## Step 2: Run Analysis
51
+
52
+ ```bash
53
+ npx scss-extract analyze-dependencies --config multi-app-config.json
54
+ ```
55
+
56
+ ## What You'll See
57
+
58
+ ### App Overview
59
+
60
+ ```
61
+ 📱 unified-app: 45 files, 127 classes, 38 variables
62
+ 📱 customer-app: 32 files, 89 classes, 25 variables
63
+ 📱 admin-app: 28 files, 76 classes, 22 variables
64
+ 📚 fluffySubby-lib: 15 files, 54 classes, 31 variables (submodule)
65
+ ```
66
+
67
+ ### Dependencies Detected
68
+
69
+ ```
70
+ Dependencies:
71
+ Strong (explicit imports):
72
+ unified-app → fluffySubby-lib (@use) ← Unified uses fluffySubby library
73
+ customer-app → fluffySubby-lib (@use) ← Customer uses fluffySubby library
74
+ unified-app → customer-app (@use) ← âš ī¸ Unified imports from customer!
75
+
76
+ Weak (shared classes):
77
+ unified-app ↔ customer-app (12 shared classes)
78
+ customer-app ↔ admin-app (8 shared classes)
79
+ ```
80
+
81
+ ### Recommendations
82
+
83
+ ```
84
+ 💡 Recommendations:
85
+
86
+ 🟡 fluffySubby-lib is a root dependency - already set up correctly as submodule ✓
87
+ 🟡 12 CSS classes shared between unified-app and customer-app - should be in fluffySubby-lib
88
+ 🟡 unified-app imports from customer-app - consider extracting shared styles to fluffySubby-lib
89
+ 🔴 Potential circular dependency if customer-app also imports from unified-app
90
+ ```
91
+
92
+ ## Step 3: Understanding the Results
93
+
94
+ ### What the Tool Tells You
95
+
96
+ **1. Which App Relies on Which:**
97
+
98
+ - ✅ fluffySubby-lib is used by unified-app and customer-app (good - it's a library)
99
+ - âš ī¸ unified-app imports from customer-app (might be problematic)
100
+ - â„šī¸ Shows you the dependency chain
101
+
102
+ **2. What Should Be Shared:**
103
+
104
+ - Classes used in 2+ apps → Move to fluffySubby-lib
105
+ - Variables used in 2+ apps → Move to fluffySubby-lib
106
+ - App-specific styles → Keep in app
107
+
108
+ **3. Organization Strategy:**
109
+
110
+ ```
111
+ Recommended Structure:
112
+
113
+ libs/fluffySubby/ (git submodule)
114
+ ├── styles/
115
+ │ ├── _variables.scss ← Shared variables (tool identifies these)
116
+ │ ├── _utilities.scss ← Shared classes (tool identifies these)
117
+ │ ├── _mixins.scss ← Shared mixins
118
+ │ └── index.scss ← Main export
119
+
120
+ apps/unified/
121
+ └── src/styles/
122
+ └── unified-specific.scss ← Only unified-specific styles
123
+
124
+ apps/customer/
125
+ └── src/styles/
126
+ └── customer-specific.scss ← Only customer-specific styles
127
+ ```
128
+
129
+ ## Step 4: Act on Recommendations
130
+
131
+ ### If Tool Says: "Move these classes to fluffySubby-lib"
132
+
133
+ **Classes detected in multiple apps:**
134
+
135
+ - `.btn-primary` (in unified, customer, admin)
136
+ - `.card-container` (in unified, customer)
137
+ - `.header-nav` (in all apps)
138
+
139
+ **Action:**
140
+
141
+ ```bash
142
+ # The tool tells you exactly what to move
143
+ # Create utilities file in fluffySubby-lib
144
+ touch libs/fluffySubby/styles/_utilities.scss
145
+
146
+ # Add the shared classes there
147
+ # Tool can show you which classes from the analysis
148
+ ```
149
+
150
+ ### If Tool Says: "Circular dependency detected"
151
+
152
+ **Example:** unified-app → customer-app → unified-app
153
+
154
+ **Action:**
155
+
156
+ 1. Review what unified-app needs from customer-app
157
+ 2. Extract those shared styles to fluffySubby-lib
158
+ 3. Both apps import from fluffySubby-lib instead
159
+
160
+ ## Step 5: Export Detailed Analysis (Optional)
161
+
162
+ ```bash
163
+ # Get JSON output for detailed review
164
+ npx scss-extract analyze-dependencies --config multi-app-config.json --format json > dependency-analysis.json
165
+
166
+ # Review:
167
+ # - Exact list of shared classes
168
+ # - Exact list of shared variables
169
+ # - Complete import graph
170
+ # - Step-by-step migration plan
171
+ ```
172
+
173
+ ## Common Patterns the Tool Detects
174
+
175
+ ### ✅ Good Pattern
176
+
177
+ ```
178
+ unified-app → fluffySubby-lib (submodule)
179
+ customer-app → fluffySubby-lib (submodule)
180
+ admin-app → fluffySubby-lib (submodule)
181
+ ```
182
+
183
+ **Tool says:** ✓ Good architecture, fluffySubby-lib is properly used as shared library
184
+
185
+ ### âš ī¸ Warning Pattern
186
+
187
+ ```
188
+ unified-app → customer-app → styles.scss
189
+ ```
190
+
191
+ **Tool says:** âš ī¸ unified-app depends on customer-app styles - extract to fluffySubby-lib
192
+
193
+ ### 🔴 Problem Pattern
194
+
195
+ ```
196
+ unified-app → customer-app
197
+ customer-app → unified-app
198
+ ```
199
+
200
+ **Tool says:** 🔴 Circular dependency - extract shared styles to fluffySubby-lib immediately
201
+
202
+ ## Real Example: Your Cafe Library
203
+
204
+ **Before Analysis:**
205
+
206
+ ```
207
+ // unified-app/styles.scss
208
+ @use '../../customer-app/src/styles/buttons'; ← Bad: app imports from app
209
+ @use '../../../libs/fluffySubby/styles' as fluffySubby; ← Good: app imports from lib
210
+ ```
211
+
212
+ **After Analysis & Refactoring:**
213
+
214
+ ```
215
+ // Move shared styles to fluffySubby-lib
216
+ libs/fluffySubby/styles/_buttons.scss
217
+
218
+ // unified-app/styles.scss
219
+ @use '../../../libs/fluffySubby/styles' as fluffySubby; ← Good: only lib imports
220
+
221
+ // customer-app/styles.scss
222
+ @use '../../../libs/fluffySubby/styles' as fluffySubby; ← Good: only lib imports
223
+ ```
224
+
225
+ ## Questions the Tool Answers
226
+
227
+ ❓ **"Where should I put this style?"**
228
+ → Tool tells you if it's used in 1 app (keep local) or 2+ apps (move to fluffySubby-lib)
229
+
230
+ ❓ **"Is my unified app correctly using the fluffySubby library?"**
231
+ → Tool shows dependency graph and highlights if it's importing from apps instead
232
+
233
+ ❓ **"What styles should be in the fluffySubby submodule vs app-specific?"**
234
+ → Tool identifies exactly which classes/variables are shared
235
+
236
+ ❓ **"Are there any circular dependencies?"**
237
+ → Tool detects and highlights them with 🔴 critical priority
238
+
239
+ ## Next Steps After Analysis
240
+
241
+ 1. **Review the recommendations** - Prioritize critical (🔴) and high (🟡) items
242
+ 2. **Move shared styles to fluffySubby-lib** - Use the tool's list of shared classes/variables
243
+ 3. **Update imports** - Change app-to-app imports to app-to-lib imports
244
+ 4. **Test** - Ensure all apps still work correctly
245
+ 5. **Commit fluffySubby-lib changes** - Update the submodule
246
+ 6. **Update apps** - Pull latest fluffySubby-lib in each app
247
+
248
+ ## Automation Coming Soon
249
+
250
+ Future versions will support:
251
+
252
+ ```bash
253
+ # Auto-migrate shared styles to library
254
+ npx scss-extract migrate-to-library --config multi-app-config.json
255
+
256
+ # Auto-update imports
257
+ npx scss-extract update-imports --config multi-app-config.json
258
+ ```
259
+
260
+ ---
261
+
262
+ **Bottom Line:** The tool analyzes your multi-app setup and tells you exactly which app relies on which, what should be shared vs app-specific, and the best way to organize everything!
package/README.md CHANGED
@@ -16,7 +16,8 @@ A standalone, reusable CLI tool that analyzes Angular project SCSS files, identi
16
16
  🔄 **Bootstrap to Material Migration** - Converts Bootstrap classes to Angular Material MDC components and utilities
17
17
  🎨 **Theme Generation** - Creates dark/light theme structure with Material Design support
18
18
  ✨ **Auto Formatting** - Prettier integration for consistent code style
19
- 🌍 **Global Styles Preservation** - Moves ::ng-deep and !important styles to global files
19
+ 🌍 **Global Styles Preservation** - Moves ::ng-deep and !important styles to global files
20
+ 🔗 **Multi-App Dependency Analysis** - Analyzes style dependencies across apps, submodules, and libraries
20
21
 
21
22
  ## Installation
22
23
 
@@ -527,7 +528,7 @@ npx scss-extract migrate-bootstrap --no-custom-utilities
527
528
 
528
529
  ### `generate-themes` - Theme Structure Generator
529
530
 
530
- Generate a complete dark/light theme structure for Angular Material applications.
531
+ Generate a complete dark/light theme structure for Angular Material applications with **automatic color extraction** from your existing styles.
531
532
 
532
533
  ```bash
533
534
  npx scss-extract generate-themes [src]
@@ -543,7 +544,7 @@ npx scss-extract generate-themes ./src --output ./src/styles --analyze
543
544
  **Options:**
544
545
 
545
546
  - `--output <dir>` - Output directory for theme files (default: `./src/styles`)
546
- - `--analyze` - Analyze existing styles for theme readiness
547
+ - `--analyze` - Analyze existing styles and extract actual colors from your app
547
548
  - `--format <format>` - Report format for analysis (table, json, markdown)
548
549
 
549
550
  **What it generates:**
@@ -559,6 +560,10 @@ npx scss-extract generate-themes ./src --output ./src/styles --analyze
559
560
 
560
561
  ✅ **Features:**
561
562
 
563
+ - **🎨 Automatic Color Extraction** - Uses actual colors from your app (with `--analyze`)
564
+ - **Intelligent Color Selection** - Automatically picks primary, accent, and warn colors based on usage
565
+ - **Smart Red Detection** - Prefers red hues for warn colors
566
+ - **Dark Theme Variants** - Auto-generates lightened colors for dark mode
562
567
  - Material Design color palettes
563
568
  - Automatic dark/light mode switching
564
569
  - CSS custom properties support
@@ -568,13 +573,27 @@ npx scss-extract generate-themes ./src --output ./src/styles --analyze
568
573
  **Example Usage:**
569
574
 
570
575
  ```bash
571
- # Generate theme structure
576
+ # Generate theme structure with default Material colors
572
577
  npx scss-extract generate-themes --output ./src/styles
573
578
 
574
- # Analyze existing styles first
579
+ # 🎨 Analyze existing styles and use YOUR app's colors
575
580
  npx scss-extract generate-themes ./src --analyze --output ./src/styles
576
581
  ```
577
582
 
583
+ **How Color Extraction Works:**
584
+
585
+ When you use `--analyze`, the tool:
586
+
587
+ 1. **Scans all SCSS files** in your source directory
588
+ 2. **Extracts all colors** (hex, rgba) and counts usage frequency
589
+ 3. **Filters out utility colors** (black, white, grays)
590
+ 4. **Intelligently categorizes**:
591
+ - Most used color → **Primary** palette
592
+ - Second most used → **Accent** palette
593
+ - Red hues (or third most used) → **Warn** palette
594
+ 5. **Generates dark variants** by lightening colors for dark theme
595
+ 6. **Creates theme files** with your actual brand colors
596
+
578
597
  **Using Generated Themes:**
579
598
 
580
599
  1. Import in your `styles.scss`:
@@ -644,6 +663,258 @@ The formatting runs automatically before releases to ensure code quality.
644
663
 
645
664
  ---
646
665
 
666
+ ## Multi-App Dependency Analysis
667
+
668
+ Perfect for **monorepos**, **multi-repo setups**, and **projects with git submodules**. Analyzes style dependencies across multiple apps to recommend the best organization strategy.
669
+
670
+ ### Use Cases
671
+
672
+ **Ideal for:**
673
+
674
+ - ✅ Multiple apps sharing styles
675
+ - ✅ Git submodules (like a fluffySubby library used by multiple apps)
676
+ - ✅ Apps that reference other apps' styles
677
+ - ✅ Determining where to put shared styles
678
+ - ✅ Identifying circular dependencies
679
+ - ✅ Planning style library extraction
680
+
681
+ ### Command
682
+
683
+ ```bash
684
+ npx scss-extract analyze-dependencies --config multi-app.json
685
+ ```
686
+
687
+ ### Configuration File
688
+
689
+ Create a `multi-app.json` file describing your workspace:
690
+
691
+ ```json
692
+ {
693
+ "workspaceRoot": ".",
694
+ "apps": [
695
+ {
696
+ "name": "unified-app",
697
+ "path": "./apps/unified/src",
698
+ "type": "app",
699
+ "description": "Unified app that references other apps"
700
+ },
701
+ {
702
+ "name": "customer-app",
703
+ "path": "./apps/customer/src",
704
+ "type": "app"
705
+ },
706
+ {
707
+ "name": "admin-app",
708
+ "path": "./apps/admin/src",
709
+ "type": "app"
710
+ }
711
+ ],
712
+ "sharedLibraries": [
713
+ {
714
+ "name": "libs",
715
+ "path": "./libs/lib1",
716
+ "type": "library",
717
+ "isSubmodule": true,
718
+ "description": "Git submodule fluffySubby library"
719
+ }
720
+ ]
721
+ }
722
+ ```
723
+
724
+ ### What It Analyzes
725
+
726
+ **1. Cross-App Dependencies:**
727
+
728
+ - Detects which apps import styles from other apps
729
+ - Identifies apps using git submodule styles
730
+ - Finds apps referencing each other
731
+
732
+ **2. Shared Styles:**
733
+
734
+ - CSS classes used in multiple apps
735
+ - SCSS variables duplicated across apps
736
+ - Mixins defined in multiple places
737
+
738
+ **3. Dependency Graph:**
739
+
740
+ - Builds a complete dependency map
741
+ - Shows which apps depend on which
742
+ - Detects circular dependencies (âš ī¸ critical issues)
743
+
744
+ **4. Organization Recommendations:**
745
+
746
+ - Suggests creating shared style libraries
747
+ - Recommends where to put common styles
748
+ - Identifies styles to consolidate
749
+
750
+ ### Example Output
751
+
752
+ ```
753
+ 🔗 Multi-App Dependency Analysis
754
+
755
+ Apps & Libraries:
756
+ 📱 unified-app: 45 files, 127 classes, 38 variables
757
+ 📱 customer-app: 32 files, 89 classes, 25 variables
758
+ 📱 admin-app: 28 files, 76 classes, 22 variables
759
+ 📚 libs: 15 files, 54 classes, 31 variables
760
+
761
+ Dependencies:
762
+ Strong (explicit imports):
763
+ unified-app → libs (@use)
764
+ customer-app → libs (@use)
765
+ unified-app → customer-app (@use)
766
+
767
+ Weak (shared classes):
768
+ customer-app ↔ admin-app (12 shared classes)
769
+ unified-app ↔ admin-app (8 shared classes)
770
+
771
+ Shared Styles:
772
+ 23 shared CSS classes
773
+ Examples: .btn-primary, .card-container, .header-nav, .footer-links
774
+ 15 shared variables
775
+ Examples: $primary-color, $spacing-md, $border-radius
776
+
777
+ 💡 Recommendations:
778
+
779
+ 🟡 [Architecture] libs is a root dependency - consider making it a shared library
780
+ 🟡 [Shared Styles] 23 CSS classes are shared across multiple apps - move to shared library
781
+ 🟡 [Shared Styles] 15 SCSS variables are shared across multiple apps - consolidate in shared library
782
+ đŸŸĸ [Best Practices] unified-app imports Material styles directly - consider creating shared theme library
783
+
784
+ 📋 Organization Plan:
785
+
786
+ 1. Create shared library structure
787
+ Set up shared styles library with proper organization
788
+ ✓ Automated: scss-extract migrate-to-library --type variables
789
+
790
+ 2. Extract shared variables
791
+ Move shared SCSS variables to library
792
+
793
+ 3. Extract shared classes
794
+ Move shared CSS classes to library
795
+
796
+ 4. Update imports in apps
797
+ Update @use/@import statements to reference shared library
798
+
799
+ 5. Test and validate
800
+ Build all apps and verify styles work correctly
801
+ ⚠ Manual step required
802
+ ```
803
+
804
+ ### Real-World Example: Cafe Library Submodule
805
+
806
+ **Your Setup:**
807
+
808
+ - Multiple apps (unified, customer, admin)
809
+ - Git submodule: `fluffySubby` library
810
+ - Apps reference each other's styles
811
+
812
+ **Problem:** Not sure where to put shared styles
813
+
814
+ **Solution:**
815
+
816
+ ```bash
817
+ # 1. Analyze dependencies
818
+ npx scss-extract analyze-dependencies --config multi-app.json --format json > analysis.json
819
+
820
+ # 2. Review recommendations
821
+ # Tool will tell you:
822
+ # - Which apps depend on fluffySubby library
823
+ # - Which styles should be in fluffySubby vs app-specific
824
+ # - If unified-app should be a library or just uses others
825
+
826
+ # 3. Create organization based on recommendations
827
+ npx scss-extract generate-themes --output ./libs/lib1/styles
828
+
829
+ # 4. Move shared styles
830
+ # Tool identifies what's truly shared vs app-specific
831
+ ```
832
+
833
+ **Recommended Structure (based on analysis):**
834
+
835
+ ```
836
+ libs/
837
+ fluffySubby/ # Git submodule
838
+ styles/
839
+ _variables.scss # Shared variables (identified by tool)
840
+ _mixins.scss # Shared mixins
841
+ _utilities.scss # Shared utility classes
842
+ index.scss # Main export
843
+ apps/
844
+ unified/
845
+ src/
846
+ styles/
847
+ app-specific.scss # Unified-specific styles
848
+ customer/
849
+ src/
850
+ styles/
851
+ app-specific.scss # Customer-specific styles
852
+ admin/
853
+ src/
854
+ styles/
855
+ app-specific.scss # Admin-specific styles
856
+ ```
857
+
858
+ ### Advanced: Detecting App Relationships
859
+
860
+ The tool understands these patterns:
861
+
862
+ **1. App A uses Library B (git submodule):**
863
+
864
+ ```scss
865
+ // unified-app/styles.scss
866
+ @use '../../../libs/lib1/styles' as fluffySubby;
867
+ ```
868
+
869
+ ✅ **Recommendation:** Keep styles in fluffySubby library, unified-app imports them
870
+
871
+ **2. App A uses App B's styles:**
872
+
873
+ ```scss
874
+ // unified-app/styles.scss
875
+ @use '../../customer-app/styles' as customer;
876
+ ```
877
+
878
+ âš ī¸ **Warning:** Circular dependency risk
879
+
880
+ 💡 **Recommendation:** Extract shared styles to library
881
+
882
+ **3. Multiple apps share classes:**
883
+
884
+ ```scss
885
+ // customer-app
886
+ .btn-primary { ... }
887
+
888
+ // admin-app
889
+ .btn-primary { ... } // Duplicate!
890
+ ```
891
+
892
+ 💡 **Recommendation:** Move to shared library
893
+
894
+ ### Quick Start
895
+
896
+ ```bash
897
+ # 1. Create config
898
+ cat > multi-app.json << EOF
899
+ {
900
+ "apps": [
901
+ { "name": "app1", "path": "./apps/app1/src" },
902
+ { "name": "app2", "path": "./apps/app2/src" }
903
+ ],
904
+ "sharedLibraries": [
905
+ { "name": "fluffySubby", "path": "./libs/lib1", "isSubmodule": true }
906
+ ]
907
+ }
908
+ EOF
909
+
910
+ # 2. Analyze
911
+ npx scss-extract analyze-dependencies --config multi-app.json
912
+
913
+ # 3. Follow recommendations
914
+ ```
915
+
916
+ ---
917
+
647
918
  ## Configuration
648
919
 
649
920
  Create a `.scssextractrc.json` file in your project root:
@@ -931,6 +1202,34 @@ MIT License - see [LICENSE](./LICENSE) file for details
931
1202
 
932
1203
  ## Changelog
933
1204
 
1205
+ ### 1.9.0 (2026-02-12)
1206
+
1207
+ - **Added:** 🎨 Automatic color extraction from existing app styles
1208
+ - **Added:** `extractColorPalettes()` function to intelligently select primary, accent, and warn colors
1209
+ - **Added:** Smart red hue detection for warn color selection
1210
+ - **Enhanced:** `generate-themes --analyze` now uses actual app colors instead of Material defaults
1211
+ - **Enhanced:** Gray shade filtering to exclude utility colors
1212
+ - **Enhanced:** Automatic dark theme variant generation (lightens colors for dark mode)
1213
+ - **Added:** Color normalization (hex3 → hex6, rgba → hex)
1214
+ - **Added:** Usage-based color ranking (most-used = primary, etc.)
1215
+ - **Documented:** Comprehensive color extraction examples in THEME-GUIDE.md
1216
+ - **Tested:** 12 new tests for color extraction (144 total tests passing)
1217
+
1218
+ ### 1.8.0 (2026-02-12)
1219
+
1220
+ - **Added:** `analyze-dependencies` command for multi-app dependency analysis
1221
+ - **Added:** Support for analyzing monorepos and multi-repo setups
1222
+ - **Added:** Git submodule detection and analysis
1223
+ - **Added:** Cross-app style dependency detection
1224
+ - **Added:** Dependency graph visualization
1225
+ - **Added:** Circular dependency detection
1226
+ - **Added:** Shared style identification across apps
1227
+ - **Added:** Organization recommendations based on app relationships
1228
+ - **Added:** Multi-app configuration file support
1229
+ - **Improved:** Better understanding of which app relies on which
1230
+ - **Improved:** Automatic detection of shared vs app-specific styles
1231
+ - **Documented:** Comprehensive guide for fluffySubby library and unified app scenarios
1232
+
934
1233
  ### 1.7.0 (2026-02-12)
935
1234
 
936
1235
  - **Added:** `generate-themes` command for automatic dark/light theme structure generation