Skip to content

Instantly share code, notes, and snippets.

@destinio
Last active December 10, 2021 18:47
Show Gist options
  • Save destinio/cd15ce44968aa4404c9bd8a99fc40b74 to your computer and use it in GitHub Desktop.
Save destinio/cd15ce44968aa4404c9bd8a99fc40b74 to your computer and use it in GitHub Desktop.
Some useful CLI snippets
// CHALK - coloring out put
import chalk from 'chalk'
console.log(chalk.redBright('Hello from chalk'))
// YARGS - parse argv
import yargs from 'yargs-parser'
const argv = yargs(process.argv.slice(2))
console.log(argv)
// EXECA - execute commands
import { execa } from 'execa'
execa('echo', ['hello']).then(m => console.log(m.stdout))
// ORA - spinners
import ora from 'ora'
function loading(title: string, list: string) {
const spinner = ora(`Loading ${title} from ${list}`)
spinner.color = 'yellow'
spinner.start()
setTimeout(() => {
spinner.succeed()
}, 3000)
}
// INQUIRER - prompts all the prompts
import inquirer from 'inquirer'
inquirer
.prompt([
{
type: 'list',
name: 'list',
choices: ['one', 'two', 'there'],
},
{
type: 'input',
name: 'title',
message: 'title',
},
])
.then(({ list, title }: { list: string; title: string }) => {
// ORA see above
loading(title, list)
})
{
"name": "yags",
"main": "index.js",
"type": "module",
"dependencies": {
"chalk": "^5.0.0",
"execa": "^6.0.0",
"inquirer": "^8.2.0",
"ora": "^6.0.1",
"yargs-parser": "^21.0.0"
},
"devDependencies": {
"@types/inquirer": "^8.1.3",
"@types/node": "^16.11.12",
"@types/yargs-parser": "^20.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment