Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make wheels that may be used in CLI

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to make CLI may use the wheel, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Before you begin, you should understand the bin usage of npm.

"bin": {

"init": "index.js"

}

Executing npm install-g installs the init command globally, and you can execute init in CMD.

After execution, since the JavaScript file is opened by VS Code by default on my machine, the effect is not to execute the code (this problem continues below, don't go away, there is a hole). As can be seen from the log printing above, Node.js actually establishes a shortcut. Init points to the index.js of the project installed into the global module, while init is added to the environment variable PATH and can be executed directly.

You can also use npm link to link index.js directly to PATH, but you need to uninstall npm uninstall-g first, otherwise a duplicate error will be reported.

Now officially start to watch the wheels, the following ranking in no particular order.

Command.js

Command.js can be used with the global commands just generated by bin. One advantage is that it still has Chinese documents. Although E is not difficult for me, Chinese is still much faster to read.

Const {program} = require ("commander")

Program

.version ("0.0.1")

.customers ("")

.description ('Login Module')

.option ("- u,-- username", "The user to authenticate as")

.option ("- p,-- password", "The user's password")

.action (function (file) {

Console.log (program.opts ())

Console.log (file)

})

.parse (process.argv)

At first, it is possible to use global commands that do not accept parameters and directly use Node.js to execute.

Later, I looked for it, and the #! / usr/bin/env node at the beginning of the main entry file was required.

#! / usr/bin/env node

Const {program} = require ("commander")

Program

.version ("0.0.1")

.customers ("")

.description ("Login Module")

.option ("- u,-- username", "The user to authenticate as")

.option ("- p,-- password", "The user's password")

.action (function (file) {

Console.log (program.opts ())

Console.log (file)

})

.parse (process.argv)

Execute it again (you may need to re-npm [un] install-g or npm [un] link), this time OK

The parameter representation in arguments is required, and if it is missing, it cannot proceed.

Parameters to define the use of required items. RequiredOption, such as program.requiredOption ('- c,-- cheese', 'pizza must have cheese');.

Commander.js also automatically generates the help command init-help for you according to the parameters.

Please refer to the official documentation for more detailed usage.

Svg-term-cli

The SVG file used by svg-term-cli to generate ASCII code animation. It requires a global installation

Npm install-g svg-term-cli

Now generate SVG motion pictures from https://asciinema.org/a/113643

Svg-term-cast 113643-out examples/parrot.svg-window-no-cursor-from=4500

After that, a parrot.svg file will be generated under examples. Open this file and have a look. It's too rough.

Progress

Progress is used to generate a waiting progress bar.

Var ProgressBar = require ("progress")

Var bar = new ProgressBar (": bar", {total: 40})

Var timer = setInterval (function () {

Bar.tick ()

If (bar.complete) {

Console.log ("\ ncomplete\ n")

ClearInterval (timer)

}

}, 1000)

Generate the following progress bar

We can use it to show our common download progress.

Ora

For uncertain progress, you can use ora. It is the kind of magic circle style of love.

Const ora = require ("ora")

Const spinner = ora ("Loading unicorns"). Start ()

SetTimeout () = > {

Spinner.color = "yellow"

Spinner.text = "Loading rainbows"

}, 1000)

SetTimeout () = > {

Spinner.fail ()

}, 3000)

The above is all the contents of the article "how to make the wheels that may be used in CLI". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report