Skip to content

Commit

Permalink
Merge pull request #14 from dinbtechit/bug/fix-nbsp-bug-chores
Browse files Browse the repository at this point in the history
Fix for the NBSP bug and upgrading to the latest version of redux store
  • Loading branch information
dinbtechit committed Sep 1, 2023
2 parents 46c2c32 + d8fc9d0 commit b204819
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# ngxs Changelog

## [Unreleased]
### Fixed
- Removing `nbsp` after files are generated [ngxs/cli#9](https://github.com/ngxs/cli/issues/9) within intellij
- Upgrading redux store package from `0.5.5` -> `0.6.1`

## [0.0.1] - 2023-08-26

### Added
- Initial NGXS Store Generation
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)

[Unreleased]: https://github.com/dinbtechit/ngxs/compare/v0.0.1...HEAD
[0.0.1]: https://github.com/dinbtechit/ngxs/commits/v0.0.1
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
](https://www.buymeacoffee.com/dinbtechit)

<!-- Plugin description -->
Provides NGXS CLI/Schematics. (Beta)
NGXS is a state management library for Angular. This plugin provides NGXS CLI/Schematics for Jetbrains IDE.

# Features
- Simply right click -> New -> NGXS CLI/Schematics to generate a boiler plate store.
- Many more coming soon. Checkout roadmap
> Please ensure you have [ngxs cli](https://www.ngxs.io/plugins/cli) installed either globally or at the project level.
# Roadmap
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
// implementation(libs.annotations)
implementation("org.reduxkotlin:redux-kotlin-threadsafe:0.5.5")
implementation("org.reduxkotlin:redux-kotlin-threadsafe:0.6.1")
}

// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
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.dinbtechit.ngxs
pluginName = ngxs
pluginRepositoryUrl = https://github.com/dinbtechit/ngxs
# SemVer format -> https://semver.org
pluginVersion = 0.0.1
pluginVersion = 0.0.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.dinbtechit.ngxs.action.cli

import com.github.dinbtechit.ngxs.NgxsIcons
import com.github.dinbtechit.ngxs.action.cli.services.FileService
import com.github.dinbtechit.ngxs.action.cli.store.Action
import com.github.dinbtechit.ngxs.action.cli.store.CLIState
import com.github.dinbtechit.ngxs.action.cli.store.GenerateCLIState
Expand All @@ -18,6 +19,11 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import org.reduxkotlin.Store
import java.nio.file.Files
import java.nio.file.Paths

Expand All @@ -40,6 +46,7 @@ class NgxsCliAction : DumbAwareAction(NgxsIcons.logo) {
store.state.project!!, store.state,
store.state.workingDir, store.state.module!!
)
removeNBSPCharacter(project, store)
}
}
}
Expand Down Expand Up @@ -84,6 +91,29 @@ class NgxsCliAction : DumbAwareAction(NgxsIcons.logo) {
null, JavaScriptBundle.message("generating.0", cli.name),
arrayOf(), *parameters.toTypedArray(),
)
}

private fun removeNBSPCharacter(project: Project, store: Store<GenerateCLIState> ) {
val connection = project.messageBus.connect()
connection.subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener {
override fun after(events: MutableList<out VFileEvent>) {
val ngxsFileService = project.service<FileService>()
for (event in events) {
if (event is VFileCreateEvent) {
if (store.store.state.workingDir != null) {
for (file in store.state.workingDir!!.children) {
if (file.isDirectory && store.state.folderName.isNotBlank()
&& file.name == store.state.folderName) {
for (storeFiles in file.children) {
ngxsFileService.replaceNbsp(storeFiles)
}
}
}
}
}
}
connection.disconnect()
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.dinbtechit.ngxs.action.cli.services

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiManager

@Service(Service.Level.PROJECT)
class FileService(val project: Project) {
fun replaceNbsp(file: VirtualFile) {
ApplicationManager.getApplication().invokeAndWait {
val psiFile = PsiManager.getInstance(project).findFile(file)
if (psiFile != null) {
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile)
if (document != null) {
val fileText = document.text
// Identify non-breaking space
val nbsp = "\u00A0" // Unicode for non-breaking space
val newText = fileText.replace(nbsp, " ")
document.setText(newText)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.vfs.VirtualFile

data class GenerateCLIState(
val name: String = "",
val folderName: String = "",
val parameter: String = "",
val project: Project? = null,
val workingDir: VirtualFile? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.dinbtechit.ngxs.action.cli.store

import com.github.dinbtechit.ngxs.NgxsBundle
import com.github.dinbtechit.ngxs.action.cli.util.CliParameterUtil.convertToCli
import com.intellij.javascript.nodejs.CompletionModuleInfo
import com.intellij.javascript.nodejs.NodeModuleSearchUtil
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterManager
Expand All @@ -10,7 +11,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.VirtualFile
import org.reduxkotlin.Reducer
import org.reduxkotlin.createThreadSafeStore
import org.reduxkotlin.threadsafe.createThreadSafeStore

@Service(Service.Level.PROJECT)
class CLIState(project: Project) {
Expand All @@ -28,6 +29,7 @@ class CLIState(project: Project) {
thisLogger().info("Action.GenerateCLIAction - $action")
state.copy(
parameter = action.options,
folderName = action.options.convertToCli()["folder-name"] ?: "",
workingDir = action.workingDir,
project = action.project,
)
Expand Down

0 comments on commit b204819

Please sign in to comment.