Skip to content

Commit 7885285

Browse files
committed
refactor: upgrade @poppinss/cliui
1 parent c63d9fc commit 7885285

23 files changed

+80
-80
lines changed

.prettierignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"devDependencies": {
4545
"@sxzz/eslint-config-prettier": "^2.4.6",
4646
"@sxzz/eslint-config-ts": "^2.4.6",
47+
"@sxzz/prettier-config": "^1.0.4",
4748
"@types/node": "^20.8.10",
4849
"bumpp": "^9.2.0",
4950
"date-fns": "^2.30.0",
@@ -57,5 +58,6 @@
5758
},
5859
"engines": {
5960
"node": ">=16.14.0"
60-
}
61+
},
62+
"prettier": "@sxzz/prettier-config"
6163
}

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command/like-rank.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { logger } from '@poppinss/cliui'
21
import { createCommand } from 'commander'
32
import { limit } from 'jike-sdk/polyfill'
3+
import { ui } from '../ui'
44
import { createClient, displayUser, filterUsers } from '../utils/user'
55
import { displayImage, renderDivider } from '../utils/terminal'
66
import type { Entity } from 'jike-sdk/polyfill'
@@ -26,7 +26,7 @@ export const likeRank = createCommand('like-rank')
2626
export const likeRanking = async ({ top, count }: LikeRankOptions) => {
2727
const [user] = filterUsers()
2828

29-
const spinner = logger.await('Fetching posts')
29+
const spinner = ui.logger.await('Fetching posts')
3030

3131
const client = createClient(user)
3232
const posts = await client.getSelf().queryPersonalUpdate({
@@ -59,8 +59,8 @@ export const likeRanking = async ({ top, count }: LikeRankOptions) => {
5959
.map(async ({ user, count }) => {
6060
const ranking = getRanking(count)
6161
let text = `${renderRanking(ranking)} ${displayUser(
62-
user
63-
)} 点赞 ${logger.colors.cyan(`${count}`)} 次,${(
62+
user,
63+
)} 点赞 ${ui.colors.cyan(`${count}`)} 次,${(
6464
(count / posts.length) *
6565
100
6666
).toFixed(2)}%`
@@ -71,7 +71,7 @@ export const likeRanking = async ({ top, count }: LikeRankOptions) => {
7171
}\n${text}\n${divider}`
7272
}
7373
return text
74-
})
74+
}),
7575
)
7676

7777
spinner.stop()

src/command/msg.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { logger } from '@poppinss/cliui'
21
import { createCommand } from 'commander'
32
import { limit } from 'jike-sdk/polyfill'
43
import { format } from 'date-fns'
4+
import { ui } from '../ui'
55
import { displayImage, printIfRaw, renderDivider } from '../utils/terminal'
66
import { createClient, displayUsers, filterUsers } from '../utils/user'
7-
import type { Spinner } from '@poppinss/cliui/build/src/Logger/Spinner'
87
import type { Entity } from 'jike-sdk/polyfill'
98

109
interface NotificationOptions {
@@ -29,7 +28,7 @@ const showNotifications = async (opts: NotificationOptions) => {
2928
const client = createClient(user)
3029

3130
const count = +(opts.count ?? 30)
32-
const spinner = logger.await('Loading notifications...')
31+
const spinner = ui.logger.await('Loading notifications...')
3332
const notifications = await client
3433
.queryNotifications({
3534
limit: limit.limitMaxCount(count),
@@ -40,19 +39,20 @@ const showNotifications = async (opts: NotificationOptions) => {
4039
100
4140
).toFixed(2)}%)`
4241
)
42+
return true
4343
},
4444
})
4545
.finally(() => spinner.stop())
4646

47-
logger.success('Loading notifications done!')
47+
ui.logger.success('Loading notifications done!')
4848

4949
printIfRaw(notifications)
5050

5151
{
5252
const divider = renderDivider()
5353

54-
let spinner: Spinner | undefined
55-
if (opts.image) spinner = logger.await('Downloading images')
54+
let spinner: ReturnType<typeof ui.logger.await> | undefined
55+
if (opts.image) spinner = ui.logger.await('Downloading images')
5656

5757
const texts = (
5858
await Promise.all(
@@ -75,7 +75,7 @@ async function renderNotification(
7575
): Promise<string[]> {
7676
const users = n.actionItem?.users ?? []
7777
let usersText = displayUsers(users)
78-
const bio = logger.colors.gray(users[0].bio ?? '')
78+
const bio = ui.colors.gray(users[0].bio ?? '')
7979

8080
const usersCount = n.actionItem?.usersCount
8181
if (typeof usersCount === 'number' && users.length !== usersCount) {
@@ -106,7 +106,7 @@ async function renderNotification(
106106

107107
if (texts) {
108108
const timeStr = format(new Date(n.createdAt), 'yyyy-MM-dd HH:mm:ss')
109-
texts.unshift(logger.colors.gray(timeStr))
109+
texts.unshift(ui.colors.gray(timeStr))
110110
return texts.filter((text) => text.trim() !== EMPTY_PLACEHOLDER)
111111
} else {
112112
warnUnknownType(n)
@@ -178,7 +178,7 @@ async function renderNotification(
178178

179179
const warnUnknownType = (n: Entity.Notification) => {
180180
const info = [n.type, n.actionType, n.actionItem.type].join('||')
181-
logger.warning(
181+
ui.logger.warning(
182182
`Unknown notification: ${info}. Please send it to developer, thanks!`
183183
)
184184
}

src/command/post/create.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { spawnSync } from 'node:child_process'
44
import { createCommand } from 'commander'
55
import { ApiOptions } from 'jike-sdk/polyfill'
66
import { format } from 'date-fns'
7-
import { logger, sticker } from '@poppinss/cliui'
87
import enquirer from 'enquirer'
8+
import { ui } from '../../ui'
99
import { configDir } from '../../utils/config'
1010
import { createClient, displayConfigUser, filterUsers } from '../../utils/user'
1111
import { errorAndExit } from '../../utils/log'
@@ -41,7 +41,7 @@ export const createPost = async ({ content, topic }: CreateOptions) => {
4141
spawnSync('vim', [draftFile], { stdio: 'inherit' })
4242

4343
content = await readFile(draftFile, 'utf-8').catch((err) => {
44-
logger.warning(err)
44+
ui.logger.warning(err)
4545
return ''
4646
})
4747
}
@@ -51,7 +51,7 @@ export const createPost = async ({ content, topic }: CreateOptions) => {
5151
errorAndExit(new Error('Content is required.'))
5252
}
5353

54-
const s = sticker().heading('✍️ Content')
54+
const s = ui.sticker().heading('✍️ Content')
5555
content.split('\n').forEach((line) => s.add(line))
5656
s.render()
5757

@@ -64,7 +64,7 @@ export const createPost = async ({ content, topic }: CreateOptions) => {
6464
initial: true,
6565
})
6666
if (!isConfirm) {
67-
logger.error('User canceled.')
67+
ui.logger.error('User canceled.')
6868
return
6969
}
7070

@@ -74,9 +74,9 @@ export const createPost = async ({ content, topic }: CreateOptions) => {
7474
.createPost(ApiOptions.PostType.ORIGINAL, content, {
7575
topicId: topic,
7676
})
77-
.catch((err) => logger.fatal(err))
78-
logger.success(
79-
`${logger.colors.bold(displayConfigUser(user))} posted successfully!`
77+
.catch((err) => ui.logger.fatal(err))
78+
ui.logger.success(
79+
`${ui.colors.bold(displayConfigUser(user))} posted successfully!`
8080
)
8181
}
8282
}

src/command/post/feed.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createCommand } from 'commander'
22
import { ApiOptions, limit } from 'jike-sdk/polyfill'
3-
import { logger } from '@poppinss/cliui'
3+
import { ui } from '../../ui'
44
import {
55
createClient,
66
displayUser,
@@ -70,8 +70,8 @@ async function renderPost(
7070
} else if (p.type === ApiOptions.PostType.ORIGINAL) {
7171
const detail = p.detail as Entity.OriginalPost
7272
const link = isMacOS
73-
? logger.colors.gray(
74-
logger.colors.underline(`jike://page.jk/originalPost/${p.id}`)
73+
? ui.colors.gray(
74+
ui.colors.underline(`jike://page.jk/originalPost/${p.id}`)
7575
)
7676
: ''
7777
texts.push(
@@ -92,8 +92,8 @@ async function renderPost(
9292
if (detail.linkInfo) {
9393
texts.push(
9494
(await displayImage(detail.linkInfo.pictureUrl)).result,
95-
`分享链接 [${detail.linkInfo.title}](${logger.colors.blue(
96-
logger.colors.underline(detail.linkInfo.linkUrl)
95+
`分享链接 [${detail.linkInfo.title}](${ui.colors.blue(
96+
ui.colors.underline(detail.linkInfo.linkUrl)
9797
)})`
9898
)
9999
}

src/command/post/list.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createCommand } from 'commander'
22
import { limit } from 'jike-sdk/polyfill'
3-
import { logger } from '@poppinss/cliui'
3+
import { ui } from '../../ui'
44
import { createClient, displayUser, filterUsers } from '../../utils/user'
55
import { displayImage, printIfRaw, renderDivider } from '../../utils/terminal'
66
import { isMacOS } from '../../utils/os'
@@ -47,8 +47,8 @@ async function renderPost(p: JikePostWithDetail) {
4747
const texts: string[] = []
4848
if (detail.type === 'ORIGINAL_POST') {
4949
const link = isMacOS
50-
? logger.colors.gray(
51-
logger.colors.underline(`jike://page.jk/originalPost/${p.id}`)
50+
? ui.colors.gray(
51+
ui.colors.underline(`jike://page.jk/originalPost/${p.id}`)
5252
)
5353
: ''
5454
texts.push(
@@ -69,8 +69,8 @@ async function renderPost(p: JikePostWithDetail) {
6969
if (detail.linkInfo) {
7070
texts.push(
7171
(await displayImage(detail.linkInfo.pictureUrl)).result,
72-
`分享链接 [${detail.linkInfo.title}](${logger.colors.blue(
73-
logger.colors.underline(detail.linkInfo.linkUrl)
72+
`分享链接 [${detail.linkInfo.title}](${ui.colors.blue(
73+
ui.colors.underline(detail.linkInfo.linkUrl)
7474
)})`
7575
)
7676
}

src/command/user/alias.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { logger } from '@poppinss/cliui'
21
import { createCommand } from 'commander'
2+
import { ui } from '../../ui'
33
import { filterUsers } from '../../utils/user'
44

55
export const alias = createCommand('alias')
@@ -10,10 +10,10 @@ export const alias = createCommand('alias')
1010
export const setAlias = ({ alias }: { alias: string }) => {
1111
const users = filterUsers()
1212
if (users.length > 1) {
13-
logger.error("You can't set alias for multiple users")
13+
ui.logger.error("You can't set alias for multiple users")
1414
process.exit(1)
1515
}
1616

1717
users[0].alias = alias
18-
logger.success(`Alias set to ${alias}`)
18+
ui.logger.success(`Alias set to ${alias}`)
1919
}

0 commit comments

Comments
 (0)