Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d83146f

Browse files
authoredOct 25, 2024··
Generate included css using sass (#3917)
1 parent 4d46129 commit d83146f

File tree

6 files changed

+1456
-120
lines changed

6 files changed

+1456
-120
lines changed
 

‎.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.dart text eol=lf
22
*.yaml text eol=lf
33

4+
lib/resources/styles.css linguist-generated=true
5+
46
# Don't collapse in github code reviews by default.
57
lib/src/version.dart linguist-generated=false
68
lib/src/html/resources.g.dart linguist-generated=false
@@ -10,6 +12,7 @@ lib/src/html/resources.g.dart linguist-generated=false
1012
# these files with `dart run tool/task.dart build`.
1113
lib/resources/docs.dart.js merge=theirs
1214
lib/resources/docs.dart.js.map merge=theirs
15+
lib/resources/styles.css merge=theirs
1316
lib/src/generator/templates.aot_renderers_for_html.dart merge=theirs
1417
lib/src/generator/templates.aot_renderers_for_md.dart merge=theirs
1518
lib/src/generator/templates.runtime_renderers.dart merge=theirs

‎lib/resources/styles.css

Lines changed: 89 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dev_dependencies:
2727
dart_style: ^2.3.7
2828
lints: ^5.0.0
2929
matcher: ^0.12.15
30+
sass: ^1.80.4
3031
test: ^1.24.2
3132
test_descriptor: ^2.0.1
3233
test_process: ^2.0.3

‎tool/task.dart

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:crypto/crypto.dart' as crypto;
1212
import 'package:dartdoc/src/io_utils.dart';
1313
import 'package:dartdoc/src/package_meta.dart';
1414
import 'package:path/path.dart' as path;
15+
import 'package:sass/sass.dart' as sass;
1516
import 'package:yaml/yaml.dart' as yaml;
1617
import 'package:yaml/yaml.dart';
1718

@@ -177,7 +178,15 @@ Future<void> buildWeb({bool debug = false}) async {
177178
]);
178179
_delete(File('lib/resources/docs.dart.js.deps'));
179180

180-
var compileSig = await _calcDartFilesSig(Directory('web'));
181+
final compileResult = sass.compileToResult('web/styles/styles.scss');
182+
if (compileResult.css.isNotEmpty) {
183+
File('lib/resources/styles.css').writeAsStringSync(compileResult.css);
184+
} else {
185+
throw StateError('Compiled CSS was empty.');
186+
}
187+
188+
var compileSig =
189+
await _calcFilesSig(Directory('web'), extensions: {'.dart', '.scss'});
181190
File(path.join('web', 'sig.txt')).writeAsStringSync('$compileSig\n');
182191
}
183192

@@ -189,14 +198,14 @@ void _delete(FileSystemEntity entity) {
189198
}
190199
}
191200

192-
/// Yields all of the trimmed lines of all of the `.dart` files in [dir].
193-
Stream<String> _dartFileLines(Directory dir) {
201+
/// Yields all of the trimmed lines of all of the files in [dir] with
202+
/// one of the specified [extensions].
203+
Stream<String> _fileLines(Directory dir, {required Set<String> extensions}) {
194204
var files = dir
195205
.listSync(recursive: true)
196206
.whereType<File>()
197-
.where((file) => file.path.endsWith('.dart'))
198-
.toList()
199-
..sort((a, b) => compareAsciiLowerCase(a.path, b.path));
207+
.where((file) => extensions.contains(path.extension(file.path)))
208+
.sorted((a, b) => compareAsciiLowerCase(a.path, b.path));
200209

201210
return Stream.fromIterable([
202211
for (var file in files)
@@ -824,11 +833,12 @@ Rebuild them with "dart tool/task.dart build" and check the results in.
824833
}
825834

826835
// Verify that the web frontend has been compiled.
827-
final currentCodeSig = await _calcDartFilesSig(Directory('web'));
836+
final currentSig =
837+
await _calcFilesSig(Directory('web'), extensions: {'.dart', '.scss'});
828838
final lastCompileSig =
829839
File(path.join('web', 'sig.txt')).readAsStringSync().trim();
830-
if (currentCodeSig != lastCompileSig) {
831-
print('current files: $currentCodeSig');
840+
if (currentSig != lastCompileSig) {
841+
print('current files: $currentSig');
832842
print('cached sig : $lastCompileSig');
833843
throw StateError(
834844
'The web frontend (web/docs.dart) needs to be recompiled; rebuild it '
@@ -985,8 +995,9 @@ int _findCount(String str, String match) {
985995
return count;
986996
}
987997

988-
Future<String> _calcDartFilesSig(Directory dir) async {
989-
final digest = await _dartFileLines(dir)
998+
Future<String> _calcFilesSig(Directory dir,
999+
{required Set<String> extensions}) async {
1000+
final digest = await _fileLines(dir, extensions: extensions)
9901001
.transform(utf8.encoder)
9911002
.transform(crypto.md5)
9921003
.single;

‎web/sig.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
A6336370D9A2C5AE421600C7D9356FC6
1+
3E2408ED7DD4454C55FBF018B65003E7

‎web/styles/styles.scss

Lines changed: 1340 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.