npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bower-installer

v1.3.6

Published

Tool for installing bower dependencies that won't include entire repos

Downloads

2,732

Readme

bower-installer Build Status

Tool for installing bower dependencies that won't include entire repos. Although Bower works great as a light-weight tool to quickly install browser dependencies, it currently does not provide much functionality for installing specific "built" components for the client.

Bower installs entire repositories

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "backbone": "latest"
    }
}

If bower install is run on this configuration file, the entire backbone repository will be pulled down and copied into a components directory. This repository is quite large, when probably only a built js and css file are needed. Bower conveniently provides the bower list --paths command to list the actual main files associated with the components (if the component doesn't define a main, then the whole repository is listed instead).

Bower Installer

Bower installer provides an easy way for the main files to be installed or moved to one or more locations. Simply add to your bower.json an install key and path attribute:

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "backbone": "latest"
    },
    "install": {
        "path": "some/path"
    }
}

Install bower-installer by executing

npm install -g bower-installer

From the terminal in the same directory as your bower.json file, enter:

bower-installer

After executing this, backbone.js will exist under some/path relative to the location of your bower.json file.

Overriding main files

A lot of registered components for bower do not include bower.json configuration. Therefore, bower does not know about any "main files" and therefore, by default bower-installer doesn't know about them either. Bower-installer can override an existing main file path or provide a non-existant one:

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "backbone": "latest",
        "requirejs": "latest"
    },
    "install": {
        "path": "some/path",
        "sources": {
            "requirejs": "bower_components/requirejs/require.js"
        }
    }
}

If bower installer is run on this configuration, require.js and backbone.js will all appear under some/path relative to your bower.json file.

Install multiple main files

For one reason or another you may want to install multiple files from a single component. You can do this by providing an Array instead of a String inside the sources hash. Or you can use file matchers https://github.com/isaacs/minimatch:

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "jquery-ui": "latest",
        "datejs": "*"
    },
    "install": {
        "path": "some/path",
        "sources": {
            "jquery-ui": [
            "bower_components/jquery-ui/ui/jquery-ui.custom.js",
            "bower_components/jquery-ui/themes/start/jquery-ui.css"
            ],
            "datejs": "bower_components/datejs/build/*.*"
        }
    }
}

Install files to multiple locations

Files can be installed to multiple locations based upon file type or regular expression. Do so by modifying the path to be a map of file-type locations. Example:

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "jquery-ui": "latest"
    },
    "install": {
        "path": {
            "css": "src/css",
            "js": "src/js",
            "/[sc|le]ss$/": "src/css"
        },
        "sources": {
            "jquery-ui": [
            "bower_components/jquery-ui/ui/jquery-ui.custom.js",
            "bower_components/jquery-ui/themes/start/jquery-ui.css"
            ]
        }
    }
}

Configurable paths

Paths can be custom configurable with variables (key, name and version):

{
    "name": "test",
    "version": "0.0.2",
    "dependencies": {
        "bootstrap": "~3.0.3"
    },
    "install": {
        "base":  "build",
        "path": {
            "js": "{name}/js",
            "css": "{name}/css",
            "eot": "{name}/fonts",
            "svg": "{name}/fonts",
            "ttf": "{name}/fonts",
            "woff": "{name}/fonts"
        }       
    }
}

Will create this output structure:

build/
    bootstrap/
        js
        css
        fonts
    jquery
        js

Rename files during copy

Files can be renamed when bower-installer is copying them to their new destination. Do so by modifying the mapping object. Example:

{
   "name": "test",
   "version": "0.1",
   "dependencies": {
       "jquery-ui": "latest"
   },
   "install": {
       "path": "some/path",
       "sources": {
           "jquery-ui": {
               "mapping": [
               {"bower_components/jquery-ui/ui/jquery-ui.js": "jquery-ui.js"},
               {"bower_components/jquery-ui/ui/minified/jquery-ui.min.js": "jquery-ui-min-new-name.js"}
               ]
           }
       }
   }
}

Ignore files

Files can be ignored and not copied. Do so by adding the appropriate to the ignore array. In the following example, ember-model has as dependency on ember and handlebars, so normally ember and the handlebars js files would be copied but in this case we don't want them copied over. Example:

{
   "name": "test",
   "version": "0.1",
   "dependencies": {
       "ember-model": "0.0.8"
   },
   "install": {
       "path": "build/src",
       "ignore": ["ember", "handlebars"]
   }
}

Benefits from glob patterns

You can specify a folder and get all files inside it preserving its folder structure. Example:

{
    "name": "test",
    "version": "0.1",
    "dependencies": {
        "datatables-bootstrap3": "latest"
    },
    "install": {
        "path": {
            "scss": "build/styles",
            "js": "build/js"
        },
        "sources": {
            "datatables-bootstrap3": "bower_components/datatables-bootstrap3/BS3/assets/**"
        }
    }
}

Mapping folders

Entire folders can be mapped. Example:

{
  "name": "test",
  "version": "0.10",
  "dependencies": {
    "jquery-ui": "latest"
  },
  "install": {
    "path": "build/src",
    "sources": {
      "jquery-ui": {
        "mapping": [
          {"bower_components/jquery-ui/themes/base/**": "base"},
          {"bower_components/jquery-ui/jquery-ui.min.js": "jquery-ui.min.js"}
        ]
      }
    }
  }
}

will result in

build/src/jquery/jquery.js
build/src/jquery-ui/jquery-ui.min.js
build/src/jquery-ui/base/*

where build/src/jquery-ui/base/* contains the CSS and JS for the base theme.

Excluding package name from destination folder

The package name can be excluded from the path. Example:

{
  "name": "test",
  "version": "0.10",
  "dependencies": {
    "jquery-ui": "latest"
  },
  "install": {
    "options": {
      "includePackageNameInInstallPath": false
    },
    "path": "build/src",
    "sources": {
      "jquery-ui": {
        "mapping": [
          {"bower_components/jquery-ui/themes/base/**": "base"},
          {"bower_components/jquery-ui/jquery-ui.min.js": "jquery-ui.min.js"}
        ]
      }
    }
  }
}

will result in

build/src/jquery.js
build/src/jquery-ui.min.js
build/src/base/*

where build/src/base/* contains the CSS and JS for the base theme.