Play Framework 2.3.4: How to run JSHint as part of a compilation task

I have a multi-project application and I want to JSHint

run as part of a compilation task. Below is how I set up my project:

1) Added JSHint plugin to myApp/project/plugins.sbt

:

...

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.1")

      

2) Include it (SbtWeb) in myApp/build.sbt

:

...

lazy val apidocs = project.in(file("modules/apidocs")).enablePlugins(play.PlayScala, SbtWeb).settings(
  javaOptions in Test += "-Dconfig.resource=apidocs-application.conf"
).dependsOn(
  common % "test->test;compile->compile"
)

      

I also tried to run the task assets

... but it looks like JSHint is not being called. How can I run JSHint as part of a compilation task? Perhaps an even better option would be to modify myApp/projects/Build.scala

and let JSHint compress any *.js

in any subproject.

+3


source to share


2 answers


Firstly, I am assuming you are using this version of sbt-jshint (there seem to be at least 3 popular versions floating around).

The general meaning of this is that we need a task that is triggered by compilation. It's pretty easy to adapt from this answer . Therefore, we add the following to build.sbt

:

val triggeredTask = taskKey[Seq[sbt.File]]("Triggered by compile")

triggeredTask <<= Def.task {
  JshintKeys.jshint.value
}.triggeredBy(compile in Compile)

      



It should be noted here that the type is taskKey

not a unit like the answer I linked to, but the type of the jshint problem. The second thing to note here is the weirdness of the jshint reference. JshintKeys.jshint

compared to just calling jshint. I kept getting "error: not found: jshint value" until I did. If you look in source , you can see that JshintKeys is an object within an object. I don't know if this is the standard for writing sbt plugins, but I know it makes it necessary. Finally, .value

is how we say our launched task depends on another task.

Once you have this location, you will see a jpg trigger:

+1


source


JShint does not compress anything, it detects and warns of bad practices in your Java scripts.

From the plugin docs (and sources), it doesn't seem like the bind task starts automatically, it just provides a "jshint" task that you could call in your sbt console to get the jshint result.



Perhaps you could integrate it with your project's compilation task so that it doesn't work when the hints come up, can't tell how exactly because of my head, although I would recommend you become best friends with sbt to understand that one of them. ( http://www.scala-sbt.org/0.13/tutorial/index.html )

0


source







All Articles