Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix benchmark-cmp-branch, remove chalk and inquirer #473

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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