| 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 'dart:io'; | |
| 8 import 'css.dart'; | |
| 9 import '../lib/file_system.dart'; | |
| 10 import '../lib/file_system_vm.dart'; | |
| 11 | |
| 12 | |
| 13 FileSystem files; | |
| 14 | |
| 15 /** Invokes [callback] and returns how long it took to execute in ms. */ | |
| 16 num time(callback()) { | |
| 17 final watch = new Stopwatch(); | |
| 18 watch.start(); | |
| 19 callback(); | |
| 20 watch.stop(); | |
| 21 return watch.elapsedMilliseconds; | |
| 22 } | |
| 23 | |
| 24 printStats(num elapsed, [String filename = '']) { | |
| 25 print('Parsed ${_GREEN_COLOR}${filename}${_NO_COLOR} in ${elapsed} msec.'); | |
| 26 } | |
| 27 | |
| 28 /** | |
| 29 * Run from the `utils/css` directory. | |
| 30 */ | |
| 31 void main(List<String> optionsArgs) { | |
| 32 assert(optionArgs.length == 2); | |
| 33 | |
| 34 String sourceFullFn = optionArgs[0]; | |
| 35 String outputFullFn = optionArgs[1]; | |
| 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 VMFileSystem(); | |
| 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 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.write(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 |