/jim

jim is your friendly javascript library manager

Primary LanguageJavaScriptMIT LicenseMIT

This fork

jim watch

The goal of the jim watch command is to spy your JS files during development. Every time you edit, create or delete a JS file, your Jimfile will be updated and your bundle will be recreated. The big advantage is that you only have to include your bundled.js file in your HTML page, you don’t have to worry about including each file separately.

When you create a new js in your project, a new entry is inserted at the bottom of your Jimfile. You’ll sometimes have to put it at the correct position by yourself (dependencies).

jim

jim is your friendly javascript library manager. He downloads, stores, bundles, vendors and compresses.

What is a jim?

I’m frustrated with a lot of copy and pasting JS files from one directory to another and downloading new versions to who knows where and only really being able to use sprockets in Rails and lots of other small annoying things about the existing JS package/asset managers.

Jim uses a lot of stolen ideas from a lot of great projects. Namely:

  • version management and flexible project fetching from rip

  • asset compression from jammit and sprockets

  • Gemfile and bundle from bundler

The goals are simple:

  • Install a file, archive, git repo, etc from a local path or a URL into a common directory stored with a specific name and version number. Because should be able to install anything from anywhere, theres no need for a central package host.

  • Specify the local and installed files required for a project by name and version number in a single place. Dependencies for each project are not managed by the system, the onus is on you to specify them in the order you want them. _The project does not have to be in Ruby or even have a backend system._

  • Run a command to bundle all the required files into a single file.

  • Run a command to bundle the files and run them through a JavaScript compressor.

So far I’ve accomplished the goals, but this is all very very very beta and the API is sure to change and thing straight-up might not work.

Install

jim is a rubygem:

$ gem install jim

You can also clone the source from github and use jeweler to install locally (requires jeweler):

$ git clone git://github.com/quirkey/jim.git
$ cd jim
$ rake install

Usage

From anywhere, install a project:

// From a URL
$ jim install http://code.jquery.com/jquery-1.4.2.js
// From a zip (with name and version)
$ jim install http://github.com/jquery/jquery-metadata/zipball/master jquery-metadata 2.0

In your project run:

$ jim init

Which creates an empty “Jimfile”. Open it up and add your requirements:

// bundled_path: public/javascripts/bundled.js
// compressed_path: public/javascripts/compressed.js
// vendor_dir: public/javascripts/vendor

jquery 1.4.2
jquery-metadata 2.0
// a local file, js/app.js (comments are fine)
js/app

If its a rack project, mount the Jim::Rack middleware which gives you live updates of your bundled and compressed js files:

use Jim::Rack, :bundled_uri => '/javascripts/bundled-live.js', 
               :compressed_uri => '/javascripts/compressed-live.js'

Otherwise and also before deploys, etc, use the command line tool from your project’s dir:

$ jim bundle 
// or
$ jim compress

In order for compress to work, you need either the yui-compressor gem or the closure-compiler gem. Closure is the default, add

Run ‘jim commands` for a full list of commands.

You’re probably wondering

Why not implement it in JavaScript itself?

CommonJS has certainly come a long way in a year, but in general the file system support and variety of libraries just isnt completely there yet for this type of project (IMHO). Also, I love Ruby and writing this was actually fun and pretty fast.

With that said, I would gladly welcome anyone cloning the API in CommonJS (I’m just being lazy about it)

Does it work with __ library or __ development platform?

Probably?? Its all very new at this point so please test it out and let me know.

Thanks

Thanks to Yehuda Katz for talking through some of the ideas with me.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches

Copyright © 2010 Aaron Quint. See LICENSE for details.