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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/command/serve.dart

Issue 23291002: Fix pub serve on windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/pub.status » ('j') | 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) 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.serve; 5 library pub.command.serve;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Add the initial sources. 219 // Add the initial sources.
220 _barback.updateSources(listAssets(package)); 220 _barback.updateSources(listAssets(package));
221 221
222 // Watch the visible package directories for changes. 222 // Watch the visible package directories for changes.
223 var packageDir = _provider.getPackageDir(package); 223 var packageDir = _provider.getPackageDir(package);
224 224
225 for (var name in getPublicDirectories(package)) { 225 for (var name in getPublicDirectories(package)) {
226 var subdirectory = path.join(packageDir, name); 226 var subdirectory = path.join(packageDir, name);
227 var watcher = new DirectoryWatcher(subdirectory); 227 var watcher = new DirectoryWatcher(subdirectory);
228 watcher.events.listen((event) { 228 watcher.events.listen((event) {
229 var relativePath = path.relative(event.path, from: packageDir); 229 var id = pathToAssetId(package, packageDir, event.path);
230 var id = new AssetId(package, relativePath);
231 if (event.type == ChangeType.REMOVE) { 230 if (event.type == ChangeType.REMOVE) {
232 _barback.removeSources([id]); 231 _barback.removeSources([id]);
233 } else { 232 } else {
234 _barback.updateSources([id]); 233 _barback.updateSources([id]);
235 } 234 }
236 }); 235 });
237 } 236 }
238 } 237 }
239 } 238 }
240 239
241 /// Lists all of the visible files in [package]. 240 /// Lists all of the visible files in [package].
242 /// 241 ///
243 /// This is the recursive contents of the "asset" and "lib" directories (if 242 /// This is the recursive contents of the "asset" and "lib" directories (if
244 /// present). If [package] is the entrypoint package, it also includes the 243 /// present). If [package] is the entrypoint package, it also includes the
245 /// contents of "web". 244 /// contents of "web".
246 List<AssetId> listAssets(String package) { 245 List<AssetId> listAssets(String package) {
247 var files = <AssetId>[]; 246 var files = <AssetId>[];
248 247
249 for (var dirPath in getPublicDirectories(package)) { 248 for (var dirPath in getPublicDirectories(package)) {
250 var packageDir = _provider.getPackageDir(package); 249 var packageDir = _provider.getPackageDir(package);
251 var dir = path.join(packageDir, dirPath); 250 var dir = path.join(packageDir, dirPath);
252 if (!dirExists(dir)) continue; 251 if (!dirExists(dir)) continue;
253 for (var entry in listDir(dir, recursive: true)) { 252 for (var entry in listDir(dir, recursive: true)) {
254 // Ignore "packages" symlinks if there. 253 // Ignore "packages" symlinks if there.
255 if (path.split(entry).contains("packages")) continue; 254 if (path.split(entry).contains("packages")) continue;
256 255
257 // Skip directories. 256 // Skip directories.
258 if (!fileExists(entry)) continue; 257 if (!fileExists(entry)) continue;
259 258
260 // AssetId paths use "/" on all platforms. 259 files.add(pathToAssetId(package, packageDir, entry));
261 var relative = path.relative(entry, from: packageDir);
262 relative = path.toUri(relative).path;
263 files.add(new AssetId(package, relative));
264 } 260 }
265 } 261 }
266 262
267 return files; 263 return files;
268 } 264 }
269 265
270 /// Gets the names of the top-level directories in [package] whose contents 266 /// Gets the names of the top-level directories in [package] whose contents
271 /// should be provided as source assets. 267 /// should be provided as source assets.
272 Iterable<String> getPublicDirectories(String package) { 268 Iterable<String> getPublicDirectories(String package) {
273 var directories = ["asset", "lib"]; 269 var directories = ["asset", "lib"];
274 if (package == entrypoint.root.name) directories.add("web"); 270 if (package == entrypoint.root.name) directories.add("web");
275 return directories; 271 return directories;
276 } 272 }
273
274 /// Converts a local file path to an [AssetId].
275 AssetId pathToAssetId(String package, String packageDir, String filePath) {
276 var relative = path.relative(filePath, from: packageDir);
277
278 // AssetId paths use "/" on all platforms.
279 relative = path.toUri(relative).path;
280
281 return new AssetId(package, relative);
282 }
277 } 283 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/pub.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698