Build a scaffolding quickly

Use NPM init to initialize the project, add bin configuration to package.json file, we set the scaffold script command name is tyro-cli, the actual command execution file is bin/index.js.

Create the scaffold entry file bin/index.js and add #! To the first line. /usr/bin/env node

Use NPM Login with NPM publish scaffolding

Global scaffolding installation and execution of the scaffolding instructions we defined after successful publishing

npm install -g tyro-test-cli

tyro-cli

Operation successful, scaffolding development complete! 🙂

Local development and debugging of scaffolding

Now we have successfully released a minimalist scaffold to the NPM warehouse. Later into the formal development stage, this stage of scaffolding debugging how to do? Do you need to write the code -> re-publish -> NPM -> NPM install -g -> command line to run the command? And repeat the process over and over again?

Of course not. Scaffolding can be developed and debugged locally in two ways. The scaffolding command is linked to a specific execution file, so the tyro-cli command links to bin/index.js. So the first way to run debugging locally is to run bin/index.js directly in the local package directory:

The second option is to create a command in the environment variable pointing to bin/index.js in the current local project by executing NPM link in the local scaffolding directory, rather than having to do a global installation through NPM during development. We can then run debugging from any location by executing the command Tyro -cli. After development, execute NPM unlink in the scaffold directory to delete the link file in the environment variable and cancel the association with the local scaffold warehouse.

Local subcontracted development of scaffolding

If our scaffolding needs to be subcontracted, how do we introduce other native packages into one package? For example, we now need to introduce the Tyro-cli-lib module

NPM link in tyro-cli-lib, NPM creates a package in the global node lib/node_modules directory and points to our local Tyro-cli-lib package

Just execute the NPM link Tyro-cli-lib directive in tyro-cli, but note that the package.json file in the Tyro-cli project does not automatically add a dependency on Tyro-cli-lib.

In case we forget to add tyro-cli-lib dependencies to tyro-cli before the project goes live, we need to manually add subcontracting dependencies in package.json file.

Removing local Dependencies

After the scaffolding is developed, run NPM unlink tyro-cli-lib in the tyro-cli directory to disassociate the local module. Run NPM unlink in the tyro-cli-lib directory to delete the association between the global node lib/node_modules and the local tyro-cli-lib.

The last

Writing here, the scaffolding development process has done a general introduction, and will continue to share with you the details of scaffolding development.