OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, 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 #library('csstool'); |
| 6 |
| 7 #import('../../frog/file_system.dart'); |
| 8 #import('../../frog/file_system_node.dart'); |
| 9 #import('../../frog/lang.dart', prefix:'lang'); |
| 10 #import('css.dart'); |
| 11 |
| 12 FileSystem files; |
| 13 |
| 14 /** Invokes [callback] and returns how long it took to execute in ms. */ |
| 15 num time(callback()) { |
| 16 final watch = new Stopwatch(); |
| 17 watch.start(); |
| 18 callback(); |
| 19 watch.stop(); |
| 20 return watch.elapsedInMs(); |
| 21 } |
| 22 |
| 23 printStats(num elapsed, [String filename = '']) { |
| 24 print('Parsed\033[32m ${filename}\033[0m in ${elapsed} msec.'); |
| 25 } |
| 26 |
| 27 /** |
| 28 * Run from the `utils/css` directory. |
| 29 */ |
| 30 void main() { |
| 31 // process.argv[0] == node and process.argv[1] == minfrog |
| 32 assert(process.argv.length == 4); |
| 33 |
| 34 String sourceFullFn = process.argv[2]; |
| 35 String outputFullFn = process.argv[3]; |
| 36 |
| 37 String sourcePath; |
| 38 String sourceFilename; |
| 39 int idxBeforeFilename = sourceFullFn.lastIndexOf('/'); |
| 40 if (idxBeforeFilename >= 0) { |
| 41 sourcePath = sourceFullFn.substring(0, idxBeforeFilename + 1); |
| 42 sourceFilename = sourceFullFn.substring(idxBeforeFilename + 1); |
| 43 } |
| 44 |
| 45 String outPath; |
| 46 idxBeforeFilename = outputFullFn.lastIndexOf('/'); |
| 47 if (idxBeforeFilename >= 0) { |
| 48 outPath = outputFullFn.substring(0, idxBeforeFilename + 1); |
| 49 } |
| 50 |
| 51 initCssWorld(); |
| 52 |
| 53 files = new NodeFileSystem(); |
| 54 if (!files.fileExists(sourceFullFn)) { |
| 55 // Display colored error message if file is missing. |
| 56 print("\033[31mCSS source file missing - ${sourceFullFn}\033[0m"); |
| 57 } else { |
| 58 String source = files.readAll(sourceFullFn); |
| 59 |
| 60 Stylesheet stylesheet; |
| 61 |
| 62 final elapsed = time(() { |
| 63 Parser parser = new Parser( |
| 64 new lang.SourceFile(sourceFullFn, source), 0, files, sourcePath); |
| 65 stylesheet = parser.parse(); |
| 66 }); |
| 67 |
| 68 printStats(elapsed, sourceFullFn); |
| 69 |
| 70 StringBuffer buff = new StringBuffer( |
| 71 '/* File generated by SCSS from source ${sourceFilename}\n' + |
| 72 ' * Do not edit.\n' + |
| 73 ' */\n\n'); |
| 74 buff.add(stylesheet.toString()); |
| 75 |
| 76 files.writeString(outputFullFn, buff.toString()); |
| 77 print("Generated file ${outputFullFn}"); |
| 78 |
| 79 // Generate CSS.dart file. |
| 80 String genDartClassFile = Generate.dartClass(files, outPath, stylesheet, |
| 81 sourceFilename); |
| 82 print("Generated file ${genDartClassFile}"); |
| 83 } |
| 84 } |
OLD | NEW |