From c2e2cee94b9360ad394b1ac504cf5604d3799621 Mon Sep 17 00:00:00 2001 From: Sungyu Kang Date: Mon, 16 Sep 2024 16:36:25 +0900 Subject: [PATCH 1/3] refactor: iconManager and support multiple prefix --- src/commands/add.ts | 52 ++++++++---- src/commands/sync.ts | 5 +- src/iconManager.spec.ts | 35 +++++++++ src/iconManager.ts | 113 +++++++++++++++++++++++++++ src/index.ts | 2 +- src/utils/checkAvailableIcons.ts | 17 ---- src/utils/config.ts | 8 -- src/utils/generateIcon.ts | 33 -------- src/utils/groupIconsByPrefix.spec.ts | 32 -------- src/utils/groupIconsByPrefix.ts | 16 ---- src/utils/saveIconCode.ts | 17 ++++ 11 files changed, 206 insertions(+), 124 deletions(-) create mode 100644 src/iconManager.spec.ts create mode 100644 src/iconManager.ts delete mode 100644 src/utils/checkAvailableIcons.ts delete mode 100644 src/utils/groupIconsByPrefix.spec.ts delete mode 100644 src/utils/groupIconsByPrefix.ts create mode 100644 src/utils/saveIconCode.ts diff --git a/src/commands/add.ts b/src/commands/add.ts index c5221fe..ad71cbc 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -1,29 +1,51 @@ -import { syncIcons } from "../utils/generateIcon"; -import { addIcons, checkIfConfigExists } from "../utils//config"; +import { checkIfConfigExists, loadConfig } from "../utils//config"; import { generateBaseCode } from "../utils/generateBaseCode"; import { init } from "./init"; -import { checkAvailableIcons } from "../utils/checkAvailableIcons"; -import { groupIconsByPrefix } from "../utils/groupIconsByPrefix"; import { log } from "../utils/console"; +import { isCancel, select } from "@clack/prompts"; +import { IconManager } from "src/iconManager"; -export const add = async (iconNames: string[]) => { +export const add = async (iconName: string) => { try { if (!checkIfConfigExists()) { await init(); } + const config = await loadConfig(); + const iconManager = new IconManager(config); - const groupedIcons = groupIconsByPrefix(iconNames); - await Promise.all( - groupedIcons.map(async ([prefix, icons]) => { - if (!(await checkAvailableIcons(prefix, icons))) { - throw new Error(`Not found ${icons.join(", ")}`); - } - }) - ); + const splitIconName = iconName.split("/"); + if (splitIconName.length >= 3) { + log.error("Invalid icon name"); + return; + } + + const overridePrefix = splitIconName.length === 2 ? splitIconName[0] : null; + const $iconName = splitIconName.length === 2 ? splitIconName[1] : iconName; + + const undecidedPrefixes = !overridePrefix + ? await iconManager.getResolutionPrefixes($iconName) + : [overridePrefix]; + + const prefix = + undecidedPrefixes.length === 1 + ? undecidedPrefixes[0] + : await select({ + message: "Pick a prefix.", + options: undecidedPrefixes.map((prefix) => ({ + value: prefix, + label: prefix, + })), + }); + + if (isCancel(prefix)) { + log.error("Operation cancelled"); + return; + } - const config = await addIcons(iconNames); + await iconManager.addIcon(prefix as string, $iconName); await generateBaseCode(config); - await syncIcons(config); + await iconManager.sync(); + log.success("Icon added successfully"); } catch (error) { if (error instanceof Error) { log.error(error.message); diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 08414ea..e0e8f40 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -1,12 +1,13 @@ -import { syncIcons } from "../utils/generateIcon"; +import { IconManager } from "../iconManager"; import { loadConfig } from "../utils/config"; import { generateBaseCode } from "../utils/generateBaseCode"; export const sync = async () => { try { const config = await loadConfig(); + const iconManager = new IconManager(config); await generateBaseCode(config); - await syncIcons(config); + await iconManager.sync(); } catch (error) { if (error instanceof Error) { console.error(error.message); diff --git a/src/iconManager.spec.ts b/src/iconManager.spec.ts new file mode 100644 index 0000000..364252f --- /dev/null +++ b/src/iconManager.spec.ts @@ -0,0 +1,35 @@ +import { expect, describe, it } from "vitest"; +import { IconManager } from "./iconManager"; + +describe("groupIconsByPrefix", () => { + it("should group icons by name", () => { + const iconManager = new IconManager({ + icons: [ + "ai/AiFillAccountBook", + "ai/AiFillAlert", + "cg/CgAddR", + "fa/FaApple", + "fa6/FaApple", + ], + outputPath: "", + typescript: false, + }); + + expect(iconManager.groupedIcons).toEqual([ + ["ai", ["AiFillAccountBook", "AiFillAlert"]], + ["cg", ["CgAddR"]], + ["fa", ["FaApple"]], + ["fa6", ["FaApple"]], + ]); + }); + + it("should handle empty array", () => { + const iconManager = new IconManager({ + icons: [], + outputPath: "", + typescript: false, + }); + + expect(iconManager.groupedIcons).toEqual([]); + }); +}); diff --git a/src/iconManager.ts b/src/iconManager.ts new file mode 100644 index 0000000..e0eefe9 --- /dev/null +++ b/src/iconManager.ts @@ -0,0 +1,113 @@ +import { initConfig, type Config } from "./utils/config"; +import fs from "fs/promises"; +import { separateCamelCase } from "./utils/separateCamelCase"; +import { uniq } from "./utils/uniq"; +import { log } from "./utils/console"; +import { generateIconCode } from "./utils/generateIcon"; +import { saveIconCode } from "./utils/saveIconCode"; + +export class IconManager { + private config: Config; + + private _groupedIcons: [string, string[]][] = []; + + private _prefixCodeMap: Map = new Map(); + + private _resolutionTable: Record = { + fa: ["fa", "fa6"], + hi: ["hi", "hi2"], + io: ["io", "io5"], + }; + + constructor(config: Config) { + this.config = config; + } + + private get icons() { + return this.config.icons; + } + + public async getResolutionPrefixes(iconName: string) { + const [prefix] = await separateCamelCase(iconName); + const lowerCasePrefix = prefix.toLowerCase(); + + const result: string[] = []; + const resolutionPrefixes = this._resolutionTable[lowerCasePrefix] ?? [ + lowerCasePrefix, + ]; + + for (const prefix of resolutionPrefixes) { + try { + const iconCode = await this.getIconCodeByPrefix(prefix); + if (iconCode?.includes(iconName)) { + result.push(prefix); + } + } catch {} + } + + return result; + } + + public async getIconCodeByPrefix(prefix: string) { + if (!this._prefixCodeMap.has(prefix)) { + try { + const prefixPath = await import.meta + .resolve(`react-icons/${prefix}`) + .replace("file://", ""); + + const prefixCode = await fs.readFile(prefixPath, "utf8"); + this._prefixCodeMap.set(prefix, prefixCode); + } catch { + return null; + } + } + + return this._prefixCodeMap.get(prefix); + } + + private groupIconsByPrefix() { + const groupedIcons: { [key: string]: string[] } = {}; + + for (const icon of this.icons) { + const [prefix, name] = icon.split("/"); + if (!groupedIcons[prefix]) { + groupedIcons[prefix] = []; + } + groupedIcons[prefix].push(name); + } + return Object.entries(groupedIcons); + } + + get groupedIcons() { + if (!this._groupedIcons.length) { + this._groupedIcons = this.groupIconsByPrefix(); + } + + return this._groupedIcons; + } + + public async addIcon(prefix: string, iconName: string) { + const updatedIcons = uniq([...this.icons, `${prefix}/${iconName}`]); + this.config.icons = updatedIcons; + return initConfig(this.config); + } + + public async sync() { + const groupedIcons = this.groupedIcons; + + await Promise.allSettled( + groupedIcons.map(async ([prefix, icons]) => { + try { + const data = await generateIconCode( + prefix, + icons, + this.config.typescript + ); + await saveIconCode(this.config.outputPath, data.filename, data.code); + } catch (error) { + log.error(`Not found ${prefix}`); + } + }) + ); + } +} diff --git a/src/index.ts b/src/index.ts index 29b1246..ae9f750 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ program program .command("add") .description("Add icons to the project") - .argument("", "The names of the icons to add") + .argument("", "The names of the icon to add") .action(add); program diff --git a/src/utils/checkAvailableIcons.ts b/src/utils/checkAvailableIcons.ts deleted file mode 100644 index 37f95c9..0000000 --- a/src/utils/checkAvailableIcons.ts +++ /dev/null @@ -1,17 +0,0 @@ -import fs from "fs/promises"; - -export const checkAvailableIcons = async ( - prefix: string, - iconNames: string[] -) => { - try { - const icons = import.meta.resolve(`react-icons/${prefix}`); - const file = await fs.readFile(icons.replace("file://", ""), "utf8"); - return ( - iconNames.length > 0 && - iconNames.every((iconName) => file.includes(iconName)) - ); - } catch (error) { - return false; - } -}; diff --git a/src/utils/config.ts b/src/utils/config.ts index 8f5c8fe..44ffc4a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -25,14 +25,6 @@ export const loadConfig = async () => { return config; }; -export const addIcons = async (iconNames: string[]) => { - const config = await loadConfig(); - const updatedIcons = uniq([...config.icons, ...iconNames]); - config.icons = updatedIcons; - - return initConfig(config); -}; - export const initConfig = async (config: Config) => { const cwd = getCwd(); diff --git a/src/utils/generateIcon.ts b/src/utils/generateIcon.ts index 9fcbd67..3e8f2f3 100644 --- a/src/utils/generateIcon.ts +++ b/src/utils/generateIcon.ts @@ -1,10 +1,5 @@ -import path from "path"; import fs from "fs/promises"; import { type ModuleItem, parse, print } from "@swc/core"; -import { groupIconsByPrefix } from "./groupIconsByPrefix"; -import type { Config } from "./config"; -import { getCwd } from "./cwd"; -import { log } from "./console"; import packageJson from "@/package.json"; export const generateIconCode = async ( @@ -103,31 +98,3 @@ ${code} code, }; }; - -const saveIcons = async ( - outputPath: string, - filename: string, - code: string -) => { - const cwd = getCwd(); - const $outputPath = path.join(cwd, outputPath); - await fs.mkdir($outputPath, { recursive: true }); - - await fs.writeFile(path.join($outputPath, filename), code, "utf8"); - log.save(path.join(outputPath, filename)); -}; - -export const syncIcons = async (config: Config) => { - const groupedIcons = groupIconsByPrefix(config.icons); - - await Promise.allSettled( - groupedIcons.map(async ([prefix, icons]) => { - try { - const data = await generateIconCode(prefix, icons, config.typescript); - await saveIcons(config.outputPath, data.filename, data.code); - } catch (error) { - log.error(`Not found ${prefix}`); - } - }) - ); -}; diff --git a/src/utils/groupIconsByPrefix.spec.ts b/src/utils/groupIconsByPrefix.spec.ts deleted file mode 100644 index 7ca40dd..0000000 --- a/src/utils/groupIconsByPrefix.spec.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect, describe, it } from "vitest"; -import { groupIconsByPrefix } from "./groupIconsByPrefix"; - -describe("groupIconsByPrefix", () => { - it("should group icons by name", () => { - const icons = ["AiFillAccountBook", "AiFillAlert", "CgAddR", "FaApple"]; - expect(groupIconsByPrefix(icons)).toEqual([ - ["ai", ["AiFillAccountBook", "AiFillAlert"]], - ["cg", ["CgAddR"]], - ["fa", ["FaApple"]], - ]); - }); - - it("should handle empty array", () => { - const icons: string[] = []; - expect(groupIconsByPrefix(icons)).toEqual([]); - }); - - it("should handle single icon", () => { - const icons = ["AiFillAccountBook"]; - expect(groupIconsByPrefix(icons)).toEqual([["ai", ["AiFillAccountBook"]]]); - }); - - it("should handle multiple icons with different prefixes", () => { - const icons = ["AiFillAccountBook", "CgAddR", "FaApple"]; - expect(groupIconsByPrefix(icons)).toEqual([ - ["ai", ["AiFillAccountBook"]], - ["cg", ["CgAddR"]], - ["fa", ["FaApple"]], - ]); - }); -}); diff --git a/src/utils/groupIconsByPrefix.ts b/src/utils/groupIconsByPrefix.ts deleted file mode 100644 index 3dcc481..0000000 --- a/src/utils/groupIconsByPrefix.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { separateCamelCase } from "./separateCamelCase"; - -export const groupIconsByPrefix = (icons: string[]) => { - const groupedIcons = icons.reduce((acc, icon) => { - const [prefix] = separateCamelCase(icon); - const lowerPrefix = prefix.toLowerCase(); - if (!acc[lowerPrefix]) { - acc[lowerPrefix] = []; - } - - acc[lowerPrefix].push(icon); - return acc; - }, {} as Record); - - return Object.entries(groupedIcons); -}; diff --git a/src/utils/saveIconCode.ts b/src/utils/saveIconCode.ts new file mode 100644 index 0000000..76c99ab --- /dev/null +++ b/src/utils/saveIconCode.ts @@ -0,0 +1,17 @@ +import path from "path"; +import { getCwd } from "./cwd"; +import fs from "fs/promises"; +import { log } from "./console"; + +export const saveIconCode = async ( + outputPath: string, + filename: string, + code: string +) => { + const cwd = getCwd(); + const $outputPath = path.join(cwd, outputPath); + await fs.mkdir($outputPath, { recursive: true }); + + await fs.writeFile(path.join($outputPath, filename), code, "utf8"); + log.save(path.join(outputPath, filename)); +}; From 047ecff0fd28ff18cf9547814bd9d64ce1263b96 Mon Sep 17 00:00:00 2001 From: Sungyu Kang Date: Mon, 16 Sep 2024 17:08:47 +0900 Subject: [PATCH 2/3] feat: icon manager and search --- package.json | 1 + pnpm-lock.yaml | 3 +++ react-native-icons-builder.json | 9 +++++++++ src/commands/add.ts | 25 +++++++++++++++++++------ src/iconManager.spec.ts | 6 +++++- src/iconManager.ts | 19 ++++++++++++++----- src/utils/console.ts | 3 +++ src/utils/searchFunction.spec.ts | 21 +++++++++++++++++++++ src/utils/searchFunction.ts | 9 +++++++++ vitest.config.ts | 11 +++++++++++ 10 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 react-native-icons-builder.json create mode 100644 src/utils/searchFunction.spec.ts create mode 100644 src/utils/searchFunction.ts create mode 100644 vitest.config.ts diff --git a/package.json b/package.json index 7f1dd52..0e58ab8 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "react-native-svg": "^15.6.0", "tsup": "^8.2.4", "typescript": "^5.6.2", + "vite": "^5.4.5", "vitest": "^2.1.1" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca8b284..30c292d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,9 @@ importers: typescript: specifier: ^5.6.2 version: 5.6.2 + vite: + specifier: ^5.4.5 + version: 5.4.5(@types/node@22.5.4)(terser@5.32.0) vitest: specifier: ^2.1.1 version: 2.1.1(@types/node@22.5.4)(terser@5.32.0) diff --git a/react-native-icons-builder.json b/react-native-icons-builder.json new file mode 100644 index 0000000..1d28a8d --- /dev/null +++ b/react-native-icons-builder.json @@ -0,0 +1,9 @@ +{ + "typescript": true, + "outputPath": "assets/icons", + "icons": [ + "bs/Bs0Circle", + "fa/Fa500Px", + "fa6/Fa500Px" + ] +} \ No newline at end of file diff --git a/src/commands/add.ts b/src/commands/add.ts index ad71cbc..7b37f9e 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -18,13 +18,26 @@ export const add = async (iconName: string) => { log.error("Invalid icon name"); return; } + const [prefixOverride, iconNameToUse] = + splitIconName.length === 2 ? splitIconName : [null, iconName]; - const overridePrefix = splitIconName.length === 2 ? splitIconName[0] : null; - const $iconName = splitIconName.length === 2 ? splitIconName[1] : iconName; + async function checkPrefixExists(prefix: string, icon: string) { + const exists = await iconManager.checkIfIconExists(prefix, icon); + return exists ? [prefix] : []; + } + + async function getDefaultPrefixes(icon: string) { + return await iconManager.getResolutionPrefixes(icon); + } - const undecidedPrefixes = !overridePrefix - ? await iconManager.getResolutionPrefixes($iconName) - : [overridePrefix]; + const undecidedPrefixes = prefixOverride + ? await checkPrefixExists(prefixOverride, iconNameToUse) + : await getDefaultPrefixes(iconNameToUse); + + if (undecidedPrefixes.length === 0) { + log.notFound(iconNameToUse); + return; + } const prefix = undecidedPrefixes.length === 1 @@ -42,7 +55,7 @@ export const add = async (iconName: string) => { return; } - await iconManager.addIcon(prefix as string, $iconName); + await iconManager.addIcon(prefix as string, iconNameToUse); await generateBaseCode(config); await iconManager.sync(); log.success("Icon added successfully"); diff --git a/src/iconManager.spec.ts b/src/iconManager.spec.ts index 364252f..2d507eb 100644 --- a/src/iconManager.spec.ts +++ b/src/iconManager.spec.ts @@ -1,6 +1,10 @@ -import { expect, describe, it } from "vitest"; +import { expect, describe, it, vi } from "vitest"; import { IconManager } from "./iconManager"; +vi.mock("./utils/generateIcon", () => ({ + generateIcon: vi.fn(), +})); + describe("groupIconsByPrefix", () => { it("should group icons by name", () => { const iconManager = new IconManager({ diff --git a/src/iconManager.ts b/src/iconManager.ts index e0eefe9..194e7b6 100644 --- a/src/iconManager.ts +++ b/src/iconManager.ts @@ -5,6 +5,7 @@ import { uniq } from "./utils/uniq"; import { log } from "./utils/console"; import { generateIconCode } from "./utils/generateIcon"; import { saveIconCode } from "./utils/saveIconCode"; +import { searchFunction } from "./utils/searchFunction"; export class IconManager { private config: Config; @@ -27,6 +28,15 @@ export class IconManager { return this.config.icons; } + public async checkIfIconExists(prefix: string, iconName: string) { + const iconCode = await this.getIconCodeByPrefix(prefix); + if (!iconCode) { + return false; + } + + return searchFunction(iconCode, iconName); + } + public async getResolutionPrefixes(iconName: string) { const [prefix] = await separateCamelCase(iconName); const lowerCasePrefix = prefix.toLowerCase(); @@ -38,8 +48,7 @@ export class IconManager { for (const prefix of resolutionPrefixes) { try { - const iconCode = await this.getIconCodeByPrefix(prefix); - if (iconCode?.includes(iconName)) { + if (await this.checkIfIconExists(prefix, iconName)) { result.push(prefix); } } catch {} @@ -65,7 +74,7 @@ export class IconManager { return this._prefixCodeMap.get(prefix); } - private groupIconsByPrefix() { + private _groupIconsByPrefix() { const groupedIcons: { [key: string]: string[] } = {}; for (const icon of this.icons) { @@ -80,7 +89,7 @@ export class IconManager { get groupedIcons() { if (!this._groupedIcons.length) { - this._groupedIcons = this.groupIconsByPrefix(); + this._groupedIcons = this._groupIconsByPrefix(); } return this._groupedIcons; @@ -105,7 +114,7 @@ export class IconManager { ); await saveIconCode(this.config.outputPath, data.filename, data.code); } catch (error) { - log.error(`Not found ${prefix}`); + log.notFound(prefix); } }) ); diff --git a/src/utils/console.ts b/src/utils/console.ts index 50e25f5..5cfa0e4 100644 --- a/src/utils/console.ts +++ b/src/utils/console.ts @@ -13,4 +13,7 @@ export const log = { error: (message: string) => { console.log(pc.red(message)); }, + notFound: (message: string) => { + console.log(`${pc.red("Not Found:")} ${pc.bgRed(message)}`); + }, }; diff --git a/src/utils/searchFunction.spec.ts b/src/utils/searchFunction.spec.ts new file mode 100644 index 0000000..664a7f8 --- /dev/null +++ b/src/utils/searchFunction.spec.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "vitest"; +import { searchFunction } from "./searchFunction"; + +const data = ` +// THIS FILE IS AUTO GENERATED +import { GenIcon } from '../lib/index.mjs'; +export function AiFillAccountBook (props) { + return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 1024 1024"},"child":[{"tag":"path","attr":{"d":"M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zM648.3 426.8l-87.7 161.1h45.7c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4v29.7h63.4c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4V752c0 5.5-4.5 10-10 10h-41.3c-5.5 0-10-4.5-10-10v-51.8h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h63.1v-29.7h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h45.2l-88-161.1c-2.6-4.8-.9-10.9 4-13.6 1.5-.8 3.1-1.2 4.8-1.2h46c3.8 0 7.2 2.1 8.9 5.5l72.9 144.3 73.2-144.3a10 10 0 0 1 8.9-5.5h45c5.5 0 10 4.5 10 10 .1 1.7-.3 3.3-1.1 4.8z"},"child":[]}]})(props); +}; +export function AiFillAlert (props) { + return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 1024 1024"},"child":[{"tag":"path","attr":{"d":"M512 244c176.18 0 319 142.82 319 319v233a32 32 0 0 1-32 32H225a32 32 0 0 1-32-32V563c0-176.18 142.82-319 319-319zM484 68h56a8 8 0 0 1 8 8v96a8 8 0 0 1-8 8h-56a8 8 0 0 1-8-8V76a8 8 0 0 1 8-8zM177.25 191.66a8 8 0 0 1 11.32 0l67.88 67.88a8 8 0 0 1 0 11.31l-39.6 39.6a8 8 0 0 1-11.31 0l-67.88-67.88a8 8 0 0 1 0-11.31l39.6-39.6zm669.6 0l39.6 39.6a8 8 0 0 1 0 11.3l-67.88 67.9a8 8 0 0 1-11.32 0l-39.6-39.6a8 8 0 0 1 0-11.32l67.89-67.88a8 8 0 0 1 11.31 0zM192 892h640a32 32 0 0 1 32 32v24a8 8 0 0 1-8 8H168a8 8 0 0 1-8-8v-24a32 32 0 0 1 32-32zm148-317v253h64V575h-64z"},"child":[]}]})(props); +}; +`; + +describe("searchFunction", () => { + it("should return true if the function exists in the data", () => { + expect(searchFunction(data, "AiFillAccountBook")).toBe(true); + expect(searchFunction(data, "AiFillAlert")).toBe(true); + expect(searchFunction(data, "A")).toBe(false); + }); +}); diff --git a/src/utils/searchFunction.ts b/src/utils/searchFunction.ts new file mode 100644 index 0000000..832ab6c --- /dev/null +++ b/src/utils/searchFunction.ts @@ -0,0 +1,9 @@ +const data = ` +function Fa1() { +} +`; + +export const searchFunction = (data: string, funcName: string): boolean => { + const regex = new RegExp(`function\\s+${funcName}\\s*\\(`); + return regex.test(data); +}; diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..eb91264 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,11 @@ +/// +import { defineConfig } from "vite"; + +export default defineConfig({ + test: { + alias: { + "@/package.json": "package.json", + }, + exclude: ["node_modules", "dist"], + }, +}); From 65e2a7efb3c2f5071a36c8b5d2bfe9eb479d4661 Mon Sep 17 00:00:00 2001 From: Sungyu Kang Date: Mon, 16 Sep 2024 17:10:18 +0900 Subject: [PATCH 3/3] fix: unused --- src/utils/searchFunction.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/utils/searchFunction.ts b/src/utils/searchFunction.ts index 832ab6c..cd91c06 100644 --- a/src/utils/searchFunction.ts +++ b/src/utils/searchFunction.ts @@ -1,8 +1,3 @@ -const data = ` -function Fa1() { -} -`; - export const searchFunction = (data: string, funcName: string): boolean => { const regex = new RegExp(`function\\s+${funcName}\\s*\\(`); return regex.test(data);