All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.catalysts.gradle.less.task.InstallLess.groovy Maven / Gradle / Ivy

There is a newer version: 0.0.29
Show newest version
package cc.catalysts.gradle.less.task

import cc.catalysts.gradle.less.LessExtension
import com.moowork.gradle.node.task.NpmTask
import org.gradle.execution.commandline.TaskConfigurationException

/**
 * @author Thomas Scheinecker, Catalysts GmbH
 */
class InstallLess extends NpmTask {
    public InstallLess() {
        this.group = 'Cat-Boot LESS'
        this.description = 'Prepares the less compiler'

        project.afterEvaluate({
            LessExtension config = LessExtension.get(project)

            outputs.upToDateWhen {
                return config
                        .getPackageJson()
                        .equals(config.getPackageJsonFile())
            }

            setWorkingDir(config.nodeModulesDir)
            setNpmCommand('install')

            outputs.dir(new File(config.nodeModulesDir, 'node_modules'))
        })
    }

    private void writePackageJson() {
        LessExtension config = LessExtension.get(project)
        File packageJsonFile = config.getPackageJsonFile()

        config.getPackageJson()
                .toFile(packageJsonFile)

        if (!packageJsonFile.exists()) {
            throw new TaskConfigurationException(path, "Couldn't create ${packageJsonFile}!", null)
        }

        logger.lifecycle("Successfully created ${packageJsonFile}")
    }

    @Override
    void exec() {
        writePackageJson();
        super.exec()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy