Created
September 9, 2025 10:16
-
-
Save AndrewDongminYoo/4eabee19398604634040f52452533444 to your computer and use it in GitHub Desktop.
Recursively compiles all '*.module.scss' files under directory into sibling '*.module.css' files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:io'; | |
| import 'package:path/path.dart' as p; | |
| import 'package:sass/sass.dart' as sass; | |
| /// Recursively compiles all `*.module.scss` files under directory into sibling `*.module.css` files. | |
| void main(List<String> arguments) { | |
| final src = arguments[0]; | |
| final srcDir = Directory('$src'); | |
| if (!srcDir.existsSync()) { | |
| stderr.writeln('$src directory not found: ${p.normalize(srcDir.path)}'); | |
| exitCode = 1; | |
| return; | |
| } | |
| final scssFiles = srcDir | |
| .listSync(recursive: true, followLinks: false) | |
| .whereType<File>() | |
| .where((f) => f.path.endsWith('.module.scss')) | |
| .toList(); | |
| if (scssFiles.isEmpty) { | |
| stdout.writeln('No .module.scss files found under $src/.'); | |
| return; | |
| } | |
| var success = 0; | |
| var failed = 0; | |
| var removed = 0; | |
| for (final file in scssFiles) { | |
| final inputPath = p.normalize(file.path); | |
| final outputPath = inputPath.replaceFirst(RegExp(r'\.module\.scss$'), '.module.css'); | |
| try { | |
| final result = sass.compileToResult(inputPath); | |
| File(outputPath).writeAsStringSync(result.css); | |
| stdout.writeln('Compiled: ${p.relative(inputPath)} → ${p.relative(outputPath)}'); | |
| success++; | |
| try { | |
| file.deleteSync(); | |
| removed++; | |
| stdout.writeln('Removed source: ${p.relative(inputPath)}'); | |
| } catch (e) { | |
| stderr.writeln('Warning: could not remove ${p.relative(inputPath)} — $e'); | |
| } | |
| } catch (e) { | |
| stderr.writeln('Failed: ${p.relative(inputPath)} — $e'); | |
| failed++; | |
| } | |
| } | |
| stdout.writeln('Done. Success: $success, Failed: $failed, Removed: $removed'); | |
| exitCode = failed > 0 ? 1 : 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment