N
N
Nikita2018-02-21 21:52:10
Node.js
Nikita, 2018-02-21 21:52:10

How to make your own command line installer for npm package?

Good day!
I was interested in one thing, how do installers for packages like react-create-app or vue-cli.
I didn’t really find any information, there is also little information in the source codes, although most likely I just don’t know where to look.
I googled, but didn't really find anything.
Tell me where to dig

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-02-22
@bingo347

vue-cli, and specifically the vue init command works extremely simply:
1. downloads the template from github (maybe it can from any git repository, did not check it, there is bitbucket in the dock) to / tmp
2. requests the meta.json or mata file from it .js and gets parameters from it
3. polls the user according to the received parameters and fills in the variables for the template engine
4. creates a project folder
5. runs each file from the template folder in the template through a text template engine (like handlebars) and saves the result in the project folder
6. deletes the template and other temporary files
by npm: There is such thing as pre and post hooks that can be set for almost any built-in npm command in the scripts section of package.json, such as preinstall (runs before npm install) or postinstall (after npm install)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question