Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: lib/src/package_configuration.dart

Issue 563213002: Generate CHANGELOG.md files in addition to README.md/LICENCE (Closed) Base URL: git@github.com:dart-lang/discovery_api_dart_client_generator.git@experimental
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of discovery_api_client_generator; 5 part of discovery_api_client_generator;
6 6
7 class Package { 7 class Package {
8 final String name; 8 final String name;
9 final List<String> apis; 9 final List<String> apis;
10 final Pubspec pubspec; 10 final Pubspec pubspec;
11 final String readme; 11 final String readme;
12 final String license; 12 final String license;
13 final String changelog;
13 14
14 Package(this.name, this.apis, this.pubspec, this.readme, this.license); 15 Package(this.name, this.apis, this.pubspec, this.readme, this.license,
16 this.changelog);
15 } 17 }
16 18
17 /** 19 /**
18 * Configuration of a set of packages generated from a set of APIs exposed by 20 * Configuration of a set of packages generated from a set of APIs exposed by
19 * a Discovery Service. 21 * a Discovery Service.
20 */ 22 */
21 class DiscoveryPackagesConfiguration { 23 class DiscoveryPackagesConfiguration {
22 Map<String, Package> packages = {}; 24 Map<String, Package> packages = {};
23 Iterable<String> excessApis; 25 Iterable<String> excessApis;
24 Iterable<String> missingApis; 26 Iterable<String> missingApis;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 packages.forEach((name, package) { 102 packages.forEach((name, package) {
101 generateAllLibraries('$discoveryDocsDir/$name', 103 generateAllLibraries('$discoveryDocsDir/$name',
102 '$generatedApisDir/$name', 104 '$generatedApisDir/$name',
103 package.pubspec); 105 package.pubspec);
104 new File('$generatedApisDir/$name/README.md') 106 new File('$generatedApisDir/$name/README.md')
105 .writeAsStringSync(package.readme); 107 .writeAsStringSync(package.readme);
106 if (package.license != null) { 108 if (package.license != null) {
107 new File('$generatedApisDir/$name/LICENSE') 109 new File('$generatedApisDir/$name/LICENSE')
108 .writeAsStringSync(package.license); 110 .writeAsStringSync(package.license);
109 } 111 }
112 if (package.changelog != null) {
113 new File('$generatedApisDir/$name/CHANGELOG.md')
114 .writeAsStringSync(package.changelog);
115 }
110 }); 116 });
111 }); 117 });
112 } 118 }
113 119
114 // Return empty list for YAML null value. 120 // Return empty list for YAML null value.
115 static List _listFromYaml(value) => value != null ? value : []; 121 static List _listFromYaml(value) => value != null ? value : [];
116 122
117 static String _generateReadme( 123 static String _generateReadme(
118 String readmeFile, List<DirectoryListItems> items) { 124 String readmeFile, List<DirectoryListItems> items) {
119 var sb = new StringBuffer(); 125 var sb = new StringBuffer();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 168
163 static Package _packageFromYaml(String name, 169 static Package _packageFromYaml(String name,
164 YamlMap values, 170 YamlMap values,
165 String configFile, 171 String configFile,
166 List<DirectoryListItems> allApis) { 172 List<DirectoryListItems> allApis) {
167 var apis = _listFromYaml(values['apis']); 173 var apis = _listFromYaml(values['apis']);
168 var version = 174 var version =
169 values['version'] != null ? values['version'] : '0.1.0-dev'; 175 values['version'] != null ? values['version'] : '0.1.0-dev';
170 var author = values['author']; 176 var author = values['author'];
171 var homepage = values['homepage']; 177 var homepage = values['homepage'];
178
179 var configUri = new Uri.file(configFile);
180
172 var readmeFile; 181 var readmeFile;
173 if (values['readme'] != null) { 182 if (values['readme'] != null) {
174 readmeFile = new Uri.file(configFile).resolve(values['readme']).path; 183 readmeFile = configUri.resolve(values['readme']).path;
175 } 184 }
176 var licenseFile; 185 var licenseFile;
177 if (values['license'] != null) { 186 if (values['license'] != null) {
178 licenseFile = 187 licenseFile = configUri.resolve(values['license']).path;
179 new Uri.file(configFile).resolve(values['license']).path; 188 }
189 var changelogFile;
190 if (values['changelog'] != null) {
191 changelogFile = configUri.resolve(values['changelog']).path;
180 } 192 }
181 193
182 // Generate package description. 194 // Generate package description.
183 var apiDescriptions = []; 195 var apiDescriptions = [];
184 var sb = new StringBuffer() 196 var sb = new StringBuffer()
185 ..write('"Auto-generated client libraries for accessing ' 197 ..write('"Auto-generated client libraries for accessing '
186 'the following APIs:'); 198 'the following APIs:');
187 bool first = true; 199 bool first = true;
188 allApis.forEach((DirectoryListItems apiDescription) { 200 allApis.forEach((DirectoryListItems apiDescription) {
189 if (apis.contains(apiDescription.id)) { 201 if (apis.contains(apiDescription.id)) {
190 if (!first) sb.write(', '); 202 if (!first) sb.write(', ');
191 sb.write(apiDescription.id); 203 sb.write(apiDescription.id);
192 apiDescriptions.add(apiDescription); 204 apiDescriptions.add(apiDescription);
193 first = false; 205 first = false;
194 } 206 }
195 }); 207 });
196 sb.write('"'); 208 sb.write('"');
197 209
198 // Generate the README.md file content. 210 // Generate the README.md file content.
199 var readme = _generateReadme(readmeFile, apiDescriptions); 211 var readme = _generateReadme(readmeFile, apiDescriptions);
200 212
201 // Read the LICENSE 213 // Read the LICENSE
202 var license = new File(licenseFile).readAsStringSync(); 214 var license = new File(licenseFile).readAsStringSync();
203 215
216 // Read CHANGELOG.md
217 var changelog = new File(changelogFile).readAsStringSync();
218
204 // Create package description with pubspec.yaml information. 219 // Create package description with pubspec.yaml information.
205 var pubspec = new Pubspec( 220 var pubspec = new Pubspec(
206 name, version, sb.toString(), author: author, homepage: homepage); 221 name, version, sb.toString(), author: author, homepage: homepage);
207 return new Package(name, apis, pubspec, readme, license); 222 return new Package(name, apis, pubspec, readme, license, changelog);
208 } 223 }
209 224
210 /// The known APIs are the APis mentioned in each package together with 225 /// The known APIs are the APis mentioned in each package together with
211 /// the APIs explicitly skipped. 226 /// the APIs explicitly skipped.
212 static Set<String> _calculateKnownApis(Map<String, Package> packages, 227 static Set<String> _calculateKnownApis(Map<String, Package> packages,
213 YamlList skippedApis) { 228 YamlList skippedApis) {
214 var knownApis = new Set(); 229 var knownApis = new Set();
215 knownApis.addAll(skippedApis); 230 knownApis.addAll(skippedApis);
216 packages.forEach((_, package) => knownApis.addAll(package.apis)); 231 packages.forEach((_, package) => knownApis.addAll(package.apis));
217 return knownApis; 232 return knownApis;
(...skipping 11 matching lines...) Expand all
229 /// The excess APIs are the APIs mentioned in the configuration but not 244 /// The excess APIs are the APIs mentioned in the configuration but not
230 /// returned from the Discovery Service. 245 /// returned from the Discovery Service.
231 static Iterable<String> _calculateExcessApis( 246 static Iterable<String> _calculateExcessApis(
232 Iterable<String> knownApis, List<DirectoryListItems> allApis) { 247 Iterable<String> knownApis, List<DirectoryListItems> allApis) {
233 var excessApis = new Set.from(knownApis); 248 var excessApis = new Set.from(knownApis);
234 allApis.forEach((item) => excessApis.remove(item.id)); 249 allApis.forEach((item) => excessApis.remove(item.id));
235 return excessApis; 250 return excessApis;
236 } 251 }
237 } 252 }
238 253
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698