diff --git a/README.md b/README.md index aa5e777..f52dfa0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ sbt-frontend [![Build Status](https://travis-ci.org/eltimn/sbt-frontend.svg?branch=master)](https://travis-ci.org/eltimn/sbt-frontend) +[![Bintray](https://img.shields.io/bintray/v/eltimn/sbt-plugins/sbt-frontend.svg)](https://bintray.com/eltimn/sbt-plugins/sbt-frontend) + [SBT](http://www.scala-sbt.org/) plugin for managing frontend code (node and npm, grunt, gulp, bower, etc.) SBT version of [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin). @@ -34,9 +36,8 @@ Upon loading SBT, Node and npm with be automatically installed locally. Also, if The plugin makes available the following `InputTask`s. Note that you must first install any apps you want to use with `npm install`. -| Task | Description | +| Input Task | Description | | ------------- | ------------- | -| nodeInstall | Installs Node and npm. Runs automatically at startup. | | npm | Runs npm commands | | bower | Runs bower commands | | grunt | Runs grunt commands | @@ -64,6 +65,14 @@ myTask := gulp.toTask(" build").value This is equivalent to ```gulp build```. +### Other Tasks + +| Task | Description | +| ------------- | ------------- | +| nodeInstall | Installs Node and npm. Runs automatically at startup. | +| frontendCleanDeps | Remove frontend dependencies (node_modules and bower_components). Must reload project afterwards. | +| frontendCleanAll | Remove Node, NPM, and dependencies. Must reload project afterwards. | + The following `FrontendKeys` are also available: | Setting | Description | diff --git a/src/main/scala/sbtfrontend/FrontendPlugin.scala b/src/main/scala/sbtfrontend/FrontendPlugin.scala index f971345..bcfb43d 100644 --- a/src/main/scala/sbtfrontend/FrontendPlugin.scala +++ b/src/main/scala/sbtfrontend/FrontendPlugin.scala @@ -33,7 +33,8 @@ object FrontendPlugin extends AutoPlugin { val webpack = inputKey[Unit]("Runs webpack commands") val ember = inputKey[Unit]("Runs ember commands") val webjars = taskKey[Unit]("Extract web jar assets") - val frontendClean = taskKey[Unit]("Clean sbt-frontend dependencies") + val frontendCleanDeps = taskKey[Unit]("Remove frontend dependencies. Must reload project afterwards.") + val frontendCleanAll = taskKey[Unit]("Remove Node, NPM, and dependencies. Must reload project afterwards.") object FrontendKeys { val frontendFactory = settingKey[FrontendPluginFactory]("The FrontendFactory instance") @@ -45,6 +46,8 @@ object FrontendPlugin extends AutoPlugin { val npmDownloadRoot = settingKey[String](s"Where to download NPM binary from. Default: ${Defaults.npmDownloadRoot}") val npmRegistryUrl = settingKey[Option[String]](s"NPM registry URL. Default: ${Defaults.npmRegistryUrl}") val nodeProxies = settingKey[Seq[ProxyConfig.Proxy]]("Seq of proxies for downloader.") + val npmFile = settingKey[File]("package.json") + val bowerFile = settingKey[File]("bower.json") } lazy val frontendSettings: Seq[Def.Setting[_]] = { @@ -58,6 +61,8 @@ object FrontendPlugin extends AutoPlugin { nodeDownloadRoot := Defaults.nodeDownloadRoot, npmDownloadRoot := Defaults.npmDownloadRoot, npmRegistryUrl := Defaults.npmRegistryUrl, + npmFile := nodeWorkingDirectory.value / "package.json", + bowerFile := nodeWorkingDirectory.value / "bower.json", nodeProxies := Nil, frontendFactory := { new FrontendPluginFactory(nodeWorkingDirectory.value, nodeInstallDirectory.value) @@ -92,10 +97,15 @@ object FrontendPlugin extends AutoPlugin { Frontend.extractWebjarAssets(jar, target.value / "webjars") } }, - frontendClean := { - IO.delete(nodeInstallDirectory.value) + frontendCleanDeps := { + IO.delete(nodeInstallDirectory.value / "bower.json.md5") + IO.delete(nodeInstallDirectory.value / "package.json.md5") IO.delete(nodeWorkingDirectory.value / "bower_components") - IO.delete(nodeWorkingDirectory.value / "npm_modules") + IO.delete(nodeWorkingDirectory.value / "node_modules") + }, + frontendCleanAll := { + IO.delete(nodeWorkingDirectory.value / ".frontend") + frontendCleanDeps.value }, onLoad in Global := { val onLoadFunc = (s: State) => { @@ -134,9 +144,8 @@ object FrontendPlugin extends AutoPlugin { } // npm install - val npmFile = nodeWorkingDirectory.value / "package.json" - if (npmFile.exists) { - runIfUpdated(npmFile) { + if (npmFile.value.exists) { + runIfUpdated(npmFile.value) { Frontend.npm( frontendFactory.value, "install", @@ -149,9 +158,8 @@ object FrontendPlugin extends AutoPlugin { } // bower install - val bowerFile = nodeWorkingDirectory.value / "bower.json" - if (bowerFile.exists) { - runIfUpdated(bowerFile) { + if (bowerFile.value.exists) { + runIfUpdated(bowerFile.value) { Frontend.bower( frontendFactory.value, "install", diff --git a/src/sbt-test/sbt-frontend/bower/test b/src/sbt-test/sbt-frontend/bower/test index 0b36fd6..d5b5b48 100644 --- a/src/sbt-test/sbt-frontend/bower/test +++ b/src/sbt-test/sbt-frontend/bower/test @@ -1,4 +1,11 @@ > show nodeInstallDirectory +$ exists node_modules/bower/bin/bower $ exists bower_components/jquery/dist/jquery.js -> frontendClean +> frontendCleanDeps +$ absent .frontend/package.json.md5 +$ absent .frontend/bower.json.md5 +$ absent node_modules $ absent bower_components +> reload +$ exists node_modules/bower/bin/bower +$ exists bower_components/jquery/dist/jquery.js diff --git a/src/sbt-test/sbt-frontend/installation/bower.json b/src/sbt-test/sbt-frontend/installation/bower.json new file mode 100644 index 0000000..542367d --- /dev/null +++ b/src/sbt-test/sbt-frontend/installation/bower.json @@ -0,0 +1,10 @@ +{ + "name": "lift-frontend", + "private": "true", + "moduleType": [ + "globals" + ], + "dependencies": { + "jquery": "~2.2.0" + } +} diff --git a/src/sbt-test/sbt-frontend/installation/package.json b/src/sbt-test/sbt-frontend/installation/package.json new file mode 100644 index 0000000..d7b0536 --- /dev/null +++ b/src/sbt-test/sbt-frontend/installation/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "devDependencies": { + "bower": "latest" + } +} diff --git a/src/sbt-test/sbt-frontend/installation/test b/src/sbt-test/sbt-frontend/installation/test index f77089f..7ab9f63 100644 --- a/src/sbt-test/sbt-frontend/installation/test +++ b/src/sbt-test/sbt-frontend/installation/test @@ -1,6 +1,14 @@ > nodeInstall $ exists .frontend/node/node $ exists .frontend/node/node_modules/npm/bin/npm-cli.js -> frontendClean +$ exists node_modules/bower/bin/bower +$ exists bower_components/jquery/dist/jquery.js +> frontendCleanAll $ absent .frontend $ absent node_modules +$ absent bower_components +> reload +$ exists .frontend/node/node +$ exists .frontend/node/node_modules/npm/bin/npm-cli.js +$ exists node_modules/bower/bin/bower +$ exists bower_components/jquery/dist/jquery.js