Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 import "dart:io"; | 1 import "dart:io"; |
| 2 import "dart:async"; | 2 import "dart:async"; |
| 3 | 3 |
| 4 import '../discovery_api_dart_client_generator/lib/generator.dart'; | 4 import '../discovery_api_dart_client_generator/lib/generator.dart'; |
| 5 import 'package:google_discovery_v1_api/discovery_v1_api_client.dart'; | 5 import 'package:google_discovery_v1_api/discovery_v1_api_client.dart'; |
| 6 import 'package:yaml/yaml.dart'; | 6 import 'package:yaml/yaml.dart'; |
| 7 | 7 |
| 8 class Package { | |
| 9 final String name; | |
| 10 final List<String> apis; | |
| 11 final Pubspec pubspec; | |
| 12 | |
| 13 Package(this.name, this.apis, this.pubspec); | |
| 14 } | |
| 15 | |
| 8 main() { | 16 main() { |
| 17 // Set up paths to directories 'discovery' and 'generated'. | |
| 18 var discoveryDocsDir = Platform.script.resolve('discovery').path; | |
| 19 var generatedApisDir = Platform.script.resolve('generated').path; | |
| 20 | |
| 9 // Read the configuration. | 21 // Read the configuration. |
| 10 var configFile = Platform.script.resolve('config.yaml').path; | 22 var configFile = Platform.script.resolve('config.yaml').path; |
| 11 var discoveryDocsDir = Platform.script.resolve('discovery').path; | |
| 12 var config = loadYaml(new File(configFile).readAsStringSync()); | 23 var config = loadYaml(new File(configFile).readAsStringSync()); |
| 13 var pkgs = config['packages']; | 24 |
| 14 var packages = {}; | 25 listAllApis().then((List<DirectoryListItems> items) { |
| 15 var supportedApis = []; | 26 var pkgs = config['packages']; |
| 16 var knownApis = []; | 27 var packages = {}; |
| 17 pkgs.forEach((pkg) { | 28 var supportedApis = []; |
| 18 pkg.forEach((name, values) { | 29 var knownApis = []; |
| 19 packages[name] = values != null ? values : []; | 30 pkgs.forEach((package) { |
| 31 package.forEach((name, values) { | |
| 32 var apis = | |
| 33 (values != null && values['apis'] != null) ? values['apis'] : []; | |
| 34 var version = | |
| 35 values['version'] != null ? values['version'] : '0.1.0-dev'; | |
| 36 var author = values['author']; | |
| 37 var homepage = values['homepage']; | |
| 38 | |
| 39 // Generate package description. | |
| 40 var sb = new StringBuffer() | |
| 41 ..write('Auto-generated client libraries for accessing ' | |
| 42 'the following APIs:'); | |
|
kustermann
2014/08/18 14:04:05
Indentation.
Søren Gjesse
2014/08/19 13:53:13
Done.
| |
| 43 items.forEach((DirectoryListItems apiDescription) { | |
| 44 if (apis.contains(apiDescription.id)) { | |
| 45 sb..writeln(' ') | |
| 46 ..write(apiDescription.id) | |
| 47 ..write(' - ') | |
| 48 ..write(apiDescription.description); | |
| 49 } | |
| 50 }); | |
| 51 | |
| 52 // Create package description with pubspec.yaml information. | |
| 53 var pubspec = new Pubspec( | |
| 54 name, version, sb.toString(), author: author, homepage: homepage); | |
| 55 packages[name] = new Package(name, apis, pubspec); | |
| 56 }); | |
| 20 }); | 57 }); |
| 21 }); | |
| 22 var skippedApis = config['skipped_apis']; | |
| 23 packages.forEach((_, values) => supportedApis.addAll(values)); | |
| 24 knownApis.addAll(supportedApis); | |
| 25 knownApis.addAll(skippedApis); | |
| 26 | 58 |
| 27 // Check that all APIs are mentioned in the configuration. | 59 // Check that all APIs are mentioned in the configuration. |
| 28 var missingApis = []; | 60 var skippedApis = config['skipped_apis']; |
| 29 listAllApis().then((List<DirectoryListItems> items) { | 61 packages.forEach((_, package) => supportedApis.addAll(package.apis)); |
| 62 knownApis.addAll(supportedApis); | |
| 63 knownApis.addAll(skippedApis); | |
| 64 var missingApis = []; | |
| 30 items.forEach((item) { | 65 items.forEach((item) { |
| 31 if (!knownApis.contains(item.id)) missingApis.add(item.id); | 66 if (!knownApis.contains(item.id)) missingApis.add(item.id); |
| 32 }); | 67 }); |
| 33 | |
| 34 if (missingApis.isNotEmpty) { | 68 if (missingApis.isNotEmpty) { |
| 35 print('No configuration for the following APIs;'); | 69 print('No configuration for the following APIs;'); |
| 36 missingApis.forEach((id) => print('- $id')); | 70 missingApis.forEach((id) => print('- $id')); |
| 37 return; | 71 return; |
| 38 } | 72 } |
| 39 | 73 |
| 40 // Delete downloaded discovery documents. | 74 // Delete downloaded discovery documents. |
| 41 var dir = new Directory(discoveryDocsDir); | 75 var dir = new Directory(discoveryDocsDir); |
| 42 if (dir.existsSync()) dir.deleteSync(recursive: true); | 76 if (dir.existsSync()) dir.deleteSync(recursive: true); |
| 43 | 77 |
| 44 // Download the discovery documents for the packages to build. | 78 // Download the discovery documents for the packages to build. |
| 45 var futures = []; | 79 var futures = []; |
| 46 packages.forEach((name, values) { | 80 packages.forEach((name, package) { |
| 47 futures.add(downloadDiscoveryDocuments('discovery/$name', ids: values)); | 81 futures.add(downloadDiscoveryDocuments('$discoveryDocsDir/$name', |
| 82 ids: package.apis)); | |
| 48 }); | 83 }); |
| 49 | 84 |
| 50 Future.wait(futures).then((_) { | 85 Future.wait(futures).then((_) { |
| 51 packages.forEach((name, values) { | 86 packages.forEach((name, package) { |
| 52 print('Generating library $name'); | 87 print('Generating library $name'); |
| 53 generateAllLibraries('discovery/$name', 'generated/$name'); | 88 generateAllLibraries('$discoveryDocsDir/$name', |
| 89 '$generatedApisDir/$name', | |
| 90 package.pubspec); | |
| 54 }); | 91 }); |
| 55 print('DONE'); | 92 print('DONE'); |
| 56 }); | 93 }); |
| 57 }); | 94 }); |
| 58 } | 95 } |
| OLD | NEW |