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

Side by Side Diff: bin/dwc_browser.dart

Issue 11092092: Support compiling templates in the browser. Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 2 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
« no previous file with comments | « .gitignore ('k') | example/explainer/build_examples.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « .gitignore ('k') | example/explainer/build_examples.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698