Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Liftoff is a lightweight CLI framework that helps you build command-line tools. It provides a way to bootstrap your CLI application with support for configuration files, environment variables, and plugins.
Command-line Interface Bootstrapping
This feature allows you to bootstrap a CLI application with Liftoff. The code sample demonstrates how to create a new Liftoff instance and launch it, printing the environment information.
const Liftoff = require('liftoff');
const MyApp = new Liftoff({
name: 'myapp',
moduleName: 'myapp',
configName: 'myappfile',
extensions: {
'.js': null
}
});
MyApp.launch({}, (env) => {
console.log('MyApp is running!');
console.log('Environment:', env);
});
Configuration File Support
Liftoff supports loading configuration files. The code sample shows how to load a configuration file if it exists and print its contents.
const Liftoff = require('liftoff');
const MyApp = new Liftoff({
name: 'myapp',
configName: 'myappfile',
extensions: {
'.js': null
}
});
MyApp.launch({}, (env) => {
if (env.configPath) {
const config = require(env.configPath);
console.log('Loaded config:', config);
} else {
console.log('No config file found.');
}
});
Environment Variable Support
Liftoff can access and utilize environment variables. The code sample demonstrates how to print all environment variables when the CLI application is launched.
const Liftoff = require('liftoff');
const MyApp = new Liftoff({
name: 'myapp',
configName: 'myappfile',
extensions: {
'.js': null
}
});
MyApp.launch({}, (env) => {
console.log('Environment Variables:', process.env);
});
Commander is a popular package for building command-line interfaces. It provides a simple and flexible way to define commands, options, and arguments. Compared to Liftoff, Commander focuses more on command parsing and less on configuration and environment management.
Yargs is another powerful library for building CLI applications. It offers extensive features for parsing arguments, generating help messages, and handling commands. Yargs provides more built-in utilities for argument parsing compared to Liftoff, which focuses on bootstrapping and configuration.
Oclif is a framework for building command-line tools, developed by Heroku. It provides a robust structure for creating complex CLI applications with plugins and command management. Oclif is more opinionated and feature-rich compared to Liftoff, which is more lightweight and flexible.
Launch your command line tool with ease.
See this blog post, 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 too.
Create an instance of Liftoff to invoke your application.
An example utilizing all options:
var Hacker = new Liftoff({
name: 'hacker',
moduleName: 'hacker',
configName: 'hackerfile',
extensions: {
'.js': null,
'.json': null,
'.coffee': 'coffee-script/require'
},
processTitle: 'hacker',
cwdFlag: 'cwd',
configPathFlag: 'hackerfile',
preloadFlag: 'require',
completionFlag: 'completion',
completions: function (type) {
console.log('Completions not implemented.');
}
});
Sugar for setting processTitle
, moduleName
, configName
& configPathFlag
automatically.
Type: String
Default: null
These are equivalent:
new Liftoff({
processTitle: 'hacker',
moduleName: 'hacker',
configName: 'hackerfile',
configPathFlag: 'hackerfile'
});
new Liftoff({name:'hacker'});
Sets which module your application expects to find locally when being run.
Type: String
Default: null
Sets the name of the configuration file Liftoff will attempt to find. Case-insensitive.
Type: String
Default: null
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}
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 cwd before calling launch
.
var MyApp = new Liftoff({
name: 'myapp'
extensions: {
".js": null,
".json": null,
".coffee": "coffee-script/require"
}
});
In this example, Liftoff will look for .myapp{rc}
.
var MyApp = new Liftoff({
name: 'myapp',
configName: '.myapp',
extensions: {
"rc": null
}
});
In this example, Liftoff will automatically attempt to load the correct module for any extension supported by node-interpret (as long as it does not require a register method).
var MyApp = new Liftoff({
name: 'myapp',
extensions: require('interpret').extensions
});
Sets what the process title will be.
Type: String
Default: null
Sets what flag to use for altering the current working directory. For example, myapp --cwd ../
would invoke your application as though you'd called it from the parent of your current directory.
Type: String
Default: cwd
Sets what flag to use for defining the path to your configfile. For example, myapp --myappfile /var/www/project/Myappfile.js
would explicitly specify the location of your config file. Note: Liftoff will assume the current working directory is the directory containing the config file unless an alternate location is specified using cwdFlag
.
Type: String
Default: same as configName
These are functionally identical:
myapp --myappfile /var/www/project/Myappfile.js
myapp --cwd /var/www/project
These will run myapp from a shared directory as though it were located in another project:
myapp --myappfile /Users/name/Myappfile.js --cwd /var/www/project1
myapp --myappfile /Users/name/Myappfile.js --cwd /var/www/project2
Sets what flag to use for pre-loading modules. For example, myapp --require coffee-script
would require a local version of coffee-script (if available) before attempting to find your configuration file. If your required module registers a new
require.extension, it will be included as an option when looking for a file matching configName
.
Type: String
Default: "require"
A method to handle bash/zsh/whatever completions.
Type: Function
Default: null
Emitted when a module is pre-loaded.
var Hacker = new Liftoff({name:'hacker'});
Hacker.on('require', function (name, module) {
console.log('Requiring external module: '+name+'...');
// automatically register coffee-script extensions
if (name === 'coffee-script') {
module.register();
}
});
Emitted when a requested module cannot be preloaded.
var Hacker = new Liftoff({name:'hacker'});
Hacker.on('requireFail', function (name, err) {
console.log('Unable to load:', name, err);
});
A function to start your application. When invoked, this
will be your instance of Liftoff. The env
param will contain the following keys:
argv
: cli arguments, as parsed by minimist, or as passed in manually.cwd
: the current working directorypreload
: an array of modules that liftoff tried to pre-loadconfigNameRegex
: the regular expression used to find your config fileconfigPath
: 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)Manually specify command line arguments. Useful for invoking the CLI programmatically.
Type: Object
Default: null
Check out the hacker project to see a working example of this tool.
To try the example, do the following:
hacker
with npm install -g hacker
.Hackerfile.js
with some arbitrary javascript it.npm install hacker
.hacker
while in the same parent folder.FAQs
Launch your command line tool with ease.
The npm package liftoff receives a total of 1,483,771 weekly downloads. As such, liftoff popularity was classified as popular.
We found that liftoff demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.