/*
 * Copyright Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.thoughtworks.go.build.YarnRunTask

tasks.register('stylelintold', YarnRunTask) {
  description = "Run stylelint for SCSS on old Rails-bundled SCSS"
  dependsOn 'yarnInstall'

  workingDir = project.railsRoot

  yarnCommand = ['stylelintold']
  source(project.file("${project.railsRoot}/app/assets/new_stylesheets"))
  source(project.file("${project.railsRoot}/.stylelintrc.yml"))
}

tasks.register('eslintold', YarnRunTask) {
  description = "Run ESLint for old javascript code"
  dependsOn 'yarnInstall'

  workingDir = project.railsRoot

  yarnCommand = ['eslintold']
  source(project.file("${project.railsRoot}/app/assets/javascripts"))
  source(project.file("${project.railsRoot}/spec/javascripts"))
  source(project.file("${project.railsRoot}/.eslintrc-old.json"))
}

tasks.register('eslint', YarnRunTask) {
  description = "Run ESLint"
  dependsOn 'yarnInstall'
  dependsOn 'generateJSRoutes'

  workingDir = project.railsRoot

  yarnCommand = ['eslint']
  source(project.file("${project.railsRoot}/webpack"))
  source(project.file("${project.railsRoot}/spec/webpack"))
  source(project.file("${project.railsRoot}/app/assets/new_stylesheets"))
  source(project.file("${project.railsRoot}/.eslintrc.json"))
}

tasks.register('tslint', YarnRunTask) {
  description = "Run TSLint"
  dependsOn 'yarnInstall'
  dependsOn 'generateJSRoutes'

  workingDir = project.railsRoot

  yarnCommand = ['tslint']
  source(project.file("${project.railsRoot}/webpack"))
  source(project.file("${project.railsRoot}/spec/webpack"))
  source(project.file("${project.railsRoot}/tslint.json"))
}

tasks.register('lintNew') {
  description = 'Run lint tools on newer js/scss'
  dependsOn eslint, tslint
}

tasks.register('lintOld') {
  description = 'Run lint tools on older legacy js/scss'
  dependsOn stylelintold, eslintold
}

tasks.register('lint') {
  description = 'Run all lint tools'
  dependsOn lintNew, lintOld
}
