-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathvslaunch.dart
78 lines (67 loc) · 1.93 KB
/
vslaunch.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
import 'dart:convert';
import 'dart:io';
import 'utils.dart' as utils;
const List<String> desktopFilters = ['linux', 'windows'];
final webtype = 'web-javascript';
void main(List<String> args) async {
final result = await Process.run(
"flutter",
["devices"],
runInShell: Platform.isWindows,
).catchError((err) {
print(err.toString());
});
final List<String> raw = result.stdout.split('\n');
final splitter = Platform.isWindows ? '•' : '•';
final filteredDevices = raw
.map((String unparsed) => unparsed.split(splitter))
.toList()
.where((subList) => subList.length > 1);
final devices = filteredDevices.map((array) {
final String name = array[0].trim();
final String deviceId = array[1].trim();
final String deviceType = array[2].trim();
final Map<String, dynamic> obj = {
"name": name,
"deviceId": deviceId,
"type": 'dart',
"request": 'launch',
};
final desktopCheck = desktopFilters.indexWhere(
(str) => str.toLowerCase().contains(
deviceId.toLowerCase(),
),
);
if (desktopCheck == -1) {
obj["args"] = ['-t', 'lib/main.firebase.dart'];
if (deviceType == webtype) {
obj["args"] = ['-t', 'lib/main.firebase.dart'];
}
}
return obj;
});
final Map<String, dynamic> newConfig = {
'version': '1.0.0',
'configurations': ([
{
'name': 'Flutter',
'request': 'launch',
'type': 'dart',
},
...devices,
]),
'compounds': [
{
'name': 'current',
'configurations': devices.map((obj) => obj["name"]).toList(),
},
],
};
utils.mkDir('.vscode');
final vsConfig = new File('.vscode/launch.json');
// final encoded = json.encode(newConfig);
final JsonEncoder jsonEncoder = JsonEncoder.withIndent(' ');
final newJson = jsonEncoder.convert(newConfig);
vsConfig.writeAsStringSync(newJson);
print(devices);
}