|
2 | 2 |
|
3 | 3 | const { spawn } = require('child_process')
|
4 | 4 |
|
5 |
| -const chalk = require('chalk') |
6 |
| -const inquirer = require('inquirer') |
| 5 | +const cliSelect = require('cli-select') |
7 | 6 | const simpleGit = require('simple-git')
|
8 | 7 |
|
9 | 8 | const git = simpleGit(process.cwd())
|
10 | 9 |
|
11 | 10 | const COMMAND = 'npm run bench'
|
12 | 11 | const DEFAULT_BRANCH = 'master'
|
13 | 12 | const PERCENT_THRESHOLD = 5
|
| 13 | +const greyColor = '\x1b[30m' |
| 14 | +const redColor = '\x1b[31m' |
| 15 | +const greenColor = '\x1b[32m' |
| 16 | +const resetColor = '\x1b[0m' |
14 | 17 |
|
15 | 18 | async function selectBranchName (message, branches) {
|
16 |
| - const result = await inquirer.prompt([{ |
| 19 | + console.log(message) |
| 20 | + const result = await cliSelect({ |
17 | 21 | type: 'list',
|
18 | 22 | name: 'branch',
|
19 |
| - choices: branches, |
20 |
| - loop: false, |
21 |
| - pageSize: 20, |
22 |
| - message |
23 |
| - }]) |
24 |
| - return result.branch |
| 23 | + values: branches |
| 24 | + }) |
| 25 | + console.log(result.value) |
| 26 | + return result.value |
25 | 27 | }
|
26 | 28 |
|
27 | 29 | async function executeCommandOnBranch (command, branch) {
|
28 |
| - console.log(chalk.grey(`Checking out "${branch}"`)) |
| 30 | + console.log(`${greyColor}Checking out "${branch}"${resetColor}`) |
29 | 31 | await git.checkout(branch)
|
30 | 32 |
|
31 |
| - console.log(chalk.grey(`Execute "${command}"`)) |
| 33 | + console.log(`${greyColor}Execute "${command}"${resetColor}`) |
32 | 34 | const childProcess = spawn(command, { stdio: 'pipe', shell: true })
|
33 | 35 |
|
34 | 36 | let result = ''
|
@@ -74,9 +76,9 @@ function compareResults (featureBranch, mainBranch) {
|
74 | 76 | const message = alignedName + percentString.padStart(7, '.')
|
75 | 77 |
|
76 | 78 | if (roundedPercent > PERCENT_THRESHOLD) {
|
77 |
| - console.log(chalk.green(message)) |
| 79 | + console.log(`${greenColor}${message}${resetColor}`) |
78 | 80 | } else if (roundedPercent < -PERCENT_THRESHOLD) {
|
79 |
| - console.log(chalk.red(message)) |
| 81 | + console.log(`${redColor}${message}${resetColor}`) |
80 | 82 | } else {
|
81 | 83 | console.log(message)
|
82 | 84 | }
|
@@ -110,5 +112,5 @@ function compareResults (featureBranch, mainBranch) {
|
110 | 112 | await git.checkout(currentBranch.commit)
|
111 | 113 | await git.checkout(currentBranch.name)
|
112 | 114 |
|
113 |
| - console.log(chalk.gray(`Back to ${currentBranch.name} ${currentBranch.commit}`)) |
| 115 | + console.log(`${greyColor}Back to ${currentBranch.name} ${currentBranch.commit}${resetColor}`) |
114 | 116 | })()
|
0 commit comments