OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Compiles Dart Web Components from within a Chrome extension. |
| 7 * The Chrome extension logic exists outside of Dart as Dart does not support |
| 8 * Chrome extension APIs at this time. |
| 9 */ |
| 10 library dwc_browser; |
| 11 |
| 12 import 'dart:html'; |
| 13 import 'package:args/args.dart'; |
| 14 import 'package:web_components/src/template/cmd_options.dart'; |
| 15 import 'package:web_components/src/template/file_system.dart'; |
| 16 import 'package:web_components/src/template/file_system_browser.dart'; |
| 17 import 'package:web_components/src/template/dartio_stub.dart'; |
| 18 import 'package:web_components/src/template/world.dart'; |
| 19 import 'package:web_components/src/template/compile.dart'; |
| 20 import 'package:web_components/src/template/utils.dart'; |
| 21 import 'package:web_components/dwc_shared.dart'; |
| 22 import 'package:js/js.dart' as js; |
| 23 |
| 24 FileSystem fileSystem; |
| 25 |
| 26 |
| 27 void main() { |
| 28 js.scoped(() { |
| 29 js.context.setOnParseCallback(new js.Callback.many(parse)); |
| 30 }); |
| 31 } |
| 32 |
| 33 /** |
| 34 * Parse all templates in [sourceFullFn]. |
| 35 * [sourcePagePort] is a Chrome extension port used to communicate back to the |
| 36 * source page that will consume these proxied urls. |
| 37 * See extension/background.js. |
| 38 */ |
| 39 void parse(js.Proxy sourcePagePort, String sourceFullFn) { |
| 40 // TODO(jacobr): we need to send error messages back to sourcePagePort. |
| 41 js.retain(sourcePagePort); |
| 42 print("Processing: $sourceFullFn"); |
| 43 // TODO(jacobr): provide a way to pass in options. |
| 44 var argParser = commandOptions(); |
| 45 ArgResults results = argParser.parse([]); |
| 46 |
| 47 fileSystem = new BrowserFileSystem(sourcePagePort); |
| 48 |
| 49 initHtmlWorld(parseOptions(results, fileSystem)); |
| 50 |
| 51 Path srcPath = new Path(sourceFullFn); |
| 52 Path outputFullDir = srcPath.directoryPath; |
| 53 |
| 54 Path srcDir = srcPath.directoryPath; |
| 55 |
| 56 String sourceFilename = srcPath.filename; |
| 57 |
| 58 asyncTime('Compiled $sourceFullFn', () { |
| 59 var compiler = new Compile(fileSystem); |
| 60 return compiler.run(srcPath.filename, srcDir.toString()).chain((_) { |
| 61 // Write out the code associated with each source file. |
| 62 print("Writing files:"); |
| 63 for (var file in compiler.output) { |
| 64 writeFile(file.filename, outputFullDir, file.contents); |
| 65 } |
| 66 var ret = fileSystem.flush(); |
| 67 js.release(sourcePagePort); |
| 68 return ret; |
| 69 }); |
| 70 }, printTime: true); |
| 71 } |
| 72 |
| 73 void writeFile(String filename, Path outdir, String contents) { |
| 74 print("XXX ${outdir}/$filename"); |
| 75 fileSystem.writeString("${outdir}/$filename", contents); |
| 76 } |
OLD | NEW |