Skip to content

Commit

Permalink
Allowing JSHint to be output to a given file
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Jun 21, 2012
1 parent dd655f2 commit 80d33df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 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 = '1.0.1'
version = '1.0.2'
group = 'com.eriwen'
ext.archivesBaseName = 'gradle-js-plugin'
ext.isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
17 changes: 13 additions & 4 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:1.0.1'
classpath 'com.eriwen:gradle-js-plugin:1.0.2'
}
}

Expand All @@ -24,6 +24,10 @@ javascript.source {
}
}

task clean(type: Delete) {
delete buildDir
}

// Combine JS files
task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
source = javascript.source.custom.js.files
Expand All @@ -32,7 +36,7 @@ task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {

// Minify with Google Closure Compiler
task minify(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = file("${buildDir}/all.js")
source = combine
dest = file("${buildDir}/all-min.js")
closure {
warningLevel = 'VERBOSE'
Expand All @@ -41,14 +45,19 @@ task minify(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
}
}

// For auto-versioning
//def version = Integer.toHexString(Integer.parseInt(new java.text.SimpleDateFormat('yyDDHHmm').format(new Date())))
def version = "1.7.2"

// GZip it!
task gzip(type: com.eriwen.gradle.js.tasks.GzipJsTask) {
source = file("${buildDir}/all-min.js")
dest = file("${buildDir}/all-min.js")
source = minify
dest = file("${buildDir}/all-${version}.min.js")
}

task jshintz(type: com.eriwen.gradle.js.tasks.JsHintTask) {
source = javascript.source.custom.js.files
dest = file("${buildDir}/jshint.out")
}

task jsdocz(type: com.eriwen.gradle.js.tasks.JsDocTask) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ import org.gradle.api.tasks.TaskAction
import com.eriwen.gradle.js.ResourceUtil
import com.eriwen.gradle.js.RhinoExec
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.OutputFile

class JsHintTask extends SourceTask {
private static final String JSHINT_PATH = 'jshint-rhino.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)

@OutputFile File dest;

@TaskAction
def run() {
final File jshintJsFile = RESOURCE_UTIL.extractFileToDirectory(
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll(source.files.collect { it.canonicalPath })
rhino.execute(args, '.', true)
rhino.execute(args, [ignoreExitCode: true, out: new FileOutputStream(dest)])
}
}
3 changes: 2 additions & 1 deletion src/test/resources/file1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @return {Boolean} True whenever we damn well feel like it
*/
function test1() {
console.log('test1');
// The following should be a JSHint warning
console && console.log('test1');
return true;
}

0 comments on commit 80d33df

Please sign in to comment.