Chromium Code Reviews| Index: main.dart |
| diff --git a/main.dart b/main.dart |
| index 11cb6aa48fa8e49a228661460cc88ed7c2e9b954..e0561ee932fa325d91a2d68ec69d0f3d99aa5b22 100644 |
| --- a/main.dart |
| +++ b/main.dart |
| @@ -5,32 +5,66 @@ 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'; |
| +class Package { |
| + final String name; |
| + final List<String> apis; |
| + final Pubspec pubspec; |
| + |
| + Package(this.name, this.apis, this.pubspec); |
| +} |
| + |
| main() { |
| + // Set up paths to directories 'discovery' and 'generated'. |
| + var discoveryDocsDir = Platform.script.resolve('discovery').path; |
| + var generatedApisDir = Platform.script.resolve('generated').path; |
| + |
| // Read the configuration. |
| var configFile = Platform.script.resolve('config.yaml').path; |
| - var discoveryDocsDir = Platform.script.resolve('discovery').path; |
| var config = loadYaml(new File(configFile).readAsStringSync()); |
| - 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) { |
| + var pkgs = config['packages']; |
| + var packages = {}; |
| + var supportedApis = []; |
| + var knownApis = []; |
| + pkgs.forEach((package) { |
| + package.forEach((name, values) { |
| + var apis = |
| + (values != null && values['apis'] != null) ? values['apis'] : []; |
| + var version = |
| + values['version'] != null ? values['version'] : '0.1.0-dev'; |
| + var author = values['author']; |
| + var homepage = values['homepage']; |
| + |
| + // Generate package description. |
| + var sb = new StringBuffer() |
| + ..write('Auto-generated client libraries for accessing ' |
| + 'the following APIs:'); |
|
kustermann
2014/08/18 14:04:05
Indentation.
Søren Gjesse
2014/08/19 13:53:13
Done.
|
| + items.forEach((DirectoryListItems apiDescription) { |
| + if (apis.contains(apiDescription.id)) { |
| + sb..writeln(' ') |
| + ..write(apiDescription.id) |
| + ..write(' - ') |
| + ..write(apiDescription.description); |
| + } |
| + }); |
| + |
| + // Create package description with pubspec.yaml information. |
| + var pubspec = new Pubspec( |
| + name, version, sb.toString(), author: author, homepage: homepage); |
| + packages[name] = new Package(name, apis, pubspec); |
| + }); |
| + }); |
| + |
| + // Check that all APIs are mentioned in the configuration. |
| + var skippedApis = config['skipped_apis']; |
| + packages.forEach((_, package) => supportedApis.addAll(package.apis)); |
| + knownApis.addAll(supportedApis); |
| + knownApis.addAll(skippedApis); |
| + var missingApis = []; |
| 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')); |
| @@ -43,14 +77,17 @@ main() { |
| // Download the discovery documents for the packages to build. |
| var futures = []; |
| - packages.forEach((name, values) { |
| - futures.add(downloadDiscoveryDocuments('discovery/$name', ids: values)); |
| + packages.forEach((name, package) { |
| + futures.add(downloadDiscoveryDocuments('$discoveryDocsDir/$name', |
| + ids: package.apis)); |
| }); |
| Future.wait(futures).then((_) { |
| - packages.forEach((name, values) { |
| + packages.forEach((name, package) { |
| print('Generating library $name'); |
| - generateAllLibraries('discovery/$name', 'generated/$name'); |
| + generateAllLibraries('$discoveryDocsDir/$name', |
| + '$generatedApisDir/$name', |
| + package.pubspec); |
| }); |
| print('DONE'); |
| }); |