UNPKG

8.86 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
7 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
8 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
9 * Google as part of the polymer project is also subject to an additional IP
10 * rights grant found at http://polymer.github.io/PATENTS.txt
11 */
12var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15}) : (function(o, m, k, k2) {
16 if (k2 === undefined) k2 = k;
17 o[k2] = m[k];
18}));
19var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20 Object.defineProperty(o, "default", { enumerable: true, value: v });
21}) : function(o, v) {
22 o["default"] = v;
23});
24var __importStar = (this && this.__importStar) || function (mod) {
25 if (mod && mod.__esModule) return mod;
26 var result = {};
27 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28 __setModuleDefault(result, mod);
29 return result;
30};
31Object.defineProperty(exports, "__esModule", { value: true });
32exports.parseFlags = exports.optDefs = exports.defaultInstallDir = void 0;
33const os = __importStar(require("os"));
34const path = __importStar(require("path"));
35const browser_1 = require("./browser");
36const defaults = __importStar(require("./defaults"));
37const types_1 = require("./types");
38const commandLineArgs = require("command-line-args");
39exports.defaultInstallDir = path.join(os.tmpdir(), 'tachometer', 'versions');
40exports.optDefs = [
41 {
42 name: 'help',
43 description: 'Show documentation',
44 type: Boolean,
45 defaultValue: false,
46 },
47 {
48 name: 'version',
49 description: 'Show the installed version of tachometer',
50 type: Boolean,
51 defaultValue: false,
52 },
53 {
54 name: 'root',
55 description: `Root directory to search for benchmarks (default ${defaults.root})`,
56 type: String,
57 },
58 {
59 name: 'host',
60 description: 'Which host to run on',
61 type: String,
62 defaultValue: '127.0.0.1',
63 },
64 {
65 name: 'remote-accessible-host',
66 description: 'When using a browser over a remote WebDriver connection, ' +
67 'the URL that those browsers should use to access the local ' +
68 'tachometer server (default to value of --host).',
69 type: String,
70 defaultValue: '',
71 },
72 {
73 name: 'port',
74 description: 'Which ports to run on (comma-delimited preference list, ' +
75 '0 for random, default [8080, 8081, ..., 0])',
76 type: (flag) => flag.split(',').map(Number),
77 defaultValue: [8080, 8081, 8082, 8083, 0],
78 },
79 {
80 name: 'config',
81 description: 'Path to JSON config file (see README for format)',
82 type: String,
83 defaultValue: '',
84 },
85 {
86 name: 'package-version',
87 description: 'Specify an NPM package version to swap in (see README)',
88 alias: 'p',
89 type: String,
90 defaultValue: [],
91 lazyMultiple: true,
92 },
93 {
94 name: 'npm-install-dir',
95 description: `Where to install custom package versions ` +
96 `(default ${exports.defaultInstallDir})`,
97 type: String,
98 defaultValue: exports.defaultInstallDir,
99 },
100 {
101 name: 'force-clean-npm-install',
102 description: `Always do a from-scratch NPM install when using custom ` +
103 `package versions. If false (the default), NPM install directories ` +
104 `will be re-used as long as the dependency versions haven't changed.`,
105 type: Boolean,
106 defaultValue: false,
107 },
108 {
109 name: 'browser',
110 description: 'Which browsers to launch in automatic mode, ' +
111 `comma-delimited (${[...browser_1.supportedBrowsers].join(', ')}) ` +
112 `(default ${defaults.browserName})`,
113 alias: 'b',
114 type: String,
115 },
116 {
117 name: 'sample-size',
118 description: 'Minimum number of times to run each benchmark' +
119 ` (default ${defaults.sampleSize})`,
120 alias: 'n',
121 type: Number,
122 },
123 {
124 name: 'manual',
125 description: 'Don\'t run automatically, just show URLs and collect results',
126 alias: 'm',
127 type: Boolean,
128 defaultValue: false,
129 },
130 {
131 name: 'json-file',
132 description: 'Save benchmark results to this JSON file.',
133 type: String,
134 defaultValue: '',
135 },
136 {
137 name: 'save',
138 description: 'Deprecated. Use --json-file instead. ' +
139 'Save benchmark JSON data to this file',
140 alias: 's',
141 type: String,
142 defaultValue: '',
143 },
144 {
145 name: 'csv-file',
146 description: 'Save benchmark results to this CSV file.',
147 type: String,
148 defaultValue: '',
149 },
150 {
151 name: 'csv-file-raw',
152 description: 'Save raw benchmark measurement samples to this CSV file.',
153 type: String,
154 defaultValue: '',
155 },
156 {
157 name: 'measure',
158 description: 'Which time interval to measure. Options:\n' +
159 '* callback: call bench.start() and bench.stop() (default)\n' +
160 '* global: set window.tachometerResult = <milliseconds>\n' +
161 '* fcp: first contentful paint',
162 type: (str) => {
163 if (!types_1.measurements.has(str)) {
164 throw new Error(`Expected --measure flag to be one of: ` +
165 `${[...types_1.measurements.values()].join(', ')} ` +
166 `but was '${str}'`);
167 }
168 return str;
169 },
170 },
171 {
172 name: 'measurement-expression',
173 description: 'Javascript expression to poll from page to retrieve global\n' +
174 'result. Only valid when --measure=global.',
175 type: String,
176 defaultValue: defaults.measurementExpression
177 },
178 {
179 name: 'horizon',
180 description: 'The degrees of difference to try and resolve when auto-sampling ' +
181 '(milliseconds, comma-delimited, optionally signed, ' +
182 // TODO Not sure why, but tslint throws a compilation error without the
183 // "|| []" short-circuit "TypeError: Cannot read property 'join' of
184 // undefined".
185 `default ${(defaults.horizons || []).join(',')})`,
186 type: String,
187 },
188 {
189 name: 'timeout',
190 description: 'The maximum number of minutes to spend auto-sampling ' +
191 `(default ${defaults.timeout}).`,
192 type: Number,
193 },
194 {
195 name: 'github-check',
196 description: 'Post benchmark results as a GitHub Check. A JSON object ' +
197 'with properties appId, installationId, repo, and commit.',
198 type: String,
199 defaultValue: '',
200 },
201 {
202 name: 'resolve-bare-modules',
203 description: 'Whether to automatically convert ES module imports with ' +
204 'bare module specifiers to paths (default true).',
205 type: booleanString('resolve-bare-modules'),
206 typeLabel: 'true|false',
207 },
208 {
209 name: 'window-size',
210 description: `"width,height" in pixels of the window to open for all browsers` +
211 ` (default "${defaults.windowWidth},${defaults.windowHeight}").`,
212 type: String,
213 },
214];
215/**
216 * Boolean flags that default to true are not supported
217 * (https://github.com/75lb/command-line-args/issues/71).
218 */
219function booleanString(flagName) {
220 return (str) => {
221 if (str === 'true' || str === '') {
222 return true;
223 }
224 else if (str === 'false') {
225 return false;
226 }
227 throw new Error(`Invalid --${flagName}. Expected true or false but was ${str}.`);
228 };
229}
230/**
231 * Parse the given CLI argument list.
232 */
233function parseFlags(argv) {
234 const opts = commandLineArgs(exports.optDefs, { partial: true, argv });
235 // Note that when a flag is used but not set to a value (i.e. "tachometer
236 // --resolve-bare-modules ..."), then the type function is not invoked, and
237 // the value will be null. Since in default-false cases (which aren't
238 // supported by command-line-args) that form should be true, we need to fix
239 // those cases up after parsing.
240 if (opts['resolve-bare-modules'] === null) {
241 opts['resolve-bare-modules'] = true;
242 }
243 return opts;
244}
245exports.parseFlags = parseFlags;
246//# sourceMappingURL=flags.js.map
\No newline at end of file