Skip to content

Commit

Permalink
fix benchmark-cmp-branch, remove chalk and inquirer (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jun 25, 2022
1 parent bcd1296 commit a93bb18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ on:
jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
with:
auto-merge-exclude: 'chalk'
30 changes: 16 additions & 14 deletions benchmark/bench-cmp-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@

const { spawn } = require('child_process')

const chalk = require('chalk')
const inquirer = require('inquirer')
const cliSelect = require('cli-select')
const simpleGit = require('simple-git')

const git = simpleGit(process.cwd())

const COMMAND = 'npm run bench'
const DEFAULT_BRANCH = 'master'
const PERCENT_THRESHOLD = 5
const greyColor = '\x1b[30m'
const redColor = '\x1b[31m'
const greenColor = '\x1b[32m'
const resetColor = '\x1b[0m'

async function selectBranchName (message, branches) {
const result = await inquirer.prompt([{
console.log(message)
const result = await cliSelect({
type: 'list',
name: 'branch',
choices: branches,
loop: false,
pageSize: 20,
message
}])
return result.branch
values: branches
})
console.log(result.value)
return result.value
}

async function executeCommandOnBranch (command, branch) {
console.log(chalk.grey(`Checking out "${branch}"`))
console.log(`${greyColor}Checking out "${branch}"${resetColor}`)
await git.checkout(branch)

console.log(chalk.grey(`Execute "${command}"`))
console.log(`${greyColor}Execute "${command}"${resetColor}`)
const childProcess = spawn(command, { stdio: 'pipe', shell: true })

let result = ''
Expand Down Expand Up @@ -74,9 +76,9 @@ function compareResults (featureBranch, mainBranch) {
const message = alignedName + percentString.padStart(7, '.')

if (roundedPercent > PERCENT_THRESHOLD) {
console.log(chalk.green(message))
console.log(`${greenColor}${message}${resetColor}`)
} else if (roundedPercent < -PERCENT_THRESHOLD) {
console.log(chalk.red(message))
console.log(`${redColor}${message}${resetColor}`)
} else {
console.log(message)
}
Expand Down Expand Up @@ -110,5 +112,5 @@ function compareResults (featureBranch, mainBranch) {
await git.checkout(currentBranch.commit)
await git.checkout(currentBranch.name)

console.log(chalk.gray(`Back to ${currentBranch.name} ${currentBranch.commit}`))
console.log(`${greyColor}Back to ${currentBranch.name} ${currentBranch.commit}${resetColor}`)
})()
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
"devDependencies": {
"@sinclair/typebox": "^0.23.3",
"benchmark": "^2.1.4",
"chalk": "^4.1.2",
"cli-select": "^1.1.2",
"compile-json-stringify": "^0.1.2",
"inquirer": "^9.0.0",
"is-my-json-valid": "^2.20.0",
"luxon": "^2.4.0",
"pre-commit": "^1.2.2",
Expand Down

0 comments on commit a93bb18

Please sign in to comment.