Skip to content

Commit 9835dd2

Browse files
committed
refactor(token): The optimization moves the token writing logic from the CLI layer to the token module
1 parent 2f1354b commit 9835dd2

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/cli.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { writeFile } from 'node:fs/promises'
21
import cac from 'cac'
32
import { resolveConfig } from '@/config.ts'
4-
import { loaderToken } from '@/token.ts'
3+
import { loaderToken, setToken } from '@/token.ts'
54
import { printWarning } from '@/utils.ts'
65
import { name, version } from '../package.json'
76

@@ -27,7 +26,7 @@ cli.command('set <token>', 'Set the local release Token')
2726
.action(async (token: string = '') => {
2827
try {
2928
const config = await resolveConfig()
30-
await writeFile(config.tokenFile, `export default "${token}"`)
29+
await setToken(config, token)
3130
}
3231
catch (error: any) {
3332
printWarning(error.message)

src/token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { IConfig } from '@/types'
22
import { writeFile } from 'node:fs/promises'
33
import { resolve } from 'node:path'
44
import { createJiti } from 'jiti'
5-
import { CACHE_FOLDER_NAME, CACHE_TOKEN_FILE_PATH } from '@/constant.ts'
5+
import { CACHE_FOLDER_NAME } from '@/constant.ts'
66
import { createDir } from '@/utils.ts'
77

88
export const setToken = async (config: IConfig, token: string): Promise<void> => {
99
createDir(resolve(config.cwd, CACHE_FOLDER_NAME))
10-
await writeFile(resolve(config.cwd, CACHE_TOKEN_FILE_PATH), `export default "${token}"`)
10+
await writeFile(config.tokenFile, `export default "${token}"`)
1111
}
1212

1313
export const loaderToken = async (config: IConfig): Promise<string> => {

0 commit comments

Comments
 (0)