From 1b70de1d20ec083e2c036eec8ba91f5d8648095a Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Wed, 29 Mar 2023 11:26:05 +0800 Subject: [PATCH] fix(githook.ts): capitalize OpenCommit in console output chore(githook.ts): remove unused import refactor(tokenCount.ts): simplify token count calculation The console output now correctly capitalizes OpenCommit for consistency with the project name. The unused import of fileURLToPath is removed. The tokenCount function is refactored to simplify the calculation of the token count. The Tiktoken library is no longer used, and the token count is now calculated based on the length of the content divided by an average token length of 2.7 characters. --- src/commands/githook.ts | 5 +++-- src/utils/tokenCount.ts | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) mode change 100644 => 100755 src/commands/githook.ts diff --git a/src/commands/githook.ts b/src/commands/githook.ts old mode 100644 new mode 100755 index e6f2dfd..59ca614 --- a/src/commands/githook.ts +++ b/src/commands/githook.ts @@ -6,6 +6,7 @@ import { existsSync } from 'fs'; import chalk from 'chalk'; import { intro, outro } from '@clack/prompts'; import { COMMANDS } from '../CommandsEnum.js'; +import { fileURLToPath } from 'url'; const HOOK_NAME = 'prepare-commit-msg'; const SYMLINK_URL = `.git/hooks/${HOOK_NAME}`; @@ -28,7 +29,7 @@ export const hookCommand = command( const { setUnset: mode } = argv._; if (mode === 'set') { - intro(`setting opencommit as '${HOOK_NAME}' hook`); + intro(`setting OpenCommit as '${HOOK_NAME}' hook`); if (isHookExists) { let realPath; @@ -40,7 +41,7 @@ export const hookCommand = command( } if (realPath === HOOK_URL) - return outro(`opencommit is already set as '${HOOK_NAME}'`); + return outro(`OpenCommit is already set as '${HOOK_NAME}'`); throw new Error( `Different ${HOOK_NAME} is already set. Remove it before setting opencommit as '${HOOK_NAME}' hook.` diff --git a/src/utils/tokenCount.ts b/src/utils/tokenCount.ts index 676445d..fafbf8f 100644 --- a/src/utils/tokenCount.ts +++ b/src/utils/tokenCount.ts @@ -1,14 +1,14 @@ -import { Tiktoken } from '@dqbd/tiktoken/lite'; -import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' }; +// import { Tiktoken } from '@dqbd/tiktoken/lite'; +// import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' }; export function tokenCount(content: string): number { - const encoding = new Tiktoken( - cl100k_base.bpe_ranks, - cl100k_base.special_tokens, - cl100k_base.pat_str - ); - const tokens = encoding.encode(content); - encoding.free(); + // const encoding = new Tiktoken( + // cl100k_base.bpe_ranks, + // cl100k_base.special_tokens, + // cl100k_base.pat_str + // ); + // const tokens = encoding.encode(content); + // encoding.free(); - return tokens.length; + return content.length / 2.7; }