How naganowl/postcss-squeaky-clean works
Project type and purpose
• This is an open-source Node.js tool (a PostCSS-based CSS/SCSS transformation library) whose purpose is to automate the transition from global SCSS stylesheets to localized CSS modules. It achieves this by exposing a series of plugins, helpers, and scripts that perform regex-based class-name rewrites, selector extraction, stylesheet flattening, and analytics of style usage.
File structure
• Top-level files
• Configuration: .eslintrc.js, .eslintignore, .gitignore, .npmignore, .travis.yml
• Documentation: README.md, API.md, docs/
• Examples: examples/
• Package manifest: package.json
• Core directories
• plugins/ – each JS file is a PostCSS plugin (analytics, clean, extract, flatten, heuristic, specificity)
• helpers/ – utility functions for file discovery, regex matching, shell invocation
• scripts/ – shell or Node scripts to orchestrate a full conversion run
• specs/ – test suite for each plugin
• Patterns and architecture
• Plugin architecture: each plugin encapsulates a single transformation phase (Phase 1 through Phase 4 described in README)
• Helper modules: share common filesystem logic, regex patterns, naming conventions
• Shell integration: spawned via helpers/run-shell.js to leverage UNIX tools for bulk find/replace
README for additional insights
• Phased migration architecture:
• Phase 1: Namespacing with regex-driven class rewrites
• Phase 2: Flattening SCSS nesting into CSS modules
• Phase 3: Heuristic analysis of selector usages
• Phase 4: Cleanup of legacy namespacing
• Emphasis on balancing performance vs. correctness by using RegExps and shell tools instead of full AST parsing
• Public API surface documented in API.md; examples in examples/