|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -const inquirer = require("inquirer"); |
4 | 3 | const chalk = require("chalk");
|
5 | 4 | const Table = require("cli-table");
|
6 | 5 | const { join } = require("path");
|
7 | 6 | const { readdirSync, readFileSync } = require("fs");
|
8 |
| -const commander = require("commander"); |
| 7 | +const { program } = require("commander"); |
9 | 8 | const { compare } = require("./lib/autocannon");
|
10 | 9 |
|
11 |
| -commander |
| 10 | +program |
12 | 11 | .option("-t, --table", "table")
|
13 | 12 | .option("-p, --percentage", "percentage")
|
14 | 13 | .option("-c --commandlineMdTable", "Print a table for use in MarkDown")
|
15 | 14 | .parse(process.argv);
|
16 | 15 |
|
17 |
| -const options = commander.opts(); |
| 16 | +const options = program.opts(); |
18 | 17 | const resultsPath = join(process.cwd(), "results");
|
19 | 18 | let choices = readdirSync(resultsPath)
|
20 | 19 | .filter((file) => file.match(/(.+)\.json$/))
|
@@ -140,45 +139,53 @@ if (!choices.length) {
|
140 | 139 |
|
141 | 140 | console.log(table.toString());
|
142 | 141 | } else {
|
143 |
| - inquirer |
144 |
| - .prompt([ |
145 |
| - { |
146 |
| - type: "list", |
147 |
| - name: "choice", |
148 |
| - message: "What's your first pick?", |
149 |
| - choices, |
150 |
| - }, |
151 |
| - ]) |
152 |
| - .then((firstChoice) => { |
153 |
| - choices = choices.filter((choice) => choice !== firstChoice.choice); |
154 |
| - inquirer |
155 |
| - .prompt([ |
156 |
| - { |
157 |
| - type: "list", |
158 |
| - name: "choice", |
159 |
| - message: "What's your second one?", |
160 |
| - choices, |
161 |
| - }, |
162 |
| - ]) |
163 |
| - .then((secondChoice) => { |
164 |
| - const [a, b] = [firstChoice.choice, secondChoice.choice]; |
165 |
| - const result = compare(a, b); |
166 |
| - if (result === true) { |
167 |
| - console.log(chalk.green.bold(`${a} and ${b} both are fast!`)); |
168 |
| - } else { |
169 |
| - const fastest = chalk.bold.yellow(result.fastest); |
170 |
| - const fastestAverage = chalk.green(result.fastestAverage); |
171 |
| - const slowest = chalk.bold.yellow(result.slowest); |
172 |
| - const slowestAverage = chalk.green(result.slowestAverage); |
173 |
| - const diff = chalk.bold.green(result.diff); |
| 142 | + async function getInquirer() { |
| 143 | + const { default: inquirer } = await import("inquirer"); |
174 | 144 |
|
175 |
| - console.log(` |
| 145 | + return inquirer; |
| 146 | + } |
| 147 | + |
| 148 | + getInquirer().then((inquirer) => { |
| 149 | + return inquirer |
| 150 | + .prompt([ |
| 151 | + { |
| 152 | + type: "list", |
| 153 | + name: "choice", |
| 154 | + message: "What's your first pick?", |
| 155 | + choices, |
| 156 | + }, |
| 157 | + ]) |
| 158 | + .then((firstChoice) => { |
| 159 | + choices = choices.filter((choice) => choice !== firstChoice.choice); |
| 160 | + inquirer |
| 161 | + .prompt([ |
| 162 | + { |
| 163 | + type: "list", |
| 164 | + name: "choice", |
| 165 | + message: "What's your second one?", |
| 166 | + choices, |
| 167 | + }, |
| 168 | + ]) |
| 169 | + .then((secondChoice) => { |
| 170 | + const [a, b] = [firstChoice.choice, secondChoice.choice]; |
| 171 | + const result = compare(a, b); |
| 172 | + if (result === true) { |
| 173 | + console.log(chalk.green.bold(`${a} and ${b} both are fast!`)); |
| 174 | + } else { |
| 175 | + const fastest = chalk.bold.yellow(result.fastest); |
| 176 | + const fastestAverage = chalk.green(result.fastestAverage); |
| 177 | + const slowest = chalk.bold.yellow(result.slowest); |
| 178 | + const slowestAverage = chalk.green(result.slowestAverage); |
| 179 | + const diff = chalk.bold.green(result.diff); |
| 180 | + |
| 181 | + console.log(` |
176 | 182 | ${chalk.blue("Both are awesome but")} ${fastest} ${chalk.blue(
|
177 |
| - "is", |
178 |
| - )} ${diff} ${chalk.blue("faster than")} ${slowest} |
| 183 | + "is", |
| 184 | + )} ${diff} ${chalk.blue("faster than")} ${slowest} |
179 | 185 | • ${fastest} ${chalk.blue("request average is")} ${fastestAverage}
|
180 | 186 | • ${slowest} ${chalk.blue("request average is")} ${slowestAverage}`);
|
181 |
| - } |
182 |
| - }); |
183 |
| - }); |
| 187 | + } |
| 188 | + }); |
| 189 | + }); |
| 190 | + }); |
184 | 191 | }
|
0 commit comments