diff --git a/build.gradle b/build.gradle index ef27569..7972c30 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'idea' defaultTasks 'clean', 'build' -version = '0.3.13-SNAPSHOT' +version = '0.3.37-SNAPSHOT' group = 'com.eriwen' archivesBaseName = 'gradle-js-plugin' isSnapshot = version.endsWith("-SNAPSHOT") diff --git a/plugin.gradle b/plugin.gradle index 6441514..b8ef1e5 100644 --- a/plugin.gradle +++ b/plugin.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.eriwen:gradle-js-plugin:0.3.13-SNAPSHOT' + classpath 'com.eriwen:gradle-js-plugin:0.3.37-SNAPSHOT' } } @@ -27,10 +27,15 @@ apply plugin: 'js' combineJs { file2 = fileTree(dir: "${projectDir}/src/test/resources", includes: ['file2.js']) file1 = fileTree(dir: "${projectDir}/src/test/resources", includes: ['file1.js']) - inputs.files file2 + file1 + inputs.files file1 + file2 outputs.file file("${buildDir}/all.js") } +task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) { + source = ["${projectDir}/src/test/resources/file1.js", "${projectDir}/src/test/resources/file2.js"] + dest = "${buildDir}/all.js" +} + // Minify with Google Closure Compiler minifyJs { inputs.file file("${buildDir}/all.js") @@ -38,6 +43,11 @@ minifyJs { warningLevel = 'QUIET' } +task minify(type: com.eriwen.gradle.js.tasks.MinifyJsTask) { + source = "${buildDir}/all.js" + dest = "${buildDir}/all-min.js" +} + // GZip it! gzipJs { inputs.file file("${buildDir}/all-min.js") diff --git a/src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy b/src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy index 00a96ed..fd22031 100644 --- a/src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy +++ b/src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy @@ -26,7 +26,7 @@ class CombineJsTask extends DefaultTask { def run() { if (!getInputs().files.files.empty) { logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = ["path1", "path2"]`') - logger.warn('This will be removed very soon') + logger.warn('This will be removed in the next version of the JS plugin') source = getInputs().files.files.collect { it.canonicalPath } } diff --git a/src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy b/src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy index 41d7b2f..5d524d1 100644 --- a/src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy +++ b/src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy @@ -20,24 +20,41 @@ import org.gradle.api.tasks.TaskAction import com.google.javascript.jscomp.CompilerOptions import com.eriwen.gradle.js.JsMinifier +import org.codehaus.groovy.runtime.GStringImpl class MinifyJsTask extends DefaultTask { private static final JsMinifier MINIFIER = new JsMinifier() + // FIXME: Wire defaults in properly through convention (#14) CompilerOptions compilerOptions = new CompilerOptions() String compilationLevel = 'SIMPLE_OPTIMIZATIONS' String warningLevel = 'DEFAULT' + def source + def dest @TaskAction def run() { - def inputFiles = getInputs().files.files.toArray() - def outputFiles = getOutputs().files.files.toArray() - if (outputFiles.size() == inputFiles.size()) { - for (int i = 0; i < inputFiles.size(); i++) { - MINIFIER.minifyJsFile(inputFiles[i] as File, outputFiles[i] as File, compilerOptions, warningLevel, compilationLevel) + if (!source) { + logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = "path1"`') + logger.warn('This will be removed in the next version of the JS plugin') + source = getInputs().files.files.collect { it.canonicalPath } + } else if (source instanceof GStringImpl || source instanceof String) { + source = [source] + } + + if (!dest) { + logger.warn('The syntax "outputs.files ..." is deprecated! Please use `dest = "dest/filename.js"`') + dest = getOutputs().files.files.collect { it.canonicalPath } + } else if (dest instanceof GStringImpl || dest instanceof String) { + dest = [dest] + } + + if (dest.size() == source.size()) { + for (int i = 0; i < source.size(); i++) { + MINIFIER.minifyJsFile(project.file(source[i]), project.file(dest[i]), compilerOptions, warningLevel, compilationLevel) } } else { - throw new IllegalArgumentException("Could not map input files to output files. Found ${inputFiles.size()} inputs and ${outputFiles.size()} outputs") + throw new IllegalArgumentException("Could not map input files to output files. Found ${source.size()} inputs and ${dest.size()} outputs") } } }