Explained: How to publish your first scaffolding tool on NPM

Explained: How to publish your first scaffolding tool on NPM

Preface

Scaffolding tools can quickly generate a complete project structure and help developers focus on project development, which is very efficient.

The implementation principle behind the tall scaffolding tool is actually not complicated. For example, vue-cliwhich is essentially based on different operating instructions in a remote repository (for example: GitHub) to pull to the different local template.

This article will combine the author's scaffolding ( lan-cli) example to quickly tell readers how to create a scaffolding and publish it to NPMit.

Due to the length of the article, this article will not explain the project code. The specific code is stored at the GitHubproject address at the end of the article.

Technology stack

  1. nodejs: the core of the scaffolding framework;
  2. commander: process command line input;
  3. co: Asynchronous process control tool;
  4. co-prompt: Enter command line instructions step by step.

Outline

  1. Create a project;
  2. Write instructions;
  3. Configure scaffolding information;
  4. Local test
  5. Publish scaffolding.

Example explanation

1. Create a project

Create a similar project file as shown in the figure.

2. Writing instructions

lan-cliThere are four instructions in total.

  1. lan add : Add project template for scaffolding;
  2. lan list : List project templates of scaffolding;
  3. lan delete : Delete the project template of the scaffolding;
  4. lan init : Initialize the scaffolding project;
    The instruction code is in the picture file.

3. Configure scaffolding information

package.jsonConfigure the scaffolding information in the file as shown in the figure .

4. Local test

bin/lanIt is the entry file of the scaffold, and the package.jsonfollowing code is configured in it.

"bin": {
        "lan": "bin/lan"
    }
 

After configuring the entry file, enter the command line in the root directory npm link, you can lanbind the command to the global, and use it directly to test whether the scaffolding work can run normally.

5. Release scaffolding

After completing the scaffolding, we can publish to NPMit.

1. you need to register an account on npm ( www.npmjs.com/ ), the registration process is omitted.

Then execute the login command in the terminal, enter the user name, password, and email to log in.

npm login
 

After logging in successfully, enter the command to publish the component.

npm publish
 

After the release is successful, there will usually be a notification email sent to you by npm, enter the npm official, log in to your account, and check the component library just released.

project address

The project Githubaddress of this article : github.com/jiangjiahen ....

Concluding remarks

The above is the entire content of this article. Thank you for reading. Some of the technical points in the article are limited by the length of the article and have not been explained. If you have any questions or suggestions, please feel free to leave a message and discuss with each other.

Finally, I wish my work success and a happy life.