Skip to content

Commit

Permalink
New task api for jsdoc and jshint tasks for issue eriwen#13
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Mar 10, 2012
1 parent 1273f6f commit 4020934
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'idea'

defaultTasks 'clean', 'build'

version = '0.3.38-SNAPSHOT'
version = '0.3.41-SNAPSHOT'
group = 'com.eriwen'
archivesBaseName = 'gradle-js-plugin'
isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
15 changes: 13 additions & 2 deletions plugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:0.3.38-SNAPSHOT'
classpath 'com.eriwen:gradle-js-plugin:0.3.41-SNAPSHOT'
}
}

Expand All @@ -21,6 +21,16 @@ dependencies {
rhino 'org.mozilla:rhino:1.7R3'
}

//javascript {
// source {
// custom {
// js {
// srcDir "src/test/resources"
// }
// }
// }
//}

apply plugin: 'js'

// Combine JS files
Expand All @@ -32,6 +42,7 @@ combineJs {
}

task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
//javascript.source.custom.js.files.toList()
source = ["${projectDir}/src/test/resources/file1.js", "${projectDir}/src/test/resources/file2.js"]
dest = file("${buildDir}/all.js")
}
Expand Down Expand Up @@ -75,7 +86,7 @@ jsdoc {

task jsdocz(type: com.eriwen.gradle.js.tasks.JsDocTask) {
source = ["${projectDir}/src/test/resources/file1.js", "${projectDir}/src/test/resources/file2.js"]
destDir = file("${buildDir}/jsdoc")
destinationDir = file("${buildDir}/jsdoc")
}

props2js {
Expand Down
50 changes: 29 additions & 21 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsDocTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,38 @@ class JsDocTask extends DefaultTask {
Iterable<String> modulePaths = ['node_modules', 'rhino_modules', '.']
Iterable<String> options = []
Boolean debug = false
def source
File destinationDir

@TaskAction
def run() {
def outputFiles = getOutputs().files
if (outputFiles.files.size() == 1) {
final File zipFile = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), JSDOC_PATH)
final File jsdocDir = RESOURCE_UTIL.extractZipFile(zipFile)
final String workingDir = "${jsdocDir.absolutePath}${File.separator}jsdoc"

final List<String> args = []
if (debug) {
args << '-debug'
}
modulePaths.each {
args.addAll(['-modules', it])
}
args.add("${workingDir}${File.separator}jsdoc.js")
args.addAll(getInputs().files.files.collect { it.canonicalPath })
args.addAll(['-d', (outputFiles.files.toArray()[0] as File).absolutePath])
args.addAll(options.collect { it })

rhino.execute(args, workingDir)
} else {
throw new IllegalArgumentException('Output must be exactly 1 File object. Example: outputs.dir = file("outputDir")')
if (!source) {
logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = ["path1", "path2"]`')
logger.warn('This will be removed in the next version of the JS plugin')
source = getInputs().files.files.collect { it.canonicalPath }
}

if (!destinationDir) {
logger.warn('The syntax "outputs.file file(..)" is deprecated! Please use `destinationDir = file("dest/file.js")`')
destinationDir = getOutputs().files.files.toArray()[0] as File
}

final File zipFile = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), JSDOC_PATH)
final File jsdocDir = RESOURCE_UTIL.extractZipFile(zipFile)
final String workingDir = "${jsdocDir.absolutePath}${File.separator}jsdoc"

final List<String> args = []
if (debug) {
args << '-debug'
}
modulePaths.each {
args.addAll(['-modules', it])
}
args.add("${workingDir}${File.separator}jsdoc.js")
args.addAll(source)
args.addAll(['-d', destinationDir.absolutePath])
args.addAll(options.collect { it })

rhino.execute(args, workingDir)
}
}
4 changes: 2 additions & 2 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.eriwen.gradle.js.RhinoExec

class JsHintTask extends DefaultTask {
private static final String JSHINT_PATH = 'jshint-rhino.js'
private static final String TMP_DIR = 'tmp/js'
private static final String TMP_DIR = "tmp${File.separator}js"
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private final RhinoExec rhino = new RhinoExec(project)

Expand All @@ -39,7 +39,7 @@ class JsHintTask extends DefaultTask {
final File jshintJsFile = RESOURCE_UTIL.extractFileToDirectory(
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll()
args.addAll(source)
rhino.execute(args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MinifyJsTask extends DefaultTask {
CompilerOptions compilerOptions = new CompilerOptions()
String compilationLevel = 'SIMPLE_OPTIMIZATIONS'
String warningLevel = 'DEFAULT'
File source
def source
File dest

@TaskAction
Expand Down

0 comments on commit 4020934

Please sign in to comment.