Chromium Code Reviews| Index: main.dart |
| diff --git a/main.dart b/main.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..27a9e4377a807c02c480852875e34742f142cd95 |
| --- /dev/null |
| +++ b/main.dart |
| @@ -0,0 +1,58 @@ |
| +import "dart:io"; |
| +import "dart:async"; |
| + |
| +import '../discovery_api_dart_client_generator/lib/generator.dart'; |
| +import 'package:google_discovery_v1_api/discovery_v1_api_client.dart'; |
| +import 'package:yaml/yaml.dart'; |
| + |
| +main() { |
| + // Read the configuration. |
| + var config = loadYaml(new File('config.yaml').readAsStringSync()); |
|
kustermann
2014/08/18 09:32:03
You could use Platform.script, so we can call this
Søren Gjesse
2014/08/18 11:10:45
Done.
|
| + var pkgs = config['packages']; |
| + var packages = {}; |
| + var supportedApis = []; |
| + var knownApis = []; |
| + pkgs.forEach((pkg) { |
| + pkg.forEach((name, values) { |
| + packages[name] = values != null ? values : []; |
| + }); |
| + }); |
| + var skippedApis = config['skipped_apis']; |
| + packages.forEach((_, values) => supportedApis.addAll(values)); |
| + knownApis.addAll(supportedApis); |
| + knownApis.addAll(skippedApis); |
| + |
| + // Check that all APIs are mentioned in the configuration. |
| + var missingApis = []; |
| + listAllApis().then((List<DirectoryListItems> items) { |
| + items.forEach((item) { |
| + if (!knownApis.contains(item.id)) missingApis.add(item.id); |
| + }); |
| + |
| + if (missingApis.isNotEmpty) { |
| + print('No configuration for the following APIs;'); |
| + missingApis.forEach((id) => print('- $id')); |
| + return; |
| + } |
| + |
| + // Delete downloaded discovery documents. |
| + packages.forEach((name, values) { |
| + var dir = new Directory('discovery'); |
| + if (dir.existsSync()) dir.deleteSync(recursive: true); |
| + }); |
|
kustermann
2014/08/18 09:32:03
There is no need for the forEach() loop here.
Søren Gjesse
2014/08/18 11:10:45
Of cause not.
|
| + |
| + // Download the discovery documents for the packages to build. |
| + var futures = []; |
| + packages.forEach((name, values) { |
| + futures.add(downloadDiscoveryDocuments('discovery/$name', ids: values)); |
| + }); |
| + |
| + Future.wait(futures).then((_) { |
| + packages.forEach((name, values) { |
| + print('Generating library $name'); |
| + generateAllLibraries('discovery/$name', 'generated/$name'); |
| + }); |
| + print('DONE'); |
| + }); |
| + }); |
| +} |