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 css; | 5 library css; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
11 | 11 |
12 import 'parser.dart'; | 12 import 'parser.dart'; |
| 13 import 'src/messages.dart'; |
13 import 'visitor.dart'; | 14 import 'visitor.dart'; |
14 import 'src/messages.dart'; | |
15 import 'src/options.dart'; | |
16 | 15 |
17 void main(List<String> arguments) { | 16 void main(List<String> arguments) { |
18 // TODO(jmesserly): fix this to return a proper exit code | 17 // TODO(jmesserly): fix this to return a proper exit code |
19 var options = PreprocessorOptions.parse(arguments); | 18 var options = PreprocessorOptions.parse(arguments); |
20 if (options == null) return; | 19 if (options == null) return; |
21 | 20 |
22 messages = new Messages(options: options); | 21 messages = new Messages(options: options); |
23 | 22 |
24 _time('Total time spent on ${options.inputFile}', () { | 23 _time('Total time spent on ${options.inputFile}', () { |
25 _compile(options.inputFile, options.verbose); | 24 _compile(options.inputFile, options.verbose); |
26 }, true); | 25 }, true); |
27 } | 26 } |
28 | 27 |
29 void _compile(String inputPath, bool verbose) { | 28 void _compile(String inputPath, bool verbose) { |
30 var ext = path.extension(inputPath); | 29 var ext = path.extension(inputPath); |
31 if (ext != '.css' && ext != '.scss') { | 30 if (ext != '.css' && ext != '.scss') { |
32 messages.error("Please provide a CSS/Sass file", null); | 31 messages.error("Please provide a CSS/Sass file", null); |
33 return; | 32 return; |
34 } | 33 } |
35 try { | 34 try { |
36 // Read the file. | 35 // Read the file. |
37 var filename = path.basename(inputPath); | 36 var filename = path.basename(inputPath); |
38 var contents = new File(inputPath).readAsStringSync(); | 37 var contents = new File(inputPath).readAsStringSync(); |
39 var file = new SourceFile(contents, url: path.toUri(inputPath)); | 38 var file = new SourceFile(contents, url: path.toUri(inputPath)); |
40 | 39 |
41 // Parse the CSS. | 40 // Parse the CSS. |
42 var tree = _time( | 41 StyleSheet tree = _time( |
43 'Parse $filename', () => new Parser(file, contents).parse(), verbose); | 42 'Parse $filename', () => new Parser(file, contents).parse(), verbose); |
44 | 43 |
45 _time('Analyzer $filename', () => new Analyzer([tree], messages), verbose) | 44 _time('Analyzer $filename', () => new Analyzer([tree], messages), verbose) |
46 .run(); | 45 .run(); |
47 | 46 |
48 // Emit the processed CSS. | 47 // Emit the processed CSS. |
49 var emitter = new CssPrinter(); | 48 var emitter = new CssPrinter(); |
50 _time('Codegen $filename', () => emitter.visitTree(tree, pretty: true), | 49 _time('Codegen $filename', () => emitter.visitTree(tree, pretty: true), |
51 verbose); | 50 verbose); |
52 | 51 |
(...skipping 16 matching lines...) Expand all Loading... |
69 return result; | 68 return result; |
70 } | 69 } |
71 | 70 |
72 void _printMessage(String message, int duration) { | 71 void _printMessage(String message, int duration) { |
73 var buf = new StringBuffer(); | 72 var buf = new StringBuffer(); |
74 buf.write(message); | 73 buf.write(message); |
75 for (int i = message.length; i < 60; i++) buf.write(' '); | 74 for (int i = message.length; i < 60; i++) buf.write(' '); |
76 buf.write(' -- '); | 75 buf.write(' -- '); |
77 if (duration < 10) buf.write(' '); | 76 if (duration < 10) buf.write(' '); |
78 if (duration < 100) buf.write(' '); | 77 if (duration < 100) buf.write(' '); |
79 buf | 78 buf..write(duration)..write(' ms'); |
80 ..write(duration) | |
81 ..write(' ms'); | |
82 print(buf.toString()); | 79 print(buf.toString()); |
83 } | 80 } |
OLD | NEW |