scss-variable-extractor 1.9.1 → 2.0.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.
package/README.md CHANGED
@@ -43,54 +43,154 @@ cd scss-variable-extractor
43
43
  npm install
44
44
  ```
45
45
 
46
+ ## ⚡ Minimal Example
47
+
48
+ **Got an Angular project? Generate a theme in one command:**
49
+
50
+ ```bash
51
+ cd my-angular-app
52
+ npx scss-extract generate-themes --analyze
53
+ ```
54
+
55
+ That's it! The tool:
56
+
57
+ - ✅ Finds your Angular project from `angular.json`
58
+ - ✅ Scans your SCSS files
59
+ - ✅ Extracts your app's actual colors
60
+ - ✅ Generates complete dark/light theme structure
61
+ - ✅ Places files in the right location
62
+
63
+ No configuration needed! 🎉
64
+
46
65
  ## Quick Start
47
66
 
48
- > **💡 Tip:** If you have an `angular.json` file, you can omit the source path - the tool will auto-detect your project structure!
67
+ > **� Zero Config:** If you have an `angular.json` file, just run the commands without any arguments - the tool automatically detects your project structure, source directories, and output paths!
49
68
 
50
69
  ### 1. Analyze (Dry Run)
51
70
 
52
71
  See what values would be extracted without modifying any files:
53
72
 
54
73
  ```bash
55
- # With angular.json (auto-detects project)
74
+ # Auto-detects everything from angular.json
56
75
  npx scss-extract analyze
57
76
 
58
77
  # Or specify path manually
59
78
  npx scss-extract analyze ./apps/subapp/src --threshold 2
60
79
  ```
61
80
 
62
- ### 2. Generate Variables File
81
+ ### 2. Generate Theme Structure (Most Used!)
82
+
83
+ Generate a complete dark/light theme with colors extracted from your app:
84
+
85
+ ```bash
86
+ # Auto-detects project and extracts YOUR colors! ✨
87
+ npx scss-extract generate-themes --analyze
88
+
89
+ # Without color extraction (uses Material defaults)
90
+ npx scss-extract generate-themes
91
+ ```
92
+
93
+ ### 3. Generate Variables File
63
94
 
64
95
  Create a `_variables.scss` file with extracted variables:
65
96
 
66
97
  ```bash
67
- # With angular.json
98
+ # Auto-detects project ✨
68
99
  npx scss-extract generate
69
100
 
70
101
  # Or specify paths manually
71
102
  npx scss-extract generate ./apps/subapp/src --output ./libs/styles/_variables.scss
72
103
  ```
73
104
 
74
- ### 3. Full Refactoring
105
+ ### 4. Full Refactoring
75
106
 
76
107
  Generate variables file AND replace hardcoded values in all SCSS files:
77
108
 
78
109
  ```bash
110
+ # Auto-detects project ✨
111
+ npx scss-extract refactor
112
+
113
+ # Or specify paths manually
79
114
  npx scss-extract refactor ./apps/subapp/src --output ./libs/styles/_variables.scss
80
115
  ```
81
116
 
82
- ### 4. Modernize Code (Remove Anti-Patterns)
117
+ ### 5. Modernize Code (Remove Anti-Patterns)
83
118
 
84
119
  Remove `::ng-deep` and `!important` following Angular Material v15+ best practices:
85
120
 
86
121
  ```bash
87
- # Preview changes first
88
- npx scss-extract modernize ./src --dry-run
122
+ # Preview changes first (auto-detects project) ✨
123
+ npx scss-extract modernize --dry-run
89
124
 
90
125
  # Apply modernization
91
- npx scss-extract modernize ./src
126
+ npx scss-extract modernize
127
+ ```
128
+
129
+ ## 🔧 Angular.json Integration
130
+
131
+ The tool **automatically detects and uses your Angular project structure** from `angular.json`. This means you can run commands **without specifying any paths**!
132
+
133
+ ### How It Works
134
+
135
+ When you run a command (like `generate-themes --analyze`), the tool:
136
+
137
+ 1. **Finds angular.json** in your current directory
138
+ 2. **Detects your project** (uses default project or specify with `--project`)
139
+ 3. **Auto-discovers:**
140
+ - ✅ Source directory (`src/app`, etc.)
141
+ - ✅ Global styles location (`src/styles.scss`)
142
+ - ✅ Output path for generated files
143
+ - ✅ Style preprocessor (scss, sass, css)
144
+ - ✅ Project prefix and configuration
145
+
146
+ ### Example
147
+
148
+ Instead of:
149
+
150
+ ```bash
151
+ # ❌ Manual paths - tedious!
152
+ npx scss-extract generate-themes ./apps/my-app/src --output ./apps/my-app/src/styles
153
+ ```
154
+
155
+ Just run:
156
+
157
+ ```bash
158
+ # ✅ Auto-detects everything!
159
+ npx scss-extract generate-themes --analyze
160
+ ```
161
+
162
+ ### Multi-Project Workspaces
163
+
164
+ If you have multiple projects in your Angular workspace:
165
+
166
+ ```bash
167
+ # Use specific project
168
+ npx scss-extract generate-themes --analyze --project my-app
169
+
170
+ # Use default project (auto-detected)
171
+ npx scss-extract generate-themes --analyze
172
+ ```
173
+
174
+ ### Disable Auto-Detection
175
+
176
+ If you want to use manual paths instead:
177
+
178
+ ```bash
179
+ npx scss-extract generate-themes ./src --output ./src/styles --no-angular
92
180
  ```
93
181
 
182
+ ### All Commands Support angular.json
183
+
184
+ Every command works with angular.json integration:
185
+
186
+ - `analyze`
187
+ - `generate`
188
+ - `refactor`
189
+ - `modernize`
190
+ - `generate-themes` ⭐
191
+ - `detect-bootstrap`
192
+ - `migrate-bootstrap`
193
+
94
194
  ## CLI Commands
95
195
 
96
196
  ### `analyze` - Dry-run Analysis
@@ -573,13 +673,66 @@ npx scss-extract generate-themes ./src --output ./src/styles --analyze
573
673
  **Example Usage:**
574
674
 
575
675
  ```bash
576
- # Generate theme structure with default Material colors
577
- npx scss-extract generate-themes --output ./src/styles
676
+ # 🚀 SIMPLEST: Auto-detects everything from angular.json and extracts YOUR colors!
677
+ npx scss-extract generate-themes --analyze
678
+
679
+ # Without color extraction (uses Material Design defaults)
680
+ npx scss-extract generate-themes
578
681
 
579
- # 🎨 Analyze existing styles and use YOUR app's colors
682
+ # Manual paths (if no angular.json)
580
683
  npx scss-extract generate-themes ./src --analyze --output ./src/styles
581
684
  ```
582
685
 
686
+ **Output Example:**
687
+
688
+ When you run with `--analyze`, you'll see:
689
+
690
+ ```
691
+ 🎨 Theme Structure Generator
692
+
693
+ 📦 Angular Project: my-app
694
+ Prefix: app
695
+ Style: scss
696
+ Source: src/app
697
+
698
+ 🔍 Analyzing styles in: src/app
699
+
700
+ Found 47 SCSS files
701
+
702
+ 📊 Theme Readiness Analysis:
703
+
704
+ Total hardcoded colors: 156
705
+ Unique colors: 12
706
+ Components needing theme mixins: 8
707
+
708
+ 🎨 Extracted Color Palettes:
709
+
710
+ Primary Color:
711
+ Light theme: #007bff
712
+ Dark theme: #66b0ff
713
+
714
+ Accent Color:
715
+ Light theme: #28a745
716
+ Dark theme: #74d77c
717
+
718
+ Warn Color:
719
+ Light theme: #dc3545
720
+ Dark theme: #dc3545
721
+
722
+ 📁 Output directory: src/styles
723
+
724
+ ✓ Using extracted colors from your app
725
+
726
+ ✓ Created _theme-base.scss
727
+ ✓ Created _theme-light.scss
728
+ ✓ Created _theme-dark.scss
729
+ ✓ Created themes.scss
730
+ ✓ Created _css-variables.scss
731
+ ✓ Created _component-theme-mixin.scss
732
+
733
+ ✓ Theme structure generated!
734
+ ```
735
+
583
736
  **How Color Extraction Works:**
584
737
 
585
738
  When you use `--analyze`, the tool:
@@ -1202,6 +1355,38 @@ MIT License - see [LICENSE](./LICENSE) file for details
1202
1355
 
1203
1356
  ## Changelog
1204
1357
 
1358
+ ### 2.0.0 (2026-02-12) - Zero Config Release 🚀
1359
+
1360
+ **BREAKING CHANGES:**
1361
+
1362
+ - `generate-themes --output` default removed (now auto-detected from angular.json)
1363
+
1364
+ **Major Improvements:**
1365
+
1366
+ - **🎉 Zero Configuration:** All commands now fully leverage angular.json integration
1367
+ - **✨ Auto-Detection:** `generate-themes` automatically finds source directory and output path
1368
+ - **📦 Smart Project Detection:** Shows Angular project info (name, prefix, style preprocessor)
1369
+ - **🔧 Simplified Usage:** Just run `npx scss-extract generate-themes --analyze` - no arguments needed!
1370
+ - **📚 Comprehensive Documentation:** New angular.json integration guide
1371
+ - **⚡ Minimal Example:** Added quick-start section showing one-command theme generation
1372
+ - **🎯 Better UX:** Clearer console output with project context and file counts
1373
+ - **💡 Helpful Tips:** Shows suggestions when auto-detection features aren't used
1374
+
1375
+ **Enhanced Commands:**
1376
+
1377
+ - `generate-themes` now accepts `--angular-json`, `--project`, `--no-angular` options
1378
+ - Auto-detects output directory from global styles configuration
1379
+ - Shows Angular project metadata in output
1380
+ - Provides context-aware help messages
1381
+
1382
+ **Documentation:**
1383
+
1384
+ - Added "Minimal Example" section showing simplest usage
1385
+ - Added "Angular.json Integration" section explaining auto-detection
1386
+ - Updated all examples to show angular.json usage first
1387
+ - Improved THEME-GUIDE.md with zero-config examples
1388
+ - Added output examples showing what users will see
1389
+
1205
1390
  ### 1.9.0 (2026-02-12)
1206
1391
 
1207
1392
  - **Added:** 🎨 Automatic color extraction from existing app styles
package/THEME-GUIDE.md CHANGED
@@ -101,8 +101,25 @@ This ensures only your **brand colors** are selected for theme palettes.
101
101
 
102
102
  Generate a complete theme structure for your Angular Material app:
103
103
 
104
+ ### With angular.json (Recommended - Zero Config!)
105
+
106
+ ```bash
107
+ # 🚀 Auto-detects everything and extracts YOUR app's colors!
108
+ npx scss-extract generate-themes --analyze
109
+ ```
110
+
111
+ That's it! The tool automatically:
112
+
113
+ - ✅ Finds your Angular project from angular.json
114
+ - ✅ Detects source directory
115
+ - ✅ Places theme files in your styles folder
116
+ - ✅ Extracts actual colors from your app
117
+ - ✅ Generates dark/light theme variants
118
+
119
+ ### Without angular.json (Manual Paths)
120
+
104
121
  ```bash
105
- # Analyze existing styles and generate themes
122
+ # Specify paths manually
106
123
  npx scss-extract generate-themes ./src --analyze --output ./src/styles
107
124
  ```
108
125
 
package/bin/cli.js CHANGED
@@ -694,58 +694,102 @@ program
694
694
  program
695
695
  .command('generate-themes')
696
696
  .description('Generate theme structure for dark/light mode support with Angular Material')
697
- .argument('[src]', 'Source directory to scan for analysis (optional)')
698
- .option('--output <dir>', 'Output directory for theme files', './src/styles')
699
- .option('--analyze', 'Analyze existing styles for theme readiness')
697
+ .argument('[src]', 'Source directory to scan for analysis (optional if using angular.json)')
698
+ .option('--output <dir>', 'Output directory for theme files (auto-detected from angular.json)')
699
+ .option('--analyze', 'Analyze existing styles and extract colors from your app')
700
700
  .option('--format <format>', 'Report format (table, json, markdown)', 'table')
701
+ .option('--angular-json <path>', 'Path to angular.json file')
702
+ .option('--project <name>', 'Angular project name (uses default if not specified)')
703
+ .option('--no-angular', 'Disable angular.json integration')
701
704
  .action(async (src, options) => {
702
705
  try {
703
706
  console.log(chalk.cyan.bold('\n🎨 Theme Structure Generator\n'));
704
707
 
705
708
  const fs = require('fs');
706
- const outputDir = path.resolve(options.output);
709
+
710
+ // Load config with angular.json integration
711
+ const config = loadConfig(null, {
712
+ useAngularJson: options.angular !== false,
713
+ angularJsonPath: options.angularJson,
714
+ projectName: options.project,
715
+ });
716
+
717
+ // Override with command-line options
718
+ if (src) {
719
+ config.src = src;
720
+ }
721
+
722
+ // Determine output directory
723
+ let outputDir;
724
+ if (options.output) {
725
+ outputDir = path.resolve(options.output);
726
+ } else if (config.angular && config.output) {
727
+ // Use the styles directory from angular.json
728
+ outputDir = path.resolve(path.dirname(config.output));
729
+ } else {
730
+ outputDir = path.resolve('./src/styles');
731
+ }
732
+
733
+ // Show Angular project info if available
734
+ if (config.angular) {
735
+ console.log(chalk.cyan(`📦 Angular Project: ${config.angular.project}`));
736
+ console.log(chalk.gray(` Prefix: ${config.angular.prefix}`));
737
+ console.log(chalk.gray(` Style: ${config.angular.stylePreprocessor}`));
738
+ console.log(chalk.gray(` Source: ${config.src}\n`));
739
+ }
740
+
707
741
  let extractedPalettes = null;
708
742
 
709
743
  // Analyze existing styles if requested
710
- if (options.analyze && src) {
711
- console.log(chalk.gray(`Analyzing: ${src}\n`));
712
- const config = loadConfig();
713
- const files = await scanScssFiles(src, config.ignore);
714
- const analysis = analyzeThemeReadiness(files);
715
-
716
- console.log(chalk.blue.bold('Theme Readiness Analysis:\n'));
717
- console.log(chalk.gray(`Total hardcoded colors: ${analysis.hardcodedColors.length}`));
718
- console.log(chalk.gray(`Unique colors: ${analysis.colorUsage.size}`));
719
- console.log(
720
- chalk.gray(`Components needing theme mixins: ${analysis.themeableComponents.length}\n`)
721
- );
744
+ if (options.analyze) {
745
+ const scanDir = config.src || './src';
746
+ console.log(chalk.gray(`🔍 Analyzing styles in: ${scanDir}\n`));
722
747
 
723
- // Extract color palettes from usage
724
- extractedPalettes = extractColorPalettes(analysis.colorUsage);
725
-
726
- console.log(chalk.green.bold('🎨 Extracted Color Palettes:\n'));
727
- console.log(chalk.cyan('Primary Color:'));
728
- console.log(chalk.gray(` Light theme: ${extractedPalettes.primary.light}`));
729
- console.log(chalk.gray(` Dark theme: ${extractedPalettes.primary.dark}`));
730
- console.log(chalk.cyan('Accent Color:'));
731
- console.log(chalk.gray(` Light theme: ${extractedPalettes.accent.light}`));
732
- console.log(chalk.gray(` Dark theme: ${extractedPalettes.accent.dark}`));
733
- console.log(chalk.cyan('Warn Color:'));
734
- console.log(chalk.gray(` Light theme: ${extractedPalettes.warn.light}`));
735
- console.log(chalk.gray(` Dark theme: ${extractedPalettes.warn.dark}\n`));
736
-
737
- if (analysis.recommendations.length > 0) {
738
- console.log(chalk.yellow.bold('📋 Recommendations:\n'));
739
- analysis.recommendations.forEach(rec => {
740
- const icon = rec.priority === 'high' ? '🔴' : '🟡';
741
- console.log(chalk.gray(`${icon} ${rec.message}`));
742
- });
743
- console.log();
748
+ const files = await scanScssFiles(scanDir, config.ignore);
749
+
750
+ if (files.length === 0) {
751
+ console.log(chalk.yellow('⚠ No SCSS files found. Using default Material colors.\n'));
752
+ } else {
753
+ console.log(chalk.gray(` Found ${files.length} SCSS files\n`));
754
+
755
+ const analysis = analyzeThemeReadiness(files);
756
+
757
+ console.log(chalk.blue.bold('📊 Theme Readiness Analysis:\n'));
758
+ console.log(chalk.gray(` Total hardcoded colors: ${analysis.hardcodedColors.length}`));
759
+ console.log(chalk.gray(` Unique colors: ${analysis.colorUsage.size}`));
760
+ console.log(
761
+ chalk.gray(
762
+ ` Components needing theme mixins: ${analysis.themeableComponents.length}\n`
763
+ )
764
+ );
765
+
766
+ // Extract color palettes from usage
767
+ extractedPalettes = extractColorPalettes(analysis.colorUsage);
768
+
769
+ console.log(chalk.green.bold('🎨 Extracted Color Palettes:\n'));
770
+ console.log(chalk.cyan('Primary Color:'));
771
+ console.log(chalk.gray(` Light theme: ${extractedPalettes.primary.light}`));
772
+ console.log(chalk.gray(` Dark theme: ${extractedPalettes.primary.dark}`));
773
+ console.log(chalk.cyan('Accent Color:'));
774
+ console.log(chalk.gray(` Light theme: ${extractedPalettes.accent.light}`));
775
+ console.log(chalk.gray(` Dark theme: ${extractedPalettes.accent.dark}`));
776
+ console.log(chalk.cyan('Warn Color:'));
777
+ console.log(chalk.gray(` Light theme: ${extractedPalettes.warn.light}`));
778
+ console.log(chalk.gray(` Dark theme: ${extractedPalettes.warn.dark}\n`));
779
+
780
+ if (analysis.recommendations.length > 0) {
781
+ console.log(chalk.yellow.bold('📋 Recommendations:\n'));
782
+ analysis.recommendations.forEach(rec => {
783
+ const icon = rec.priority === 'high' ? '🔴' : '🟡';
784
+ console.log(chalk.gray(` ${icon} ${rec.message}`));
785
+ });
786
+ console.log();
787
+ }
744
788
  }
745
789
  }
746
790
 
747
791
  // Generate theme files
748
- console.log(chalk.gray(`Generating theme files in: ${outputDir}\n`));
792
+ console.log(chalk.gray(`📁 Output directory: ${outputDir}\n`));
749
793
 
750
794
  const themeOptions = {
751
795
  outputDir,
@@ -757,11 +801,8 @@ program
757
801
  themeOptions.themePalettes = extractedPalettes;
758
802
  console.log(chalk.green('✓ Using extracted colors from your app\n'));
759
803
  } else {
760
- console.log(
761
- chalk.yellow(
762
- 'ℹ Using default Material Design colors (use --analyze to extract from your app)\n'
763
- )
764
- );
804
+ console.log(chalk.yellow('ℹ Using default Material Design colors\n'));
805
+ console.log(chalk.gray(' 💡 Tip: Use --analyze to extract colors from your app\n'));
765
806
  }
766
807
 
767
808
  const themeStructure = generateThemeStructure(themeOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scss-variable-extractor",
3
- "version": "1.9.1",
3
+ "version": "2.0.1",
4
4
  "description": "Analyzes Angular SCSS files and extracts repeated hardcoded values into reusable variables",
5
5
  "bin": {
6
6
  "scss-extract": "./bin/cli.js"