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

Side by Side Diff: lib/dwc.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 | « extension/manifest.json ('k') | lib/dwc_shared.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 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 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 /** The entry point to the compiler. Used to implement `bin/dwc.dart`. */ 5 /** The entry point to the compiler. Used to implement `bin/dwc.dart`. */
6 library dwc; 6 library dwc;
7 7
8 import 'dart:io';
9 import 'package:args/args.dart'; 8 import 'package:args/args.dart';
10 import 'src/template/cmd_options.dart'; 9 import 'src/template/cmd_options.dart';
11 import 'src/template/file_system.dart'; 10 import 'src/template/file_system.dart';
12 import 'src/template/file_system_vm.dart'; 11 import 'src/template/file_system_vm.dart';
13 import 'src/template/file_system_memory.dart'; 12 import 'src/template/file_system_memory.dart';
14 import 'src/template/compile.dart'; 13 import 'src/template/compile.dart';
15 import 'src/template/utils.dart'; 14 import 'src/template/utils.dart';
16 import 'src/template/world.dart'; 15 import 'src/template/world.dart';
17 16 import 'dwc_shared.dart';
18 ArgParser commandOptions() { 17 import 'dart:io';
19 var args = new ArgParser();
20 args.addFlag('verbose', help: 'Display detail info', defaultsTo: false);
21 args.addFlag('clean', help: 'Remove all generated files', defaultsTo: false);
22 args.addFlag('dump', help: 'Dump AST', defaultsTo: false);
23 args.addFlag('suppress_warnings', help: 'Warnings not displayed',
24 defaultsTo: true);
25 args.addFlag('warnings_as_errors', help: 'Warning handled as errors',
26 defaultsTo: false);
27 args.addFlag('throw_on_errors', help: 'Throw on errors encountered',
28 defaultsTo: false);
29 args.addFlag('throw_on_warnings', help: 'Throw on warnings encountered',
30 defaultsTo: false);
31 args.addFlag('no_colors', help: 'Display errors/warnings in colored text',
32 defaultsTo: true);
33 args.addFlag('help', help: 'Displays this help message', defaultsTo: false);
34
35 return args;
36 }
37
38 void initHtmlWorld(CmdOptions opts) {
39 var fs = new MemoryFileSystem();
40 initializeWorld(fs, opts);
41
42 // TODO(terry): Should be set by arguments. When run as a tool these aren't
43 // set when run internaly set these so we can compile CSS and catch any
44 // problems programmatically.
45 // options.throwOnErrors = true;
46 // options.throwOnFatal = true;
47 // options.useColors = commandLine ? true : false;
48 }
49 18
50 FileSystem fileSystem; 19 FileSystem fileSystem;
51 20
52 /** bin/dwc.dart [options...] <sourcefile fullpath> <outputfile fullpath> */ 21 /** bin/dwc.dart [options...] <sourcefile fullpath> <outputfile fullpath> */
53 void run(List<String> args) { 22 Future run(List<String> args) {
54 var argParser = commandOptions(); 23 var argParser = commandOptions();
55 ArgResults results = argParser.parse(args); 24 ArgResults results = argParser.parse(args);
56 if (results['help'] || results.rest.length == 0) { 25 if (results['help'] || results.rest.length == 0) {
57 print('Usage: [options...] sourcefile [outputPath]\n'); 26 print('Usage: [options...] sourcefile [outputPath]\n');
58 print(argParser.getUsage()); 27 print(argParser.getUsage());
59 print(" sourcefile - template file filename.html"); 28 print(" sourcefile - template file filename.html");
60 print(" outputPath - if specified directory to generate files; if not"); 29 print(" outputPath - if specified directory to generate files; if not");
61 print(" same directory as sourcefile"); 30 print(" same directory as sourcefile");
62 return; 31 return;
63 } 32 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // If outputFullDirectory not specified use the directory of the source file. 66 // If outputFullDirectory not specified use the directory of the source file.
98 if (outputFullDir == null || outputFullDir.isEmpty()) { 67 if (outputFullDir == null || outputFullDir.isEmpty()) {
99 outputFullDir = srcDir.path; 68 outputFullDir = srcDir.path;
100 } 69 }
101 70
102 Directory outDirectory = new Directory(outputFullDir); 71 Directory outDirectory = new Directory(outputFullDir);
103 if (!outDirectory.existsSync()) { 72 if (!outDirectory.existsSync()) {
104 outDirectory.createSync(); 73 outDirectory.createSync();
105 } 74 }
106 75
107 String source = fileSystem.readAll(sourceFullFn); 76 return fileSystem.readAll(sourceFullFn).chain((source) {
108 time('Compiled $sourceFullFn', () { 77 return asyncTime('Compiled $sourceFullFn', () {
109 var compiler = new Compile(fileSystem); 78 var compiler = new Compile(fileSystem);
110 compiler.run(srcPath.filename, srcDir.path); 79 return compiler.run(srcPath.filename, srcDir.path).chain((_) {
111 80 // Write out the code associated with each source file.
112 // Write out the code associated with each source file. 81 print("Write files to ${outDirectory.path}:");
113 print("Write files to ${outDirectory.path}:"); 82 for (var file in compiler.output) {
114 for (var file in compiler.output) { 83 writeFile(file.filename, outDirectory, file.contents);
115 writeFile(file.filename, outDirectory, file.contents); 84 }
116 } 85 return fileSystem.flush();
117 }, printTime: true); 86 });
87 }, printTime: true);
88 });
118 } 89 }
119 90
120 void writeFile(String filename, Directory outdir, String contents) { 91 void writeFile(String filename, Directory outdir, String contents) {
121 String path = "${outdir.path}/$filename"; 92 String path = "${outdir.path}/$filename";
122 if (options.clean) { 93 if (options.clean) {
123 File fileOut = new File.fromPath(new Path(path)); 94 File fileOut = new File.fromPath(new Path(path));
124 if (fileOut.existsSync()) { 95 if (fileOut.existsSync()) {
125 fileOut.deleteSync(); 96 fileOut.deleteSync();
126 print(" Deleting $filename"); 97 print(" Deleting $filename");
127 } 98 }
128 } else { 99 } else {
129 fileSystem.writeString(path, contents); 100 fileSystem.writeString(path, contents);
130 print(" Writing $filename"); 101 print(" Writing $filename");
131 } 102 }
132 } 103 }
OLDNEW
« no previous file with comments | « extension/manifest.json ('k') | lib/dwc_shared.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698