Giter VIP home page Giter VIP logo

cli-cheatsheet's Introduction

this list is now archived - look inside https://github.com/sw-yx/brain if you would like an updated list! thank you.

cli-cheatsheet

helpful libraries and resources for building Node.js CLIs. Not a list of CLIs.

I put together a 90 minute Egghead.io Course and Workshop on how to put these tools together, if you like video learning. I also make some money if you watch those videos if you want to help :)

CLI Design Thinking

  • 12 Factor CLI Apps (Blogpost, Talk): Jeff Dickey's list of requirements for UX.

  • Heroku CLI Style Guide (Guide, Talk, Talk): Heroku's CLI Style Guide.

  • CLI Guidelines (Guide, Source): An open-source guide to help you write better command-line programs, taking traditional UNIX principles and updating them for the modern day.

  • The Poetics of CLI Command Names: Command naming anti-patterns and excellent names

  • CLI State Machines (Gist): My little thoughts on state management

  • Add a dry run mode for expensive commands like gatsby dry-run

  • The Art of Command Line

Frameworks

  • Commander: Built by TJ, used in create-react-app, vue-cli, and many others. Key feature: pluggability. Vorpal is another framework inspired by Commander and is seeking maintainers
  • Oclif: Built by Heroku, used in Heroku and Salesforce CLI's. Key feature: pluggability.
  • Sade: Built by lukeed, used in tsdx. Key feature: lightweight?
  • Gluegun: Built by Infinite Red, used in Ignite and AWS Amplify. Key feature: templating/filesystem
  • Ink: Built by Vadim & Sindre. Key Feature: React Components and Yoga Layout. See also import-jsx
  • Scritch: Built by Jamie, used at Eventbrite. Key Feature: compose multiple scripts regardless of language into one CLI.
  • Yargs: Built by bcoe, used by webpack-cli, mocha, react-native, nyc, and 14,343 other modules.
  • arg: Built by Vercel, used by vercel, ncc, micro, serve, and many others. Key Feature: tiny
  • cac: Built by Egoist, used by create-nuxt-app and many others.
  • Pastel for React-ink - used in Twilio https://www.twilio.com/blog/building-conference-cli-in-react

New: see CLUI https://blog.repl.it/clui

Inspiration from other languages - the http://charm.sh/ universe.

Utility Libraries

Performance Optimization

For performance logging, you can try process.htime() instead of console.time() (altho the latter uses the former under the hood)

Update Management/Nagging

Context/Config

Context from Git/CI

Context from filesystem/PATH

Config validation

Loading config from json, rc file, etc*

don't need but nice to know: https://www.npmjs.com/package/read-package-json

Beware the race condition when you check if file exists and then open it. the file could be deleted in betwee. instead, just open the file and handle the error if it doesnt exist.

Loading/Storing config from a persistent store

⚠️ Be aware of the XDG spec. Sindre's libraries use env-paths to get paths compliant with this.

🌟Input

Stdin Parsing

Argument Parsing

⚠️ Your framework may come with parsing built in

Input/Stdin/Argument Processing

make sure to also normalize inputted stuff before you compare

🌟Processing

Command execution

Remember Windows users for cross-platform nodejs (Guide). e.g. dont execute pkg.json or shell commands with single quotes instead of escaped double quotes

Sometimes processes can spawn processes. This is troublesome for watch/reload features. Kill them all with tree-kill.

You'll probably also use these in conjunction with port monitors (e.g. the process you're working with opens a port, like CRA for Netlify Dev):

If child_processes are going to be a key part of your CLI, be sure to read the docs and this guide to be aware of the API.

You may also want to poll for conditions to be true to execute async processes:

Spinners/Loaders

Templating

Temp folders

🌟Output

Files

Icons & Coloring

Note that you may want to offer the option to FORCE_COLOR in CI logging.

PrettyPrinting

there are also react based renderers

Boxing

Tables

Banners

Debug Logging

You often also find specialized logger tools for each domain, like @dazn/lambda-powertools-logger for AWS Lambda, but at their core they all support the core pattern of Log Levels DEBUG, INFO, WARN and ERROR.

Plugin/Release Management

⚠️ None of these are offline-first. Keen on finding one that respects offline first.

Dependency installs and Upgrading Scaffolds

import { spawn, hasYarn } from 'yarn-or-npm'
// optionalDir for installing?
const prefixFlag = hasYarn() ? '--cwd' : '--prefix'
spawn.sync(['install', prefixFlag, optionalDir], { stdio: 'inherit' })

Error Stacks/Error Handling

Serving Files

Misc

New: see CLUI https://blog.repl.it/clui

Other useful lists

Beginner Tutorials

cli-cheatsheet's People

Contributors

aghassi avatar anubhavsrivastava avatar bnb avatar dominikwilkowski avatar jamesgeorge007 avatar jeroenouw avatar jsjoeio avatar m0nica avatar styfle avatar swyxio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cli-cheatsheet's Issues

Where would those projects fit?

Hey there,

I started working on those two a while ago:

If I would know where they would fit into your TOC I would be happy to file a PR, but I'm just not sure.

By the way would you also accept a PR that actually adds an easily maintainable TOC to your README? 😉

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.