以 markdown-clear ,建立过程为例,讲解整个NPM包建立和发布流程node
在GitHub上新建一个仓库,其名markdown-clear
git
clone
这个工程到本地es6
LICENCE
或LICENSE
文件, 说明对应的开源协议到SPDX License List 或者Open Source Initiative,下载相应协议的模板,咱们这里选用MITgithub
修改必要的协议时间和做者typescript
MIT License Copyright (c) <year> <copyright holders> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README
或者ReadMe.md
或者README.md
文件说明项目的一些信息npm
给出详细参考资料的连接json
给读者一个总体的导航内容api
.gitignore
文件,忽略不须要提交的文件变动能够去github gitignore 下载一个最相近的模板而后改改babel
能够去gitignore.io生成一个,而后把内容拿下了markdown
能够参考gitignore.io 文档,本身配命令行工具,以便随时能够玩
咱们这里生成了一个Node + IntellJ-all 的结果
内容语法参考gitignore doc
使用npm init
初始化工程
按照提示填入相应的内容
工程三大件以及npm包配置文件都有了
markdown-clear ------------- .gitignore ------------- LICENCE ------------- README.md ------------- package.json
跨编辑器的编辑器设置,网站挂了,EditorConfig
新一代JavaScript代码质量检测工具ESLint
markdown-clear -------------- src // 源代码目录 好比coffee,typescript,es6+等代码的目录 -------------- lib // 转义生成的代码目录,好比babel转义后的es5代码的目录 -------------- docs // 代码相关的设计和使用文档 -------------- tests // 相关的测试目录
写代码 src 目录
转换后的代码 lib 目录
babel 配置文件 .babelrc
{ "presets":["es2015","stage-0"] }
添加 npm 命令
"scripts": { "build": "babel src -d lib", }
添加package.json
的配置
"bin": { "markdown-clear": "./lib/cli.js" }
cli.js
文件第一行添加
#!/usr/bin/env node
写测试用例 tests 目录
调用最终生成的 lib 下面的目录
能够考虑使用测试框架 mocha, jasmine, karma...
使用npm 安装本地文件 做为本地包
npm install path/to/markdown-clear
使用npm 安装本地文件 做为全局包
npm install path/to/markdown-clear -g
写文档 docs 目录
写代码相关的设计和使用文档,没有天然能够不用写
这里的文档应该在README.md 中会有入口。
若是没有注册npm帐户
npm adduser USERNAME
若是没有登陆
npm login
登陆后发布包,在工程目录下执行
npm publish