| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library polymer.src.compiler_options; | |
| 6 | |
| 7 import 'package:args/args.dart'; | |
| 8 | |
| 9 class CompilerOptions { | |
| 10 /** Report warnings as errors. */ | |
| 11 final bool warningsAsErrors; | |
| 12 | |
| 13 /** True to show informational messages. The `--verbose` flag. */ | |
| 14 final bool verbose; | |
| 15 | |
| 16 /** Remove any generated files. */ | |
| 17 final bool clean; | |
| 18 | |
| 19 /** Whether to use colors to print messages on the terminal. */ | |
| 20 final bool useColors; | |
| 21 | |
| 22 /** Force mangling any generated name (even when --out is provided). */ | |
| 23 final bool forceMangle; | |
| 24 | |
| 25 /** Generate component's dart code, but not the main entry point file. */ | |
| 26 final bool componentsOnly; | |
| 27 | |
| 28 /** File to process by the compiler. */ | |
| 29 String inputFile; | |
| 30 | |
| 31 /** Directory where all sources are found. */ | |
| 32 final String baseDir; | |
| 33 | |
| 34 /** Directory where all output will be generated. */ | |
| 35 final String outputDir; | |
| 36 | |
| 37 /** Directory where to look for 'package:' imports. */ | |
| 38 final String packageRoot; | |
| 39 | |
| 40 /** | |
| 41 * Adjust resource URLs in the output HTML to point back to the original | |
| 42 * location in the file system. Commonly this is enabled during development, | |
| 43 * but disabled for deployment. | |
| 44 */ | |
| 45 final bool rewriteUrls; | |
| 46 | |
| 47 /** | |
| 48 * Whether to print error messages using the json format understood by the | |
| 49 * Dart editor. | |
| 50 */ | |
| 51 final bool jsonFormat; | |
| 52 | |
| 53 /** Emulate scoped styles using a CSS polyfill. */ | |
| 54 final bool emulateScopedCss; | |
| 55 | |
| 56 /** Use CSS file for CSS Reset. */ | |
| 57 final String resetCssFile; | |
| 58 | |
| 59 // We could make this faster, if it ever matters. | |
| 60 factory CompilerOptions() => parse(['']); | |
| 61 | |
| 62 CompilerOptions.fromArgs(ArgResults args) | |
| 63 : warningsAsErrors = args['warnings_as_errors'], | |
| 64 verbose = args['verbose'], | |
| 65 clean = args['clean'], | |
| 66 useColors = args['colors'], | |
| 67 baseDir = args['basedir'], | |
| 68 outputDir = args['out'], | |
| 69 packageRoot = args['package-root'], | |
| 70 rewriteUrls = args['rewrite-urls'], | |
| 71 forceMangle = args['unique_output_filenames'], | |
| 72 jsonFormat = args['json_format'], | |
| 73 componentsOnly = args['components_only'], | |
| 74 emulateScopedCss = args['scoped-css'], | |
| 75 resetCssFile = args['css-reset'], | |
| 76 inputFile = args.rest.length > 0 ? args.rest[0] : null; | |
| 77 | |
| 78 /** | |
| 79 * Returns the compiler options parsed from [arguments]. Set [checkUsage] to | |
| 80 * false to suppress checking of correct usage or printing help messages. | |
| 81 */ | |
| 82 // TODO(sigmund): convert all flags to use dashes instead of underscores | |
| 83 static CompilerOptions parse(List<String> arguments, | |
| 84 {bool checkUsage: true}) { | |
| 85 var parser = new ArgParser() | |
| 86 ..addFlag('verbose', abbr: 'v') | |
| 87 ..addFlag('clean', help: 'Remove all generated files', | |
| 88 defaultsTo: false, negatable: false) | |
| 89 ..addFlag('warnings_as_errors', abbr: 'e', | |
| 90 help: 'Warnings handled as errors', | |
| 91 defaultsTo: false, negatable: false) | |
| 92 ..addFlag('colors', help: 'Display errors/warnings in colored text', | |
| 93 defaultsTo: true) | |
| 94 ..addFlag('rewrite-urls', | |
| 95 help: 'Adjust every resource url to point to the original location in' | |
| 96 ' the filesystem.\nThis on by default during development and can be' | |
| 97 ' disabled to make the generated code easier to deploy.', | |
| 98 defaultsTo: true) | |
| 99 ..addFlag('unique_output_filenames', abbr: 'u', | |
| 100 help: 'Use unique names for all generated files, so they will not ' | |
| 101 'have the\nsame name as your input files, even if they are in a' | |
| 102 ' different directory', | |
| 103 defaultsTo: false, negatable: false) | |
| 104 ..addFlag('json_format', | |
| 105 help: 'Print error messsages in a json format easy to parse by tools,' | |
| 106 ' such as the Dart editor', | |
| 107 defaultsTo: false, negatable: false) | |
| 108 ..addFlag('components_only', | |
| 109 help: 'Generate only the code for component classes, do not generate ' | |
| 110 'HTML files or the main bootstrap code.', | |
| 111 defaultsTo: false, negatable: false) | |
| 112 ..addFlag('scoped-css', help: 'Emulate scoped styles with CSS polyfill', | |
| 113 defaultsTo: false) | |
| 114 ..addOption('css-reset', abbr: 'r', help: 'CSS file used to reset CSS') | |
| 115 // TODO(sigmund): remove this flag | |
| 116 ..addFlag('deploy', help: '(deprecated) currently a noop', | |
| 117 defaultsTo: false, negatable: false) | |
| 118 ..addOption('out', abbr: 'o', help: 'Directory where to generate files' | |
| 119 ' (defaults to the same directory as the source file)') | |
| 120 ..addOption('basedir', help: 'Base directory where to find all source ' | |
| 121 'files (defaults to the source file\'s directory)') | |
| 122 ..addOption('package-root', help: 'Where to find "package:" imports' | |
| 123 '(defaults to the "packages/" subdirectory next to the source file)') | |
| 124 ..addFlag('help', abbr: 'h', help: 'Displays this help message', | |
| 125 defaultsTo: false, negatable: false); | |
| 126 try { | |
| 127 var results = parser.parse(arguments); | |
| 128 if (checkUsage && (results['help'] || results.rest.length == 0)) { | |
| 129 showUsage(parser); | |
| 130 return null; | |
| 131 } | |
| 132 return new CompilerOptions.fromArgs(results); | |
| 133 } on FormatException catch (e) { | |
| 134 print(e.message); | |
| 135 showUsage(parser); | |
| 136 return null; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 static showUsage(parser) { | |
| 141 print('Usage: dwc [options...] input.html'); | |
| 142 print(parser.getUsage()); | |
| 143 } | |
| 144 } | |
| OLD | NEW |