Skip to content

Commit

Permalink
fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic-kneier committed Jan 15, 2019
1 parent 58065a7 commit 13919bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'de.solugo.gradle'
version '0.6.0'
version '0.6.1'

repositories {
mavenCentral()
Expand Down
25 changes: 8 additions & 17 deletions src/main/groovy/de/solugo/gradle/nodejs/NodeJsTask.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package de.solugo.gradle.nodejs

import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.internal.file.archive.compression.AbstractArchiver
import org.gradle.api.resources.MissingResourceException
import org.gradle.api.resources.ReadableResource
import org.gradle.api.resources.ResourceException
import org.gradle.api.tasks.AbstractExecTask
import org.gradle.api.tasks.Input

Expand Down Expand Up @@ -89,22 +85,17 @@ class NodeJsTask<T extends NodeJsTask<T>> extends AbstractExecTask<T> {
name = command
}

final File absoluteFile = new File(name);
if (absoluteFile.exists()) {
return absoluteFile
}

final File globalFile = new File(nodeJsUtil.bin, name)
if (globalFile.exists()) {
return globalFile
}
final File[] files = [
new File(nodeJsUtil.bin, name),
new File(this.joinPaths(this.project.nodejs.rootPath, "node_modules", ".bin", name)),
new File(name)
]

final File localFile = new File(this.joinPaths(this.project.nodejs.rootPath, "node_modules", ".bin", name))
if (localFile.exists()) {
return localFile
for (File file : files){
if (file.exists()) return file
}

return null
throw new RuntimeException("Could not find '$command' at $files")
}

protected File resolveModule(final NodeJsUtil nodeJsUtil, final String module) {
Expand Down
11 changes: 4 additions & 7 deletions src/main/groovy/de/solugo/gradle/nodejs/NodeJsUtil.groovy
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package de.solugo.gradle.nodejs


import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project
import org.gradle.api.file.FileTree

import java.nio.file.Files
import java.nio.file.StandardCopyOption

class NodeJsUtil {

static synchronized NodeJsUtil getInstance(Project project, String version) {
Expand Down Expand Up @@ -49,7 +45,7 @@ class NodeJsUtil {
throw new UnsupportedOperationException("Architecture not supported")
}

if (!target.exists()) {
if (!target.exists() || target.listFiles().size() == 0) {
final root = "node-v${version}-${platform}-${arch}"
final file = "${root}.${ext}"
final downloadFile = new File(cache, file)
Expand Down Expand Up @@ -79,9 +75,10 @@ class NodeJsUtil {

tree.visit { source ->
final name = source.relativePath.pathString
final int start = name.indexOf(File.separator)
final int start = name.indexOf("/")

if (start != -1) {
final destination = new File(target, name.substring(name.indexOf(File.separator)))
final destination = new File(target, name.substring(start + 1))
if (source.isDirectory()) {
destination.mkdirs()
} else {
Expand Down

0 comments on commit 13919bb

Please sign in to comment.