Skip to content

Commit

Permalink
Increased compatibility with Mac & Win install types (#9)
Browse files Browse the repository at this point in the history
* Implemented command changes after user feedback and increased compatibility

* Fixed typo
  • Loading branch information
lupor authored Feb 19, 2025
1 parent ce3e5e6 commit 83e3fb3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This plugin it is required to have the spectral CLI installed on your system. Fo
install the binary without going through Nodejs.

> **Warning** Should you still want to use the spectral package via NodeJs on Windows then
you must check "Use node package on on Windows" in the plugin settings. This is necessary for the node packages to
you must check "Use node package on Windows" in the plugin settings. This is necessary for the node packages to
work and will have a performance cost.

If you don't have it installed yet make sure to follow this
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginGroup=com.lupor.spectral-linter-intellij-plugin
pluginName=Spectral-Linter
pluginRepositoryUrl=https://github.com/lupor/spectral-intellij-plugin
pluginVersion=0.0.9
pluginVersion=0.0.10
pluginSinceBuild=223
pluginUntilBuild=243.*
platformType=IC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class CommandLineExecutor {
}

fun execute(commandLine: GeneralCommandLine, timeout: Duration? = null): ProcessOutput {
val handler = OSProcessHandler(commandLine)
val command = commandLine.commandLineString
val process = commandLine.createProcess()
val handler = OSProcessHandler(process, command, Charsets.UTF_8)
val output = ProcessOutput()

logger.debug("Executing command: ${handler.commandLine}")
logger.debug("Executing command: $command")

handler.addProcessListener(object : ProcessAdapter() {
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
Expand All @@ -36,7 +38,7 @@ class CommandLineExecutor {

if (ended) {
logger.debug("Command successfully executed with exit code ${output.exitCode}")
output.exitCode = handler.exitCode!!
output.exitCode = process.exitValue()
} else {
logger.debug("Command timed out after ${timeout?.toMillis()} ms")
handler.destroyProcess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@ class SpectralRunner(private val project: Project) {
settings: ProjectSettingsState,
filePath: String
): GeneralCommandLine {
var commandString = "spectral -r ${settings.ruleset} -f json lint $filePath"
var commandString = "-r ${settings.ruleset} -f json lint $filePath"
if (SystemInfo.isWindows && settings.useNodePackageWin) {
commandString = "cmd /c $commandString"
commandString = "cmd /c spectral $commandString"
} else if (SystemInfo.isWindows) {
commandString = "spectral.exe $commandString"
} else {
commandString = "spectral $commandString"
}
val command = commandString.split(" ")
val commandLine = GeneralCommandLine(command[0])
.withParameters(command.drop(1))
.withWorkDirectory(project.basePath)
.withCharset(Charsets.UTF_8)
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.SYSTEM)
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)

val commandEnv = mapOf("NODE_OPTIONS" to "--no-warnings")
commandLine.withEnvironment(commandLine.parentEnvironment + commandEnv)
val cleanEnv = mapOf("PATH" to commandLine.parentEnvironment["PATH"]) + commandEnv
commandLine.withEnvironment(cleanEnv)

return commandLine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SettingsComponent {
val rulesetInput = JBTextField()
val includedFilesInput = JBTextArea()
val useFileOverrides = JBCheckBox("Use file level overrides", false)
val useNodePackageWin = JBCheckBox("Use node package on on Windows", false)
val useNodePackageWin = JBCheckBox("Use node package on Windows", false)

init {
val overrideTooltip = """
Expand Down

0 comments on commit 83e3fb3

Please sign in to comment.