liftoff / 2.2.0 last updated 6 months ago created on Jan 31st 2014
Install
npm install --save liftoff
Clone
git clone git@github.com:tkellen/node-liftoff.git
dependencies
show all 15
| main |
|
extend | 2.0.1 | MIT |
|
|
flagged-respawn | 0.3.1 | MIT | |
|
|
rechoir | 0.6.2 | MIT | |
|
|
resolve | 1.1.7 | MIT | |
|
|
findup-sync | 0.3.0 | MIT |
maintainers
versions
47 total
| 2.2.0 | 6 months ago | phated |
| 2.1.0 | 10 months ago | tkellen |
| 2.0.3 | a year ago | tkellen |
| 2.0.2 | a year ago | tkellen |
| 2.0.1 | a year ago | tkellen |
| 2.0.0 | a year ago | tkellen |
| 1.0.4 | a year ago | tkellen |
| 1.0.3 | a year ago | tkellen |
| 1.0.2 | a year ago | tkellen |
| 1.0.0 | a year ago | tkellen |
| 0.13.6 | a year ago | tkellen |
| 0.13.5 | a year ago | tkellen |
| 0.13.3 | a year ago | tkellen |
| 0.13.2 | 2 years ago | tkellen |
| 0.13.1 | 2 years ago | tkellen |
| 0.13.0 | 2 years ago | tkellen |
| 0.12.1 | 2 years ago | tkellen |
| 0.12.0 | 2 years ago | tkellen |
| 0.11.3 | 2 years ago | tkellen |
| 0.11.2 | 2 years ago | tkellen |
| 0.11.1 | 2 years ago | tkellen |
| 0.11.0 | 2 years ago | tkellen |
| 0.10.0 | 2 years ago | tkellen |
| 0.9.8 | 2 years ago | tkellen |
| 0.9.7 | 2 years ago | tkellen |
| 0.9.6 | 2 years ago | tkellen |
| 0.9.5 | 2 years ago | tkellen |
| 0.9.4 | 2 years ago | tkellen |
| 0.9.3 | 2 years ago | tkellen |
| 0.9.2 | 2 years ago | tkellen |
| 0.9.1 | 2 years ago | tkellen |
| 0.9.0 | 2 years ago | tkellen |
| 0.8.7 | 2 years ago | tkellen |
| 0.8.6 | 2 years ago | tkellen |
| 0.8.5 | 2 years ago | tkellen |
| 0.8.4 | 2 years ago | tkellen |
| 0.8.3 | 2 years ago | tkellen |
| 0.8.2 | 2 years ago | tkellen |
| 0.8.1 | 2 years ago | tkellen |
| 0.8.0 | 2 years ago | tkellen |
| 0.7.0 | 2 years ago | tkellen |
| 0.6.0 | 2 years ago | tkellen |
| 0.5.0 | 2 years ago | tkellen |
| 0.4.0 | 2 years ago | tkellen |
| 0.3.0 | 2 years ago | tkellen |
| 0.2.0 | 2 years ago | tkellen |
| 0.1.0 | 2 years ago | tkellen |
readme
liftoff
Launch your command line tool with ease.
What is it?
See this blog post, check out this proof of concept, or read on.
Say you're writing a CLI tool. Let's call it hacker. You want to configure it using a Hackerfile. This is node, so you install hacker locally for each project you use it in. But, in order to get the hacker command in your PATH, you also install it globally.
Now, when you run hacker, you want to configure what it does using the Hackerfile in your current directory, and you want it to execute using the local installation of your tool. Also, it'd be nice if the hacker command was smart enough to traverse up your folders until it finds a Hackerfile—for those times when you're not in the root directory of your project. Heck, you might even want to launch hacker from a folder outside of your project by manually specifying a working directory. Liftoff manages this for you.
So, everything is working great. Now you can find your local hacker and Hackerfile with ease. Unfortunately, it turns out you've authored your Hackerfile in coffee-script, or some other JS variant. In order to support that, you have to load the compiler for it, and then register the extension for it with node. Good news, Liftoff can do that, and a whole lot more, too.
API
constructor(opts)
Create an instance of Liftoff to invoke your application.
An example utilizing all options:
opts.name
Sugar for setting processTitle, moduleName, configName automatically.
Type: String
Default: null
These are equivalent:
opts.moduleName
Sets which module your application expects to find locally when being run.
Type: String
Default: null
opts.configName
Sets the name of the configuration file Liftoff will attempt to find. Case-insensitive.
Type: String
Default: null
opts.extensions
Set extensions to include when searching for a configuration file. If an external module is needed to load a given extension (e.g. .coffee), the module name should be specified as the value for the key.
Type: Object
Default: {".js":null,".json":null}
Examples:
In this example Liftoff will look for myappfile{.js,.json,.coffee}. If a config with the extension .coffee is found, Liftoff will try to require coffee-script/require from the current working directory.
In this example, Liftoff will look for .myapp{rc}.
In this example, Liftoff will automatically attempt to load the correct module for any javascript variant supported by node-interpret (as long as it does not require a register method).
opts.v8flags
Any flag specified here will be applied to node, not your program. Useful for supporting invocations like myapp --harmony command, where --harmony should be passed to node, not your program. This functionality is implemented using flagged-respawn. To support all v8flags, see node-v8flags.
Type: Array|Function
Default: null
If this method is a function, it should take a node-style callback that yields an array of flags.
opts.processTitle
Sets what the process title will be.
Type: String
Default: null
opts.completions(type)
A method to handle bash/zsh/whatever completions.
Type: Function
Default: null
launch(opts, callback(env))
Launches your application with provided options, builds an environment, and invokes your callback, passing the calculated environment as the first argument.
Example Configuration w/ Options Parsing:
opts.cwd
Change the current working directory for this launch. Relative paths are calculated against process.cwd().
Type: String
Default: process.cwd()
Example Configuration:
Matching CLI Invocation:
opts.configPath
Don't search for a config, use the one provided. Note: Liftoff will assume the current working directory is the directory containing the config file unless an alternate location is explicitly specified using cwd.
Type: String
Default: null
Example Configuration:
Matching CLI Invocation:
Examples using cwd and configPath together:
These are functionally identical:
These can run myapp from a shared directory as though it were located in another project:
opts.require
A string or array of modules to attempt requiring from the local working directory before invoking the launch callback.
Type: String|Array
Default: null
Example Configuration:
Matching CLI Invocation:
callback(env)
A function to start your application. When invoked, this will be your instance of Liftoff. The env param will contain the following keys:
cwd: the current working directoryrequire: an array of modules that liftoff tried to pre-loadconfigNameSearch: the config files searched forconfigPath: the full path to your configuration file (if found)configBase: the base directory of your configuration file (if found)modulePath: the full path to the local module your project relies on (if found)modulePackage: the contents of the local module's package.json (if found)
events
require(name, module)
Emitted when a module is pre-loaded.
requireFail(name, err)
Emitted when a requested module cannot be preloaded.
respawn(flags, child)
Emitted when Liftoff re-spawns your process (when a nodeFlag is detected).
Event will be triggered for this command:
hacker --harmony commmand
Examples
Check out how gulp uses Liftoff.
For a bare-bones example, try the hacker project.
To try the example, do the following:
- Install the sample project
hackerwithnpm install -g hacker. - Make a
Hackerfile.jswith some arbitrary javascript it. - Install hacker next to it with
npm install hacker. - Run
hackerwhile in the same parent folder.
