Skip to content

Latest commit

 

History

History
215 lines (130 loc) · 5.05 KB

README.md

File metadata and controls

215 lines (130 loc) · 5.05 KB

Node.js - rock

Rock generates file structures or project skeletons based off of predefined templates.

Why?

Do you constantly finding yourself writing a lot of new libraries for Node.js and having to create the package.json, README, LICENSE, lib/, test/ files over and over again? Well, I did. I was getting annoyed of having to create the same file structure over and over again.

I stumbled upon a few solutions, but they all seem to do more than just generate a file structure from a template. That's all I wanted. Oh, and I wanted it to be programmatic too. So, if I wanted to build a blogging engine or another Rails clone in JS, I could leverage rock to generate the empty templates.

As it stands now, rock is written in Node.js. But the actual templates themselves could be for any language.

Installation

You will need Node.js and npm (Node.js Package Manager). This is bundled with Node.js. If you don't have npm, mozy on over to the Node.js download page. There are prebuilt binaries and installers for most platforms including Mac OS X, Windows, and Linux.

After you have installed Node.js and npm, you can install rock by running the following command:

npm install -g rock

Don't forget the -g flag. This will ensure that the rock command is available system wide.

Usage

rock [path] -r [rock]

example:

rock mylib -r node-lib

or

rock /tmp/mylib -r node-lib

Options

   --version              Print version and exit.
   -r ROCK, --rock ROCK   The rock path or Github repo.
   -c, --config           The config file. Defaults to ~/.rock/rock.conf.json
   -f, --file             If the rock is a single file. Supports http as well.  [false]
   --topen                Opening template value. Defaults to {{  [{{]
   --tclose               Closing template value. Defaults to }}  [}}]

Want to create a project from a rock hosted somewhere else? No problem:

rock myapp -r git@github.com:johndoe/myrepo.git

or use Github shorthand:

rock myapp -r johndoe/myrepo

Make Your Own Rocks

It's stupidly simple to make your own rocks. Create a Git repository on Github or an empty directory on your filesystem. Start making template files.

Example (myproject.js):

/*
   Author: {{author}} <{{email}}>
   File: {{-file}}
   Created: {{-date}}
*/

function main() {

}

Now, when you run:

rock myproj -r /path/to/my/rock/repo

Rock will prompt:

author: [YOU_TYPE_YOUR_NAME_HERE]
email: [YOU_TYPE_YOUR_EMAIL_HERE]

Rock, then will create the file structure of your new project with the values of your template tokens replaced with what you typed. Rock already understands -file, -date, and a few others.

Ignore Directories

In your rock repo, add a file .rock/rock.json. Add the following:

{
    "ignoreDirs": ["./dirToIgnore"]
}

Why would you do this? Let's say that you're calling rock programmatically and you don't want rock to prompt you for any tokens because you are going to use Mustache/Hogan/Handlebars in your own code.

Open / Close Templates

If you don't want to use the default {{ and }} and want to use something else, you can configure this behavior for your Rock in .rock/rock.json:

{
  "tokens": {
    "open": "#{",
    "close": "}"
  }
}

You may want to do this if you generate files that actually use Mustache templates.

Single File Rocks

Rock doesn't need to be used with just whole repos. It can be used with individual files as well.

Example:

http://localhost/data.txt:

Hi, @@author@@ is going to build:
@@project-name@@.

command:

rock /tmp/outputfile.txt -f --topen '@@' --tclose '@@' -r http://localhost/data.txt

prompts:

author: JP
project-name: Rock

output:

/tmp/outputfile.txt:

Hi, JP is going to build:
Rock

rock.conf.json

This file defaults to ~/.rock/rock.conf.json. You can set default values (prompt or skip).

{
  "templateValues": {
    "author": "JP Richardson"
  },
  "defaultValues": {
    "email": "jprichardson@gmail.com"
  }
}

So, if you were to run:

rock myapp -r rocktemplates/node-bin

it would not prompt you for author and it would prompt you for email but with a default of jprichardson@gmail.com.

Rocks

See more rocks at: https://github.com/rocktemplates or browse 3rd party Rocks here: https://github.com/rocktemplates/rock/wiki/rocks

Roadmap to v1.0.0

  • Will probably change configuration from JSON to TOML. TOML needs to achieve stability first.
  • Create/fork site similar to component.io

Contributors

License

(The MIT License)

Copyright (c) 2012-2013, JP Richardson