@rolandjlevy/css-ghost 1.0.1 → 1.0.2

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
@@ -4,7 +4,7 @@ Find orphaned CSS class selectors in your codebase — defined in style files bu
4
4
 
5
5
  ## What it does
6
6
 
7
- Scans one or more directories for style files, extracts every class selector defined, then cross-references them against usages in your component files. Anything defined but never used is reported as an orphan.
7
+ Scans one or more directories for style files, extracts every class selector defined, then cross-references them against usages in your component files. Anything defined but never used is reported as an orphan — with its line number and the actual CSS printed inline.
8
8
 
9
9
  **Supported style files:**
10
10
  - `.css`, `.module.css`, `.scss`, `.sass`, `.less`
@@ -22,13 +22,13 @@ Files containing `styles[variable]` or template literal class names are flagged
22
22
  ## Install
23
23
 
24
24
  ```bash
25
- npm install -g css-ghost
25
+ npm install -g @rolandjlevy/css-ghost
26
26
  ```
27
27
 
28
- Or run directly without installing:
28
+ Or run without installing:
29
29
 
30
30
  ```bash
31
- npx css-ghost ./src
31
+ npx @rolandjlevy/css-ghost ./src
32
32
  ```
33
33
 
34
34
  ## Usage
@@ -47,44 +47,95 @@ css-ghost <directory> [directory2] ... [options]
47
47
  ## Examples
48
48
 
49
49
  ```bash
50
- # Scan a single directory
50
+ # Scan your src folder
51
51
  css-ghost ./src
52
52
 
53
53
  # Scan multiple directories
54
54
  css-ghost ./src ./components ./pages
55
55
 
56
- # Custom output path
56
+ # Write report to a custom path
57
57
  css-ghost ./src --output ./reports/css-audit.md
58
58
  ```
59
59
 
60
- ## Output
60
+ ## CLI output
61
61
 
62
- Generates a markdown report (`orphan-report.md` by default):
62
+ Running `css-ghost ./src` prints a live summary to your terminal:
63
+
64
+ ```
65
+ ✅ Report written to orphan-report.md
66
+ 📊 3 orphaned selectors across 1 file
67
+
68
+ 📄 src/components/Button/Button.module.css
69
+ 👻 .iconLeft (line 4)
70
+ .iconLeft {
71
+ margin-right: 6px;
72
+ flex-shrink: 0;
73
+ }
74
+
75
+ 👻 .loadingSpinner (line 12)
76
+ .loadingSpinner {
77
+ animation: spin 0.8s linear infinite;
78
+ }
79
+
80
+ 👻 .disabled (line 18)
81
+ .disabled {
82
+ opacity: 0.4;
83
+ pointer-events: none;
84
+ }
85
+
86
+ 📁 1 style file scanned
87
+ ```
88
+
89
+ Each orphan shows:
90
+ - the selector name and the **exact line number** where it's defined
91
+ - the **full CSS rule** so you can see what it does before deciding to delete it
92
+
93
+ ## Markdown report
94
+
95
+ A full report is also written to `orphan-report.md` (or your `--output` path):
63
96
 
64
97
  ---
65
98
 
66
- # 👻 css-ghost — Orphaned Selector Report
99
+ ### 👻 Orphaned selectors
67
100
 
68
- ## Summary
69
- | Metric | Value |
70
- | --- | --- |
71
- | Style files scanned | 12 |
72
- | Total selectors defined | 84 |
73
- | Total orphaned selectors | 7 |
74
- | Files with orphans | 3 |
75
- | Overall unused rate | 8% |
101
+ #### `.iconLeft` — line 4
76
102
 
77
- ## `src/components/Button/Button.module.css`
78
- | Defined | Orphaned | Unused % |
79
- | --- | --- | --- |
80
- | 6 | 2 | 33% |
103
+ ```css
104
+ .iconLeft {
105
+ margin-right: 6px;
106
+ flex-shrink: 0;
107
+ }
108
+ ```
81
109
 
82
- **Orphaned selectors:**
83
- - `.iconLeft`
84
- - `.loadingSpinner`
110
+ #### `.loadingSpinner` — line 12
111
+
112
+ ```css
113
+ .loadingSpinner {
114
+ animation: spin 0.8s linear infinite;
115
+ }
116
+ ```
85
117
 
86
118
  ---
87
119
 
120
+ ## Using with npm scripts
121
+
122
+ If you're working inside the project itself, add a `scan` script to `package.json`:
123
+
124
+ ```json
125
+ "scripts": {
126
+ "scan": "css-ghost ./src"
127
+ }
128
+ ```
129
+
130
+ Then run:
131
+
132
+ ```bash
133
+ npm run scan
134
+
135
+ # Pass extra args with --
136
+ npm run scan -- --output ./reports/audit.md
137
+ ```
138
+
88
139
  ## No dependencies
89
140
 
90
141
  Built with Node.js built-ins only (`fs`, `path`). No npm packages required.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@rolandjlevy/css-ghost",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Find orphaned CSS class selectors in your codebase",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "css-ghost": "bin/css-ghost.js"
8
8
  },
9
9
  "scripts": {
10
- "start": "node bin/css-ghost.js"
10
+ "start": "node bin/css-ghost.js",
11
+ "scan": "node bin/css-ghost.js ./test"
11
12
  },
12
13
  "files": [
13
14
  "bin",
package/src/reporter.js CHANGED
@@ -89,13 +89,12 @@ export function generateReport(results, outputPath = 'orphan-report.md') {
89
89
  writeFileSync(outputPath, content, 'utf-8');
90
90
 
91
91
  // Console output — also print orphans inline
92
- console.log(`✅ Report written to ${outputPath}`);
93
- console.log(`📊 ${totalOrphaned} orphaned selector${totalOrphaned !== 1 ? 's' : ''} across ${filesWithOrphans} file${filesWithOrphans !== 1 ? 's' : ''}\n`);
92
+ console.log(`📊 ${totalOrphaned} orphaned selector${totalOrphaned !== 1 ? 's' : ''} in ${filesWithOrphans} file${filesWithOrphans !== 1 ? 's' : ''}. See: ${outputPath}\n`);
94
93
 
95
94
  for (const result of results) {
96
95
  if (result.orphaned.length === 0) continue;
97
96
  const relPath = relative(process.cwd(), result.filePath);
98
- console.log(`📄 ${relPath}`);
97
+ console.log(`✅ ${relPath}\n`);
99
98
  result.orphaned.forEach(({ name, line, rule }) => {
100
99
  console.log(` 👻 .${name} (line ${line})`);
101
100
  if (rule) {
@@ -105,6 +104,4 @@ export function generateReport(results, outputPath = 'orphan-report.md') {
105
104
  console.log('');
106
105
  });
107
106
  }
108
-
109
- console.log(`📁 ${results.length} style file${results.length !== 1 ? 's' : ''} scanned\n`);
110
107
  }