Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * Definitions used to run the polymer linter and deploy tools without using | 6 * Definitions used to run the polymer linter and deploy tools without using |
| 7 * pub serve or pub deploy. | 7 * pub serve or pub deploy. |
| 8 */ | 8 */ |
| 9 library polymer.src.build.runner; | 9 library polymer.src.build.runner; |
| 10 | 10 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 .then((_) => assets); | 203 .then((_) => assets); |
| 204 }); | 204 }); |
| 205 } | 205 } |
| 206 | 206 |
| 207 Future _emitTransformedFiles(AssetSet assets, BarbackOptions options) { | 207 Future _emitTransformedFiles(AssetSet assets, BarbackOptions options) { |
| 208 // Copy all the assets we transformed | 208 // Copy all the assets we transformed |
| 209 var futures = []; | 209 var futures = []; |
| 210 var currentPackage = options.currentPackage; | 210 var currentPackage = options.currentPackage; |
| 211 var transformTests = options.transformTests; | 211 var transformTests = options.transformTests; |
| 212 var outPackages = path.join(options.outDir, 'packages'); | 212 var outPackages = path.join(options.outDir, 'packages'); |
| 213 for (var asset in assets) { | 213 |
| 214 return Future.forEach(assets, (asset) { | |
| 214 var id = asset.id; | 215 var id = asset.id; |
| 215 var dir = _firstDir(id.path); | 216 var dir = _firstDir(id.path); |
| 216 if (dir == null) continue; | 217 if (dir == null) return null; |
| 217 | 218 |
| 218 var filepath; | 219 var filepath; |
| 219 if (dir == 'lib') { | 220 if (dir == 'lib') { |
| 220 // Put lib files directly under the packages folder (e.g. 'lib/foo.dart' | 221 // Put lib files directly under the packages folder (e.g. 'lib/foo.dart' |
| 221 // will be emitted at out/packages/package_name/foo.dart). | 222 // will be emitted at out/packages/package_name/foo.dart). |
| 222 filepath = path.join(outPackages, id.package, | 223 filepath = path.join(outPackages, id.package, |
| 223 _toSystemPath(id.path.substring(4))); | 224 _toSystemPath(id.path.substring(4))); |
| 224 } else if (id.package == currentPackage && | 225 } else if (id.package == currentPackage && |
| 225 (dir == 'web' || (transformTests && dir == 'test'))) { | 226 (dir == 'web' || (transformTests && dir == 'test'))) { |
| 226 filepath = path.join(options.outDir, _toSystemPath(id.path)); | 227 filepath = path.join(options.outDir, _toSystemPath(id.path)); |
| 227 } else { | 228 } else { |
| 228 // TODO(sigmund): do something about other assets? | 229 // TODO(sigmund): do something about other assets? |
| 229 continue; | 230 return null; |
| 230 } | 231 } |
| 231 | 232 |
| 232 futures.add(_writeAsset(filepath, asset)); | 233 return _writeAsset(filepath, asset); |
| 233 } | 234 }); |
| 234 return Future.wait(futures); | |
| 235 } | 235 } |
| 236 | 236 |
| 237 /** | 237 /** |
| 238 * Adds a package symlink from each directory under `out/web/foo/` to | 238 * Adds a package symlink from each directory under `out/web/foo/` to |
| 239 * `out/packages`. | 239 * `out/packages`. |
| 240 */ | 240 */ |
| 241 Future _addPackagesSymlinks(AssetSet assets, BarbackOptions options) { | 241 Future _addPackagesSymlinks(AssetSet assets, BarbackOptions options) { |
| 242 var outPackages = path.join(options.outDir, 'packages'); | 242 var outPackages = path.join(options.outDir, 'packages'); |
| 243 var currentPackage = options.currentPackage; | 243 var currentPackage = options.currentPackage; |
| 244 for (var asset in assets) { | 244 for (var asset in assets) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 273 // Copy all the files we didn't process | 273 // Copy all the files we didn't process |
| 274 var futures = []; | 274 var futures = []; |
| 275 var dirs = options.packageDirs; | 275 var dirs = options.packageDirs; |
| 276 for (var package in _polymerPackageDependencies) { | 276 for (var package in _polymerPackageDependencies) { |
| 277 for (var relpath in _listPackageDir(package, 'lib', options)) { | 277 for (var relpath in _listPackageDir(package, 'lib', options)) { |
| 278 var inpath = path.join(dirs[package], relpath); | 278 var inpath = path.join(dirs[package], relpath); |
| 279 var outpath = path.join(outPackages, package, relpath.substring(4)); | 279 var outpath = path.join(outPackages, package, relpath.substring(4)); |
| 280 futures.add(_copyFile(inpath, outpath)); | 280 futures.add(_copyFile(inpath, outpath)); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 return Future.wait(futures); | 283 return Future.wait(futures); |
|
Siggi Cherem (dart-lang)
2013/10/07 16:29:35
change here also to use forEach?
kevmoo-old
2013/10/07 17:08:05
Done.
| |
| 284 } | 284 } |
| 285 | 285 |
| 286 /** Ensure [dirpath] exists. */ | 286 /** Ensure [dirpath] exists. */ |
| 287 void _ensureDir(String dirpath) { | 287 void _ensureDir(String dirpath) { |
| 288 new Directory(dirpath).createSync(recursive: true); | 288 new Directory(dirpath).createSync(recursive: true); |
| 289 } | 289 } |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * Returns the first directory name on a url-style path, or null if there are no | 292 * Returns the first directory name on a url-style path, or null if there are no |
| 293 * slashes. | 293 * slashes. |
| 294 */ | 294 */ |
| 295 String _firstDir(String url) { | 295 String _firstDir(String url) { |
| 296 var firstSlash = url.indexOf('/'); | 296 var firstSlash = url.indexOf('/'); |
| 297 if (firstSlash == -1) return null; | 297 if (firstSlash == -1) return null; |
| 298 return url.substring(0, firstSlash); | 298 return url.substring(0, firstSlash); |
| 299 } | 299 } |
| 300 | 300 |
| 301 /** Copy a file from [inpath] to [outpath]. */ | 301 /** Copy a file from [inpath] to [outpath]. */ |
| 302 Future _copyFile(String inpath, String outpath) { | 302 Future _copyFile(String inpath, String outpath) { |
| 303 _ensureDir(path.dirname(outpath)); | 303 _ensureDir(path.dirname(outpath)); |
| 304 var writer = new File(outpath).openWrite(); | 304 return new File(inpath).openRead().pipe(new File(outpath).openWrite()); |
| 305 return writer.addStream(new File(inpath).openRead()) | |
| 306 .then((_) => writer.close()); | |
| 307 } | 305 } |
| 308 | 306 |
| 309 /** Write contents of an [asset] into a file at [filepath]. */ | 307 /** Write contents of an [asset] into a file at [filepath]. */ |
| 310 Future _writeAsset(String filepath, Asset asset) { | 308 Future _writeAsset(String filepath, Asset asset) { |
| 311 _ensureDir(path.dirname(filepath)); | 309 _ensureDir(path.dirname(filepath)); |
| 312 var writer = new File(filepath).openWrite(); | 310 return asset.read().pipe(new File(filepath).openWrite()); |
| 313 return writer.addStream(asset.read()).then((_) => writer.close()); | |
| 314 } | 311 } |
| OLD | NEW |