Skip to content

Commit

Permalink
Prepare for initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
WarningImHack3r committed Jan 8, 2024
1 parent 119cb79 commit c9c2be8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
[![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

<!-- Plugin description -->
Manage your shadcn/ui components in your project. Supports Svelte, React, Vue, and Solid.

This plugin will help you manage your shadcn/ui components through a simple tool window. Add, remove, update them with a single click.
**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
Expand All @@ -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
<!-- Plugin description end -->

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ReactSource(project: Project) : Source<ReactConfig>(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("/"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class SolidSource(project: Project) : Source<SolidConfig>(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)
Expand All @@ -54,7 +48,7 @@ class SolidSource(project: Project) : Source<SolidConfig>(project, SolidConfig.s
fun variablesToUtilities(classes: String, lightColors: Map<String, String>, darkColors: Map<String, String>): 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-")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,22 +39,21 @@ class VueSource(project: Project) : Source<VueConfig>(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
}
Expand All @@ -67,7 +68,7 @@ class VueSource(project: Project) : Source<VueConfig>(project, VueConfig.seriali
fun variablesToUtilities(classes: String, lightColors: Map<String, String>, darkColors: Map<String, String>): 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-")
Expand Down

0 comments on commit c9c2be8

Please sign in to comment.