目录
editorconfig
同一个项目,在不同的编辑器编写代码,格式风格统一的文件
root = true
# 匹配所有
[*]
# tab 或者 space 使用缩进的方式 空格缩进
indent_style = space
# 定义缩进的字数
indent_size = 2
# 换行字符的格式 有 lf cr 和 crlf
end_of_line = lf
# 设置字符的转码格式
charset = utf-8
# 开启之后会删除换行之前多余的空格符
trim_trailing_whitespace = true
# 开启后结尾会自动空一行
insert_final_newline = true
# 匹配.md
[*.md]
trim_trailing_whitespace = false
gitattributes
* text=auto
文件的行尾序列自动转换 ( CRLF or LF )
文件入Git库时,行尾自动转换为LF
如果Git 库文件有对应的行尾序列,入库时会自动转为相匹配的行尾序列
package.json的字段分析
name
库的名字。发布到 NPM 的需要独一无二的名字 名字开头有限制:不以大写字母、斜划线或者点开头
"name": "cac",
version
库的版本。 默认是最新的 名称和版本一起构成唯一的标识符,相当于ID
如果不发布 名称和版本字段是可选的
- 版本号
有三个段位
兼容版本:功能更新次版本:bug修复的版本
比如 1.2.3
兼容版本是1
功能更新版本是2
bug修复版本是3
- 版本的符号
^ 是限定版本
比如^1.2.3
1.2.3 ≥ 区间 <2.0.0
比如^0.2.3
0.2.3≥ 区间 < 0.3.0
~ 表示次版本 不管第一个数字,只管第二个数
比如~1.2.3
1.2.3 ≥ 区间 <1.3.0
比如~1.0.0 没有次版本号了
1.0.0≥ 区间 < 2.0.0
"version": "6.0.0",
description
对库的描述。它是一个字符串。会被NPM搜索引擎查询到,这可以帮助人们发现你的包
"description": "Simple yet powerful framework for building command-line apps.",
repository
NPM包托管的地方,想要贡献的人可以留意一下
"repository": {
"url": "egoist/cac",
"type": "git"
},
files
里面填写的字段,是需要发布的NPM 的文件名 字符串数组结构
main & module
main 指定NPM包的入口文件
在不同环境下使用NPM 包的时候 (也就是import NPM 包里的方法) 指定的入口文件
module
当web端 和服务端 不同环境下加载入口的时候 main满足不了,需要module来区分不同的环境
衍生出来了 module 与 browser 字段
有两种模块规范
ESM 和 commonJS 两种
当存在 index.mjs 和 index.js这种同名不同后缀的文件时,优先级 ** >**
"main": "index-compat.js",
"module": "dist/index.mjs",
license
许可证。了解 NPM 包使用的方式
author
NPM 包的作者
engines
指定这个 NPM 包使用的node 版本 如果不指定,表示任何版本下都能运行
scripts
能够运行的文件
devDependencies
开发的时候需要的依赖
config
一些配置文件
exports
设置 package 的导出
发包基本需要的字段
name、version、description、repository、files、license、author、engines
README ?
一般的结构
- 项目简介
- 功能特性
- 目录结构描述
- 环境的依赖
- 部署的步骤
- 参考或声明
- 协议
快速生成README的库
或者window系统: shift 右键文件 打开命令行 写入 tree
|-- cac
|-- .editorconfig
|-- .gitattributes
|-- .gitignore
|-- .prettierrc
|-- circle.yml
|-- index-compat.js
|-- jest.config.js
|-- LICENSE
|-- mod.js
|-- mod.ts
|-- mod_test.ts
|-- package.json
|-- README.md
|-- rollup.config.js
|-- tsconfig.json
|-- yarn.lock
|-- .github
| |-- FUNDING.yml
| |-- ISSUE_TEMPLATE.md
|-- examples
| |-- basic-usage.js
| |-- command-examples.js
| |-- command-options.js
| |-- dot-nested-options.js
| |-- help.js
| |-- ignore-default-value.js
| |-- negated-option.js
| |-- sub-command.js
| |-- variadic-arguments.js
| |-- cac
| |-- .editorconfig
| |-- .gitattributes
| |-- .gitignore
| |-- .prettierrc
| |-- circle.yml
| |-- index-compat.js
| |-- jest.config.js
| |-- LICENSE
| |-- mod.js
| |-- mod.ts
| |-- mod_test.ts
| |-- package.json
| |-- README.md
| |-- rollup.config.js
| |-- tsconfig.json
| |-- yarn.lock
| |-- .github
| | |-- FUNDING.yml
| | |-- ISSUE_TEMPLATE.md
| |-- examples
| | |-- basic-usage.js
| | |-- command-examples.js
| | |-- command-options.js
| | |-- dot-nested-options.js
| | |-- help.js
| | |-- ignore-default-value.js
| | |-- negated-option.js
| | |-- sub-command.js
| | |-- variadic-arguments.js
| |-- scripts
| | |-- build-deno.ts
| |-- src
| |-- CAC.ts
| |-- Command.ts
| |-- deno.ts
| |-- index.ts
| |-- node.ts
| |-- Option.ts
| |-- utils.ts
| |-- __test__
| |-- index.test.ts
| |-- __snapshots__
| |-- index.test.ts.snap
|-- scripts
| |-- build-deno.ts
|-- src
|-- CAC.ts
|-- Command.ts
|-- deno.ts
|-- index.ts
|-- node.ts
|-- Option.ts
|-- utils.ts
|-- __test__
|-- index.test.ts
|-- __snapshots__
|-- index.test.ts.snap