NPM mono repository
以下所有命令行操作都在 git-bash
窗口中执行
安装全局依赖
npm i -g c8 lerna rollup tsx
创建新项目
克隆新项目仓库
git clone git@git.foo.com:<group>/<project> && cd <project>
# 比如
git clone git@git.foo.com:foo/uc && cd uc
初始化仓库
# GitLab
git archive --remote=git@github.com:waitingsong/npm-mono-base.git HEAD package.json | tar -x > package.json
# GitHub
curl -kL https://github.com.cnpmjs.org/waitingsong/npm-mono-base/raw/main/package.json > package.json
git add package.json
git commit -m "chore: initialize"
npm run bp:add
git fetch bp -v && git merge bp/main --allow-unrelated-histories -m "Merge remote-tracking branch 'bp/main'"
# 使用目录名作为项目名
sh init-project.sh
# 或者指定项目名
sh init-project.sh @foo/my_project
# 初始化依赖
npm install
根据模板选择初始化子包
创建目录
npm run add:pkg my_pkg
更新项目配置
- 更新仓库顶级
package.json
文件description
等字段 - 修改新建各子包配置文件
package.json
- 更新本文档 Packages 表格的子包信息
Packages
Package | Version | Dependencies | DevDependencies |
---|---|---|---|
demo |
[![main-d-svg]][main-d-link] | [![main-dd-svg]][main-dd-link] | |
demo-cli |
[![cli-d-svg]][cli-d-link] | [![cli-dd-svg]][cli-dd-link] |
Initialize and install dependencies
run it at first time and any time
npm run repo:init
Compile
Run under root folder
npm run build
# specify scope
npm run build @scope/demo-docs
# specify scopes
npm run build @scope/demo-docs @scope/demo-serivce
Update package
npm run bootstrap
Add package
npm run add:pkg new_module
Test
- Use
npm run lint
to check code style. - Use
npm run test
to run unit test.
Clan or Purge
# clean build dist, cache and build
npm run clean
# clean and remove all node_modules
npm run purge
Note
- Run
npm run clean
beforenpm run build
, if any file under typescript outDir folder was deleted manually. - Default publish registry is
NPM
, configurated in filelerna.json
- Any commands above (such as
npm run build
) running inGit-Bash
under Windows OS