-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathgrind.dart
95 lines (81 loc) · 2.56 KB
/
grind.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:grinder/grinder.dart';
import 'package:http/http.dart' as http;
void main(List<String> args) => grind(args);
@Task('Check plugin URLs for live-ness')
void checkUrls() async {
log('checking URLs in FlutterBundle.properties...');
var lines =
await File(
'flutter-idea/src/io/flutter/FlutterBundle.properties',
).readAsLines();
for (var line in lines) {
var split = line.split('=');
if (split.length == 2) {
// flutter.io.gettingStarted.url | flutter.analytics.privacyUrl
if (split[0].toLowerCase().endsWith('url')) {
var url = split[1];
var response = await http.get(Uri.parse(url));
log('checking: $url...');
if (response.statusCode != 200) {
fail(
'$url GET failed: [${response.statusCode}] ${response.reasonPhrase}',
);
}
}
}
}
log('OK!');
}
@Task('Create Outline view icons from svgs')
void outlineIcons() async {
Directory previewIconsDir = getDir('resources/icons/preview');
log('using svgexport (npm install -g svgexport)');
for (File file in previewIconsDir
.listSync()
.whereType<File>()
.cast<File>()
.where((file) => file.path.endsWith('.svg'))) {
log('processing ${file.path}...');
String name = fileName(file);
name = name.substring(0, name.indexOf('.'));
_createPng(file, '$name.png', size: 24, forLight: true);
_createPng(file, '[email protected]', size: 48, forLight: true);
_createPng(file, '${name}_dark.png', size: 24, forLight: false);
_createPng(file, '$name@2x_dark.png', size: 48, forLight: false);
}
}
void _createPng(
File sourceSvg,
String targetName, {
required int? size,
bool forLight = false,
}) {
File targetFile = joinFile(sourceSvg.parent, [targetName]);
String color = forLight ? '#7a7a7a' : '#9e9e9e';
String originalContent = sourceSvg.readAsStringSync();
String newContent = originalContent.replaceAll(
'<svg ',
'<svg fill="$color" ',
);
sourceSvg.writeAsStringSync(newContent);
try {
ProcessResult result = Process.runSync('svgexport', [
sourceSvg.path,
targetFile.path,
'100%',
'$size:$size',
]);
if (result.exitCode != 0) {
print(
'Error resizing image with imagemagick: ${result.stdout}\n${result.stderr}',
);
exit(1);
}
} finally {
sourceSvg.writeAsStringSync(originalContent);
}
}