<commit_before>package com.github.ksoichiro.web.resource

import com.moowork.gradle.node.task.NodeTask
import groovy.json.JsonOutput
import groovy.text.SimpleTemplateEngine
import org.gradle.api.tasks.TaskAction

class WebResourceCompileTask extends NodeTask {
    static final String NAME = "webResourceCompile"
    WebResourceExtension extension

    WebResourceCompileTask() {
        dependsOn([WebResourceInstallBowerDependenciesTask.NAME])
        this.project.afterEvaluate {
            extension = this.project.extensions.webResource
            getInputs().files(retrieveValidPaths(getSrcCoffee(), getSrcLess()))
            getOutputs().files(retrieveValidPaths(getDestCoffee(), getDestLess(), getDestLib()))
            setWorkingDir(extension.workDir)
        }
    }

    @TaskAction
    void exec() {
        def gulp = this.project.file(new File(extension.workDir, "node_modules/gulp/bin/gulp.js"))
        setScript(gulp)
        setArgs(['default'])
        def bindings = [
                srcLess     : getSrcLess(),
                destLess    : getDestLess(),
                filterLess  : extension.less.filter ? JsonOutput.toJson(extension.less.filter).toString() : "['**/*', '!**/_*.less']",
                srcCoffee   : getSrcCoffee(),
                destCoffee  : getDestCoffee(),
                filterCoffee: extension.coffeeScript.filter ? JsonOutput.toJson(extension.coffeeScript.filter).toString() : "['**/*', '!**/_*.coffee']",
                destLib     : resolveDestPath(extension.lib?.dest),
                workDir     : "../../${extension.workDir.absolutePath.replace(this.project.projectDir.absolutePath, "").replaceAll("\\\\", "/").replaceAll("^/", "")}"
        ]
        new File(extension.workDir, "gulpfile.js").text =
                new SimpleTemplateEngine()
                        .createTemplate(getClass().getResourceAsStream('/gulpfile.js').text)
                        .make(bindings)
        super.exec()
    }

    String resolveSrcPath(def path) {
        String src = "../../"
        if (path) {
            src += extension.base?.src ? "${extension.base?.src}/" : ""
            src += path
        }
        src
    }

    String resolveDestPath(def path) {
        String dest = ""
        if (path) {
            dest = extension.base?.dest ? "${extension.base?.dest}/" : ""
            dest += path
            dest = "../../${dest}"
        }
        dest
    }

    String getSrcCoffee() {
        resolveSrcPath(extension.coffeeScript?.src)
    }

    String getSrcLess() {
        resolveSrcPath(extension.less?.src)
    }

    String getDestCoffee() {
        resolveDestPath(extension.coffeeScript?.dest)
    }

    String getDestLess() {
        resolveDestPath(extension.less?.dest)
    }

    String getDestLib() {
        resolveDestPath(extension.lib?.dest)
    }

    List retrieveValidPaths(String... paths) {
        List result = []
        paths.each {
            if (project.file("${extension.workDir}/${it}")) {
                result += "${extension.workDir}/${it}"
            }
        }
        result
    }
}<commit_msg>Added generated gulpfile.js as an output.<commit_after>package com.github.ksoichiro.web.resource

import com.moowork.gradle.node.task.NodeTask
import groovy.json.JsonOutput
import groovy.text.SimpleTemplateEngine
import org.gradle.api.tasks.TaskAction

class WebResourceCompileTask extends NodeTask {
    static final String NAME = "webResourceCompile"
    WebResourceExtension extension

    WebResourceCompileTask() {
        dependsOn([WebResourceInstallBowerDependenciesTask.NAME])
        this.project.afterEvaluate {
            extension = this.project.extensions.webResource
            getInputs().files(retrieveValidPaths(getSrcCoffee(), getSrcLess()))
            getOutputs().files(retrieveValidPaths(getDestCoffee(), getDestLess(), getDestLib()), getGulpfile())
            setWorkingDir(extension.workDir)
        }
    }

    @TaskAction
    void exec() {
        def gulp = this.project.file(new File(extension.workDir, "node_modules/gulp/bin/gulp.js"))
        setScript(gulp)
        setArgs(['default'])
        def bindings = [
                srcLess     : getSrcLess(),
                destLess    : getDestLess(),
                filterLess  : extension.less.filter ? JsonOutput.toJson(extension.less.filter).toString() : "['**/*', '!**/_*.less']",
                srcCoffee   : getSrcCoffee(),
                destCoffee  : getDestCoffee(),
                filterCoffee: extension.coffeeScript.filter ? JsonOutput.toJson(extension.coffeeScript.filter).toString() : "['**/*', '!**/_*.coffee']",
                destLib     : resolveDestPath(extension.lib?.dest),
                workDir     : "../../${extension.workDir.absolutePath.replace(this.project.projectDir.absolutePath, "").replaceAll("\\\\", "/").replaceAll("^/", "")}"
        ]
        getGulpfile().text =
                new SimpleTemplateEngine()
                        .createTemplate(getClass().getResourceAsStream('/gulpfile.js').text)
                        .make(bindings)
        super.exec()
    }

    String resolveSrcPath(def path) {
        String src = "../../"
        if (path) {
            src += extension.base?.src ? "${extension.base?.src}/" : ""
            src += path
        }
        src
    }

    String resolveDestPath(def path) {
        String dest = ""
        if (path) {
            dest = extension.base?.dest ? "${extension.base?.dest}/" : ""
            dest += path
            dest = "../../${dest}"
        }
        dest
    }

    String getSrcCoffee() {
        resolveSrcPath(extension.coffeeScript?.src)
    }

    String getSrcLess() {
        resolveSrcPath(extension.less?.src)
    }

    String getDestCoffee() {
        resolveDestPath(extension.coffeeScript?.dest)
    }

    String getDestLess() {
        resolveDestPath(extension.less?.dest)
    }

    String getDestLib() {
        resolveDestPath(extension.lib?.dest)
    }

    List retrieveValidPaths(String... paths) {
        List result = []
        paths.each {
            if (project.file("${extension.workDir}/${it}")) {
                result += "${extension.workDir}/${it}"
            }
        }
        result
    }

    File getGulpfile() {
        new File(extension.workDir, "gulpfile.js")
    }
}
{'fraction_non_alphanumeric': 0.13910428865326793, 'fraction_numerical': 0.0, 'mean_word_length': 2.1087063453025086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1698894', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1734, 'n_words': 265}