diff --git a/README.md b/README.md index dc5912c..b445715 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,15 @@ [![Version](https://img.shields.io/jetbrains/plugin/v/com.github.warningimhack3r.intellijshadcnplugin.svg)](https://plugins.jetbrains.com/plugin/com.github.warningimhack3r.intellijshadcnplugin) [![Downloads](https://img.shields.io/jetbrains/plugin/d/com.github.warningimhack3r.intellijshadcnplugin.svg)](https://plugins.jetbrains.com/plugin/com.github.warningimhack3r.intellijshadcnplugin) +## ToDo list before 1.0.0 + +- Rework `class`es replacement detection mechanism to be 100% accurate + - Add tests for this +- Add support for Vue's `typescript` option (transpiling TypeScript to JavaScript in `*.vue` files) +- Parse `vite.config.(js|ts)` to resolve aliases as a fallback of `tsconfig.json` + ## Description + Manage your shadcn/ui components in your project. Supports Svelte, React, Vue, and Solid. @@ -12,6 +20,7 @@ This plugin will help you manage your shadcn/ui components through a simple tool **This plugin will only work with an existing `components.json` file. Manually copied components will not be detected otherwise.** ## Features + - Automatically detect shadcn/ui components in your project - Instantly add, remove, update them with a single click - Refreshes on opening the tool window @@ -22,10 +31,14 @@ This plugin will help you manage your shadcn/ui components through a simple tool - ...and more! ## Usage + Simply open the `shadcn/ui` tool window and start managing your components. -If you don't see the tool window, you can open it from `View > Tool Windows > shadcn/ui`. +If you don't see the tool window, you can open it from `View > Tool Windows > shadcn/ui`. +**When adding or removing components, the tool window won't refresh automatically yet. You can refresh it by closing and reopening it.** ## Planned Features + +- Figure out a clean way to refresh the tool window automatically after adding or removing components - Add support for monorepos diff --git a/gradle.properties b/gradle.properties index 09edd87..6bc4a09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.github.warningimhack3r.intellijshadcnplugin pluginName = intellij-shadcn-plugin pluginRepositoryUrl = https://github.com/WarningImHack3r/intellij-shadcn-plugin # SemVer format -> https://semver.org -pluginVersion = 1.0.0 +pluginVersion = 0.7.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 213 diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReactSource.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReactSource.kt index 383cd35..ca18735 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReactSource.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReactSource.kt @@ -22,8 +22,8 @@ class ReactSource(project: Project) : Source(project, ReactConfig.s ?.jsonObject?.get("paths") ?.jsonObject?.get("${alias.substringBefore("/")}/*") ?.jsonArray?.get(0) - ?.jsonPrimitive?.content ?: throw Exception("Cannot find alias $alias") // TODO: fallback to vite.config.(j|t)s for all - return aliasPath.replace(Regex("^\\./"), "") + ?.jsonPrimitive?.content ?: throw Exception("Cannot find alias $alias") + return aliasPath.replace(Regex("^\\.+/"), "") .replace(Regex("\\*$"), alias.substringAfter("/")) } diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SolidSource.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SolidSource.kt index 1d045ea..1f4d985 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SolidSource.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SolidSource.kt @@ -27,12 +27,6 @@ class SolidSource(project: Project) : Source(project, SolidConfig.s } override fun adaptFileToConfig(contents: String): String { - fun cleanAlias(alias: String): String { - return if (alias.startsWith("\$")) { - "\\$alias" // fixes Kotlin silently crashing when the replacement starts with $ with a regex - } else alias - } - val config = getLocalConfig() val newContents = contents.replace( Regex("@/registry/[^/]+"), cleanAlias(config.aliases.components) @@ -54,7 +48,7 @@ class SolidSource(project: Project) : Source(project, SolidConfig.s fun variablesToUtilities(classes: String, lightColors: Map, darkColors: Map): String { // Note: this does not include `border` classes at the beginning or end of the string, // but I'm once again following what the original code does for parity - // (https://github.com/shadcn-ui/ui/blob/fb614ac2921a84b916c56e9091aa0ae8e129c565/packages/cli/src/utils/transformers/transform-css-vars.ts#L142-L145). + // (https://github.com/hngngn/shadcn-solid/blob/b808e0ecc9fd4689572d9fc0dfb7af81606a11f2/packages/cli/src/utils/transformers/transform-css-vars.ts#L144-L147). val newClasses = classes.replace(" border ", " border border-border ") val prefixesToReplace = listOf("bg-", "text-", "border-", "ring-offset-", "ring-") diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/VueSource.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/VueSource.kt index 7005ab3..0a16dc3 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/VueSource.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/VueSource.kt @@ -3,6 +3,8 @@ package com.github.warningimhack3r.intellijshadcnplugin.backend.sources.impl import com.github.warningimhack3r.intellijshadcnplugin.backend.helpers.FileManager import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.Source import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.config.VueConfig +import com.github.warningimhack3r.intellijshadcnplugin.notifications.NotificationManager +import com.intellij.notification.NotificationType import com.intellij.openapi.project.Project import com.intellij.util.applyIf import kotlinx.serialization.json.Json @@ -37,22 +39,21 @@ class VueSource(project: Project) : Source(project, VueConfig.seriali } override fun adaptFileToConfig(contents: String): String { - fun cleanAlias(alias: String): String { - return if (alias.startsWith("\$")) { - "\\$alias" // fixes Kotlin silently crashing when the replacement starts with $ with a regex - } else alias - } - val config = getLocalConfig() val newContents = contents.replace( Regex("@/lib/registry/[^/]+"), cleanAlias(config.aliases.components) ).replace( // Note: this does not prevent additional imports other than "cn" from being replaced, - // but I'm once again following what the original code does for parity + // but I'm following what the original code does for parity // (https://github.com/radix-vue/shadcn-vue/blob/9d9a6f929ce0f281b4af36161af80ed2bbdc4a16/packages/cli/src/utils/transformers/transform-import.ts#L19-L29). Regex(".*\\{.*[ ,\n\t]+cn[ ,].*}.*\"@/lib/utils"), cleanAlias(config.aliases.utils) ).applyIf(!config.typescript) { + NotificationManager(project).sendNotification( + "TypeScript option for Vue", + "You have TypeScript disabled in your shadcn/ui config. This feature is not supported yet. Please install/update your components with the CLI for now.", + NotificationType.WARNING + ) // TODO: detype Vue file this } @@ -67,7 +68,7 @@ class VueSource(project: Project) : Source(project, VueConfig.seriali fun variablesToUtilities(classes: String, lightColors: Map, darkColors: Map): String { // Note: this does not include `border` classes at the beginning or end of the string, // but I'm once again following what the original code does for parity - // (https://github.com/shadcn-ui/ui/blob/fb614ac2921a84b916c56e9091aa0ae8e129c565/packages/cli/src/utils/transformers/transform-css-vars.ts#L142-L145). + // (https://github.com/radix-vue/shadcn-vue/blob/4214134e1834fdabcc5f0354e11593360f076e8d/packages/cli/src/utils/transformers/transform-css-vars.ts#L87-L89). val newClasses = classes.replace(" border ", " border border-border ") val prefixesToReplace = listOf("bg-", "text-", "border-", "ring-offset-", "ring-")