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 /** Whether to analyze the input for warnings without generating any code. */ |
| 60 final bool analysisOnly; |
| 61 |
| 62 // We could make this faster, if it ever matters. |
| 63 factory CompilerOptions() => parse(['']); |
| 64 |
| 65 CompilerOptions.fromArgs(ArgResults args) |
| 66 : warningsAsErrors = args['warnings_as_errors'], |
| 67 verbose = args['verbose'], |
| 68 clean = args['clean'], |
| 69 useColors = args['colors'], |
| 70 baseDir = args['basedir'], |
| 71 outputDir = args['out'], |
| 72 packageRoot = args['package-root'], |
| 73 rewriteUrls = args['rewrite-urls'], |
| 74 forceMangle = args['unique_output_filenames'], |
| 75 jsonFormat = args['json_format'], |
| 76 componentsOnly = args['components_only'], |
| 77 emulateScopedCss = args['scoped-css'], |
| 78 resetCssFile = args['css-reset'], |
| 79 analysisOnly = !args['deploy'], |
| 80 inputFile = args.rest.length > 0 ? args.rest[0] : null; |
| 81 |
| 82 /** |
| 83 * Returns the compiler options parsed from [arguments]. Set [checkUsage] to |
| 84 * false to suppress checking of correct usage or printing help messages. |
| 85 */ |
| 86 // TODO(sigmund): convert all flags to use dashes instead of underscores |
| 87 static CompilerOptions parse(List<String> arguments, |
| 88 {bool checkUsage: true}) { |
| 89 var parser = new ArgParser() |
| 90 ..addFlag('verbose', abbr: 'v') |
| 91 ..addFlag('clean', help: 'Remove all generated files', |
| 92 defaultsTo: false, negatable: false) |
| 93 ..addFlag('warnings_as_errors', abbr: 'e', |
| 94 help: 'Warnings handled as errors', |
| 95 defaultsTo: false, negatable: false) |
| 96 ..addFlag('colors', help: 'Display errors/warnings in colored text', |
| 97 defaultsTo: true) |
| 98 ..addFlag('rewrite-urls', |
| 99 help: 'Adjust every resource url to point to the original location in' |
| 100 ' the filesystem.\nThis on by default during development and can be' |
| 101 ' disabled to make the generated code easier to deploy.', |
| 102 defaultsTo: true) |
| 103 ..addFlag('unique_output_filenames', abbr: 'u', |
| 104 help: 'Use unique names for all generated files, so they will not ' |
| 105 'have the\nsame name as your input files, even if they are in a' |
| 106 ' different directory', |
| 107 defaultsTo: false, negatable: false) |
| 108 ..addFlag('json_format', |
| 109 help: 'Print error messsages in a json format easy to parse by tools,' |
| 110 ' such as the Dart editor', |
| 111 defaultsTo: false, negatable: false) |
| 112 ..addFlag('components_only', |
| 113 help: 'Generate only the code for component classes, do not generate ' |
| 114 'HTML files or the main bootstrap code.', |
| 115 defaultsTo: false, negatable: false) |
| 116 ..addFlag('scoped-css', help: 'Emulate scoped styles with CSS polyfill', |
| 117 defaultsTo: false) |
| 118 ..addOption('css-reset', abbr: 'r', help: 'CSS file used to reset CSS') |
| 119 ..addFlag('deploy', help: 'Emit code used for deploying a polymer app,' |
| 120 ' if false just show warnings and errors (default)', |
| 121 defaultsTo: false, negatable: false) |
| 122 ..addOption('out', abbr: 'o', help: 'Directory where to generate files' |
| 123 ' (defaults to the same directory as the source file)') |
| 124 ..addOption('basedir', help: 'Base directory where to find all source ' |
| 125 'files (defaults to the source file\'s directory)') |
| 126 ..addOption('package-root', help: 'Where to find "package:" imports' |
| 127 '(defaults to the "packages/" subdirectory next to the source file)') |
| 128 ..addFlag('help', abbr: 'h', help: 'Displays this help message', |
| 129 defaultsTo: false, negatable: false); |
| 130 try { |
| 131 var results = parser.parse(arguments); |
| 132 if (checkUsage && (results['help'] || results.rest.length == 0)) { |
| 133 showUsage(parser); |
| 134 return null; |
| 135 } |
| 136 return new CompilerOptions.fromArgs(results); |
| 137 } on FormatException catch (e) { |
| 138 print(e.message); |
| 139 showUsage(parser); |
| 140 return null; |
| 141 } |
| 142 } |
| 143 |
| 144 static showUsage(parser) { |
| 145 print('Usage: dwc [options...] input.html'); |
| 146 print(parser.getUsage()); |
| 147 } |
| 148 } |
OLD | NEW |