# kyle-cli-dev **Repository Path**: kyel/kyle-cli-dev ## Basic Information - **Project Name**: kyle-cli-dev - **Description**: 脚手架开发仓库 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-09 - **Last Updated**: 2024-11-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 初始化项目仓库 git init kyle-cli-dev && cd kyle-cli-dev ### 创建项目 npm init -y ### 安装 lerna 工具到开发环境(推荐全局安装 -g) yarn add lerna -D ### lerna 初始化 lerna init(lerna 包 packages 下的模块,不需要提交,加入.gitignore。`packages/**/node_modules`) ### 创建 lerna package 包 [--文档][https://github.com/lerna/lerna/tree/main/commands/create#readme] lerna create [loc] - 创建 core 包 ```shell lerna create core //创建 @kyle-cli-dev/core //重命名( 分组:`kyle-cli-dev`,项目:`core` ) ``` ```shell lerna notice cli v4.0.0 lerna WARN ENOREMOTE No git remote found, skipping repository property package name: (core) @kyle-cli-dev/core version: (1.0.0) description: kyle-cli-dev core keywords: homepage: license: (ISC) entry point: (lib/core.js) git repository: ``` - 创建 utils 包 ```shell lerna create utils @kyle-cli-dev/utils ``` ### 使用 lerna 安装依赖 - lerna add axios //安装到所有 packages 包里面的依赖 - lerna clean //删除所有的 packages 包里面的依赖 (删除后需要手动删除 package.json 中的依赖配置文件) ```shell lerna `WARN` No packages found where @imooc-cli/utils can be added. `报错处理` 删除后需要手动删除 package.json 中的依赖配置文件 ``` - lerna add axios packages/core/ //安装到指定文件 - lerna add -h //查看帮助文档(文档中有:示例) - lerna bootstrap //安装 package.json 中的依赖 - lerna link //自动帮我们软连接本地的 package 包依赖 [yarn link 与 npm link 使用及原理][https://juejin.cn/post/6844904164468768776] ```shell 包A:`npm/yarn link` --意思是在公共包管理路径/usr/local/lib/node_modules/连接了本地的 `包A` 包B:`npm/yarn link 包A` --它就会去/usr/local/lib/node_modules/这个路径下寻找是否有这个包,如果有就建立软链。 不想使用 `包A` 时可以执行 `npm unlink 包A` 解除连接。 (在使用时需要在dependencies里面添加版本号`^1.0.6`;推荐使用真实地址`file:../../包A/包A`) ``` - lerna exec - lerna run test //运行所有 packages 项目的 scripts 脚本 test - --scope 指定 package 包 - lerna run --scope @kyle-cli-dev/utils test //运行指定 packages 项目的 scripts 脚本 test - lerna version //发布前,确认版本号 ```shell lerna notice cli v4.0.0 lerna info current version 1.0.0 lerna ERR! ENOREMOTEBRANCH Branch 'master' doesn't exist in remote 'origin'. 没有关联远程分支 lerna ERR! ENOREMOTEBRANCH If this is a new branch, please make sure you push it to the remote first. ``` - lerna changed //查看有哪些 package 项目会被发布 - lerna diff //查看有哪些 package 做了变更 ```shell git add . git commit -m "init" ``` - 添加 gitee 仓库地址 && 设置快速发布 master 分支 && 发布分支 ```shell PS F:\kyle-cli-dev> `git remote add origin git@gitee.com:kyel/kyle-cli-dev.git` PS F:\kyle-cli-dev> `git remote -v` origin git@gitee.com:kyel/kyle-cli-dev.git (fetch) origin git@gitee.com:kyel/kyle-cli-dev.git (push) PS F:\kyle-cli-dev> `git push` fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use PS F:\kyle-cli-dev> `git push --set-upstream origin master` PS F:\kyle-cli-dev> `git push` ``` - lerna version 配置版本号 > 发布一个补丁 ``` lerna info Assuming all packages changed ? Select a new version (currently 1.0.0) (Use arrow keys) > Patch (1.0.1) Minor (1.1.0) Major (2.0.0) Prepatch (1.0.1-alpha.0) Preminor (1.1.0-alpha.0) Premajor (2.0.0-alpha.0) Custom Prerelease Custom Version ``` - 是否创建版本号 > 当前还没有发布 1.0.1 版本,所以选择创建版本号 ``` Changes: - @kyle-cli-dev/core: 1.0.0 => 1.0.1 - @kyle-cli-dev/utils: 1.0.0 => 1.0.1 ? Are you sure you want to create these versions? (ynH) n ``` - lerna publish 发布 > 选择 `Patch (1.0.1)` > 选择 `Y` - git checkout -- lerna-debug.log 减去追踪文件 lerna-debug.log > 减去之前 ``` $ git status Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: .gitignore modified: lerna-debug.log modified: readme.md ``` > 减去之后 ``` $ git status Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: .gitignore modified: readme.md ``` ``` git add . git commit -m "edit .gitignore" git push ``` - 接着发布 lerna publish ``` 错误信息: One way to fix this is to add a LICENSE.md file to the root of this repository. 需要添加一个 LICENSE.md 文件 并可以吧版本号 更改为1.0.0 重新发布 ``` ``` 错误信息: You must sign up for private packages 由于使用 group `@kyle-cli-dev` 分组的形式发布,默认为private 私有的 ``` - packages 的项目都添加 public 配置描述 [_参考自_][https://www.yuque.com/iyum9i/uur0qi/iyg4fz] ``` "publishConfig": { "access": "public" } ``` ``` 错误信息: lerna fatal: tag 'v1.0.2' already exists 版本号 已经存在,需要查看gitee仓库中的版本号 +1然后再次 提交 发布 原因:lerna 在publish 之后会在仓库中 +1 版本号 ``` > 两个包都发布完成 > npm 搜索 @kyle-cli-dev/core @kyle-cli-dev/utils 可以看到 - 使用 lerna 指定目录安装 npmlog ``` lerna add npmlog utils/log/ ```