About the bin file in the npm project

recently, when I looked at the vue-cli 2.9.0 source code, I saw that some instructions were defined in the vue file under the bin file

-sharp!/usr/bin/env node

require("commander")
  .version(require("../package").version)
  .usage("<command> [options]")
  .command("init", "generate a new project from a template")
  .command("list", "list available official templates")
  .command("build", "prototype a new project")
  .parse(process.argv)

there are also vue-init, vue-list and other files in the bin folder.
I would like to ask why, after defining the init instruction in commander, you can type the vue init instruction on the command line to execute the code in vue-init. This is what kind of implementation principle, or npm did it for us.

Jul.02,2021

what you should see is here and the corresponding source code

.

description in README

The commander will try to search the executables in the directory of the entry script (like. / examples/pm) with the name program-command, like pm-install, pm-search

you just look at the place where the command is received, and of course you don't know what vue init executes.

vue-cli/blob/dev/packages/@vue/cli/bin/vue.js-sharpL127

Menu