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 library pub.command.build; | 5 library pub.command.build; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 () => server.barback.getAllAssets()); | 63 () => server.barback.getAllAssets()); |
64 }).then((assets) { | 64 }).then((assets) { |
65 // Don't copy Dart libraries. Their contents will already be included | 65 // Don't copy Dart libraries. Their contents will already be included |
66 // in the generated JavaScript. | 66 // in the generated JavaScript. |
67 assets = assets.where((asset) => asset.id.extension != ".dart"); | 67 assets = assets.where((asset) => asset.id.extension != ".dart"); |
68 | 68 |
69 return Future.forEach(assets, (asset) { | 69 return Future.forEach(assets, (asset) { |
70 // Figure out the output directory for the asset, which is the same | 70 // Figure out the output directory for the asset, which is the same |
71 // as the path pub serve would use to serve it. | 71 // as the path pub serve would use to serve it. |
72 var relativeUrl = barback.idtoUrlPath(entrypoint.root.name, asset.id); | 72 var relativeUrl = barback.idtoUrlPath(entrypoint.root.name, asset.id); |
| 73 |
| 74 // Remove the leading "/". |
| 75 relativeUrl = relativeUrl.substring(1); |
| 76 |
73 var relativePath = path.fromUri(new Uri(path: relativeUrl)); | 77 var relativePath = path.fromUri(new Uri(path: relativeUrl)); |
74 var destPath = path.join(target, relativePath); | 78 var destPath = path.join(target, relativePath); |
75 | 79 |
76 ensureDir(path.dirname(destPath)); | 80 ensureDir(path.dirname(destPath)); |
77 // TODO(rnystrom): Should we display this to the user? | 81 // TODO(rnystrom): Should we display this to the user? |
78 return createFileFromStream(asset.read(), destPath); | 82 return createFileFromStream(asset.read(), destPath); |
79 }).then((_) { | 83 }).then((_) { |
80 _copyBrowserJsFiles(dart2jsTransformer.entrypoints); | 84 _copyBrowserJsFiles(dart2jsTransformer.entrypoints); |
81 // TODO(rnystrom): Should this count include the JS files? | 85 // TODO(rnystrom): Should this count include the JS files? |
82 log.message("Built ${assets.length} files!"); | 86 log.message("Built ${assets.length} files!"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // TODO(nweiz): do something more principled when issue 6101 is fixed. | 124 // TODO(nweiz): do something more principled when issue 6101 is fixed. |
121 /// Ensures that the [name].js file is copied into [directory] in [target], | 125 /// Ensures that the [name].js file is copied into [directory] in [target], |
122 /// under `packages/browser/`. | 126 /// under `packages/browser/`. |
123 void _addBrowserJs(String directory, String name) { | 127 void _addBrowserJs(String directory, String name) { |
124 var jsPath = path.join( | 128 var jsPath = path.join( |
125 target, directory, 'packages', 'browser', '$name.js'); | 129 target, directory, 'packages', 'browser', '$name.js'); |
126 ensureDir(path.dirname(jsPath)); | 130 ensureDir(path.dirname(jsPath)); |
127 copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath); | 131 copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath); |
128 } | 132 } |
129 } | 133 } |
OLD | NEW |