Skip to content

Commit

Permalink
💡 feat: replace chalk with picocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
unickowl committed Feb 29, 2024
1 parent 8581624 commit cd897e7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
20 changes: 10 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const prompts = require('prompts')
const execa = require('execa')
const types = require('./types')
const projects = require('./projects')
const chalk = require('chalk')
const picocolors = require('picocolors')
const fs = require('fs')

let defaultProjectValue = ''
try {
const config = fs.readFileSync(`${__dirname}/cz_config.json`)
defaultProjectValue = JSON.parse(config).defaultProject
} catch (e) {
console.log(chalk.yellow.italic(' 💡 You can try `cz -i` to choose a default project prefix. '))
console.log(picocolors.yellow(' 💡 You can try `cz -i` to choose a default project prefix. '))
defaultProjectValue = ''
}

Expand Down Expand Up @@ -86,7 +86,7 @@ const step_jira_id = {
name: 'jira_id',
message: 'Jira issue id',
onRender () {
this.msg = chalk.bgBlueBright.white(' Jira issue ID ')
this.msg = picocolors.bgBlueBright.white(' Jira issue ID ')
},
validate: value => {
if (!value) {
Expand Down Expand Up @@ -120,7 +120,7 @@ module.exports = async () => {
})

if (isCanceled) {
console.log(chalk.magentaBright(' commit abort. '))
console.log(picocolors.magenta(' commit abort. '))
return false
}

Expand All @@ -138,17 +138,17 @@ module.exports = async () => {
const branchHashName = commitResult.stdout.match(/\[(.*)\]/).pop()
const [branchName, branchHash] = branchHashName.split(' ')
console.log('-----------------------------------------------------------')
console.log(chalk(commitResult.stdout))
console.log(picocolors.dim(commitResult.stdout))
if (commitResult.stderr !== '') {
console.log('-----------------------------------------------------------')
console.log(chalk(commitResult.stderr))
console.log(picocolors.dim(commitResult.stderr))
}
console.log('-----------------------------------------------------------')
console.log(chalk.green(result))
console.log(chalk.bold(branchName), chalk.bgCyanBright.black(` ${branchHash} `))
console.log(picocolors.green(result))
console.log(picocolors.bold(branchName), picocolors.bgCyan(` ${branchHash} `))
} catch (error) {
console.log(chalk.redBright(error.stderr))
if (error.exitCode === 1) console.log(chalk.bgRed.white(' Nothing to commit. '))
console.log(picocolors.red(error.stderr))
if (error.exitCode === 1) console.log(picocolors.bgRed(' No changes added to commit. '))
else console.error(error)
}
}
8 changes: 4 additions & 4 deletions cz_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs')
const projects = require('./projects')
const prompts = require('prompts')
const chalk = require('chalk')
const picocolors = require('picocolors')

const projectsList = projects.map(project => ({
title: project.name,
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = async () => {
})

if (isCanceled) {
console.log(chalk.magentaBright(' init abort. '))
console.log(picocolors.magenta(' init abort. '))
return false
}

Expand All @@ -45,8 +45,8 @@ module.exports = async () => {
`${__dirname}/cz_config.json`,
`${JSON.stringify({ defaultProject: set_default_project } || {}, null, 2)}`,
)
console.log(chalk.green(` default project set: ${set_default_project} `))
console.log(picocolors.green(` default project set: ${set_default_project} `))
} catch (error) {
console.log(chalk.bgRed.white(' init Fail ', error))
console.log(picocolors.bgRed.white(' init Fail ', error))
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "owlting_cz",
"version": "2.0.1",
"version": "2.1.0",
"description": "create-commit for OwlTing",
"dependencies": {
"chalk": "^4.1.2",
"execa": "^5.1.1",
"picocolors": "^1.0.0",
"prompts": "^2.4.2",
"yargs": "^17.7.2"
},
Expand Down
30 changes: 7 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd897e7

Please sign in to comment.