Code Monkey home page Code Monkey logo

sbt-concat's Introduction

sbt-concat

Build Status

sbt-web plugin for concatenating files together, using the sbt-web asset pipeline.

Plugin

Add the plugin to your project/plugins.sbt:

addSbtPlugin("com.github.sbt" % "sbt-concat" % "1.0.0")

Enable the sbt-web plugin for your project:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

Add the concat task to your asset pipeline in your build.sbt:

pipelineStages := Seq(concat)

Configuration options

Specifying concat groups

Below is an example of specifying concat groups within your build.sbt file. You can use PathFinder objects or a Seq[String] to specify the files to concatenate together.

Concat.groups := Seq(
  "style-group.css" -> group(Seq("css/style1.css", "css/style2.css")),
  "script-group.js" -> group(Seq("js/script1.js", "js/script2.js")),
  "style-group2.css" -> group((sourceDirectory.value / "assets" / "style") * "*.css")
)

Note that with a PathFinder, you will need to take care to ensure that the files it selects will be concatenated in the order that you desire.

To match entries in Seq[String] in group PathMapping is used. Only relative paths up to one level deep are guaranteed match.

This will produce three files with concatenated contents:

style-group.css

/** css/style1.css **/
body { color: #000; }
/** css/style2.css **/
#main { background-color: #fff; }

script-group.js

/** js/script1.js **/
function onDomReady(){ ... }
/** js/script2.js **/
$(onDomReady);

style-group2.css

/** assets/style/main.css **/
body { font-weight: bold; }
/** assets/style/base.css **/
section { font-size: 15em; }

These will reside under the asset build directory in the base target directory by default. You can change the name of this directory using the Concat.parentDir SettingKey.

License

This code is licensed under the MIT License.

sbt-concat's People

Contributors

almoehi avatar dwijnand avatar john-bernardo1 avatar jroper avatar lmnet avatar mkurz avatar olegstepura avatar scala-steward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-concat's Issues

This plugin does not work with wildcard setting.

I was trying to bundle all css under a directory and its sub-directories. However, I found that only the files under direct level of the specified directory would be bundled, but not the ones in sub-directories.

Then, I tried something like this to indicate that it is for everything including
"lib.css" -> group(((sourceDirectory in Assets).value / "css" / "core" / "lib") * "*/.css")
This is not working for me.

Not found exception for public assets

I'm trying to combine some css in the server's /public directory.

I used the following concat group:

Concat.groups := Seq(
      "styles.css" -> group{
        val x = (resourceDirectory.in(Assets).value / "css") * "*.css"
        println(x.absString)
        x
      }
    ),

This prints the correct files, but I receive not-found warnings.

Plugin prevents sbt 0.13.9 `-=` operator from working

In sbt 0.13.9, a new operator -= has been added which is supposed to be the 'opposite' of += and is a very useful operator. However, if a project uses the wonderfully useful sbt-concat, the said operator does not work. Here's a repro. Removing sbt-concat from the list of plugins would make the operator work.

git clone https://github.com/SRGOM/SbtMinus 
cd SbtMinus
source fail.sh

Do you think you could dig in to this? @dwjinand may help if this is a problem on the sbt side

Project including sbt-concat can no longer use sbteclipse plugin.

We have an angular project where we use sbt-concat. After including the plugin, we can no longer use sbt eclipse as there is an incompatible version of scalaz included with the old version of sbt-web used with the latest release of this plugin. The sbt-web plugin needs updated.

sourceDirectory.value is not working

Here is my build.sbt file

name := "webapp"

version := "1.0-SNAPSHOT"

scalaVersion := "2.10.4"

lazy val root = (project in file(".")).enablePlugins(PlayScala).enablePlugins(SbtTwirl).enablePlugins(SbtWeb)

resolvers += Resolver.sonatypeRepo("releases")

libraryDependencies ++= Seq(
cache,
filters,
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"com.typesafe.play" %% "play-slick" % "0.7.0-M1",
"com.github.tminglei" %% "slick-pg" % "0.5.3",
"com.github.tminglei" %% "slick-pg_play-json" % "0.5.3",
"com.github.tminglei" %% "slick-pg_jts" % "0.5.3"
)

pipelineStages in Assets := Seq(concat)

Concat.groups := Seq(
"base.css" -> group(Seq("css/vendor/bootstrap/bootstrap.css")),
"lib.css" -> group((sourceDirectory.value / "assets" / "css" / "core" / "lib") * ".css"),
"core.css" -> group(Seq("css/core/layout.css")),
"base.js" -> group(Seq("js/vendor/jquery/jquery.js", "js/vendor/jquery/jquery.qtip.js", "js/vendor/bootstrap/bootstrap.js")),
"lib.js" -> group((sourceDirectory.value / "assets" / "js" / "core" / "lib") * "
.js"),
"core.js" -> group(Seq("js/core/jy.js"))
)

TaskKeyUnit := println("test my output" + sourceDirectory.value)

Please note that
"base.css" -> group(Seq("css/vendor/bootstrap/bootstrap.css"))
"base.js" -> group(Seq("js/vendor/jquery/jquery.js", "js/vendor/jquery/jquery.qtip.js", "js/vendor/bootstrap/bootstrap.js"))
worked fine.
However the one using sourceDirectory.value does not work. Anyone has any insights?

Using with Less Compression

I have a bunch of Less files with sbt-web, and the asset pipeline is compiling the Less files into CSS files and minifying them just fine. However, I am completely unable to get sbt-concat to concatenate the resulting css files.

The original Less files are in app/assets/stylesheets. The resulting files are in public/main/stylesheets.

I configure like this:

pipelineStages := Seq(rjs, concat, digest, gzip)
Concat.groups := Seq(
"style-group.css" -> group(Seq("stylesheets/myfile.css"))
)

...as well as a ton of other ways including using absolute paths for fun. Nothing has worked.

I have found that I can concatenate other files--but only when I do "activator start" rather than "activator run."

So it seems I have two problems--getting sbt-concat to work when I just run and getting it to pick up CSS files generated from LESS files.

Any insight into what I'm doing wrong is appreciated.

Option to emit warning when directories or files are not found

Misconfigurations can be time consuming to debug with sbt-concat because it is not obvious what is in the target directory when (for example when you compress files that will later be concatenated). Please add an option to emit warnings for missing directories or files.

PathFinder Mappings filtering all files

I am using Play Framework with sbt-concat.

This is my mapping in the build.sbt:
Concat.groups := Seq(
"scripts.js" -> group(((resourceDirectory in Assets).value / "javascripts") * "*.js")
)

But sadly, no file it is being concatenated. I was debugging the plugin and found where are my files being filtered. That happen in the following lines:

        groupsValue.foreach {
          case (groupName, fileNames) =>
            fileNames.foreach { fileName =>
              val mapping = filteredMappings.filter(_._2 == fileName)
              if (mapping.nonEmpty) {
                // TODO This is not as memory efficient as it could be, write to file instead
                concatGroups.getOrElseUpdate(groupName, new StringBuilder)
                  .append(s"\n/** $fileName **/\n")
                  .append(IO.read(mapping.head._1))
                reverseMapping.remove(fileName)
              }
            }
        }

The filter which is comparing the names is excluding all my scripts, for example:

"hello.js" == "javascripts/hello.js"

I am not sure if it is an Issue or I simply forgot to do something.

Thank you very much, I hope I explained my self good enough :)

Problem with Filter

Hi, i tried to get this plugin working but it seems to be that only the way via Pathfinders is working:
I use sbt-concat with the play framework, which is quite standard configured. As i debugged the code i saw that the if (mapping.nonEmpty) { is always false. Maybe you can have a look at this and help me. :-)

//includeFilter in concat := GlobFilter("app/assets/js/*.js")

Concat.parentDir := "/js/"

Concat.groups := Seq(
  "modernizr.js" -> group((baseDirectory.value / "app" / "assets" / "js" / "modernizr") * "*.js"),
  "main.js" -> group(Seq("app/assets/js/plugin.js", "app/assets/js/main.js"))
)

pipelineStages in Assets := Seq(concat)

I am new in Scala and i have no clue what this is doing. Looks like magic. In past you would be burnt at the stake. ๐Ÿ‘

val filteredMappings = mappings.filter(m => (includeFilter in concat).value.accept(m._1) && m._1.isFile)

Does not work with Play 2.4

I have tried everything I can think of and no matter what it will not work with Play 2.4. No exceptions being thrown, just the concatenated file is no where to be found.

I have followed all the steps and am just trying to get this simple example working with no success. I am running in Dev which is why i have pipelineSages in Assets.

[code]
lazy val webSettings = Seq(
Concat.groups := Seq(
"combined.js" -> group(Seq(
"app/app.js",
"app/controller/DialogController.js"
))
),
pipelineStages in Assets := Seq(concat)
)
[/code]

TypeError: 'float' object cannot be interpreted as an index

Getting an odd casting error on up-do-date pyFASST while attempting some blind source separation... have tried reinstalling numpy and scikits.audiolab to no avail:

Python 2.7.13 :: Anaconda 4.3.0 (x86_64)
numpy 1.13.0
scikits.audiolab 0.11.0
pyFASST 0.9.3

pip install -U numpy scikits.audiolab pyfasst

import pyfasst.audioModel as am
model = am.MultiChanNMFInst_FASST(audio='stereo.wav',nbComps=2, nbNMFComps=32, spatial_rank=1,verbose=1, iter_num=50)
('Computing the chosen signal representation:', 'stft')
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/peckjon/anaconda/lib/python2.7/site-packages/pyfasst/audioModel.py", line 2339, in __init__
    self.comp_transf_Cx()
  File "/Users/peckjon/anaconda/lib/python2.7/site-packages/pyfasst/audioModel.py", line 278, in comp_transf_Cx
    self.tft.computeTransform(self.audioObject.data[:,n],)
  File "/Users/peckjon/anaconda/lib/python2.7/site-packages/pyfasst/tftransforms/stft.py", line 382, in computeTransform
    fs=self.fs, nfft=self.ftlen
  File "/Users/peckjon/anaconda/lib/python2.7/site-packages/pyfasst/tftransforms/stft.py", line 47, in stft
    data = np.concatenate((np.zeros(lengthWindow/2.0), data))
TypeError: 'float' object cannot be interpreted as an index

I can resolve the error by casting lengthWindow to int and changing the offending line to np.zeros(lengthWindow/2) (plus a few similar lines later on), but this results in empty output files, so clearly I'm missing something... (among others, why would one ever attempt to use a float as a parameter to np.zeros!?)

when using PathFinder the files should preserve their alphabetical order

On line 57 the collected files are converted to a Map:

(groupName, r.toMap.values)

this results in unpredictable order of concatenation of the matched files and eventually results in JS errors.

The files should be concatenated in their natural (e.g. alphabetical) order - isn't it possible to use the value of rdirectly ?

error: value addPlugins is not a member of sbt.Project

Hi,
I followed the steps in the README but as soon as I add the "addSbtPlugin" entry to my plugins.sbt I get the following error when running SBT:

error: value addPlugins is not a member of sbt.Project
possible cause: maybe a semicolon is missing before `value addPlugins'?
    .addPlugins(PlayScala)

I'm using play 2.3 and sbt 0.13.5-M2 - any idea how to fix this ?

Thanks !

Relative paths in CSS

I have a few CSS files with relative paths to other resources(images, fonts), I'm using the plugin to concatenate all the css, including some form webjars.
Taken from Font Awesome:
@font-face{font-family:'FontAwesome';src:url('../fonts/fontawesome-webfont.eot?v=4.1.0')

Since the path to the css changes, all the relative paths stop working.
I know the easy fixes are either just copy those resources to the appropriate place, but that would be hard to keep track of; or edit the paths, which is not always possible if using webjars.

Generate one big (concatenated) minified css

Hi, I am using your sbt-css-compress plugin and would like to use it after concatenating all my css files together to one. Is it possible to create a group saying "concatenate all css files you find in stylesheets/ ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.