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
nodejs: the core of the scaffolding framework;
commander: process command line input;
co: Asynchronous process control tool;
co-prompt: Enter command line instructions step by step.
Outline
Create a project;
Write instructions;
Configure scaffolding information;
Local test
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.
lan add : Add project template for scaffolding;
lan list : List project templates of scaffolding;
lan delete : Delete the project template of the scaffolding;
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.
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.
https://juejin.cn/post/6844904019979141133 Detailed explanation: How to publish your first scaffolding tool on NPM