| OLD | NEW |
| (Empty) | |
| 1 library angular.tools.html_expression_extractor; |
| 2 |
| 3 import 'dart:io'; |
| 4 import 'package:angular/tools/html_extractor.dart'; |
| 5 import 'package:angular/tools/source_metadata_extractor.dart'; |
| 6 import 'package:angular/tools/source_crawler_impl.dart'; |
| 7 import 'package:angular/tools/io.dart'; |
| 8 import 'package:angular/tools/io_impl.dart'; |
| 9 import 'package:angular/tools/common.dart'; |
| 10 |
| 11 import 'package:di/di.dart'; |
| 12 import 'package:di/dynamic_injector.dart'; |
| 13 import 'package:angular/core/parser/parser_library.dart'; |
| 14 import 'package:angular/tools/parser_generator/dart_code_gen.dart'; |
| 15 import 'package:angular/tools/parser_generator/generator.dart'; |
| 16 |
| 17 main(args) { |
| 18 if (args.length < 5) { |
| 19 print('Usage: expression_extractor file_to_scan html_root header_file ' |
| 20 'footer_file output [package_roots+]'); |
| 21 exit(0); |
| 22 } |
| 23 IoService ioService = new IoServiceImpl(); |
| 24 |
| 25 var packageRoots = |
| 26 (args.length < 6) ? [Platform.packageRoot] : args.sublist(5); |
| 27 var sourceCrawler = new SourceCrawlerImpl(packageRoots); |
| 28 var sourceMetadataExtractor = new SourceMetadataExtractor(sourceCrawler); |
| 29 List<DirectiveInfo> directives = |
| 30 sourceMetadataExtractor.gatherDirectiveInfo(args[0]); |
| 31 var htmlExtractor = new HtmlExpressionExtractor(directives, ioService); |
| 32 htmlExtractor.crawl(args[1]); |
| 33 |
| 34 var expressions = htmlExtractor.expressions; |
| 35 expressions.add('null'); |
| 36 |
| 37 var headerFile = args[2]; |
| 38 var footerFile = args[3]; |
| 39 var outputFile = args[4]; |
| 40 SourcePrinter _prt; |
| 41 if (outputFile == '--') { |
| 42 _prt = new SourcePrinter(); |
| 43 } else { |
| 44 _prt = new FileSourcePrinter(outputFile); |
| 45 } |
| 46 |
| 47 // Output the header file first. |
| 48 if (headerFile != '') { |
| 49 _prt.printSrc(_readFile(headerFile)); |
| 50 } |
| 51 |
| 52 _prt.printSrc('// Found ${expressions.length} expressions'); |
| 53 Module module = new Module() |
| 54 ..type(ParserBackend, implementedBy: DartCodeGen) |
| 55 ..value(SourcePrinter, _prt); |
| 56 Injector injector = |
| 57 new DynamicInjector(modules: [module], allowImplicitInjection: true); |
| 58 |
| 59 // Run the generator. |
| 60 injector.get(ParserGenerator).generateParser(htmlExtractor.expressions); |
| 61 |
| 62 // Output footer last. |
| 63 if (footerFile != '') { |
| 64 _prt.printSrc(_readFile(footerFile)); |
| 65 } |
| 66 } |
| 67 |
| 68 String _readFile(String filePath) => new File(filePath).readAsStringSync(); |
| 69 |
| 70 class FileSourcePrinter implements SourcePrinter { |
| 71 final File _file; |
| 72 |
| 73 FileSourcePrinter(String filePath) |
| 74 : _file = new File(filePath) { |
| 75 // clear file |
| 76 _file.writeAsStringSync(''); |
| 77 } |
| 78 |
| 79 printSrc(src) => _file.writeAsStringSync('$src\n', mode: FileMode.APPEND); |
| 80 } |
| OLD | NEW |