Skip to content

Commit

Permalink
refactor(live-mini): use ansis
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Oct 24, 2022
1 parent 4a7cf52 commit 6c04c36
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/bilicli/bin/bilicli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../dist/main.js')
import '../dist/index.js'
4 changes: 2 additions & 2 deletions packages/bilicli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"bilicli": "bin/bilicli.js"
},
"type": "module",
"main": "dist/main.js",
"exports": "./dist/main.js",
"main": "dist/index.js",
"exports": "./dist/index.js",
"files": [
"bin",
"dist"
Expand Down
9 changes: 7 additions & 2 deletions packages/live-mini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"description": "Bili-Live danmu client, lite version",
"type": "module",
"main": "dist/index.js",
"exports": "./dist/index.js",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"types": "dist/index.d.ts",
"scripts": {
"dev": "tsup --watch",
Expand All @@ -25,8 +30,8 @@
"author": "ddiu8081 <ddiu8081@gmail.com>",
"license": "MIT",
"dependencies": {
"ansis": "^1.5.5",
"blive-message-listener": "^0.3.1",
"chalk": "^5.1.2",
"ohmyfetch": "^0.4.20"
}
}
6 changes: 3 additions & 3 deletions packages/live-mini/src/component/roomInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import chalk from 'chalk'
import ansis from 'ansis'
import type { RoomInfo } from '../utils/getInfo'

export const roomInfoCom = (roomInfo: RoomInfo) => {
const components = [
chalk.bold(chalk.green(roomInfo.room_id)),
chalk.green(`(${roomInfo.parent_area_name}·${roomInfo.area_name})`),
ansis.bold.green(`${roomInfo.room_id}`),
ansis.green(`(${roomInfo.parent_area_name}·${roomInfo.area_name})`),
roomInfo.title
]
return components.join(' ')
Expand Down
10 changes: 5 additions & 5 deletions packages/live-mini/src/component/username.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import chalk from 'chalk'
import ansis from 'ansis'
import type { User } from 'blive-message-listener'
import { getGuardColor } from '../utils/parse'

export const usernameCom = (user: User) => {
let badge, rank, admin
if (user.badge) {
const badgeColor = user.badge.anchor.is_same_room ? user.badge.color : '#999999'
badge = chalk.bgHex(badgeColor)(` ${user.badge.name} `) + chalk.bgHex('#ffffff').hex(badgeColor)(` ${user.badge.level} `)
badge = ansis.bgHex(badgeColor)(` ${user.badge.name} `) + ansis.bgHex('#ffffff').hex(badgeColor)(` ${user.badge.level} `)
}
if (user.identity?.rank) {
rank = chalk.bgBlue(` 榜${user.identity.rank} `)
rank = ansis.bgBlue(` 榜${user.identity.rank} `)
}
if (user.identity?.room_admin) {
admin = chalk.bgRed(` 房 `)
admin = ansis.bgRed(` 房 `)
}
const uname = chalk.hex(getGuardColor(user.identity?.guard_level))(user.uname)
const uname = ansis.hex(getGuardColor(user.identity?.guard_level))(user.uname)
const components = [
badge,
rank,
Expand Down
2 changes: 1 addition & 1 deletion packages/live-mini/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup'

export default defineConfig({
format: ['esm'],
format: ['esm', 'cjs'],
entry: [
'src/index.ts',
],
Expand Down
14 changes: 7 additions & 7 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 6c04c36

Please sign in to comment.