From 938b12ae6ce6cea0cfc448ddb552cfd6dce3f993 Mon Sep 17 00:00:00 2001 From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com> Date: Wed, 20 Mar 2024 23:19:51 +0100 Subject: [PATCH] 0.7.5 - Fix deprecated component alert always displaying - Fix replacement with new shadcn-svelte formats --- gradle.properties | 2 +- .../backend/sources/Source.kt | 63 ++++++++++--------- .../backend/sources/impl/SvelteSource.kt | 2 +- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9ac40a2..eb9d5d4 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 = 0.7.4 +pluginVersion = 0.7.5 # 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/Source.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/Source.kt index 60edc6f..8e6bb55 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/Source.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/Source.kt @@ -116,41 +116,44 @@ abstract class Source(val project: Project, private val serializer: "${resolveAlias(getLocalConfig().aliases.components)}/${component.type.substringAfterLast(":")}" + if (usesDirectoriesForComponents()) { "/${downloadedComponent.name}" } else "" + // Check for deprecated components if (usesDirectoriesForComponents()) { val remotelyDeletedFiles = fileManager.getFileAtPath(path)?.children?.filter { file -> downloadedComponent.files.none { it.name == file.name } } ?: emptyList() - val multipleFiles = remotelyDeletedFiles.size > 1 - notifManager.sendNotification( - "Deprecated component file${if (multipleFiles) "s" else ""} in ${downloadedComponent.name}", - "The following file${if (multipleFiles) "s are" else " is"} no longer part of ${downloadedComponent.name}: ${ - remotelyDeletedFiles.joinToString(", ") { file -> - file.name - } - }. Do you want to remove ${if (multipleFiles) "them" else "it"}?" - ) { notification -> - listOf( - NotificationAction.createSimple("Remove " + if (multipleFiles) "them" else "it") { - remotelyDeletedFiles.forEach { file -> - runWriteAction { fileManager.deleteFile(file) } + if (remotelyDeletedFiles.isNotEmpty()) { + val multipleFiles = remotelyDeletedFiles.size > 1 + notifManager.sendNotification( + "Deprecated component file${if (multipleFiles) "s" else ""} in ${downloadedComponent.name}", + "The following file${if (multipleFiles) "s are" else " is"} no longer part of ${downloadedComponent.name}: ${ + remotelyDeletedFiles.joinToString(", ") { file -> + file.name } - log.info( - "Removed deprecated file${if (multipleFiles) "s" else ""} from ${downloadedComponent.name} (${ - downloadedComponent.files.joinToString(", ") { file -> - file.name - } - }): ${ - remotelyDeletedFiles.joinToString(", ") { file -> - file.name - } - }" - ) - notification.expire() - }, - NotificationAction.createSimple("Keep " + if (multipleFiles) "them" else "it") { - notification.expire() - } - ) + }. Do you want to remove ${if (multipleFiles) "them" else "it"}?" + ) { notification -> + listOf( + NotificationAction.createSimple("Remove " + if (multipleFiles) "them" else "it") { + remotelyDeletedFiles.forEach { file -> + runWriteAction { fileManager.deleteFile(file) } + } + log.info( + "Removed deprecated file${if (multipleFiles) "s" else ""} from ${downloadedComponent.name} (${ + downloadedComponent.files.joinToString(", ") { file -> + file.name + } + }): ${ + remotelyDeletedFiles.joinToString(", ") { file -> + file.name + } + }" + ) + notification.expire() + }, + NotificationAction.createSimple("Keep " + if (multipleFiles) "them" else "it") { + notification.expire() + } + ) + } } } downloadedComponent.files.forEach { file -> diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SvelteSource.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SvelteSource.kt index ab7775f..450269b 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SvelteSource.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SvelteSource.kt @@ -81,7 +81,7 @@ class SvelteSource(project: Project) : Source(project, SvelteConfi override fun adaptFileToConfig(contents: String): String { val config = getLocalConfig() return contents.replace( - Regex("@/registry/[^/]+"), cleanAlias(config.aliases.components) + Regex("([\"'])[^\r\n/]+/registry/[^/]+"), "$1${cleanAlias(config.aliases.components)}" ).replace( "\$lib/utils", config.aliases.utils )