generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02406e3
commit c67871b
Showing
31 changed files
with
784 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.idea | ||
.qodana | ||
build | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
<!-- Keep a Changelog guide -> https://keepachangelog.com --> | ||
<!-- Types of changes memo: | ||
— “Added” for new features. | ||
— “Changed” for changes in existing functionality. | ||
— “Deprecated” for soon-to-be removed features. | ||
— “Removed” for now removed features. | ||
— “Fixed” for any bug fixes. | ||
— “Security” in case of vulnerabilities. | ||
--> | ||
|
||
# intellij-shadcn-plugin Changelog | ||
|
||
## [Unreleased] | ||
|
||
### Added | ||
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template) | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
[versions] | ||
# libraries | ||
annotations = "24.1.0" | ||
|
||
# plugins | ||
kotlin = "1.9.22" | ||
changelog = "2.2.0" | ||
gradleIntelliJPlugin = "1.16.1" | ||
qodana = "0.1.13" | ||
kover = "0.7.5" | ||
|
||
[libraries] | ||
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" } | ||
|
||
[plugins] | ||
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } | ||
gradleIntelliJPlugin = { id = "org.jetbrains.intellij", version.ref = "gradleIntelliJPlugin" } | ||
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } | ||
serialization = { id = "plugin.serialization", version.ref = "kotlin" } | ||
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } | ||
qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/MyBundle.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/ISPScanner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend | ||
|
||
import com.github.warningimhack3r.intellijshadcnplugin.backend.helpers.FileManager | ||
import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.ISPSource | ||
import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.ISPSvelteSource | ||
import com.intellij.openapi.project.Project | ||
|
||
object ISPScanner { | ||
|
||
fun findShadcnImplementation(project: Project): ISPSource? { | ||
FileManager(project).getVirtualFilesByName("components.json").firstOrNull()?.let { componentsJson -> | ||
val contents = componentsJson.contentsToByteArray().decodeToString() | ||
if (contents.contains("shadcn-svelte.com")) { | ||
return ISPSvelteSource(project) | ||
} | ||
} | ||
// TODO: Add other sources | ||
return null | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ain/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/FileManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.helpers | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.search.FilenameIndex | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import java.nio.file.NoSuchFileException | ||
|
||
class FileManager(private val project: Project) { | ||
fun saveFileAtPath(file: PsiFile, path: String) { | ||
var deepest = getDeepestFileForPath(path) | ||
val deepestRelativePath = deepest.path.substringAfter("${project.basePath!!}/") | ||
path.substringAfter(deepestRelativePath).split('/').filterNot { it.isEmpty() }.forEach { subdirectory -> | ||
deepest = deepest.createChildDirectory(this, subdirectory) | ||
} | ||
deepest.createChildData(this, file.name).apply { | ||
setBinaryContent(file.text.toByteArray()) | ||
} | ||
} | ||
|
||
fun deleteFileAtPath(path: String): Boolean { | ||
return getFileAtPath(path)?.delete(this)?.let { true } ?: false | ||
} | ||
|
||
fun getVirtualFilesByName(name: String): Collection<VirtualFile> { | ||
return FilenameIndex.getVirtualFilesByName( | ||
name, | ||
GlobalSearchScope.projectScope(project) | ||
).filter { file -> | ||
val nodeModule = file.path.contains("node_modules") | ||
if (!name.startsWith(".")) { | ||
!nodeModule && !file.path.substringAfter(project.basePath!!).startsWith(".") | ||
} else !nodeModule | ||
} | ||
} | ||
|
||
private fun getDeepestFileForPath(filePath: String): VirtualFile { | ||
var paths = filePath.split('/') | ||
var currentFile = getVirtualFilesByName(paths.first()).firstOrNull() ?: throw NoSuchFileException("No file found at path $filePath") | ||
paths = paths.drop(1) | ||
for (path in paths) { | ||
val child = currentFile.findChild(path) | ||
if (child == null) { | ||
return currentFile | ||
} else { | ||
currentFile = child | ||
} | ||
} | ||
return currentFile | ||
} | ||
|
||
fun getFileAtPath(filePath: String): VirtualFile? { | ||
try { | ||
val deepest = getDeepestFileForPath(filePath) | ||
return if (deepest.name == filePath.substringAfterLast('/')) deepest else null | ||
} catch (e: Exception) { | ||
return null | ||
} | ||
} | ||
|
||
fun getFileContentsAtPath(path: String): String? { | ||
return getFileAtPath(path)?.contentsToByteArray()?.decodeToString() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ain/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/ShellRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.helpers | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.jetbrains.rd.util.printlnError | ||
import java.io.File | ||
|
||
class ShellRunner(private val project: Project? = null) { | ||
private val failedCommands = mutableSetOf<String>() | ||
|
||
private fun isWindows() = System.getProperty("os.name").lowercase().contains("win") | ||
|
||
fun execute(command: Array<String>): String? { | ||
val commandName = command.firstOrNull() ?: return null | ||
if (isWindows() && failedCommands.contains(commandName)) { | ||
command[0] = "$commandName.cmd" | ||
} | ||
return try { | ||
val process = ProcessBuilder(*command) | ||
.redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
.directory(project?.basePath?.let { File(it) }) | ||
.start() | ||
process.waitFor() | ||
process.inputStream.bufferedReader().readText() | ||
} catch (e: Exception) { | ||
if (isWindows() && !commandName.endsWith(".cmd")) { | ||
failedCommands.add(commandName) | ||
return execute(arrayOf("$commandName.cmd") + command.drop(1).toTypedArray()) | ||
} | ||
printlnError("Error while executing \"${command.joinToString(" ")}\": ${e.message}") | ||
null | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/http/RequestSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.http | ||
|
||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
|
||
// Credit to: https://gist.github.com/GrzegorzDyrda/be47602fc855a52fba240dd2c2adc2d5 | ||
object RequestSender { | ||
|
||
/** | ||
* Sends an HTTP request to the given [url], using the given HTTP [method]. The request can also | ||
* include custom [headers] and [body]. | ||
* | ||
* Returns the [Response] object containing [statusCode][Response.statusCode], | ||
* [headers][Response.headers] and [body][Response.body]. | ||
*/ | ||
fun sendRequest(url: String, method: String = "GET", headers: Map<String, String>? = null, body: String? = null): Response { | ||
val conn = URL(url).openConnection() as HttpURLConnection | ||
|
||
with(conn) { | ||
requestMethod = method | ||
doOutput = body != null | ||
headers?.forEach(::setRequestProperty) | ||
} | ||
|
||
if (body != null) { | ||
conn.outputStream.use { | ||
it.write(body.toByteArray()) | ||
} | ||
} | ||
|
||
val responseBody = conn.inputStream.use { it.readBytes() }.toString(Charsets.UTF_8) | ||
|
||
return Response(conn.responseCode, conn.headerFields, responseBody) | ||
} | ||
|
||
data class Response(val statusCode: Int, val headers: Map<String, List<String>>? = null, val body: String? = null) | ||
} |
6 changes: 6 additions & 0 deletions
6
...in/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/ISPComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources | ||
|
||
data class ISPComponent( | ||
val name: String, | ||
val description: String? = null | ||
) |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/ISPSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources | ||
|
||
interface ISPSource { | ||
|
||
var domain: String | ||
var language: String | ||
|
||
fun fetchAllComponents(): List<ISPComponent> | ||
|
||
fun fetchAllStyles(): List<ISPStyle> | ||
|
||
fun getInstalledComponents(): List<String> | ||
|
||
fun addComponent(componentName: String) | ||
|
||
fun isComponentUpToDate(componentName: String): Boolean | ||
|
||
fun removeComponent(componentName: String) | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/sources/ISPStyle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources | ||
|
||
data class ISPStyle( | ||
val name: String, | ||
val label: String | ||
) |
Oops, something went wrong.