OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('lock_file'); | 5 #library('lock_file'); |
6 | 6 |
7 #import('dart:json'); | 7 #import('dart:json'); |
8 #import('package.dart'); | 8 #import('package.dart'); |
9 #import('source_registry.dart'); | 9 #import('source_registry.dart'); |
10 #import('utils.dart'); | 10 #import('utils.dart'); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 packages.forEach((name, id) { | 86 packages.forEach((name, id) { |
87 packagesObj[name] = { | 87 packagesObj[name] = { |
88 'version': id.version.toString(), | 88 'version': id.version.toString(), |
89 'source': id.source.name, | 89 'source': id.source.name, |
90 'description': id.description | 90 'description': id.description |
91 }; | 91 }; |
92 }); | 92 }); |
93 | 93 |
94 // TODO(nweiz): Serialize using the YAML library once it supports | 94 // TODO(nweiz): Serialize using the YAML library once it supports |
95 // serialization. For now, we use JSON, since it's a subset of YAML anyway. | 95 // serialization. For now, we use JSON, since it's a subset of YAML anyway. |
96 return JSON.stringify({'packages': packagesObj}); | 96 // |
| 97 // (prujohn@gmail.com) remove the _stringifyPretty() wrapper once the |
| 98 // YAML impl ready. |
| 99 return _stringifyPretty(packagesObj); |
| 100 // return JSON.stringify({'packages' : packagesObj}); |
| 101 } |
| 102 |
| 103 /** |
| 104 * Provides a stringify on [packagesObj] to make the lock file more |
| 105 * human-readable. |
| 106 */ |
| 107 String _stringifyPretty(Map<String, Map> packagesObj){ |
| 108 final sb = new StringBuffer(); |
| 109 |
| 110 sb.add('packages:\n'); |
| 111 packagesObj.forEach((name, map){ |
| 112 sb.add(' ${name}:\n'); |
| 113 map.forEach((key, value){ |
| 114 if (key == "description" && value is Map){ |
| 115 sb.add(' description:\n'); |
| 116 value.forEach((dkey, dvalue){ |
| 117 sb.add(' ${dkey}: $dvalue\n'); |
| 118 }); |
| 119 }else{ |
| 120 sb.add(' ${key}: $value\n'); |
| 121 } |
| 122 }); |
| 123 }); |
| 124 return sb.toString(); |
97 } | 125 } |
98 } | 126 } |
OLD | NEW |