-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.dart
74 lines (60 loc) · 1.69 KB
/
build.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
import 'dart:convert';
import 'dart:io';
const String lastYear = '1983';
const String firstYear = '1982';
void main() async {
final last = readResopurce('./resources/$lastYear.json');
final first = readResopurce('./resources/$firstYear.json');
// last 相较于 first
Map added = {};
Map nameChanged = {};
for (var element in last.entries) {
if (first.containsKey(element.key) && last.containsKey(element.key)) {
if (first[element.key] != last[element.key]) {
nameChanged['${element.key} <> ${first[element.key]}'] =
last[element.key];
continue;
}
}
if (!first.containsKey(element.key)) {
added[element.key] = element.value;
}
}
final removed = {};
for (var element in first.entries) {
if (!last.containsKey(element.key)) {
removed[element.key] = element.value;
}
}
// 写入到 diff 文件
final file = File('./diff2.txt');
String changedString = '';
String addedString = '';
String removedString = '';
for (var element in nameChanged.entries) {
changedString += '${element.key} > ${element.value}\n';
}
for (var element in added.entries) {
addedString += '${element.key} <> ${element.value}\n';
}
for (var element in removed.entries) {
removedString += '${element.key} <> ${element.value}\n';
}
await file.writeAsString('''
====== $lastYear 相较于 $firstYear ======
改名的:
$changedString
==============
新增的:
$addedString
==============
移除的:
$removedString
''');
}
// Read file and parse it as a JSON object.
Map<String, dynamic> readResopurce(String path) {
final File file = File(path);
// return {};
return json.decode(file.readAsStringSync());
}