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

easy-oclif-cli

v1.1.19

Published

![easy](images/easy-oclif-cli-logo.png) build a professional cli easily! powered by oclif and ns-flip.

Downloads

69

Readme

easy build a professional cli easily! powered by oclif and ns-flip.

Why

The combination of the power of oclif with the simple updates of ns-flip is amazing. You create a cli instantly and when necessary you can update the template without affecting your custom changes.

How

Here's a 1-minute video:

Introducing easy-oclif-cli

Follow the steps below.

(1) Create a Starter CLI

Define $CODE_DIR as the path to your desired directory for your cli. Then run

npx easy-oclif-cli $CODE_DIR

and answer the interactive questions.

Then you can run it with the starter cli:

cd $CODE_DIR
npm install
npm link

Call the name of your cli (or whatever you put for the command bin name when you built it).

(2) Update the Commands

Call

npx ns-flip settings $CODE_DIR

and follow the prompts.

You will be prompted to regenerate your code after you make changes. You can also call that separately:

npx ns-flip generate $CODE_DIR

After you have generated updates to your commands, you can run the prepack command built into oclif to regenerate the commands descriptions in your README:

cd $CODE_DIR
npm run prepack

(3) Change the Custom Code

Of course, you still have to create your code. You should be able to do just about anything possible in Node using Typescript. But, follow the safe custom code practices of ns-flip to be able to reapply this template in the future without losing anything.

Basically here's what is recommended:

  • Find the code for any command in the src/commands/<commandName>.ts file. Modify the code inside of the designated run and customImports areas.
  • Add any files or directories you like in the src/custom directory.
  • You will have to modify the test code also at test/commands/command.test.ts. You can also add anything you want into test/custom.

(4) Updating Your Template

Take a minute and set up alerts about releases to this template.

  1. Go to the GitHub repo and click the arrow by the Watch button on the upper right.
  1. Choose "Custom", and then select "Releases".

Before you update your template, make sure to check your code for safety by calling: npx ns-flip check $CODE_DIR To reapply the template with a newly released version, just the first command again. Make sure to use he same path for the legacy $CODE_DIR.

npx ns-flip settings $CODE_DIR

All of the settings and custom changes in the $CODE_DIR cli will be retained if you followed the safe custom code practices of ns-flip.

Alternatives

The classic generator for creating an oclif cli is oclif. Both that package and this one use the same core packages, including @oclif/command and @oclif/config. Theirs offers more alternatives (e.g. yarn and js). So if you want to use js rather than ts (although they discourage the practice), you can do so with that package. On the debit side, you can't update your template and regenerate your code without replacing your legacy changes. Also, sadly they do not seem to be maintaining it much.

The classic node package for CLI creation is Commander. Commander is not a generator--it is a package you can include when you build a cli from scratch. If you are interested, you can find some Yeoman generators based on it--none seem to have taken off. Let us know if one works well for you. Also, if someone wants to build a ns-flip generator for Commander, please let us know.

But, the best alternatives to easy-oflif-cli have not been created yet. Let us know what you'd like to see--it's easy to create ns-flip templates! :smiley:

Help

Post on the ns-flip Community.

See Also