├── .env-example ├── .gitignore ├── CHANGELOG.md ├── LICENCE ├── README.md ├── commitlint.config.js ├── docs ├── Commands.md ├── Documents.md ├── assets │ ├── css │ ├── der.png │ ├── dergo.png │ ├── derinit.png │ ├── dist.js.下载 │ ├── favicon.ico │ ├── icon-linux.svg │ ├── icon-mac.svg │ ├── icon-windows.svg │ ├── logo-der.png │ ├── square-pattern.png │ └── style.css ├── index.html └── learn-der-cli │ ├── der-cli 架构图.xmind │ ├── der-cli执行流程.xmind │ ├── der-cli架构方案.md │ ├── imgs │ ├── der-cli架构图.png │ ├── gitflow-finish.png │ ├── gitflow-init.png │ ├── gitflow-prepare.png │ └── gitflow-todo.png │ └── 项目发布架构设计图.xmind ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── commands │ ├── add │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── add.test.js │ │ ├── lib │ │ │ └── index.js │ │ └── package.json │ ├── cache │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── cache.test.js │ │ ├── lib │ │ │ ├── const.js │ │ │ ├── error.js │ │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock │ ├── clean │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── clean.test.js │ │ ├── lib │ │ │ ├── const.js │ │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock │ ├── go │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── publish.test.js │ │ ├── lib │ │ │ ├── error.js │ │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── yarn-error.log │ │ └── yarn.lock │ ├── init │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── init.test.js │ │ ├── lib │ │ │ ├── const.js │ │ │ ├── error.js │ │ │ ├── getProjectTemplate.js │ │ │ └── index.js │ │ ├── package.json │ │ ├── yarn-error.log │ │ └── yarn.lock │ └── tpl │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ └── tpl.test.js │ │ ├── lib │ │ ├── error.js │ │ ├── getProjectTemplate.js │ │ └── index.js │ │ ├── package.json │ │ └── yarn.lock ├── core │ ├── cli │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── core.test.js │ │ ├── bin │ │ │ └── index.js │ │ ├── lib │ │ │ ├── const.js │ │ │ ├── error.js │ │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock │ └── exec │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ └── exec.test.js │ │ ├── lib │ │ ├── const.js │ │ └── index.js │ │ ├── package-lock.json │ │ └── package.json ├── models │ ├── command │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ │ └── Command.test.js │ │ ├── lib │ │ │ ├── const.js │ │ │ ├── error.js │ │ │ └── index.js │ │ ├── package.json │ │ └── yarn.lock │ ├── git │ │ ├── CHANGELOG.md │ │ ├── Git │ │ │ ├── ComponentRequest.js │ │ │ ├── GitIgore.js │ │ │ ├── GitServer.js │ │ │ ├── Gitee.js │ │ │ ├── GiteeRequest.js │ │ │ ├── Github.js │ │ │ └── GithubRequest.js │ │ ├── README.md │ │ ├── __tests__ │ │ │ ├── git.test.js │ │ │ ├── gitee.test.js │ │ │ └── github.test.js │ │ ├── lib │ │ │ ├── const.js │ │ │ ├── error.js │ │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock │ └── package │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── __tests__ │ │ └── package.test.js │ │ ├── lib │ │ ├── const.js │ │ ├── error.js │ │ └── index.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── yarn.lock └── utils │ ├── format-path │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ │ └── format-path.test.js │ ├── lib │ │ └── index.js │ └── package.json │ ├── get-npm-info │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ │ └── get-npm-info.test.js │ ├── lib │ │ ├── const.js │ │ └── index.js │ ├── package-lock.json │ ├── package.json │ └── yarn.lock │ ├── locale │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ │ └── locale.test.js │ ├── lib │ │ ├── en_us.js │ │ ├── getEnvLocale.js │ │ ├── index.js │ │ ├── loadLocale.js │ │ └── zh_cn.js │ └── package.json │ ├── log │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ │ └── log.test.js │ ├── lib │ │ └── index.js │ ├── package-lock.json │ ├── package.json │ └── yarn.lock │ ├── request │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ │ └── request.test.js │ ├── lib │ │ └── index.js │ ├── package.json │ └── yarn.lock │ └── utils │ ├── CHANGELOG.md │ ├── README.md │ ├── __tests__ │ └── utils.test.js │ ├── lib │ ├── exec.js │ ├── file.js │ ├── index.js │ ├── inquirer.js │ ├── isObject.js │ ├── sleep.js │ ├── spinnerStart.js │ └── terminalLink.js │ ├── package-lock.json │ ├── package.json │ └── yarn.lock ├── scripts └── tests.js └── yarn.lock /.env-example: -------------------------------------------------------------------------------- 1 | # Some environment variables example, you'd better not change them. 2 | # C:/Users/home/.env 3 | 4 | # 脚手架调试模式 [info / verbose] 5 | DER_CLI_LOG_LEVEL = 'info' 6 | # 脚手架工作区 [本地] 7 | DER_CLI_TARGET_PATH = '\\der-cli\\commands\\init' 8 | # 脚手架缓存本地缓存目录名 9 | DER_CLI_HOME = '.der-cli' || '' 10 | # 脚手架缓存本地缓存地址 11 | DER_CLI_HOME_PATH = 'C:\\Users\\hostname\\.der-cli' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | node_modules 4 | 5 | packages/**/node_modules 6 | lerna-debug.log 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.4](https://github.com/der-cli/der-cli/compare/v0.5.3...v0.5.4) (2022-05-01) 18 | 19 | **Note:** Version bump only for package der-cli 20 | 21 | 22 | 23 | 24 | 25 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 26 | 27 | 28 | ### Bug Fixes 29 | 30 | * 修复site star ([4dc7849](https://github.com/der-cli/der-cli/commit/4dc78496df0a3b723c23a06c09bbfb2af916a99c)) 31 | 32 | 33 | 34 | 35 | 36 | ## [0.5.2](https://github.com/der-cli/der-cli/compare/v0.5.0...v0.5.2) (2022-03-15) 37 | 38 | 39 | ### Performance Improvements 40 | 41 | * up ([e0caec1](https://github.com/der-cli/der-cli/commit/e0caec1bdafb33b6f3f2c048306222c40f512b29)) 42 | 43 | 44 | 45 | 46 | 47 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 48 | 49 | 50 | ### Features 51 | 52 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 53 | 54 | 55 | 56 | 57 | 58 | ## [0.4.7](https://github.com/der-cli/der-cli/compare/v0.4.6...v0.4.7) (2022-03-12) 59 | 60 | **Note:** Version bump only for package der-cli 61 | 62 | 63 | 64 | 65 | 66 | ## [0.4.6](https://github.com/der-cli/der-cli/compare/v0.4.5...v0.4.6) (2022-03-12) 67 | 68 | 69 | ### Performance Improvements 70 | 71 | * emmm ([c5637fd](https://github.com/der-cli/der-cli/commit/c5637fde98ef0f47f1b402d6b1ab33c3a4ead37b)) 72 | 73 | 74 | 75 | 76 | 77 | ## [0.4.5](https://github.com/der-cli/der-cli/compare/v0.4.4...v0.4.5) (2022-03-12) 78 | 79 | 80 | ### Performance Improvements 81 | 82 | * cut down go check ([2305f64](https://github.com/der-cli/der-cli/commit/2305f64db6206439eb79d0021ddc52a814ba2392)) 83 | 84 | 85 | 86 | 87 | 88 | ## [0.4.4](https://github.com/der-cli/der-cli/compare/v0.4.3...v0.4.4) (2022-03-12) 89 | 90 | 91 | ### Performance Improvements 92 | 93 | * 优化发布前检查流程 ([70cda90](https://github.com/der-cli/der-cli/commit/70cda90e1558bc400ccfc114b5d2dd56278ef106)) 94 | 95 | 96 | 97 | 98 | 99 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 100 | 101 | **Note:** Version bump only for package der-cli 102 | 103 | 104 | 105 | 106 | 107 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 108 | 109 | **Note:** Version bump only for package der-cli 110 | 111 | 112 | 113 | 114 | 115 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 116 | 117 | 118 | ### Bug Fixes 119 | 120 | * 修复了控制台打印效果 ([b1842e4](https://github.com/der-cli/der-cli/commit/b1842e40169e39ebe56608995e0ea73ad00bcac9)) 121 | 122 | 123 | 124 | 125 | 126 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 127 | 128 | 129 | ### Bug Fixes 130 | 131 | * 修改测试用例 ([e17279d](https://github.com/der-cli/der-cli/commit/e17279da3f6646eeca3b86e2097072722017df96)) 132 | 133 | 134 | ### Features 135 | 136 | * 添加CHANGELOG ([00d4b09](https://github.com/der-cli/der-cli/commit/00d4b09d2b31334b6ac5cd0b136074b09f245699)) 137 | * 添加husky ([3d9a848](https://github.com/der-cli/der-cli/commit/3d9a848d33e1bb3a8a12f7fb99e4c8464ab2241d)) 138 | * 新增代码规范检查 ([b1f2ad5](https://github.com/der-cli/der-cli/commit/b1f2ad53df133717c73334f3dec6c091a1e18614)) 139 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | der 3 |

4 |

5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | star 16 | GPL 17 |

18 |

⚡𝓓𝓮𝓻 - A scaffolding tool for FE

19 | 20 | ## What's 𝓓𝓮𝓻? 21 | 22 | A **scaffolding tool** to improve development efficiency for FE, build with **Node.js**. 23 | 24 | ## 𝓓𝓮𝓻 can do 25 | 26 | - [x] Create a new project 27 | - [x] Auto commit & create a remote repo(github/gitee) 28 | - [x] Version control(Git Flow) 29 | - [x] Specification submission code 30 | 31 | ## Quick Start 32 | 33 | #### Install CLI 34 | 35 | ```shell 36 | $ npm install @der-cli/core -g 37 | # or 38 | $ yarn global add @der-cli/core 39 | ``` 40 | 41 | #### Create a project with 'der init' 42 | 43 | ```shell 44 | $ mikdir mytest && cd mytest 45 | 46 | $ der init test-demo 47 | ``` 48 | 49 | Before initialization, you can execute the **`der tpl`** command to see which templates are available(Network dependent). 50 | 51 | #### Commit to Github/Gitee with 'der go' 52 | 53 | This command initializes the repo locally (.git) and commits the code to the remote repo. 54 | 55 | Please check: 56 | 57 | - package.json 58 | - App Token 59 | 60 | ```shell 61 | $ der go 62 | ``` 63 | 64 | **Note**: ` der go` will commit the code to the remote repo with the same name of the project ( **repo name is the name attribute value of package.json**). If the remote repo does not exist, it will be created **automatically**. This requires you to prepare your remote repo APP Token in advance. GitHub users can apply for a token [here](https://github.com/settings/tokens). For Gitee users, see [App Token](https://github.com/der-cli/cli/blob/master/docs/Documents.md#App-Token). 65 | 66 | If you have created a remote repo, check package.json file, you can use this command directly. 67 | 68 | After executing the command, a `dev / x.x.x` branch will be generated remotely. 69 | 70 | #### Release tag with 'der go -re' 71 | 72 | ```shell 73 | $ der go --release 74 | # or abbreviation 75 | $ der go -re 76 | ``` 77 | 78 | 该命令会将代码合并到 master 分发删除当前版本开发分支,创建同版本 tag 分支合并到远程 master 分支,然后提交至远程仓库(远程与本地操作同步)。 79 | 80 | 例: dev/1.0.1 => release/1.0.1,详见 [Git_Flow](https://github.com/der-cli/cli/blob/master/docs/Documents.md#Git-Flow-自动化). 81 | 82 | 每次执行 `der go [-re]` 时,脚手架会检查代码冲突,检查通过则正常提交, 未通过会退出命令进程,这需要你手动解决代码冲突,控制台会将冲突代码位置打印出来,解决冲突再次执行即可。 83 | 84 | ## More Commands 85 | 86 | #### View template list 87 | 88 | ```shell 89 | $ der tpl 90 | 91 | # Or only project template 92 | $ der tpl --pro 93 | # Or only component template 94 | $ der tpl --com 95 | ``` 96 | 97 | #### View local cache 98 | 99 | ```shell 100 | $ der cache --all 101 | 102 | # or 103 | $ der cache --git [--token] 104 | # or 105 | $ der cache --template 106 | # or 107 | $ der cache --dependencies 108 | ``` 109 | 110 | #### Empty local cache 111 | 112 | > For scaffold cache, see [Cache](https://github.com/der-cli/cli/blob/master/docs/Documents.md#Cache-缓存). 113 | 114 | ```shell 115 | # Default: clean all 116 | $ der clean 117 | $ der clean --all 118 | 119 | # or just clean dependencies 120 | $ der clean --dep 121 | ``` 122 | 123 | #### DEBUG Mode 124 | 125 | ```shell 126 | $ der --debug 127 | # or 128 | $ der -d 129 | ``` 130 | 131 | More Commands [here](https://github.com/der-cli/cli/blob/master/docs/Documents.md). 132 | 133 | #### Debug local package 134 | 135 | see [docs](./docs/Documents.md) 136 | 137 | ## TODOs 138 | 139 | - [ ] Add feat: choice yarn/npm 140 | - [ ] Add feat: add page cmd(may) 141 | - [ ] Add feat: add component cmd(may) 142 | - [ ] Add feat: Commit code to GitHub and gitee at the same time 143 | 144 | ## Documents 145 | 146 | 详情参考: [docs](https://github.com/der-cli/cli/blob/master/docs/Documents.md) 147 | 148 | ## Change Log 149 | 150 | [CHANGELOG](./CHANGELOG.md) 151 | 152 | ## Q & A 153 | 154 | #### 1.Can I Commit code directly after initialization? 155 | 156 | A: Sure. The premise is to prepare your [App Token](https://github.com/der-cli/cli/blob/master/docs/Documents.md#App-Token). 157 | 158 | #### 2.Can I use the 'der go' command for projects I create directly? 159 | 160 | A: Sure. `der go` will be based on your **package.json** content creates a repository and commits branch code. 161 | 162 | ## Licence 163 | 164 | Der cli is open source software licensed as [GPL](LICENSE) 165 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | } -------------------------------------------------------------------------------- /docs/Commands.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | der 4 | 5 | ## der 客户端命令 6 | 7 | 客户端命令 8 | 9 | ### init 10 | 11 | ```shell 12 | $ cd your-project 13 | 14 | $ der init my-project -f -d 15 | ``` 16 | 17 | ### publish 18 | 19 | ```shell 20 | $ cd your-project 21 | 22 | $ der go -d 23 | # 更新平台、token 24 | $ der go -d -rs -rt 25 | # 更新平台、token、仓库类型 26 | $ der go -d -rs -rt -ro 27 | # 发布tag 28 | $ der go -re 29 | ``` 30 | 31 | ### tpl 32 | 33 | ```shell 34 | $ der tpl 35 | 36 | # Or only project template 37 | $ der tpl --pro 38 | # Or only component template 39 | $ der tpl --com 40 | ``` 41 | 42 | ### cache 43 | 44 | ```shell 45 | $ der cache --all 46 | 47 | # or 查看本地Git缓存信息 48 | $ der cache --git 49 | # or 查看本地模板缓存信息 50 | $ der cache --template 51 | # or 查看本地依赖缓存信息 52 | $ der cache --dependencies 53 | # or 查看App Token 54 | $ der cache --token 55 | ``` 56 | 57 | ## der-cli 开发者调试命令 58 | 59 | 本地调试 60 | 61 | ### init 62 | 63 | ```shell 64 | $ cd your-project 65 | 66 | $ der init my-project 67 | $ der init my-project -d 68 | $ der init my-project -f 69 | $ der init my-project -d -f 70 | ``` 71 | 72 | ### publish 73 | 74 | ```shell 75 | $ cd your-project 76 | 77 | $ der go -tp D:\\repository\\QuickStart\\der-cli\\commands\\publish -d 78 | # 更新平台、token 79 | $ der go -tp D:\\repository\\QuickStart\\der-cli\\commands\\publish -d -rs -rt 80 | # 更新平台、token、仓库类型 81 | $ der go -tp D:\\repository\\QuickStart\\der-cli\\commands\\publish -d -rs -rt -ro 82 | # 发布tag 83 | $ der go -tp D:\\repository\\QuickStart\\der-cli\\commands\\publish -re 84 | ``` 85 | 86 | ## lerna 命令 87 | 88 | ### 新建模块 89 | 90 | ```shell 91 | $ lerna create @der-cli/my-module 92 | ``` 93 | 94 | ### 安装依赖 95 | 96 | ```shell 97 | $ lerna add axios 98 | # or 99 | $ yarn add axios 100 | ``` 101 | 102 | ### 代码提交 103 | 104 | ```shell 105 | $ npm config set registry https://registry.npmjs.org/ 106 | $ yarn cp 107 | ``` 108 | 109 | ## der 模板 110 | 111 | 发布 npm 112 | 113 | ```shell 114 | $ npm publish 115 | ``` 116 | 117 | ## der 服务端 118 | 119 | `der-cli-server`: [der-cli/der-cli-server]() 120 | 121 | #### 本地调试 122 | 123 | ```shell 124 | $ yarn dev 125 | 126 | # or 127 | $ yarn start 128 | ``` 129 | -------------------------------------------------------------------------------- /docs/Documents.md: -------------------------------------------------------------------------------- 1 | # Documents 说明文档 2 | 3 | > #### Goodbye, context switching. 4 | > 5 | > #### Hello, terminal. 6 | 7 | ## Feature 8 | 9 | - 😎 专一性: 专注于前端**模板**与**自动化发布功能**; 10 | - ⚡ 高性能: 基于 Node.js 多进程执行任务, 并配合本地缓存; 11 | - 🔨 扩展性: 基于 Class 式编程,功能扩展更便捷; 12 | - 🔥 规范化: 使用 **Lerna** 工具架构仓库, 优化工作流程; 13 | - 🔰 安全性: 所有私人信息以本地缓存保存. 14 | 15 | ## 需求 & 使用场景 16 | 17 | > 所有需求与场景仅限解决本人日常开发问题,如果你有与本人同样的需求,那么此脚手架工具应该能解决你的一些问题。 18 | 19 | 关于为什么要设计这个脚手架,当然是有需求,~~没有需求的产品都是耍流氓~~,那具体需求是啥?且看小 y 娓娓道来~ 20 | 21 | ### 项目初始化 22 | 23 | 首先,作为一个前端,需要学的东西有亿点点多,特别是现在框架横行的时代,光初始化一个项目就杂七杂八多得一匹,什么 `vue create xxx` `create-react-app` `npx create-nuxt-app` `yarn create vite` 那简直太多了,不专门拿个小本本记上谁背得住,这些是开发一个稍微正经一点的项目的必备阶段,要是每次都要去搜一下怎么初始化也太浪费时间了,于是,`der-cli` 的第一个需求来了:**初始化任意前端项目, 并且可以后续自由扩展**。 24 | 25 | 初始化什么样的前端项目呢? 26 | 27 | 答:当然是想怎样就怎样!不仅是平时个人开发经常使用的模板,还可以把官方的标准模板也加上去,当然一般来说普通的标准模板不满足开发需求,所以脚手架主要会提供一些配置完善的模板,具体有多完善可以参考[这个模板](https://github.com/study-vue3/fast-vue3)...开个玩笑,有这模板的一半完善都 ok,主要包括一些 webpack 配置、路由、ESlint、Store 等等基本配置,能实现一个完整的、能跑起来的小 demo,这就是`der-cli` 对 `init` 功能的定义。 28 | 29 | ### 发布项目 30 | 31 | 初始化过后,就该认认真真(~~划水水摸鱼鱼~~)写代码了,写到一半,~~群友提醒你做提肛运动了~~,那你是不是该保存一下代码,怎么保存?相信大部分人都将代码放在 Github 或者 Gitee 上吧,那你又要去上面先创建个仓库,然后 add remote,然后你也许会熟练的在 terminal 里面敲上了三个命令: `git add .` `git commit -m 'feat:add a bug'` `git push` ,又或许是打开文件夹,找到当前项目,然后打开 TortoiseGit,点点点提交走人,但是我懒了,我就不想点三下,我就点一下,想搞定所有,那这需求不就来了: `der-cli` **能通过一个命令完成本地/远程仓库初始化、提交代码、创建分支、发布分支**。 32 | 33 | 这就是 `der go [-re] ` 的意义(~~提高效率才不是为了摸鱼~~) 34 | 35 | 一般开发中,整个流水线基本流程可包括 `初始化 -> 开发 -> 代码测试 -> 代码发布 -> 项目部署 `,而 `der-cli` 在整个 [workflow]() 中,占据了 **初始化**、**代码发布** 两个流程。 36 | 37 | 不管是独立开发还是团队开发,**打通项目流程,完成闭环** 是提升后期开发效率的必需事项,`der-cli`让你从初始化到项目发布 Tag 一步到位,可以专注于代码逻辑编写。 38 | 39 | 当然,一些 [github action]() 也可以完成自动发布 tag 的功能,为什么不选择它们呢? `der-cli` 把 一些 workflow 流程放到了客户端来完成,只需要全局安装了此脚手架,那么在所有项目中都能够使用这个 workflow,如果是使用类似 [github action]() 的话,需要给每个项目都写一份 yaml 作为 workflow 配置,这让开发者的工作有了一定的重复,当然 workflow 的可定制性非常强大,是鄙人小小脚手架不可比拟的,所以 `der-cli` **主要还是面向一些简单的、独立开发者的项目而定制的脚手架**。 40 | 41 | ## 架构设计 42 | 43 | `der-cli` 采用单仓库多工具包模式开发,使用 [Lerna](https://github.com/lerna/lerna) 管理工作流程,前端流行的开源库 Babel、React 等也采用了这种架构模式,每一个包都能单独下载使用,且方便管理与维护。 44 | 45 | 更多架构设计请查看 [der-cli 架构方案](https://github.com/der-cli/cli/packages/assets/learn-der-cli/der-cli架构方案.md). 46 | 47 | ## Git Flow 自动化 48 | 49 | Git 工作流程自动化。 50 | 51 | 简单来说,就是代替了手动执行 `git add `、`git commit`、`git checkout` 、`git push` 等命令,通过 `der go` 以及 `der go -re` 完成了初始化仓库、代码提交、发布版本等操作,这对有一定 git 操作经验的用户来说很容易理解,即使你是新手也完全可以使用此脚手架来完成你的项目规范发布。 52 | 53 | 下面详细介绍其执行流程。 54 | 55 | ### Git Flow - Prepare 阶段 56 | 57 | ![gitflow-Commit](https://fastly.jsdelivr.net/gh/yesmore/img/img/gitflow-prepare.png) 58 | 59 | ### Git Flow - Init 阶段 60 | 61 | ![gitflow-init](https://fastly.jsdelivr.net/gh/yesmore/img/img/gitflow-init.png) 62 | 63 | ### Git Flow - Commit 阶段 64 | 65 | ![gitflow-Finish](https://fastly.jsdelivr.net/gh/yesmore/img/img/gitflow-todo.png) 66 | 67 | ### Git Flow - Finish 阶段 68 | 69 | ![gitflow-finish](https://fastly.jsdelivr.net/gh/yesmore/img/img/gitflow-finish.png) 70 | 71 | ### Git Flow 命令 72 | 73 | > 根据上面的流程图,可以知道下面两个命令分别执行了哪些阶段 74 | 75 | - `der go` 提交代码到远程仓库: 76 | - Prepare 77 | - Init 78 | - Commit 79 | - `der go -re` 提交代码到远程仓库并发布 Tag: 80 | - Prepare 81 | - Init 82 | - Commit 83 | - Finish 84 | 85 | ## Cache 缓存 86 | 87 | `der-cli` 为了提高运行效率,在初始化应用以及自动发布时都采用了**缓存机制**,充分利用了客户端应用本地机制。但这不需要你提供 `root` 环境,`der-cli` 与其他脚手架工具遵循同样的原则: no-root,这在一定程度上能保护你的电脑文件不被误操作从而引起不必要的错误。 88 | 89 | `der-cli` 缓存文件默认位于:`C:\users\[hostname]\.der-cli\` 90 | 91 | 下面将解释 `der-cli` 缓存文件的位置及作用。 92 | 93 | ### .git 94 | 95 | Located at `C:\users\[hostname]\.der-cli\.git` 96 | 97 | 用于缓存 Git 操作信息,这些信息将用于代码提交、创建远程仓库、发布分支,是 [Git Flow](#Git Flow) 流程的**必要**缓存。**建议**不要随意删除。 98 | 99 | #### APP Token 100 | 101 | 在本地缓存 `.git` 目录下,有一个名为 `.git_token` 的文件,用于保存 Github / Gitee 的 [App Token]() 信息,这将用于 [Git Flow](#Git_Flow_自动化) 流程。包括以下值: 102 | 103 | - xxxxxxxxxxxxxxxxxxxxxx (随机字符串) 104 | 105 | App Token 需要用户手动生成,生成地址: 106 | 107 | - Github: https://github.com/settings/tokens 108 | - Gitee: https://gitee.com/profile/personal_access_tokens 109 | 110 | > 由于 App Token 仅在创建时可见,这需要你**自己在本地备份一个 Token 信息**,以免当脚手架缓存文件被误删后,能快速找回;如果不这样做,也不是不行,你就需要重新在上面的链接中重新生成一个 Token. 111 | 112 | #### Git Server 113 | 114 | 以 `.git_server` 文件保存的信息,用于确认远程仓库平台,包括以下值: 115 | 116 | - Github 117 | - Gitee 118 | 119 | #### Git Own 120 | 121 | 以 `.git_own` 文件保存,用于确认仓库所属类型,包括以下值: 122 | 123 | - user 表示该仓库所属个人用户 124 | - org 表示该仓库所属于一个组织 125 | 126 | #### Git Login 127 | 128 | 以 `.git_login` 文件保存,用于保存仓库拥有者名称,包括以下值: 129 | 130 | - Github name or Gitee name 131 | 132 | ### dependencies 133 | 134 | Located at `C:\users\[hostname]\.der-cli\dependencies` 135 | 136 | 用于缓存项目依赖文件,包括 `der-cli` 源码文件。 137 | 138 | 每次运行 (任意命令) 时,脚手架会在启动阶段检查脚手架源码版本,当发现新版本时,会自动更新 npm。 139 | 140 | > 建议国内用户切换淘宝镜像源: 141 | > 142 | > `npm config set registry https://registry.npmjs.org/` 143 | 144 | ### template 145 | 146 | Located at `C:\users\[hostname]\.der-cli\template` 147 | 148 | 用于缓存 项目/组件模板 源码。 149 | 150 | 当用户选中某个模板,在其 `init` 阶段时,脚手架会自动检测其 npm 发布版本,若发现有更新,则会自动更新为最新版。 151 | 152 | ## Commands 命令 153 | 154 | ### init 初始化项目 155 | 156 | ```shell 157 | $ mikdir mytest && cd mytest 158 | 159 | 160 | $ der init test-demo 161 | 162 | # or 163 | $ der init my-project --debug 164 | $ der init my-project --force 165 | # 简写 166 | $ der init my-project -d -f 167 | ``` 168 | 169 | ### go 提交代码 170 | 171 | ```shell 172 | $ der go 173 | 174 | # or 175 | # 更新缓存信息: 平台、token 176 | $ der go --refreshServer --refreshToken 177 | # 更新缓存信息: 平台、token、仓库类型 178 | $ der go --refreshServer --refreshToken --refreshOwn 179 | 180 | # 简写 181 | $ der go -d -rs -rt -ro 182 | ``` 183 | 184 | ### go 发布代码 185 | 186 | ```shell 187 | $ der go -re 188 | ``` 189 | 190 | ### More 191 | 192 | #### tpl 查看模板列表 193 | 194 | ```shell 195 | $ der tpl 196 | 197 | # Or only project template 198 | $ der tpl --pro 199 | # Or only component template 200 | $ der tpl --com 201 | ``` 202 | 203 | #### cache 查看本地缓存 204 | 205 | ```shell 206 | $ der cache --all 207 | 208 | # or 查看本地Git缓存信息 209 | $ der cache --git 210 | # or 查看本地模板缓存信息 211 | $ der cache --template 212 | # or 查看本地依赖缓存信息 213 | $ der cache --dependencies 214 | # or 查看App Token 215 | $ der cache --token 216 | ``` 217 | 218 | #### clean 清空本地缓存 219 | 220 | > 关于脚手架缓存,详见 [docs: Cache](https://github.com/der-cli/cli/blob/master/docs/Documents.md#Cache). 221 | 222 | ```shell 223 | # Default: clean all 224 | $ der clean 225 | $ der clean --all 226 | 227 | # or just clean dependencies 228 | $ der clean --dep 229 | ``` 230 | 231 | #### debug 模式 232 | 233 | ```shell 234 | $ der --debug 235 | # or 236 | $ der -d 237 | ``` 238 | 239 | 更多命令 [详情](https://github.com/der-cli/cli/blob/master/docs/Commands.md). 240 | 241 | ## 本地开发 242 | 243 | TODO 244 | 245 | ## Other 246 | 247 | ### env 248 | 249 | `der-cli` 支持客户端环境变量设置,一般情况不需要关注环境变量。 250 | 251 | 但如果你想开发本项目或其他需求,可以在你的主机自定义一些变量,通过修改 `.env` 文件即可。`.env` 文件位于`C:\users\[hostname]\`路径下,即 `C:\users\[hostname]\.der-cli\.env` ,若你的主机没有这个文件,手动创建即可,设置好后保存,`der-cli` 会自动读取这些变量。 252 | 253 | 下面是一些环境变量示例: 254 | 255 | ```shell 256 | # Some environment variables example, you'd better not change them. 257 | # C:/Users/hostname/.env 258 | 259 | # 脚手架调试模式 [info / verbose] 260 | DER_CLI_LOG_LEVEL = 'info' 261 | 262 | # 脚手架工作区 [本地] 263 | DER_CLI_TARGET_PATH = '\\der-cli\\commands\\init' 264 | 265 | # 脚手架缓存本地缓存目录名 266 | DER_CLI_HOME = '.der-cli' || '' 267 | 268 | # 脚手架缓存本地缓存地址 269 | DER_CLI_HOME_PATH = 'C:\\Users\\hostname\\.der-cli' 270 | ``` 271 | 272 | 同 [.env-example](https://github.com/der-cli/cli/blob/master/.env-example) 273 | -------------------------------------------------------------------------------- /docs/assets/css: -------------------------------------------------------------------------------- 1 | /* cyrillic-ext */ 2 | @font-face { 3 | font-family: 'Roboto'; 4 | font-style: italic; 5 | font-weight: 400; 6 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xFIzIFKw.woff2) format('woff2'); 7 | unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; 8 | } 9 | /* cyrillic */ 10 | @font-face { 11 | font-family: 'Roboto'; 12 | font-style: italic; 13 | font-weight: 400; 14 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xMIzIFKw.woff2) format('woff2'); 15 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; 16 | } 17 | /* greek-ext */ 18 | @font-face { 19 | font-family: 'Roboto'; 20 | font-style: italic; 21 | font-weight: 400; 22 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xEIzIFKw.woff2) format('woff2'); 23 | unicode-range: U+1F00-1FFF; 24 | } 25 | /* greek */ 26 | @font-face { 27 | font-family: 'Roboto'; 28 | font-style: italic; 29 | font-weight: 400; 30 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xLIzIFKw.woff2) format('woff2'); 31 | unicode-range: U+0370-03FF; 32 | } 33 | /* vietnamese */ 34 | @font-face { 35 | font-family: 'Roboto'; 36 | font-style: italic; 37 | font-weight: 400; 38 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xHIzIFKw.woff2) format('woff2'); 39 | unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; 40 | } 41 | /* latin-ext */ 42 | @font-face { 43 | font-family: 'Roboto'; 44 | font-style: italic; 45 | font-weight: 400; 46 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xGIzIFKw.woff2) format('woff2'); 47 | unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; 48 | } 49 | /* latin */ 50 | @font-face { 51 | font-family: 'Roboto'; 52 | font-style: italic; 53 | font-weight: 400; 54 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1Mu51xIIzI.woff2) format('woff2'); 55 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; 56 | } 57 | /* cyrillic-ext */ 58 | @font-face { 59 | font-family: 'Roboto'; 60 | font-style: normal; 61 | font-weight: 300; 62 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fCRc4EsA.woff2) format('woff2'); 63 | unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; 64 | } 65 | /* cyrillic */ 66 | @font-face { 67 | font-family: 'Roboto'; 68 | font-style: normal; 69 | font-weight: 300; 70 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fABc4EsA.woff2) format('woff2'); 71 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; 72 | } 73 | /* greek-ext */ 74 | @font-face { 75 | font-family: 'Roboto'; 76 | font-style: normal; 77 | font-weight: 300; 78 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fCBc4EsA.woff2) format('woff2'); 79 | unicode-range: U+1F00-1FFF; 80 | } 81 | /* greek */ 82 | @font-face { 83 | font-family: 'Roboto'; 84 | font-style: normal; 85 | font-weight: 300; 86 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fBxc4EsA.woff2) format('woff2'); 87 | unicode-range: U+0370-03FF; 88 | } 89 | /* vietnamese */ 90 | @font-face { 91 | font-family: 'Roboto'; 92 | font-style: normal; 93 | font-weight: 300; 94 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fCxc4EsA.woff2) format('woff2'); 95 | unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; 96 | } 97 | /* latin-ext */ 98 | @font-face { 99 | font-family: 'Roboto'; 100 | font-style: normal; 101 | font-weight: 300; 102 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fChc4EsA.woff2) format('woff2'); 103 | unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; 104 | } 105 | /* latin */ 106 | @font-face { 107 | font-family: 'Roboto'; 108 | font-style: normal; 109 | font-weight: 300; 110 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fBBc4.woff2) format('woff2'); 111 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; 112 | } 113 | /* cyrillic-ext */ 114 | @font-face { 115 | font-family: 'Roboto'; 116 | font-style: normal; 117 | font-weight: 400; 118 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu72xKOzY.woff2) format('woff2'); 119 | unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; 120 | } 121 | /* cyrillic */ 122 | @font-face { 123 | font-family: 'Roboto'; 124 | font-style: normal; 125 | font-weight: 400; 126 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu5mxKOzY.woff2) format('woff2'); 127 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; 128 | } 129 | /* greek-ext */ 130 | @font-face { 131 | font-family: 'Roboto'; 132 | font-style: normal; 133 | font-weight: 400; 134 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu7mxKOzY.woff2) format('woff2'); 135 | unicode-range: U+1F00-1FFF; 136 | } 137 | /* greek */ 138 | @font-face { 139 | font-family: 'Roboto'; 140 | font-style: normal; 141 | font-weight: 400; 142 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu4WxKOzY.woff2) format('woff2'); 143 | unicode-range: U+0370-03FF; 144 | } 145 | /* vietnamese */ 146 | @font-face { 147 | font-family: 'Roboto'; 148 | font-style: normal; 149 | font-weight: 400; 150 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu7WxKOzY.woff2) format('woff2'); 151 | unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; 152 | } 153 | /* latin-ext */ 154 | @font-face { 155 | font-family: 'Roboto'; 156 | font-style: normal; 157 | font-weight: 400; 158 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu7GxKOzY.woff2) format('woff2'); 159 | unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; 160 | } 161 | /* latin */ 162 | @font-face { 163 | font-family: 'Roboto'; 164 | font-style: normal; 165 | font-weight: 400; 166 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu4mxK.woff2) format('woff2'); 167 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; 168 | } 169 | /* cyrillic-ext */ 170 | @font-face { 171 | font-family: 'Roboto'; 172 | font-style: normal; 173 | font-weight: 700; 174 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfCRc4EsA.woff2) format('woff2'); 175 | unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; 176 | } 177 | /* cyrillic */ 178 | @font-face { 179 | font-family: 'Roboto'; 180 | font-style: normal; 181 | font-weight: 700; 182 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfABc4EsA.woff2) format('woff2'); 183 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; 184 | } 185 | /* greek-ext */ 186 | @font-face { 187 | font-family: 'Roboto'; 188 | font-style: normal; 189 | font-weight: 700; 190 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfCBc4EsA.woff2) format('woff2'); 191 | unicode-range: U+1F00-1FFF; 192 | } 193 | /* greek */ 194 | @font-face { 195 | font-family: 'Roboto'; 196 | font-style: normal; 197 | font-weight: 700; 198 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfBxc4EsA.woff2) format('woff2'); 199 | unicode-range: U+0370-03FF; 200 | } 201 | /* vietnamese */ 202 | @font-face { 203 | font-family: 'Roboto'; 204 | font-style: normal; 205 | font-weight: 700; 206 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfCxc4EsA.woff2) format('woff2'); 207 | unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; 208 | } 209 | /* latin-ext */ 210 | @font-face { 211 | font-family: 'Roboto'; 212 | font-style: normal; 213 | font-weight: 700; 214 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfChc4EsA.woff2) format('woff2'); 215 | unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; 216 | } 217 | /* latin */ 218 | @font-face { 219 | font-family: 'Roboto'; 220 | font-style: normal; 221 | font-weight: 700; 222 | src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfBBc4.woff2) format('woff2'); 223 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; 224 | } 225 | -------------------------------------------------------------------------------- /docs/assets/der.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/der.png -------------------------------------------------------------------------------- /docs/assets/dergo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/dergo.png -------------------------------------------------------------------------------- /docs/assets/derinit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/derinit.png -------------------------------------------------------------------------------- /docs/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/favicon.ico -------------------------------------------------------------------------------- /docs/assets/icon-linux.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/assets/icon-mac.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/assets/icon-windows.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /docs/assets/logo-der.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/logo-der.png -------------------------------------------------------------------------------- /docs/assets/square-pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/assets/square-pattern.png -------------------------------------------------------------------------------- /docs/learn-der-cli/der-cli 架构图.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/der-cli 架构图.xmind -------------------------------------------------------------------------------- /docs/learn-der-cli/der-cli执行流程.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/der-cli执行流程.xmind -------------------------------------------------------------------------------- /docs/learn-der-cli/der-cli架构方案.md: -------------------------------------------------------------------------------- 1 | # der-cli 架构图 2 | 3 | ![der-cli](https://fastly.jsdelivr.net/gh/yesmore/img/img/der-cli架构图.png) 4 | 5 | ## 脚手架核心框架 6 | 7 | - [x] 执行准备 8 | - [ ] 命令注册 9 | - [ ] 命令执行 10 | 11 | ### 本地缓存体系 12 | 13 | - [ ] 本地文件&环境变量(配置信息等) 14 | 15 | ## Git 操作规范体系 16 | 17 | - [ ] 仓库初始化(本地 / 远程) 18 | - [ ] 开发模式(dev 分支同步) 19 | - [ ] 发布模式(branch / tag) 20 | 21 | ### 代码仓库 22 | 23 | - [x] Github 24 | - [x] Gitee 25 | 26 | ## 初始化体系 27 | 28 | > 依赖 Open API 29 | 30 | - [ ] 项目初始化 31 | - [ ] 组件初始化 32 | - [ ] 初始化模式(自定义 / 标准) 33 | 34 | ### 模板库-NPM 35 | 36 | - [x] 项目模板 37 | - [x] 组件模板 38 | 39 | ## Open API 40 | 41 | - [ ] 项目/组件模板 42 | 43 | ### 数据体系 44 | 45 | - [ ] MongoDB - 项目模板信息 46 | 47 | # der-cli 模块化策略 48 | 49 | ### 拆分原则 50 | 51 | - 核心模块:core 52 | - 命令模块:commands 53 | - 模型模块:models 54 | - 工具模块:utils 55 | 56 | ### 细节 57 | 58 | - 核心流程 `core` 59 | - 命令 `commands` 60 | - [x] 初始化 61 | - [x] 发布 62 | - [x] 清除缓存 63 | - 模型层 `models` 64 | - [x] Command 命令 65 | - [x] Project 项目 66 | - [x] Component 组件 67 | - [x] Npm 模块 68 | - [x] Git 仓库 69 | - 支撑模块 `utils` 70 | - [x] Git 操作 71 | - [x] 工具方法 72 | - [x] API 请求 73 | 74 | ### Core 模块 75 | 76 | #### 命令执行流程 77 | 78 | - 准备阶段 79 | - 命令注册 80 | - 命令执行 81 | 82 | ### Commands 模块 83 | 84 | #### init 85 | 86 | ### Models 模块 87 | 88 | > 通用模块 89 | 90 | 关键词: 91 | 92 | - 高性能:基于**缓存**与**Node 多进程**实现动态命令加载和执行 93 | - 可扩展:Class 编程 94 | 95 | #### 通用 Package Class 96 | 97 | #### 通用 Command Class 98 | -------------------------------------------------------------------------------- /docs/learn-der-cli/imgs/der-cli架构图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/imgs/der-cli架构图.png -------------------------------------------------------------------------------- /docs/learn-der-cli/imgs/gitflow-finish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/imgs/gitflow-finish.png -------------------------------------------------------------------------------- /docs/learn-der-cli/imgs/gitflow-init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/imgs/gitflow-init.png -------------------------------------------------------------------------------- /docs/learn-der-cli/imgs/gitflow-prepare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/imgs/gitflow-prepare.png -------------------------------------------------------------------------------- /docs/learn-der-cli/imgs/gitflow-todo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/imgs/gitflow-todo.png -------------------------------------------------------------------------------- /docs/learn-der-cli/项目发布架构设计图.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/docs/learn-der-cli/项目发布架构设计图.xmind -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/core/*", 4 | "packages/commands/*", 5 | "packages/models/*", 6 | "packages/utils/*" 7 | ], 8 | "command": { 9 | "bootstrap": { 10 | "hoist": true 11 | }, 12 | "version": { 13 | "conventionalCommits": true 14 | } 15 | }, 16 | "name": "root", 17 | "version": "0.5.5", 18 | "ignoreChanges": [ 19 | "**/*.md" 20 | ] 21 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "der-cli", 3 | "version": "0.0.1", 4 | "main": "index.js", 5 | "license": "GPL-3.0", 6 | "scripts": { 7 | "c": "git add . && git cz", 8 | "cp": "git add . && git cz && git push", 9 | "cpp": "git add . && git cz && yarn p", 10 | "p": "lerna publish", 11 | "test": "mocha 'packages/**/**/__tests__/*.test.js'" 12 | }, 13 | "devDependencies": { 14 | "lerna": "^4.0.0" 15 | }, 16 | "dependencies": { 17 | "@commitlint/cli": "^16.2.1", 18 | "@commitlint/config-conventional": "^16.2.1", 19 | "cz-customizable": "^6.3.0", 20 | "cz-lerna-changelog": "^2.0.3", 21 | "husky": "^7.0.4", 22 | "lint-staged": "^12.3.4", 23 | "standard": "^16.0.4" 24 | }, 25 | "config": { 26 | "commitizen": { 27 | "path": "./node_modules/cz-lerna-changelog" 28 | } 29 | }, 30 | "husky": { 31 | "hooks": { 32 | "pre-commit": "lint-staged", 33 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 34 | } 35 | }, 36 | "lint-staged": { 37 | "*.js": [ 38 | "standard --fix", 39 | "git add" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/commands/add/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/add 9 | 10 | 11 | 12 | 13 | 14 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 15 | 16 | **Note:** Version bump only for package @der-cli/add 17 | -------------------------------------------------------------------------------- /packages/commands/add/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/add` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const add = require('@der-cli/add'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/add/__tests__/add.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const add = require('../lib'); 4 | 5 | describe('@der-cli/add', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/commands/add/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = add; 4 | 5 | function add() { 6 | // TODO 7 | } 8 | -------------------------------------------------------------------------------- /packages/commands/add/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/add", 3 | "version": "0.5.0", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/commands/cache/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | **Note:** Version bump only for package @der-cli/cache 9 | 10 | 11 | 12 | 13 | 14 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 15 | 16 | **Note:** Version bump only for package @der-cli/cache 17 | 18 | 19 | 20 | 21 | 22 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 23 | 24 | **Note:** Version bump only for package @der-cli/cache 25 | 26 | 27 | 28 | 29 | 30 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 31 | 32 | **Note:** Version bump only for package @der-cli/cache 33 | 34 | 35 | 36 | 37 | 38 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 39 | 40 | 41 | ### Features 42 | 43 | * 添加CHANGELOG ([00d4b09](https://github.com/der-cli/der-cli/commit/00d4b09d2b31334b6ac5cd0b136074b09f245699)) 44 | -------------------------------------------------------------------------------- /packages/commands/cache/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/cache` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const cache = require('@der-cli/cache'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/cache/__tests__/cache.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const cache = require('..'); 4 | 5 | describe('@der-cli/cache', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/commands/cache/lib/const.js: -------------------------------------------------------------------------------- 1 | const DEPENDENCIES_CACHE_PATH = 'dependencies/node_modules'; 2 | const TPL_CACHE_PATH = 'template/node_modules'; 3 | const GIT_CACHE_PATH = '.git'; 4 | const GIT_OWN_CACHE_PATH = '.git_own' 5 | const GIT_LOGIN_CACHE_PATH = '.git_login' 6 | const GIT_TOKEN_CACHE_PATH = '.git_token' 7 | const GIT_SERVER_CACHE_PATH = '.git_server' 8 | 9 | module.exports = { 10 | DEPENDENCIES_CACHE_PATH, 11 | TPL_CACHE_PATH, 12 | GIT_CACHE_PATH, 13 | GIT_OWN_CACHE_PATH, 14 | GIT_LOGIN_CACHE_PATH, 15 | GIT_TOKEN_CACHE_PATH, 16 | GIT_SERVER_CACHE_PATH 17 | } -------------------------------------------------------------------------------- /packages/commands/cache/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_FOLDER_NOT_EXISTS = () => { 2 | throw new Error('[Cache] Local Cache is not exsits.') 3 | }; 4 | 5 | const Error_FILE_CACHE_NOT_EXISTS = (filePath) => { 6 | throw new Error(`[Cache] Cache file is not exsits: ${filePath}`) 7 | } 8 | 9 | module.exports = { 10 | Error_FOLDER_NOT_EXISTS, 11 | Error_FILE_CACHE_NOT_EXISTS 12 | } -------------------------------------------------------------------------------- /packages/commands/cache/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const fse = require('fs-extra'); 6 | const log = require('@der-cli/log'); 7 | const Command = require('@der-cli/command'); 8 | const { readFile } = require('@der-cli/utils'); 9 | const { 10 | DEPENDENCIES_CACHE_PATH, 11 | GIT_CACHE_PATH, 12 | TPL_CACHE_PATH, 13 | GIT_OWN_CACHE_PATH, 14 | GIT_LOGIN_CACHE_PATH, 15 | GIT_TOKEN_CACHE_PATH, 16 | GIT_SERVER_CACHE_PATH 17 | } = require('./const'); 18 | const { 19 | Error_FOLDER_NOT_EXISTS, 20 | Error_FILE_CACHE_NOT_EXISTS 21 | } = require('./error'); 22 | 23 | class CacheCommand extends Command { 24 | init() { 25 | // 参数处理 26 | this.options = { 27 | ...this._argv[0] 28 | } 29 | } 30 | 31 | exec() { 32 | try { 33 | this.doCache() 34 | } catch (e) { 35 | log.error(e.message); 36 | if (process.env.DER_CLI_LOG_LEVEL === 'verbose') { 37 | console.log(e); 38 | } 39 | } 40 | } 41 | 42 | doCache() { 43 | const cliPath = process.env.DER_CLI_HOME_PATH; 44 | let depPath = path.resolve(process.env.DER_CLI_HOME_PATH, DEPENDENCIES_CACHE_PATH) 45 | let gitPath = path.resolve(process.env.DER_CLI_HOME_PATH, GIT_CACHE_PATH) 46 | let tplPath = path.resolve(process.env.DER_CLI_HOME_PATH, TPL_CACHE_PATH) 47 | 48 | if (!fs.existsSync(cliPath)) { 49 | Error_FOLDER_NOT_EXISTS() 50 | } 51 | 52 | if (this.options.all) { 53 | this.gitCache(gitPath) 54 | this.tplCache(tplPath) 55 | this.depCache(depPath) 56 | } else if (this.options.dependencies) { 57 | this.depCache(depPath) 58 | } else if (this.options.git) { 59 | this.gitCache(gitPath) 60 | } else if (this.options.template) { 61 | this.tplCache(tplPath) 62 | } else { 63 | log.notice('[Cache]', 'No options.(--all/--git/--template/--dependencies)'); 64 | } 65 | } 66 | 67 | depCache(depPath) { 68 | if (fs.existsSync(depPath)) { 69 | this.toolStart('DEPEMDENCIES CACHE') 70 | let files = []; 71 | fs.readdirSync(depPath).forEach(file => { 72 | files.push(file); 73 | }) 74 | log.info('[Cache] Dependencies total cache files:', files.length); 75 | } else { 76 | Error_FILE_CACHE_NOT_EXISTS(depPath) 77 | } 78 | } 79 | 80 | gitCache(gitPath) { 81 | if (fs.existsSync(gitPath)) { 82 | this.toolStart('GIT CACHE') 83 | const own = path.resolve(gitPath, GIT_OWN_CACHE_PATH); 84 | const login = path.resolve(gitPath, GIT_LOGIN_CACHE_PATH); 85 | const token = path.resolve(gitPath, GIT_TOKEN_CACHE_PATH); 86 | const server = path.resolve(gitPath, GIT_SERVER_CACHE_PATH); 87 | 88 | const ownCache = readFile(own); 89 | const loginCache = readFile(login); 90 | const tokenCache = readFile(token); 91 | const serverCache = readFile(server); 92 | 93 | if (!loginCache || !tokenCache || !serverCache || !ownCache) { 94 | Error_FILE_CACHE_NOT_EXISTS(gitPath) 95 | } else { 96 | log.info('[Cache] Git远程平台:', serverCache); 97 | log.info('[Cache] Git仓库类型:', `${ownCache}(${ownCache === 'org' ? '组织' : '个人'})`); 98 | log.info('[Cache] Git登录用户:', loginCache); 99 | log.info('[Cache] Git App Token:', this.options.token ? tokenCache : '******'); 100 | } 101 | 102 | } else { 103 | Error_FILE_CACHE_NOT_EXISTS(gitPath) 104 | } 105 | } 106 | 107 | tplCache(tplPath) { 108 | if (fs.existsSync(tplPath)) { 109 | this.toolStart('TEMPLATE CACHE') 110 | let files = []; 111 | fs.readdirSync(tplPath).forEach(file => { 112 | if (file.startsWith('_@der-cli')) { 113 | log.info('[Cache] Template:', file); 114 | files.push(tplPath); 115 | } 116 | }) 117 | log.info('[Cache] Template total cache files:', files.length); 118 | } else { 119 | Error_FILE_CACHE_NOT_EXISTS(tplPath) 120 | } 121 | } 122 | 123 | toolStart(info) { 124 | console.log(); 125 | log.info(`******** ${info} ********`); 126 | } 127 | } 128 | 129 | function init(argv) { 130 | return new CacheCommand(argv); 131 | } 132 | 133 | module.exports = init 134 | module.exports.CacheCommand = CacheCommand; -------------------------------------------------------------------------------- /packages/commands/cache/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/cache", 3 | "version": "0.5.5", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "fs-extra": { 8 | "version": "10.0.1", 9 | "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", 10 | "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", 11 | "requires": { 12 | "graceful-fs": "^4.2.0", 13 | "jsonfile": "^6.0.1", 14 | "universalify": "^2.0.0" 15 | }, 16 | "dependencies": { 17 | "graceful-fs": { 18 | "version": "4.2.9", 19 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz", 20 | "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==" 21 | }, 22 | "jsonfile": { 23 | "version": "6.1.0", 24 | "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", 25 | "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", 26 | "requires": { 27 | "graceful-fs": "^4.1.6", 28 | "universalify": "^2.0.0" 29 | } 30 | }, 31 | "universalify": { 32 | "version": "2.0.0", 33 | "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", 34 | "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/commands/cache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/cache", 3 | "version": "0.5.5", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | }, 29 | "dependencies": { 30 | "@der-cli/command": "^0.5.5", 31 | "@der-cli/log": "^0.5.0", 32 | "@der-cli/utils": "^0.5.0", 33 | "fs-extra": "^10.0.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/commands/clean/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | **Note:** Version bump only for package @der-cli/clean 9 | 10 | 11 | 12 | 13 | 14 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 15 | 16 | **Note:** Version bump only for package @der-cli/clean 17 | 18 | 19 | 20 | 21 | 22 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 23 | 24 | **Note:** Version bump only for package @der-cli/clean 25 | 26 | 27 | 28 | 29 | 30 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 31 | 32 | **Note:** Version bump only for package @der-cli/clean 33 | 34 | 35 | 36 | 37 | 38 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 39 | 40 | 41 | ### Features 42 | 43 | * 添加CHANGELOG ([00d4b09](https://github.com/der-cli/der-cli/commit/00d4b09d2b31334b6ac5cd0b136074b09f245699)) 44 | -------------------------------------------------------------------------------- /packages/commands/clean/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/clean` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const clean = require('@der-cli/clean'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/clean/__tests__/clean.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const clean = require('..'); 4 | 5 | describe('@der-cli/clean', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/commands/clean/lib/const.js: -------------------------------------------------------------------------------- 1 | const DEPENDENCIES_PATH = 'dependencies'; 2 | 3 | module.exports = { 4 | DEPENDENCIES_PATH 5 | } -------------------------------------------------------------------------------- /packages/commands/clean/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const fse = require('fs-extra'); 6 | const log = require('@der-cli/log'); 7 | const Command = require('@der-cli/command'); 8 | const { DEPENDENCIES_PATH } = require('./const'); 9 | 10 | class CleanCommand extends Command { 11 | init() { 12 | // 参数处理 13 | this.options = { 14 | ...this._argv[0] 15 | } 16 | } 17 | 18 | exec() { 19 | try { 20 | this.doClean() 21 | } catch (e) { 22 | log.error(e.message); 23 | if (process.env.DER_CLI_LOG_LEVEL === 'verbose') { 24 | console.log(e); 25 | } 26 | } 27 | } 28 | 29 | doClean() { 30 | const cliPath = process.env.DER_CLI_HOME_PATH; 31 | log.notice('[Clean] Removing Cache files...'); 32 | if (this.options.all) { 33 | this.cleanAll(cliPath) 34 | } else if (this.options.dep) { 35 | const depPath = path.resolve(process.env.DER_CLI_HOME_PATH, DEPENDENCIES_PATH); 36 | if (fs.existsSync(depPath)) { 37 | fse.emptyDirSync(depPath); 38 | log.success('[Clean] Remove:', `${depPath} ...done`); 39 | } else { 40 | log.success('[Clean] Folder is not exsits:', depPath); 41 | } 42 | } else { 43 | this.cleanAll(cliPath) 44 | } 45 | } 46 | 47 | cleanAll(cliPath) { 48 | if (fs.existsSync(cliPath)) { 49 | fse.emptyDirSync(cliPath); 50 | log.success('[Clean] Remove:', `${cliPath} ...done`); 51 | } else { 52 | log.notice('[Clean] Folder is not exsits:', cliPath); 53 | } 54 | } 55 | } 56 | 57 | function init(argv) { 58 | return new CleanCommand(argv); 59 | } 60 | 61 | module.exports = init 62 | module.exports.CleanCommand = CleanCommand; -------------------------------------------------------------------------------- /packages/commands/clean/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/clean", 3 | "version": "0.5.5", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "fs-extra": { 8 | "version": "10.0.1", 9 | "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", 10 | "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", 11 | "requires": { 12 | "graceful-fs": "^4.2.0", 13 | "jsonfile": "^6.0.1", 14 | "universalify": "^2.0.0" 15 | } 16 | }, 17 | "graceful-fs": { 18 | "version": "4.2.9", 19 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz", 20 | "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==" 21 | }, 22 | "jsonfile": { 23 | "version": "6.1.0", 24 | "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", 25 | "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", 26 | "requires": { 27 | "graceful-fs": "^4.1.6", 28 | "universalify": "^2.0.0" 29 | } 30 | }, 31 | "universalify": { 32 | "version": "2.0.0", 33 | "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", 34 | "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/commands/clean/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/clean", 3 | "version": "0.5.5", 4 | "description": "der cli 'clean' command", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "ISC", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | }, 29 | "dependencies": { 30 | "@der-cli/command": "^0.5.5", 31 | "@der-cli/log": "^0.5.0", 32 | "fs-extra": "^10.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/commands/clean/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@der-cli/log@^0.1.9": 6 | version "0.1.9" 7 | resolved "https://registry.yarnpkg.com/@der-cli/log/-/log-0.1.9.tgz#2c096c6ca701e394115448725c360952c39b94b8" 8 | integrity sha512-RXqHOT9CxxfA03NrHM/0eJRVMhqjs8bBOj55bwA4t0DNXlmHWtmS2/YBvyolDKBN3DuJebDGnnHPEjFk9EyAAg== 9 | dependencies: 10 | npmlog "^6.0.1" 11 | 12 | ansi-regex@^5.0.1: 13 | version "5.0.1" 14 | resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" 15 | integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== 16 | 17 | "aproba@^1.0.3 || ^2.0.0": 18 | version "2.0.0" 19 | resolved "https://registry.yarnpkg.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc" 20 | integrity sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ== 21 | 22 | are-we-there-yet@^3.0.0: 23 | version "3.0.0" 24 | resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d" 25 | integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw== 26 | dependencies: 27 | delegates "^1.0.0" 28 | readable-stream "^3.6.0" 29 | 30 | color-support@^1.1.3: 31 | version "1.1.3" 32 | resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" 33 | integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== 34 | 35 | console-control-strings@^1.1.0: 36 | version "1.1.0" 37 | resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" 38 | integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= 39 | 40 | delegates@^1.0.0: 41 | version "1.0.0" 42 | resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" 43 | integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= 44 | 45 | emoji-regex@^8.0.0: 46 | version "8.0.0" 47 | resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" 48 | integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== 49 | 50 | fs-extra@^10.0.1: 51 | version "10.0.1" 52 | resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.1.tgz#27de43b4320e833f6867cc044bfce29fdf0ef3b8" 53 | integrity sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag== 54 | dependencies: 55 | graceful-fs "^4.2.0" 56 | jsonfile "^6.0.1" 57 | universalify "^2.0.0" 58 | 59 | gauge@^4.0.0: 60 | version "4.0.2" 61 | resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.2.tgz#c3777652f542b6ef62797246e8c7caddecb32cc7" 62 | integrity sha512-aSPRm2CvA9R8QyU5eXMFPd+cYkyxLsXHd2l5/FOH2V/eml//M04G6KZOmTap07O1PvEwNcl2NndyLfK8g3QrKA== 63 | dependencies: 64 | ansi-regex "^5.0.1" 65 | aproba "^1.0.3 || ^2.0.0" 66 | color-support "^1.1.3" 67 | console-control-strings "^1.1.0" 68 | has-unicode "^2.0.1" 69 | signal-exit "^3.0.7" 70 | string-width "^4.2.3" 71 | strip-ansi "^6.0.1" 72 | wide-align "^1.1.5" 73 | 74 | graceful-fs@^4.1.6, graceful-fs@^4.2.0: 75 | version "4.2.9" 76 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" 77 | integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== 78 | 79 | has-unicode@^2.0.1: 80 | version "2.0.1" 81 | resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" 82 | integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= 83 | 84 | inherits@^2.0.3: 85 | version "2.0.4" 86 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 87 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 88 | 89 | is-fullwidth-code-point@^3.0.0: 90 | version "3.0.0" 91 | resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" 92 | integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== 93 | 94 | jsonfile@^6.0.1: 95 | version "6.1.0" 96 | resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" 97 | integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== 98 | dependencies: 99 | universalify "^2.0.0" 100 | optionalDependencies: 101 | graceful-fs "^4.1.6" 102 | 103 | npmlog@^6.0.1: 104 | version "6.0.1" 105 | resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.1.tgz#06f1344a174c06e8de9c6c70834cfba2964bba17" 106 | integrity sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg== 107 | dependencies: 108 | are-we-there-yet "^3.0.0" 109 | console-control-strings "^1.1.0" 110 | gauge "^4.0.0" 111 | set-blocking "^2.0.0" 112 | 113 | readable-stream@^3.6.0: 114 | version "3.6.0" 115 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" 116 | integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== 117 | dependencies: 118 | inherits "^2.0.3" 119 | string_decoder "^1.1.1" 120 | util-deprecate "^1.0.1" 121 | 122 | safe-buffer@~5.2.0: 123 | version "5.2.1" 124 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" 125 | integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== 126 | 127 | set-blocking@^2.0.0: 128 | version "2.0.0" 129 | resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" 130 | integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= 131 | 132 | signal-exit@^3.0.7: 133 | version "3.0.7" 134 | resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" 135 | integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== 136 | 137 | "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: 138 | version "4.2.3" 139 | resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" 140 | integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== 141 | dependencies: 142 | emoji-regex "^8.0.0" 143 | is-fullwidth-code-point "^3.0.0" 144 | strip-ansi "^6.0.1" 145 | 146 | string_decoder@^1.1.1: 147 | version "1.3.0" 148 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" 149 | integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== 150 | dependencies: 151 | safe-buffer "~5.2.0" 152 | 153 | strip-ansi@^6.0.1: 154 | version "6.0.1" 155 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" 156 | integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== 157 | dependencies: 158 | ansi-regex "^5.0.1" 159 | 160 | universalify@^2.0.0: 161 | version "2.0.0" 162 | resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" 163 | integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== 164 | 165 | util-deprecate@^1.0.1: 166 | version "1.0.2" 167 | resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 168 | integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= 169 | 170 | wide-align@^1.1.5: 171 | version "1.1.5" 172 | resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3" 173 | integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg== 174 | dependencies: 175 | string-width "^1.0.2 || 2 || 3 || 4" 176 | -------------------------------------------------------------------------------- /packages/commands/go/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 18 | 19 | **Note:** Version bump only for package @der-cli/publish 20 | 21 | 22 | 23 | 24 | 25 | ## [0.5.2](https://github.com/der-cli/der-cli/compare/v0.5.0...v0.5.2) (2022-03-15) 26 | 27 | **Note:** Version bump only for package @der-cli/publish 28 | 29 | 30 | 31 | 32 | 33 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 34 | 35 | 36 | ### Features 37 | 38 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 39 | 40 | 41 | 42 | 43 | 44 | ## [0.4.6](https://github.com/der-cli/der-cli/compare/v0.4.5...v0.4.6) (2022-03-12) 45 | 46 | 47 | ### Performance Improvements 48 | 49 | * emmm ([c5637fd](https://github.com/der-cli/der-cli/commit/c5637fde98ef0f47f1b402d6b1ab33c3a4ead37b)) 50 | 51 | 52 | 53 | 54 | 55 | ## [0.4.5](https://github.com/der-cli/der-cli/compare/v0.4.4...v0.4.5) (2022-03-12) 56 | 57 | 58 | ### Performance Improvements 59 | 60 | * cut down go check ([2305f64](https://github.com/der-cli/der-cli/commit/2305f64db6206439eb79d0021ddc52a814ba2392)) 61 | 62 | 63 | 64 | 65 | 66 | ## [0.4.4](https://github.com/der-cli/der-cli/compare/v0.4.3...v0.4.4) (2022-03-12) 67 | 68 | **Note:** Version bump only for package @der-cli/publish 69 | 70 | 71 | 72 | 73 | 74 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 75 | 76 | **Note:** Version bump only for package @der-cli/publish 77 | 78 | 79 | 80 | 81 | 82 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 83 | 84 | **Note:** Version bump only for package @der-cli/publish 85 | 86 | 87 | 88 | 89 | 90 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 91 | 92 | **Note:** Version bump only for package @der-cli/publish 93 | 94 | 95 | 96 | 97 | 98 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 99 | 100 | **Note:** Version bump only for package @der-cli/publish 101 | -------------------------------------------------------------------------------- /packages/commands/go/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/publish` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const publish = require('@der-cli/publish'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/go/__tests__/publish.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const publish = require('..'); 4 | 5 | describe('@der-cli/publish', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/commands/go/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_PACKAGE_JSON_NOT_FOUND = () => { 2 | throw new Error('[Go] package.json不存在'); 3 | } 4 | 5 | const Error_PACKAGE_JSON_INFO_NOT_COMPLETE = () => { 6 | throw new Error('[Go] package.json信息不完整, 请检查name, version属性是否填写'); 7 | } 8 | 9 | module.exports = { 10 | Error_PACKAGE_JSON_NOT_FOUND, 11 | Error_PACKAGE_JSON_INFO_NOT_COMPLETE 12 | } -------------------------------------------------------------------------------- /packages/commands/go/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const fse = require('fs-extra'); 6 | const Command = require('@der-cli/command'); 7 | const Git = require('@der-cli/git'); 8 | const log = require('@der-cli/log'); 9 | const { 10 | Error_PACKAGE_JSON_NOT_FOUND, 11 | Error_PACKAGE_JSON_INFO_NOT_COMPLETE 12 | } = require('./error') 13 | 14 | class PublishCommand extends Command { 15 | init() { 16 | // 参数处理 17 | this.options = { 18 | ...this._argv[0] 19 | } 20 | } 21 | 22 | async exec() { 23 | try { 24 | const startTime = new Date().getTime(); 25 | // 1.初始化检查 26 | this.prepare() 27 | // 2.Git Flow自动化 28 | const git = new Git(this.projectInfo, this.options); 29 | await git.prepare(); // 代码提交准备、初始化仓库 30 | await git.commit(); // 提交代码 31 | if (this.options.release === true) { 32 | await git.releaseTag(startTime); // 发布 tag 33 | } 34 | } catch (e) { 35 | log.error(e.message); 36 | if (process.env.DER_CLI_LOG_LEVEL === 'verbose') { 37 | console.log(e); 38 | } 39 | } 40 | } 41 | 42 | prepare() { 43 | // 1.检查项目是否为npm项目 44 | const projectPath = process.cwd(); 45 | const pkgPath = path.join(projectPath, 'package.json'); 46 | log.verbose('[Go] 项目包路径:', pkgPath); 47 | if (!fs.existsSync(pkgPath)) { 48 | Error_PACKAGE_JSON_NOT_FOUND() 49 | } 50 | // 2.检查是否包含name、version、build字段 51 | const pkg = fse.readJsonSync(pkgPath); 52 | const { name, version, scripts } = pkg; 53 | // log.verbose('package.json:', name, version, scripts); 54 | if (!name || !version) { 55 | Error_PACKAGE_JSON_INFO_NOT_COMPLETE() 56 | } 57 | 58 | this.projectInfo = { name, version, dir: projectPath }; 59 | } 60 | } 61 | 62 | function init(argv) { 63 | return new PublishCommand(argv); 64 | } 65 | 66 | module.exports = init 67 | module.exports.PublishCommand = PublishCommand; -------------------------------------------------------------------------------- /packages/commands/go/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/publish", 3 | "version": "0.5.5", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | }, 29 | "dependencies": { 30 | "@der-cli/command": "^0.5.5", 31 | "@der-cli/git": "^0.5.5", 32 | "@der-cli/log": "^0.5.0" 33 | }, 34 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 35 | } 36 | -------------------------------------------------------------------------------- /packages/commands/init/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 18 | 19 | **Note:** Version bump only for package @der-cli/init 20 | 21 | 22 | 23 | 24 | 25 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 26 | 27 | **Note:** Version bump only for package @der-cli/init 28 | 29 | 30 | 31 | 32 | 33 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 34 | 35 | **Note:** Version bump only for package @der-cli/init 36 | 37 | 38 | 39 | 40 | 41 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 42 | 43 | 44 | ### Bug Fixes 45 | 46 | * 修复了控制台打印效果 ([b1842e4](https://github.com/der-cli/der-cli/commit/b1842e40169e39ebe56608995e0ea73ad00bcac9)) 47 | 48 | 49 | 50 | 51 | 52 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 53 | 54 | **Note:** Version bump only for package @der-cli/init 55 | -------------------------------------------------------------------------------- /packages/commands/init/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/init` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const init = require('@der-cli/init'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/init/__tests__/init.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const init = require('..'); 4 | 5 | describe('@der-cli/init', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/commands/init/lib/const.js: -------------------------------------------------------------------------------- 1 | const TYPE_PROJECT = 'project'; 2 | const TYPE_COMPONENT = 'component'; 3 | const COMPONENT_FILE = '.componentrc'; 4 | const TEMPLATE_TYPE_NORMAL = 'normal'; 5 | const TEMPLATE_TYPE_CUSTOM = 'custom'; 6 | const WHITE_COMMAND = ['npm', 'cnpm', 'yarn']; 7 | 8 | module.exports = { 9 | TYPE_PROJECT, 10 | TYPE_COMPONENT, 11 | TEMPLATE_TYPE_NORMAL, 12 | TEMPLATE_TYPE_CUSTOM, 13 | WHITE_COMMAND, 14 | COMPONENT_FILE 15 | } -------------------------------------------------------------------------------- /packages/commands/init/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_PROJECT_TEMPLATE_IS_NOT_EXSITS = () => { 2 | throw new Error('[Init] 模板不存在') 3 | } 4 | 5 | const Error_PROJECT_NAME_IS_INVALID = (title) => { 6 | return `[Init] 请输入合法的${title}名称(eg:derderder/der-cli)` 7 | } 8 | 9 | const Error_PROJECT_VERSION_IS_INVALID = () => { 10 | return '[Init] 请输入合法的版本号(eg:1.0.0)' 11 | } 12 | 13 | const Error_UNRECOGNIZED_TEMPLATE_TYPE = () => { 14 | throw new Error('[Init] 无法识别项目模板类型'); 15 | } 16 | 17 | const Error_TEMPLATE_INFO_IS_NOT_EXISTS = () => { 18 | throw new Error('[Init] 项目模板信息不存在'); 19 | } 20 | 21 | const Error_DEPENDENCY_INSTALLATION_FAILD = () => { 22 | return '[Init] 依赖安装失败'; 23 | } 24 | 25 | const Error_NPM_START_FAILD = () => { 26 | return '[Init] 启动执行命令失败' 27 | } 28 | 29 | const Error_COMMAND_IS_NOT_EXISTS = (command) => { 30 | throw new Error(`[Init] 命令 ${command} 不存在`); 31 | } 32 | 33 | const Error_COMPONENT_DESCRIPTION_INFO_IS_EMPTY = () => { 34 | return '[Init] 请输入组件描述信息' 35 | } 36 | 37 | const Error_COSTOM_TEMPLATE_INDEX_IS_NOT_EXISTS = () => { 38 | throw new Error('[Init] 自定义模板入口文件不存在!'); 39 | } 40 | 41 | module.exports = { 42 | Error_PROJECT_TEMPLATE_IS_NOT_EXSITS, 43 | Error_PROJECT_NAME_IS_INVALID, 44 | Error_PROJECT_VERSION_IS_INVALID, 45 | Error_UNRECOGNIZED_TEMPLATE_TYPE, 46 | Error_TEMPLATE_INFO_IS_NOT_EXISTS, 47 | Error_DEPENDENCY_INSTALLATION_FAILD, 48 | Error_NPM_START_FAILD, 49 | Error_COMMAND_IS_NOT_EXISTS, 50 | Error_COMPONENT_DESCRIPTION_INFO_IS_EMPTY, 51 | Error_COSTOM_TEMPLATE_INDEX_IS_NOT_EXISTS 52 | } -------------------------------------------------------------------------------- /packages/commands/init/lib/getProjectTemplate.js: -------------------------------------------------------------------------------- 1 | const request = require('@der-cli/request'); 2 | 3 | module.exports = function () { 4 | return request({ 5 | url: '/project/tpl', 6 | }); 7 | }; -------------------------------------------------------------------------------- /packages/commands/init/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/init", 3 | "version": "0.5.5", 4 | "description": "der-cli init", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "dependencies": { 23 | "@der-cli/command": "^0.5.5", 24 | "@der-cli/log": "^0.5.0", 25 | "@der-cli/package": "^0.5.5", 26 | "@der-cli/request": "^0.5.0", 27 | "@der-cli/utils": "^0.5.0", 28 | "ejs": "^3.1.6", 29 | "fs-extra": "^10.0.0", 30 | "glob": "^7.2.0", 31 | "inquirer": "^8.2.0", 32 | "kebab-case": "^1.0.1", 33 | "semver": "^7.3.5", 34 | "spinner": "^0.3.4" 35 | }, 36 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 37 | } 38 | -------------------------------------------------------------------------------- /packages/commands/tpl/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | **Note:** Version bump only for package @der-cli/tpl 9 | 10 | 11 | 12 | 13 | 14 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 15 | 16 | **Note:** Version bump only for package @der-cli/tpl 17 | 18 | 19 | 20 | 21 | 22 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 23 | 24 | **Note:** Version bump only for package @der-cli/tpl 25 | 26 | 27 | 28 | 29 | 30 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 31 | 32 | **Note:** Version bump only for package @der-cli/tpl 33 | 34 | 35 | 36 | 37 | 38 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 39 | 40 | **Note:** Version bump only for package @der-cli/tpl 41 | -------------------------------------------------------------------------------- /packages/commands/tpl/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/tpl` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const tpl = require('@der-cli/tpl'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/commands/tpl/__tests__/tpl.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const tpl = require('..'); 4 | 5 | describe('@der-cli/tpl', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/commands/tpl/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_PROJECT_TEMPLATE_IS_NOT_EXSITS = () => { 2 | throw new Error('[Tpl] 模板不存在') 3 | } 4 | 5 | module.exports = { 6 | Error_PROJECT_TEMPLATE_IS_NOT_EXSITS 7 | } -------------------------------------------------------------------------------- /packages/commands/tpl/lib/getProjectTemplate.js: -------------------------------------------------------------------------------- 1 | const request = require('@der-cli/request'); 2 | 3 | module.exports = function () { 4 | return request({ 5 | url: '/project/tpl', 6 | }); 7 | }; -------------------------------------------------------------------------------- /packages/commands/tpl/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const colors = require('colors/safe'); 4 | const Command = require('@der-cli/command'); 5 | const log = require('@der-cli/log'); 6 | const getProjectTemplate = require('./getProjectTemplate'); 7 | const { Error_PROJECT_TEMPLATE_IS_NOT_EXSITS } = require('./error'); 8 | 9 | class TplCommand extends Command { 10 | init() { 11 | // 参数处理 12 | this.options = { 13 | ...this._argv[0] 14 | } 15 | } 16 | 17 | async exec() { 18 | try { 19 | const template = await getProjectTemplate() 20 | if (!template || template.length === 0) { 21 | Error_PROJECT_TEMPLATE_IS_NOT_EXSITS() 22 | } 23 | 24 | if (!this.options.pro && !this.options.com) { 25 | this.template = template; 26 | } else { 27 | const type = this.options.com ? 'component' : 'project'; 28 | this.template = template.filter(tpl => 29 | tpl.tag.includes(type)); 30 | } 31 | 32 | this.fmtNameAndLog() 33 | } catch (e) { 34 | log.error(e.message); 35 | if (process.env.DER_CLI_LOG_LEVEL === 'verbose') { 36 | console.log(e); 37 | } 38 | } 39 | } 40 | 41 | fmtNameAndLog() { 42 | console.log(); 43 | log.notice(`******** TEMPLATES ********`); 44 | this.template.forEach((tpl, index) => { 45 | console.log(colors.cyan(` [${index + 1}] ${tpl.name} -- v${tpl.version}`)); 46 | }) 47 | } 48 | } 49 | 50 | function init(argv) { 51 | return new TplCommand(argv); 52 | } 53 | 54 | module.exports = init 55 | module.exports.TplCommand = TplCommand; -------------------------------------------------------------------------------- /packages/commands/tpl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/tpl", 3 | "version": "0.5.5", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | }, 29 | "dependencies": { 30 | "@der-cli/command": "^0.5.5", 31 | "@der-cli/log": "^0.5.0", 32 | "@der-cli/request": "^0.5.0", 33 | "colors": "^1.4.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/commands/tpl/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@der-cli/command@^0.3.0": 6 | version "0.3.0" 7 | resolved "https://registry.yarnpkg.com/@der-cli/command/-/command-0.3.0.tgz#62eed450e31ebb22dd5fa80eda4085e22333825d" 8 | integrity sha512-Q4S69GSXOv49zKUeSsrwHx145INacawNhjNAai28rpmkz7iGkeSB3Cd0hhxmIEWuW9YBIlMNUv8XKEXeeLIepg== 9 | dependencies: 10 | "@der-cli/log" "^0.3.0" 11 | colors "^1.4.0" 12 | 13 | "@der-cli/log@^0.3.0": 14 | version "0.3.0" 15 | resolved "https://registry.yarnpkg.com/@der-cli/log/-/log-0.3.0.tgz#d49b7a36eddd30e7117eecdc7dc1df8cda860748" 16 | integrity sha512-GX42Eo+WMVwgMSyCOxoEPcbSUkFUmUjMIevAY/63dkDiHYfPZrMd8ZYcfM5F9VrM1wzaMlZN55BGcwxmx4fVvA== 17 | dependencies: 18 | npmlog "^6.0.1" 19 | 20 | "@der-cli/request@^0.3.0": 21 | version "0.3.0" 22 | resolved "https://registry.yarnpkg.com/@der-cli/request/-/request-0.3.0.tgz#aeec7bee8886f6cfc7fb9f922aee715168228f5f" 23 | integrity sha512-7YTs95TIOhSqmhU+/4wK3V7XH6cwYhddMmb0C13kB5pNDFn5/ObTqprQo+f424RSTlWXqu2soEpOm+z4f78lWw== 24 | dependencies: 25 | axios "^0.26.0" 26 | 27 | ansi-regex@^5.0.1: 28 | version "5.0.1" 29 | resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" 30 | integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== 31 | 32 | "aproba@^1.0.3 || ^2.0.0": 33 | version "2.0.0" 34 | resolved "https://registry.yarnpkg.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc" 35 | integrity sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ== 36 | 37 | are-we-there-yet@^3.0.0: 38 | version "3.0.0" 39 | resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d" 40 | integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw== 41 | dependencies: 42 | delegates "^1.0.0" 43 | readable-stream "^3.6.0" 44 | 45 | axios@^0.26.0: 46 | version "0.26.0" 47 | resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" 48 | integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== 49 | dependencies: 50 | follow-redirects "^1.14.8" 51 | 52 | color-support@^1.1.3: 53 | version "1.1.3" 54 | resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" 55 | integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== 56 | 57 | colors@^1.4.0: 58 | version "1.4.0" 59 | resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" 60 | integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== 61 | 62 | console-control-strings@^1.1.0: 63 | version "1.1.0" 64 | resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" 65 | integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= 66 | 67 | delegates@^1.0.0: 68 | version "1.0.0" 69 | resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" 70 | integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= 71 | 72 | emoji-regex@^8.0.0: 73 | version "8.0.0" 74 | resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" 75 | integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== 76 | 77 | follow-redirects@^1.14.8: 78 | version "1.14.9" 79 | resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" 80 | integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== 81 | 82 | gauge@^4.0.0: 83 | version "4.0.2" 84 | resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.2.tgz#c3777652f542b6ef62797246e8c7caddecb32cc7" 85 | integrity sha512-aSPRm2CvA9R8QyU5eXMFPd+cYkyxLsXHd2l5/FOH2V/eml//M04G6KZOmTap07O1PvEwNcl2NndyLfK8g3QrKA== 86 | dependencies: 87 | ansi-regex "^5.0.1" 88 | aproba "^1.0.3 || ^2.0.0" 89 | color-support "^1.1.3" 90 | console-control-strings "^1.1.0" 91 | has-unicode "^2.0.1" 92 | signal-exit "^3.0.7" 93 | string-width "^4.2.3" 94 | strip-ansi "^6.0.1" 95 | wide-align "^1.1.5" 96 | 97 | has-unicode@^2.0.1: 98 | version "2.0.1" 99 | resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" 100 | integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= 101 | 102 | inherits@^2.0.3: 103 | version "2.0.4" 104 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 105 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 106 | 107 | is-fullwidth-code-point@^3.0.0: 108 | version "3.0.0" 109 | resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" 110 | integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== 111 | 112 | npmlog@^6.0.1: 113 | version "6.0.1" 114 | resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.1.tgz#06f1344a174c06e8de9c6c70834cfba2964bba17" 115 | integrity sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg== 116 | dependencies: 117 | are-we-there-yet "^3.0.0" 118 | console-control-strings "^1.1.0" 119 | gauge "^4.0.0" 120 | set-blocking "^2.0.0" 121 | 122 | readable-stream@^3.6.0: 123 | version "3.6.0" 124 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" 125 | integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== 126 | dependencies: 127 | inherits "^2.0.3" 128 | string_decoder "^1.1.1" 129 | util-deprecate "^1.0.1" 130 | 131 | safe-buffer@~5.2.0: 132 | version "5.2.1" 133 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" 134 | integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== 135 | 136 | set-blocking@^2.0.0: 137 | version "2.0.0" 138 | resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" 139 | integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= 140 | 141 | signal-exit@^3.0.7: 142 | version "3.0.7" 143 | resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" 144 | integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== 145 | 146 | "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: 147 | version "4.2.3" 148 | resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" 149 | integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== 150 | dependencies: 151 | emoji-regex "^8.0.0" 152 | is-fullwidth-code-point "^3.0.0" 153 | strip-ansi "^6.0.1" 154 | 155 | string_decoder@^1.1.1: 156 | version "1.3.0" 157 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" 158 | integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== 159 | dependencies: 160 | safe-buffer "~5.2.0" 161 | 162 | strip-ansi@^6.0.1: 163 | version "6.0.1" 164 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" 165 | integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== 166 | dependencies: 167 | ansi-regex "^5.0.1" 168 | 169 | util-deprecate@^1.0.1: 170 | version "1.0.2" 171 | resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 172 | integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= 173 | 174 | wide-align@^1.1.5: 175 | version "1.1.5" 176 | resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3" 177 | integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg== 178 | dependencies: 179 | string-width "^1.0.2 || 2 || 3 || 4" 180 | -------------------------------------------------------------------------------- /packages/core/cli/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | **Note:** Version bump only for package @der-cli/core 9 | 10 | 11 | 12 | 13 | 14 | ## [0.5.4](https://github.com/der-cli/der-cli/compare/v0.5.3...v0.5.4) (2022-05-01) 15 | 16 | **Note:** Version bump only for package @der-cli/core 17 | 18 | 19 | 20 | 21 | 22 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 23 | 24 | **Note:** Version bump only for package @der-cli/core 25 | 26 | 27 | 28 | 29 | 30 | ## [0.5.2](https://github.com/der-cli/der-cli/compare/v0.5.0...v0.5.2) (2022-03-15) 31 | 32 | 33 | ### Performance Improvements 34 | 35 | * up ([e0caec1](https://github.com/der-cli/der-cli/commit/e0caec1bdafb33b6f3f2c048306222c40f512b29)) 36 | 37 | 38 | 39 | 40 | 41 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 42 | 43 | 44 | ### Features 45 | 46 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 47 | 48 | 49 | 50 | 51 | 52 | ## [0.4.7](https://github.com/der-cli/der-cli/compare/v0.4.6...v0.4.7) (2022-03-12) 53 | 54 | **Note:** Version bump only for package @der-cli/core 55 | 56 | 57 | 58 | 59 | 60 | ## [0.4.4](https://github.com/der-cli/der-cli/compare/v0.4.3...v0.4.4) (2022-03-12) 61 | 62 | 63 | ### Performance Improvements 64 | 65 | * 优化发布前检查流程 ([70cda90](https://github.com/der-cli/der-cli/commit/70cda90e1558bc400ccfc114b5d2dd56278ef106)) 66 | 67 | 68 | 69 | 70 | 71 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 72 | 73 | **Note:** Version bump only for package @der-cli/core 74 | 75 | 76 | 77 | 78 | 79 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 80 | 81 | **Note:** Version bump only for package @der-cli/core 82 | 83 | 84 | 85 | 86 | 87 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 88 | 89 | 90 | ### Bug Fixes 91 | 92 | * 修复了控制台打印效果 ([b1842e4](https://github.com/der-cli/der-cli/commit/b1842e40169e39ebe56608995e0ea73ad00bcac9)) 93 | 94 | 95 | 96 | 97 | 98 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 99 | 100 | **Note:** Version bump only for package @der-cli/core 101 | -------------------------------------------------------------------------------- /packages/core/cli/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/core` 2 | 3 | > der-cli/core is a CLI tool for der-cli. 4 | 5 | ## Usage 6 | 7 | ``` 8 | \(^o^)/~ 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /packages/core/cli/__tests__/core.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const core = require('..'); 4 | 5 | describe('core', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/core/cli/bin/index.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | const importLocal = require('import-local'); 4 | const log = require('@der-cli/log'); 5 | 6 | // 生产/开发环境 7 | if (importLocal(__filename)) { 8 | log.info('cli', '欢迎━(*`∀´*)ノ亻! 使用 der-cli 本地版本') 9 | } else { 10 | require('../lib')(process.argv.slice(2)); 11 | } -------------------------------------------------------------------------------- /packages/core/cli/lib/const.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | const locale = require('@der-cli/locale'); 3 | 4 | const DEFAULT_CLI_HOME = '.der-cli'; 5 | 6 | const DER_CLI_LOGO = colors.cyan(` ________ 7 | ___ __ \\____________ 8 | __ / / / _ \\_ ___/ 9 | _ /_/ // __/ / ${colors.white(locale.welcome)} 10 | /_____/ \\___//_/ ${colors.green('')} with ${colors.red('♥')} by yesmore ©2022 11 | `) 12 | 13 | module.exports = { 14 | DEFAULT_CLI_HOME, 15 | DER_CLI_LOGO, 16 | }; -------------------------------------------------------------------------------- /packages/core/cli/lib/error.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | 3 | const Error_USER_HOME_NOT_EXISTS = () => { 4 | throw new Error(colors.red('[Core/cli] 当前登录用户主目录不存在!')); 5 | } 6 | 7 | const Error_ROOT_USER = () => { 8 | return colors.red('[Core/cli] 请避免使用 root 账户启动本应用') 9 | } 10 | 11 | const Error_NPM_VERSION = (npmName, currentVersion, lastVersion) => { 12 | return colors.yellow(`[Core/cli] 更新说明: ${npmName}@${lastVersion} 为最新版本 13 | 当前版本: ${currentVersion} => ${lastVersion}, 建议手动更新 14 | 更新命令: npm install -g ${npmName}`); 15 | } 16 | 17 | const Error_UNKNOWN_CMD = (cmd) => { 18 | return colors.red('[Core/cli] 未知的命令: ' + cmd) 19 | } 20 | 21 | const Error_ALL_CMDS = (cmds) => { 22 | return colors.white('[Core/cli] 可用命令: ' + cmds.join(' ')) 23 | } 24 | 25 | module.exports = { 26 | Error_USER_HOME_NOT_EXISTS, 27 | Error_ROOT_USER, 28 | Error_NPM_VERSION, 29 | Error_UNKNOWN_CMD, 30 | Error_ALL_CMDS 31 | } -------------------------------------------------------------------------------- /packages/core/cli/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = core; 4 | 5 | const path = require('path'); 6 | const semver = require('semver'); 7 | const { homedir } = require('os') 8 | const userHome = homedir(); 9 | const pathExists = require('path-exists').sync; 10 | const { Command } = require('commander'); 11 | const rootCheck = require('root-check'); 12 | const pkg = require('../package.json'); 13 | const log = require('@der-cli/log'); 14 | const exec = require('@der-cli/exec'); 15 | const { 16 | DEFAULT_CLI_HOME, 17 | DER_CLI_LOGO 18 | } = require('./const'); 19 | const { 20 | Error_USER_HOME_NOT_EXISTS, 21 | Error_ROOT_USER, 22 | Error_NPM_VERSION, 23 | Error_UNKNOWN_CMD, 24 | Error_ALL_CMDS 25 | } = require('./error'); 26 | 27 | const program = new Command(); 28 | 29 | // let args; 30 | 31 | async function core() { 32 | try { 33 | await prepare(); 34 | registerCommand(); 35 | } catch (e) { 36 | log.error(`${e}`); 37 | if (program.debug) { 38 | console.log(e); 39 | } 40 | } 41 | } 42 | 43 | // 1.准备 44 | async function prepare() { 45 | printLogo() 46 | checkPkgVersion(); 47 | checkRoot(); 48 | checkUserHome(); 49 | checkEnv(); 50 | await checkGlobalUpdate(); 51 | } 52 | 53 | // 2.脚手架初始化: 注册命令 54 | function registerCommand() { 55 | const options = program.opts(); 56 | 57 | program 58 | .name(Object.keys(pkg.bin)[0]) // der 59 | .description(pkg.description) 60 | .usage(' [options]') 61 | .version(pkg.version) 62 | .option('-d, --debug', '开启调试模式', false) 63 | .option('-tp, --targetPath ', '指定本地调试文件路径', ''); 64 | 65 | program 66 | .command('init [projectName]') 67 | .description('初始化项目') 68 | .option('-f, --force', '强制初始化项目(Clear folder)') 69 | .action(exec) // 子进程 ☆ 70 | 71 | program 72 | .command('go') 73 | .description('发布项目') 74 | .option('-rs, --refreshServer', '强制更新本地Git平台缓存', false) 75 | .option('-rt, --refreshToken', '强制更新本地Git Token缓存', false) 76 | .option('-ro, --refreshOwner', '强制更新Git Owner信息', false) 77 | .option('-re, --release', '发布Tag版本', false) 78 | .option('-f, --force', '强制更新所有缓存信息(TODO)', false) 79 | .action(exec) 80 | 81 | program 82 | .command('tpl') 83 | .description('查看所有模板') 84 | .option('--pro', '查看所有项目模板', false) 85 | .option('--com', '查看所有组件模板', false) 86 | .action(exec) 87 | 88 | program 89 | .command('cache') 90 | .description('查看本地缓存') 91 | .option('-ca, --all', '查看本地所有缓存信息', false) 92 | .option('-cg, --git', '查看本地Git缓存信息', false) 93 | .option('-ct, --template', '查看本地模板缓存信息', false) 94 | .option('-cd, --dependencies', '查看本地依赖缓存信息', false) 95 | .option('-cs, --token', '查看App Token', false) 96 | .action(exec) 97 | 98 | program 99 | .command('clean') 100 | .description('清空缓存文件') 101 | .option('-a, --all', '清空全部') 102 | .option('--dep', '清空依赖文件') 103 | .action(exec) 104 | 105 | 106 | // 开启debug模式 107 | program.on('option:debug', function () { 108 | if (options.debug) { 109 | process.env.DER_CLI_LOG_LEVEL = 'verbose'; 110 | } else { 111 | process.env.DER_CLI_LOG_LEVEL = 'info'; 112 | } 113 | log.level = process.env.DER_CLI_LOG_LEVEL; 114 | log.verbose('[Core/cli]', 'You have turned on debugging.'); 115 | }); 116 | 117 | // 指定targetPath 118 | program.on('option:targetPath', function () { 119 | // 保存targetPath 120 | process.env.DER_CLI_TARGET_PATH = options.targetPath; 121 | }); 122 | 123 | // 对未知命令监听 124 | program.on('command:*', function (obj) { 125 | // All CMDS 126 | const availableCommands = program.commands.map(cmd => cmd.name()); 127 | log.warn(Error_UNKNOWN_CMD(obj[0])); 128 | if (availableCommands.length > 0) { 129 | log.warn(Error_ALL_CMDS(availableCommands)); 130 | } 131 | }); 132 | 133 | program.parse(process.argv); 134 | 135 | // der init/create/... 136 | if (program.args && program.args.length < 1) { 137 | // output help information without exiting 138 | program.outputHelp(); 139 | console.log(); 140 | } 141 | } 142 | 143 | // 1.0 der logo 144 | function printLogo() { 145 | console.log(DER_CLI_LOGO); 146 | } 147 | 148 | // 1.1 检查 @der-cli/core 版本号 149 | function checkPkgVersion() { 150 | log.info('[Core/cli]', `${pkg.name}@${pkg.version}`); 151 | } 152 | 153 | // 1.2 检查是否为root用户启动 154 | function checkRoot() { 155 | rootCheck(Error_ROOT_USER()); 156 | } 157 | 158 | // 1.3 检查用户主目录 159 | function checkUserHome() { 160 | if (!userHome || !pathExists(userHome)) { 161 | Error_USER_HOME_NOT_EXISTS() 162 | } 163 | } 164 | 165 | // 1.4 检查环境变量 166 | function checkEnv() { 167 | const dotenv = require('dotenv'); 168 | // 检查本地是否存在 .env 文件 169 | const dotenvPath = path.resolve(userHome, '.env'); 170 | 171 | if (pathExists(dotenvPath)) { 172 | dotenv.config({ 173 | path: dotenvPath, 174 | }); 175 | } 176 | createDefaultConfig(); 177 | // log.verbose('环境变量', process.env.DER_CLI_HOME_PATH); 178 | // C:\Users\hostname\.der-cli 179 | } 180 | 181 | // 1.5 创建默认配置文件 182 | function createDefaultConfig() { 183 | const cliConfig = { 184 | home: userHome, 185 | }; 186 | if (process.env.DER_CLI_HOME) { 187 | cliConfig['cliHome'] = path.join(userHome, process.env.DER_CLI_HOME); 188 | } else { 189 | cliConfig['cliHome'] = path.join(userHome, DEFAULT_CLI_HOME); 190 | } 191 | process.env.DER_CLI_HOME_PATH = cliConfig.cliHome; 192 | } 193 | 194 | // 1.6 检查是否需要全局更新 195 | async function checkGlobalUpdate() { 196 | // 获取当前信息 197 | const currentVersion = pkg.version; 198 | const npmName = pkg.name; 199 | // 获取 npm 所有版本号 200 | const { getNpmSemverVersion } = require('@der-cli/get-npm-info'); 201 | const lastVersion = await getNpmSemverVersion(currentVersion, npmName); 202 | // 判断是否需要更新 203 | if (lastVersion && semver.gt(lastVersion, currentVersion)) { 204 | log.warn(Error_NPM_VERSION(npmName, currentVersion, lastVersion)); 205 | } 206 | // else { 207 | // log.info('cli', `当前版本为最新版: v${currentVersion}`); 208 | // } 209 | } 210 | 211 | // TODO 212 | process.on('unhandleRejection', (reason, p) => { 213 | console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); 214 | throw reason; 215 | }) 216 | 217 | // 监听全局错误 218 | process.on('uncaughtException', (err) => { 219 | log.error('uncaughtException', err); 220 | process.exit(1); 221 | }) -------------------------------------------------------------------------------- /packages/core/cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/core", 3 | "version": "0.5.5", 4 | "description": "How to use der? 'Just derderder~'", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "bin/index.js", 9 | "bin": { 10 | "der": "bin/index.js" 11 | }, 12 | "directories": { 13 | "lib": "lib", 14 | "test": "__tests__" 15 | }, 16 | "files": [ 17 | "lib", 18 | "bin" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from core\"" 25 | }, 26 | "dependencies": { 27 | "@der-cli/exec": "^0.5.5", 28 | "@der-cli/get-npm-info": "^0.5.0", 29 | "@der-cli/init": "^0.5.5", 30 | "@der-cli/locale": "^0.5.0", 31 | "@der-cli/log": "^0.5.0", 32 | "colors": "^1.4.0", 33 | "commander": "^9.0.0", 34 | "dotenv": "^16.0.0", 35 | "import-local": "^3.1.0", 36 | "minimist": "^1.2.5", 37 | "root-check": "^1.0.0", 38 | "semver": "^7.3.5" 39 | }, 40 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 41 | } 42 | -------------------------------------------------------------------------------- /packages/core/exec/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 18 | 19 | **Note:** Version bump only for package @der-cli/exec 20 | 21 | 22 | 23 | 24 | 25 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 26 | 27 | **Note:** Version bump only for package @der-cli/exec 28 | 29 | 30 | 31 | 32 | 33 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 34 | 35 | **Note:** Version bump only for package @der-cli/exec 36 | 37 | 38 | 39 | 40 | 41 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 42 | 43 | **Note:** Version bump only for package @der-cli/exec 44 | 45 | 46 | 47 | 48 | 49 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 50 | 51 | 52 | ### Bug Fixes 53 | 54 | * 修复了控制台打印效果 ([b1842e4](https://github.com/der-cli/der-cli/commit/b1842e40169e39ebe56608995e0ea73ad00bcac9)) 55 | 56 | 57 | 58 | 59 | 60 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 61 | 62 | **Note:** Version bump only for package @der-cli/exec 63 | -------------------------------------------------------------------------------- /packages/core/exec/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/exec` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const exec = require('@der-cli/exec'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/core/exec/__tests__/exec.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const exec = require('..'); 4 | 5 | describe('@der-cli/exec', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/core/exec/lib/const.js: -------------------------------------------------------------------------------- 1 | // 默认本地依赖缓存路径 2 | const CACHE_DIR = 'dependencies'; 3 | 4 | // 默认推荐用户安装最新版 5 | const DEFAULT_CORE_PACKAGE_VERSION = 'latest'; 6 | 7 | // Cmd映射表: cmdName -> packageName 8 | const SETTINGS = { 9 | init: '@der-cli/init', 10 | go: '@der-cli/publish', 11 | clean: '@der-cli/clean', 12 | cache: '@der-cli/cache', 13 | tpl: '@der-cli/tpl', 14 | }; 15 | 16 | module.exports = { 17 | CACHE_DIR, 18 | DEFAULT_CORE_PACKAGE_VERSION, 19 | SETTINGS 20 | } -------------------------------------------------------------------------------- /packages/core/exec/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const Package = require('@der-cli/package'); 5 | const log = require('@der-cli/log'); 6 | const { exec: spawn } = require('@der-cli/utils'); 7 | const { 8 | CACHE_DIR, 9 | DEFAULT_CORE_PACKAGE_VERSION, 10 | SETTINGS 11 | } = require('./const'); 12 | 13 | /** 14 | * 执行命令, 开启子进程 15 | */ 16 | async function exec() { 17 | let targetPath = process.env.DER_CLI_TARGET_PATH; // -tp /xxx 18 | const homePath = process.env.DER_CLI_HOME_PATH; // C:\user\username\.der-cli 19 | 20 | let storeDir = ''; 21 | let pkg; 22 | log.verbose('[Core/exec] 检查调试区:', targetPath || '未指定(默认使用线上版本)'); 23 | log.verbose('[Core/exec] 检查缓存路径:', homePath); 24 | 25 | const cmdObj = arguments[arguments.length - 1]; 26 | const cmdName = cmdObj.name(); // init/create/... 27 | const packageName = SETTINGS[cmdName]; 28 | const packageVersion = DEFAULT_CORE_PACKAGE_VERSION; 29 | 30 | if (!targetPath) { 31 | targetPath = path.resolve(homePath, CACHE_DIR); // 生成缓存路径 32 | storeDir = path.resolve(targetPath, 'node_modules'); 33 | log.verbose('[Core/exec] No targetPath model.'); 34 | 35 | pkg = new Package({ 36 | targetPath, 37 | storeDir, 38 | packageName, 39 | packageVersion, 40 | }); 41 | 42 | // 若本地依赖缓存(C:/user/username/.der-cli/dependencies/node_modules/xxx_package)已存在,则检查/更新 43 | if (await pkg.exists()) { 44 | // 更新package 45 | await pkg.update(); 46 | } else { 47 | // 否则安装package 48 | await pkg.install(); 49 | } 50 | } else { 51 | pkg = new Package({ 52 | targetPath, 53 | packageName, 54 | packageVersion, 55 | }); 56 | } 57 | 58 | const rootFile = pkg.getRootFilePath(); 59 | // rootFile: C:/Users/username/.der-cli/dependencies/node_modules/_@der-cli_init@1.1.3@@der-cli/init/lib/index.js 60 | 61 | if (rootFile) { 62 | try { 63 | // 优化: 在node子进程中调用 64 | const args = Array.from(arguments); // 参数转数组 65 | const cmd = args[args.length - 1]; 66 | const o = Object.create(null); 67 | Object.keys(cmd).forEach(key => { // 过滤属性,减小args体积 68 | if (cmd.hasOwnProperty(key) && 69 | !key.startsWith('_') && 70 | key !== 'parent') { 71 | o[key] = cmd[key]; 72 | } 73 | }); 74 | 75 | args[args.length - 1] = o; 76 | // 动态执行 der-cli/init/lib/index.js 文件, 开启子进程 77 | const code = `require('${rootFile}').call(null, ${JSON.stringify(args)})`; 78 | const child = spawn('node', ['-e', code], { 79 | cwd: process.cwd(), 80 | stdio: 'inherit', // 控制台输出日志 81 | }); 82 | log.verbose(`[Core/exec] ${cmdName}命令进程:`, child.pid); 83 | child.on('error', e => { 84 | log.error(e); 85 | process.exit(1); 86 | }); 87 | child.on('exit', e => { 88 | console.log(); 89 | log.verbose(`[Core/exec] End with code ${e}.\n`); 90 | process.exit(e); 91 | }); 92 | } catch (e) { 93 | log.error(e); 94 | } 95 | } 96 | } 97 | 98 | module.exports = exec; -------------------------------------------------------------------------------- /packages/core/exec/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli-dev/exec", 3 | "version": "0.5.5", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@der-cli-dev/log": { 8 | "version": "file:../../utils/log", 9 | "requires": { 10 | "npmlog": "^6.0.1" 11 | }, 12 | "dependencies": { 13 | "ansi-regex": { 14 | "version": "5.0.1", 15 | "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", 16 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" 17 | }, 18 | "aproba": { 19 | "version": "2.0.0", 20 | "resolved": "https://registry.npmmirror.com/aproba/-/aproba-2.0.0.tgz", 21 | "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" 22 | }, 23 | "are-we-there-yet": { 24 | "version": "3.0.0", 25 | "resolved": "https://registry.npmmirror.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz", 26 | "integrity": "sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw==", 27 | "requires": { 28 | "delegates": "^1.0.0", 29 | "readable-stream": "^3.6.0" 30 | } 31 | }, 32 | "color-support": { 33 | "version": "1.1.3", 34 | "resolved": "https://registry.npmmirror.com/color-support/-/color-support-1.1.3.tgz", 35 | "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==" 36 | }, 37 | "console-control-strings": { 38 | "version": "1.1.0", 39 | "resolved": "https://registry.npmmirror.com/console-control-strings/-/console-control-strings-1.1.0.tgz", 40 | "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" 41 | }, 42 | "delegates": { 43 | "version": "1.0.0", 44 | "resolved": "https://registry.npmmirror.com/delegates/-/delegates-1.0.0.tgz", 45 | "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" 46 | }, 47 | "emoji-regex": { 48 | "version": "8.0.0", 49 | "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", 50 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" 51 | }, 52 | "gauge": { 53 | "version": "4.0.0", 54 | "resolved": "https://registry.npmmirror.com/gauge/-/gauge-4.0.0.tgz", 55 | "integrity": "sha512-F8sU45yQpjQjxKkm1UOAhf0U/O0aFt//Fl7hsrNVto+patMHjs7dPI9mFOGUKbhrgKm0S3EjW3scMFuQmWSROw==", 56 | "requires": { 57 | "ansi-regex": "^5.0.1", 58 | "aproba": "^1.0.3 || ^2.0.0", 59 | "color-support": "^1.1.2", 60 | "console-control-strings": "^1.0.0", 61 | "has-unicode": "^2.0.1", 62 | "signal-exit": "^3.0.0", 63 | "string-width": "^4.2.3", 64 | "strip-ansi": "^6.0.1", 65 | "wide-align": "^1.1.2" 66 | } 67 | }, 68 | "has-unicode": { 69 | "version": "2.0.1", 70 | "resolved": "https://registry.npmmirror.com/has-unicode/-/has-unicode-2.0.1.tgz", 71 | "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" 72 | }, 73 | "inherits": { 74 | "version": "2.0.4", 75 | "resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz", 76 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 77 | }, 78 | "is-fullwidth-code-point": { 79 | "version": "3.0.0", 80 | "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 81 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" 82 | }, 83 | "npmlog": { 84 | "version": "6.0.1", 85 | "resolved": "https://registry.npmmirror.com/npmlog/-/npmlog-6.0.1.tgz", 86 | "integrity": "sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg==", 87 | "requires": { 88 | "are-we-there-yet": "^3.0.0", 89 | "console-control-strings": "^1.1.0", 90 | "gauge": "^4.0.0", 91 | "set-blocking": "^2.0.0" 92 | } 93 | }, 94 | "readable-stream": { 95 | "version": "3.6.0", 96 | "resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-3.6.0.tgz", 97 | "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", 98 | "requires": { 99 | "inherits": "^2.0.3", 100 | "string_decoder": "^1.1.1", 101 | "util-deprecate": "^1.0.1" 102 | } 103 | }, 104 | "safe-buffer": { 105 | "version": "5.2.1", 106 | "resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz", 107 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 108 | }, 109 | "set-blocking": { 110 | "version": "2.0.0", 111 | "resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz", 112 | "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" 113 | }, 114 | "signal-exit": { 115 | "version": "3.0.7", 116 | "resolved": "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz", 117 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 118 | }, 119 | "string-width": { 120 | "version": "4.2.3", 121 | "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", 122 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 123 | "requires": { 124 | "emoji-regex": "^8.0.0", 125 | "is-fullwidth-code-point": "^3.0.0", 126 | "strip-ansi": "^6.0.1" 127 | } 128 | }, 129 | "string_decoder": { 130 | "version": "1.3.0", 131 | "resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.3.0.tgz", 132 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 133 | "requires": { 134 | "safe-buffer": "~5.2.0" 135 | } 136 | }, 137 | "strip-ansi": { 138 | "version": "6.0.1", 139 | "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", 140 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 141 | "requires": { 142 | "ansi-regex": "^5.0.1" 143 | } 144 | }, 145 | "util-deprecate": { 146 | "version": "1.0.2", 147 | "resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz", 148 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 149 | }, 150 | "wide-align": { 151 | "version": "1.1.5", 152 | "resolved": "https://registry.npmmirror.com/wide-align/-/wide-align-1.1.5.tgz", 153 | "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", 154 | "requires": { 155 | "string-width": "^1.0.2 || 2 || 3 || 4" 156 | } 157 | } 158 | } 159 | }, 160 | "@der-cli-dev/package": { 161 | "version": "file:../../models/package" 162 | }, 163 | "@der-cli-dev/utils": { 164 | "version": "file:../../utils/utils" 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /packages/core/exec/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/exec", 3 | "version": "0.5.5", 4 | "description": "动态init库", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "dependencies": { 23 | "@der-cli/log": "^0.5.0", 24 | "@der-cli/package": "^0.5.5", 25 | "@der-cli/utils": "^0.5.0" 26 | }, 27 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 28 | } 29 | -------------------------------------------------------------------------------- /packages/models/command/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 18 | 19 | 20 | ### Features 21 | 22 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 23 | 24 | 25 | 26 | 27 | 28 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 29 | 30 | **Note:** Version bump only for package @der-cli/command 31 | 32 | 33 | 34 | 35 | 36 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 37 | 38 | **Note:** Version bump only for package @der-cli/command 39 | -------------------------------------------------------------------------------- /packages/models/command/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/Command` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const command = require('@der-cli/Command'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/models/command/__tests__/Command.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const command = require('..'); 4 | 5 | describe('@der-cli/Command', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/models/command/lib/const.js: -------------------------------------------------------------------------------- 1 | const LOWEST_NODE_VERSION = '12.0.0' 2 | 3 | module.exports = { 4 | LOWEST_NODE_VERSION 5 | } -------------------------------------------------------------------------------- /packages/models/command/lib/error.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | 3 | const Error_EMPTY_ARGS = () => { 4 | throw new Error('[models/Command] 参数不能为空!'); 5 | } 6 | 7 | const Error_ARGS_IS_NOT_ARRAY = () => { 8 | throw new Error('[models/Command] 参数必须为数组!'); 9 | } 10 | 11 | const Error_ARGS_IS_EMPTY = () => { 12 | throw new Error('[models/Command] 参数列表为空!'); 13 | } 14 | 15 | const Error_INIT_IS_NOT_EXSITS = () => { 16 | throw new Error('[models/Command] init必须实现!'); 17 | } 18 | 19 | const Error_EXEC_IS_NOT_EXSITS = () => { 20 | throw new Error('[models/Command] exec必须实现!'); 21 | } 22 | 23 | const Error_NODE_VERSION_IS_TOO_LOW = (lowestVersion) => { 24 | throw new Error(colors.red(`[models/Command] der-cli 需要安装 v${lowestVersion} 以上版本的 Node.js (官网http://nodejs.cn/download/)`)); 25 | } 26 | 27 | module.exports = { 28 | Error_EMPTY_ARGS, 29 | Error_ARGS_IS_NOT_ARRAY, 30 | Error_ARGS_IS_EMPTY, 31 | Error_INIT_IS_NOT_EXSITS, 32 | Error_EXEC_IS_NOT_EXSITS, 33 | Error_NODE_VERSION_IS_TOO_LOW 34 | } -------------------------------------------------------------------------------- /packages/models/command/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const semver = require('semver'); 4 | const log = require('@der-cli/log'); 5 | const { LOWEST_NODE_VERSION } = require('./const'); 6 | const { 7 | Error_EMPTY_ARGS, 8 | Error_ARGS_IS_NOT_ARRAY, 9 | Error_ARGS_IS_EMPTY, 10 | Error_INIT_IS_NOT_EXSITS, 11 | Error_EXEC_IS_NOT_EXSITS, 12 | Error_NODE_VERSION_IS_TOO_LOW 13 | } = require('./error'); 14 | 15 | /** 16 | * Command 抽象类 17 | * 18 | * @class Command 19 | */ 20 | class Command { 21 | constructor(argv) { 22 | // log.verbose('Command', argv); 23 | 24 | if (!argv) { 25 | Error_EMPTY_ARGS() 26 | } 27 | if (!Array.isArray(argv)) { 28 | Error_ARGS_IS_NOT_ARRAY() 29 | } 30 | if (argv.length < 1) { 31 | Error_ARGS_IS_EMPTY() 32 | } 33 | this._argv = argv; 34 | 35 | // 执行初始化内容 36 | let runner = new Promise((resolve, reject) => { 37 | let _chain = Promise.resolve(); 38 | _chain = _chain.then(() => this.checkNodeVersion()); 39 | _chain = _chain.then(() => this.initArgs()); 40 | _chain = _chain.then(() => this.init()); 41 | _chain = _chain.then(() => this.exec()); 42 | _chain.catch(err => { 43 | log.error(err); 44 | }); 45 | }); 46 | } 47 | 48 | // 参数初始化 49 | initArgs() { 50 | this._cmd = this._argv[this._argv.length - 1]; 51 | this._argv = this._argv.slice(0, this._argv.length - 1); 52 | } 53 | 54 | // 检查 node.js 版本号 55 | checkNodeVersion() { 56 | // 获取当前版本号与最低版本号 57 | const currentVersion = process.version; 58 | const lowestVersion = LOWEST_NODE_VERSION; 59 | // 判断当前版本号是否比最低版本号低 60 | if (!semver.gte(currentVersion, lowestVersion)) { 61 | (Error_NODE_VERSION_IS_TOO_LOW(lowestVersion)) 62 | } 63 | } 64 | 65 | // 用户自定义init 66 | init() { 67 | Error_INIT_IS_NOT_EXSITS() 68 | } 69 | 70 | // 用户自定义exec 71 | exec() { 72 | Error_EXEC_IS_NOT_EXSITS() 73 | } 74 | } 75 | 76 | module.exports = Command; -------------------------------------------------------------------------------- /packages/models/command/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/command", 3 | "version": "0.5.5", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "dependencies": { 23 | "@der-cli/log": "^0.5.0", 24 | "colors": "^1.4.0" 25 | }, 26 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 27 | } 28 | -------------------------------------------------------------------------------- /packages/models/command/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@der-cli/log@^0.4.3": 6 | version "0.4.3" 7 | resolved "https://registry.yarnpkg.com/@der-cli/log/-/log-0.4.3.tgz#5b55fea5520a401e0008cc120c5044b83c4b012c" 8 | integrity sha512-/wtsqYqYR5cveBWnaEDPkd/8BfbAoICPDNA7MIOEJeJXQvN7oZBVKk5WMMMudybgabdDkG0wssNuJOaLxt7FTQ== 9 | dependencies: 10 | npmlog "^6.0.1" 11 | 12 | ansi-regex@^5.0.1: 13 | version "5.0.1" 14 | resolved "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" 15 | integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== 16 | 17 | "aproba@^1.0.3 || ^2.0.0": 18 | version "2.0.0" 19 | resolved "https://registry.npmmirror.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc" 20 | integrity sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ== 21 | 22 | are-we-there-yet@^3.0.0: 23 | version "3.0.0" 24 | resolved "https://registry.npmmirror.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d" 25 | integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw== 26 | dependencies: 27 | delegates "^1.0.0" 28 | readable-stream "^3.6.0" 29 | 30 | color-support@^1.1.2: 31 | version "1.1.3" 32 | resolved "https://registry.npmmirror.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" 33 | integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== 34 | 35 | colors@^1.4.0: 36 | version "1.4.0" 37 | resolved "https://registry.npmmirror.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" 38 | integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== 39 | 40 | console-control-strings@^1.0.0, console-control-strings@^1.1.0: 41 | version "1.1.0" 42 | resolved "https://registry.npmmirror.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" 43 | integrity sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ== 44 | 45 | delegates@^1.0.0: 46 | version "1.0.0" 47 | resolved "https://registry.npmmirror.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" 48 | integrity sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ== 49 | 50 | emoji-regex@^8.0.0: 51 | version "8.0.0" 52 | resolved "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" 53 | integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== 54 | 55 | gauge@^4.0.0: 56 | version "4.0.0" 57 | resolved "https://registry.npmmirror.com/gauge/-/gauge-4.0.0.tgz#afba07aa0374a93c6219603b1fb83eaa2264d8f8" 58 | integrity sha512-F8sU45yQpjQjxKkm1UOAhf0U/O0aFt//Fl7hsrNVto+patMHjs7dPI9mFOGUKbhrgKm0S3EjW3scMFuQmWSROw== 59 | dependencies: 60 | ansi-regex "^5.0.1" 61 | aproba "^1.0.3 || ^2.0.0" 62 | color-support "^1.1.2" 63 | console-control-strings "^1.0.0" 64 | has-unicode "^2.0.1" 65 | signal-exit "^3.0.0" 66 | string-width "^4.2.3" 67 | strip-ansi "^6.0.1" 68 | wide-align "^1.1.2" 69 | 70 | has-unicode@^2.0.1: 71 | version "2.0.1" 72 | resolved "https://registry.npmmirror.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" 73 | integrity sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ== 74 | 75 | inherits@^2.0.3: 76 | version "2.0.4" 77 | resolved "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 78 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 79 | 80 | is-fullwidth-code-point@^3.0.0: 81 | version "3.0.0" 82 | resolved "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" 83 | integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== 84 | 85 | npmlog@^6.0.1: 86 | version "6.0.1" 87 | resolved "https://registry.npmmirror.com/npmlog/-/npmlog-6.0.1.tgz#06f1344a174c06e8de9c6c70834cfba2964bba17" 88 | integrity sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg== 89 | dependencies: 90 | are-we-there-yet "^3.0.0" 91 | console-control-strings "^1.1.0" 92 | gauge "^4.0.0" 93 | set-blocking "^2.0.0" 94 | 95 | readable-stream@^3.6.0: 96 | version "3.6.0" 97 | resolved "https://registry.npmmirror.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" 98 | integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== 99 | dependencies: 100 | inherits "^2.0.3" 101 | string_decoder "^1.1.1" 102 | util-deprecate "^1.0.1" 103 | 104 | safe-buffer@~5.2.0: 105 | version "5.2.1" 106 | resolved "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" 107 | integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== 108 | 109 | set-blocking@^2.0.0: 110 | version "2.0.0" 111 | resolved "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" 112 | integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw== 113 | 114 | signal-exit@^3.0.0: 115 | version "3.0.7" 116 | resolved "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" 117 | integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== 118 | 119 | "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: 120 | version "4.2.3" 121 | resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" 122 | integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== 123 | dependencies: 124 | emoji-regex "^8.0.0" 125 | is-fullwidth-code-point "^3.0.0" 126 | strip-ansi "^6.0.1" 127 | 128 | string_decoder@^1.1.1: 129 | version "1.3.0" 130 | resolved "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" 131 | integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== 132 | dependencies: 133 | safe-buffer "~5.2.0" 134 | 135 | strip-ansi@^6.0.1: 136 | version "6.0.1" 137 | resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" 138 | integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== 139 | dependencies: 140 | ansi-regex "^5.0.1" 141 | 142 | util-deprecate@^1.0.1: 143 | version "1.0.2" 144 | resolved "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 145 | integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== 146 | 147 | wide-align@^1.1.2: 148 | version "1.1.5" 149 | resolved "https://registry.npmmirror.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3" 150 | integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg== 151 | dependencies: 152 | string-width "^1.0.2 || 2 || 3 || 4" 153 | -------------------------------------------------------------------------------- /packages/models/git/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * 修复site star ([4dc7849](https://github.com/der-cli/der-cli/commit/4dc78496df0a3b723c23a06c09bbfb2af916a99c)) 23 | 24 | 25 | 26 | 27 | 28 | ## [0.5.2](https://github.com/der-cli/der-cli/compare/v0.5.0...v0.5.2) (2022-03-15) 29 | 30 | **Note:** Version bump only for package @der-cli/git 31 | 32 | 33 | 34 | 35 | 36 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 37 | 38 | 39 | ### Features 40 | 41 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 42 | 43 | 44 | 45 | 46 | 47 | ## [0.4.4](https://github.com/der-cli/der-cli/compare/v0.4.3...v0.4.4) (2022-03-12) 48 | 49 | 50 | ### Performance Improvements 51 | 52 | * 优化发布前检查流程 ([70cda90](https://github.com/der-cli/der-cli/commit/70cda90e1558bc400ccfc114b5d2dd56278ef106)) 53 | 54 | 55 | 56 | 57 | 58 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 59 | 60 | **Note:** Version bump only for package @der-cli/git 61 | 62 | 63 | 64 | 65 | 66 | ## [0.4.2](https://github.com/der-cli/der-cli/compare/v0.4.1...v0.4.2) (2022-03-03) 67 | 68 | **Note:** Version bump only for package @der-cli/git 69 | 70 | 71 | 72 | 73 | 74 | ## [0.4.1](https://github.com/der-cli/der-cli/compare/v0.4.0...v0.4.1) (2022-03-03) 75 | 76 | 77 | ### Bug Fixes 78 | 79 | * 修复了控制台打印效果 ([b1842e4](https://github.com/der-cli/der-cli/commit/b1842e40169e39ebe56608995e0ea73ad00bcac9)) 80 | 81 | 82 | 83 | 84 | 85 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 86 | 87 | **Note:** Version bump only for package @der-cli/git 88 | -------------------------------------------------------------------------------- /packages/models/git/Git/ComponentRequest.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | 3 | module.exports = { 4 | createComponent: async function(component) { 5 | try { 6 | const response = await axios.post('http://book.youbaobao.xyz:7002/api/v1/components', component); 7 | const { data } = response; 8 | if (data.code === 0) { 9 | return data.data; 10 | } else { 11 | return null; 12 | } 13 | } catch (e) { 14 | throw e; 15 | } 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /packages/models/git/Git/GitIgore.js: -------------------------------------------------------------------------------- 1 | const COMPONENT_LIBRARY_IGNORE = `.DS_Store 2 | node_modules 3 | 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | 15 | # Editor directories and files 16 | .idea 17 | .vscode 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | *.sw?` 23 | 24 | const PROJECT_IGNORE = `.DS_Store 25 | node_modules 26 | /dist 27 | 28 | 29 | # local env files 30 | .env.local 31 | .env.*.local 32 | 33 | # Log files 34 | npm-debug.log* 35 | yarn-debug.log* 36 | yarn-error.log* 37 | pnpm-debug.log* 38 | 39 | # Editor directories and files 40 | .idea 41 | .vscode 42 | *.suo 43 | *.ntvs* 44 | *.njsproj 45 | *.sln 46 | *.sw?` 47 | 48 | module.exports = { 49 | COMPONENT_LIBRARY_IGNORE, 50 | PROJECT_IGNORE 51 | } -------------------------------------------------------------------------------- /packages/models/git/Git/GitServer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * GitServer 基类 3 | * 用于实现 Github/Gitee类 4 | */ 5 | class GitServer { 6 | constructor(type, token) { 7 | this.type = type; // github or gitee 8 | this.token = token; // 调用API的token 9 | } 10 | 11 | // 设置token 12 | setToken() { 13 | error('setToken'); 14 | }; 15 | // 创建个人仓库 16 | createRepo() { 17 | error('createRepo'); 18 | }; 19 | // 创建组织仓库 20 | createOrgRepo() { 21 | error('createOrgRepo'); 22 | }; 23 | // 获取仓库 24 | getRepo() { 25 | error('getRepo'); 26 | }; 27 | // 获取平台用户信息 28 | getUser() { 29 | error('getUser'); 30 | }; 31 | // 获取组织用户信息 32 | getOrgs() { 33 | error('getOrgs'); 34 | }; 35 | // 获取 36 | getTokenHelpUrl() { 37 | error('getTokenHelpUrl'); 38 | }; 39 | 40 | getSSHKeysUrl() { 41 | error('getSSHKeysUrl'); 42 | }; 43 | 44 | getSSHKeysHelpUrl() { 45 | error('getSSHKeysHelpUrl'); 46 | }; 47 | 48 | getRemote() { 49 | error('getRemote'); 50 | }; 51 | 52 | isHttpResponse(response) { 53 | return response && response.status && response.statusText && 54 | response.headers && response.data && response.config; 55 | }; 56 | 57 | handleResponse(response) { 58 | if (this.isHttpResponse(response) && response !== 200) { 59 | return null; 60 | } else { 61 | return response; 62 | } 63 | }; 64 | } 65 | 66 | const error = (methodName) => { 67 | throw new Error(`${methodName} must be implemented!`); 68 | } 69 | 70 | module.exports = GitServer; -------------------------------------------------------------------------------- /packages/models/git/Git/Gitee.js: -------------------------------------------------------------------------------- 1 | const GitServer = require('./GitServer'); 2 | const GiteeRequest = require('./GiteeRequest'); 3 | 4 | class Gitee extends GitServer { 5 | constructor() { 6 | super('gitee'); // git server type 7 | this.request = null 8 | } 9 | 10 | getTokenHelpUrl() { 11 | return 'https://gitee.com/profile/personal_access_tokens'; 12 | }; 13 | 14 | getUser() { 15 | return this.request.get('/user').then(response => { 16 | return this.handleResponse(response); 17 | }); 18 | }; 19 | 20 | getOrgs() { 21 | return this.request.get('/user/orgs', { 22 | page: 1, 23 | per_page: 100, 24 | admin: true, 25 | }).then(response => { 26 | return this.handleResponse(response); 27 | }); 28 | }; 29 | 30 | setToken(token) { 31 | // super.setToken(token); 32 | // 创建API请求实例, 并携带token参数 33 | this.request = new GiteeRequest(token); 34 | }; 35 | 36 | getRepo(owner, repo) { 37 | return new Promise((resolve, reject) => { 38 | this.request.get(`/repos/${owner}/${repo}`) 39 | .then(response => { 40 | resolve(this.handleResponse(response)); 41 | // resolve(response); 42 | }).catch(error => { 43 | reject(error); 44 | }); 45 | }) 46 | }; 47 | 48 | createRepo(repo) { 49 | return this.request.post('/user/repos', { 50 | name: repo, 51 | }); 52 | }; 53 | 54 | createOrgRepo(repo, login) { 55 | return this.request.post(`/orgs/${login}/repos`, { 56 | name: repo, 57 | }); 58 | }; 59 | 60 | getRemote(login, repo) { 61 | return `git@gitee.com:${login}/${repo}.git`; 62 | }; 63 | 64 | getSSHKeysUrl() { 65 | return 'https://gitee.com/profile/sshkeys'; 66 | }; 67 | 68 | getSSHKeysHelpUrl() { 69 | return 'https://gitee.com/help/articles/4191'; 70 | }; 71 | } 72 | 73 | module.exports = Gitee; -------------------------------------------------------------------------------- /packages/models/git/Git/GiteeRequest.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | // const log = require('../log'); 3 | 4 | const BASE_URL = 'https://gitee.com/api/v5'; 5 | 6 | class GithubRequest { 7 | constructor(token) { 8 | this.token = token; 9 | this.service = axios.create({ 10 | baseURL: BASE_URL, 11 | timeout: 5000, 12 | }); 13 | this.service.interceptors.response.use( 14 | response => { 15 | return response.data; 16 | }, 17 | error => { 18 | if (error.response && error.response.data) { 19 | return error.response; 20 | } else { 21 | return Promise.reject(error); 22 | } 23 | }, 24 | ); 25 | } 26 | 27 | get(url, params, headers) { 28 | return this.service({ 29 | url, 30 | params: { 31 | ...params, 32 | access_token: this.token, 33 | }, 34 | method: 'get', 35 | headers, 36 | }); 37 | } 38 | 39 | post(url, data, headers) { 40 | return this.service({ 41 | url, 42 | params: { 43 | access_token: this.token, 44 | }, 45 | data, 46 | method: 'post', 47 | headers, 48 | }); 49 | } 50 | } 51 | 52 | module.exports = GithubRequest; -------------------------------------------------------------------------------- /packages/models/git/Git/Github.js: -------------------------------------------------------------------------------- 1 | const GitServer = require('./GitServer'); 2 | const GithubRequest = require('./GithubRequest'); 3 | 4 | /** 5 | * Git 类 6 | */ 7 | class Github extends GitServer { 8 | constructor() { 9 | super('github'); // git server type 10 | this.request = null 11 | } 12 | 13 | getTokenHelpUrl() { 14 | return 'https://github.com/settings/tokens'; 15 | }; 16 | 17 | getUser() { 18 | return this.request.get('/user').then(response => { 19 | return this.handleResponse(response); 20 | }); 21 | }; 22 | 23 | getOrgs() { 24 | return this.request.get('/user/orgs', { 25 | page: 1, 26 | per_page: 100, 27 | }).then(response => { 28 | return this.handleResponse(response); 29 | }); 30 | }; 31 | 32 | setToken(token) { 33 | this.request = new GithubRequest(token); 34 | }; 35 | 36 | // 获取仓库详情 37 | getRepo(owner, repo) { 38 | return new Promise((resolve, reject) => { 39 | this.request.get(`/repos/${owner}/${repo}`) 40 | .then(response => { 41 | resolve(this.handleResponse(response)); 42 | // resolve(response); 43 | }).catch(error => { 44 | reject(error); 45 | }); 46 | }) 47 | }; 48 | 49 | // 创建个人仓库 50 | createRepo(repo) { 51 | return this.request.post('/user/repos', { 52 | name: repo, 53 | }, { 54 | Accept: 'application/vnd.github.v3+json', 55 | }); 56 | }; 57 | 58 | // 创建组织仓库 59 | createOrgRepo(repo, login) { 60 | return this.request.post(`/orgs/${login}/repos`, { 61 | name: repo, 62 | }, { 63 | Accept: 'application/vnd.github.v3+json', 64 | }); 65 | }; 66 | 67 | // 获取远程仓库地址 68 | getRemote(login, repo) { 69 | return `git@github.com:${login}/${repo}.git`; 70 | }; 71 | 72 | getSSHKeysUrl() { 73 | return 'https://github.com/settings/keys'; 74 | }; 75 | 76 | getSSHKeysHelpUrl() { 77 | return 'https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/connecting-to-github-with-ssh'; 78 | }; 79 | } 80 | 81 | module.exports = Github; -------------------------------------------------------------------------------- /packages/models/git/Git/GithubRequest.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | // const log = require('../log'); 3 | 4 | const BASE_URL = 'https://api.github.com'; 5 | 6 | /** 7 | * 参考: https://docs.github.com/cn/rest/overview/resources-in-the-rest-api 8 | */ 9 | class GithubRequest { 10 | constructor(token) { 11 | this.token = token; 12 | this.service = axios.create({ 13 | baseURL: BASE_URL, 14 | timeout: 5000, 15 | }); 16 | this.service.interceptors.request.use( 17 | config => { 18 | config.headers['Authorization'] = `token ${this.token}`; 19 | return config; 20 | }, 21 | error => { 22 | return Promise.reject(error); 23 | }, 24 | ); 25 | this.service.interceptors.response.use( 26 | response => { 27 | // 返回data对象 28 | return response.data; 29 | }, 30 | error => { 31 | if (error.response && error.response.data) { 32 | // 返回response对象 33 | return error.response; 34 | } else { 35 | return Promise.reject(error); 36 | } 37 | }, 38 | ); 39 | } 40 | 41 | get(url, params, headers) { 42 | return this.service({ 43 | url, 44 | data: params, 45 | method: 'get', 46 | headers, 47 | }); 48 | } 49 | 50 | post(url, data, headers) { 51 | return this.service({ 52 | url, 53 | data, 54 | method: 'post', 55 | headers, 56 | }); 57 | } 58 | } 59 | 60 | module.exports = GithubRequest; -------------------------------------------------------------------------------- /packages/models/git/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/git` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const git = require('@der-cli/git'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/models/git/__tests__/git.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const should = require('should'); 4 | const Git = require('../lib'); 5 | 6 | function createGitInstance({ complexName = false } = {}) { 7 | if (complexName) { 8 | return new Git({ 9 | name: '@der-ui/vui', 10 | version: '0.0.9', 11 | dir: 'D:\\repository\\QuickStart\\test-ct1', 12 | }, {}) 13 | } else { 14 | return new Git({ 15 | name: 'der-ui', 16 | version: '1.0.0', 17 | dir: 'D:\\repository\\QuickStart\\test-ct2', 18 | }, {}); 19 | } 20 | } 21 | 22 | // describe('Class Git测试', function () { 23 | // it('Class Git实例化测试', function () { 24 | // const git_instance = createGitInstance({ complexName: true }); 25 | // // console.log(git_instance.name); 26 | // git_instance.name.should.equal('der-ui-vui'); 27 | // }) 28 | 29 | // it('获取正确的分支号', async function () { 30 | // const git_instance = createGitInstance({ complexName: true }); 31 | // const branch = await git_instance.getCorrectVersion(); 32 | 33 | // }) 34 | // }) -------------------------------------------------------------------------------- /packages/models/git/__tests__/gitee.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const should = require('should'); 5 | const Gitee = require('../Git/Gitee'); 6 | const GiteeRequest = require('../Git/GiteeRequest'); 7 | 8 | const GIT_TOKEN_PATH = 'C:/Users/86136/.der-cli/.git/.git_token' 9 | const OWN_GITEE_REPO = 'DailyCode1.0' 10 | 11 | function createGiteeInstance() { 12 | const token = fs.readFileSync(GIT_TOKEN_PATH).toString(); 13 | const gitee = new Gitee(); 14 | gitee.setToken(token); 15 | return gitee; 16 | } 17 | 18 | describe('Class Gitee 实例化', function () { 19 | it('Gitee实例化检查', function () { 20 | const gitee = new Gitee(); 21 | gitee.setToken('123456') 22 | gitee.type.should.equal('gitee'); 23 | // gitee.token.should.equal('123456'); 24 | gitee.request.should.not.equal(null) 25 | // 检查gitee.request是否为GiteeRequest实例化对象 26 | gitee.request.__proto__.should.equal(GiteeRequest.prototype) 27 | gitee.request.token.should.equal('123456') 28 | }); 29 | }); 30 | 31 | describe('Gitee获取个人或组织信息', function () { 32 | it('[http] 获取个人信息', async function () { 33 | const gitee_instance = createGiteeInstance(); 34 | const user = await gitee_instance.getUser(); 35 | user.login.should.equal('ok-song'); 36 | }) 37 | it('[http] 获取组织信息', async function () { 38 | const gitee_instance = createGiteeInstance(); 39 | const user = await gitee_instance.getUser(); 40 | const org = await gitee_instance.getOrgs(user.login); 41 | org.should.be.an.Array(); 42 | org[0].login.should.equal('der-cli'); 43 | }) 44 | }) 45 | 46 | describe('Gitee获取仓库信息', function () { 47 | it('[http] 获取指定仓库信息', async function () { 48 | const gitee_instance = createGiteeInstance(); 49 | const user = await gitee_instance.getUser(); 50 | const { login } = user; 51 | const repo = await gitee_instance.getRepo(login, OWN_GITEE_REPO); 52 | repo.full_name.should.equal(`${login}/${OWN_GITEE_REPO}`); 53 | }) 54 | }) -------------------------------------------------------------------------------- /packages/models/git/__tests__/github.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Github = require('../Git/Github'); 4 | 5 | describe('@der-cli/git', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/models/git/lib/const.js: -------------------------------------------------------------------------------- 1 | const DEFAULT_CLI_HOME = '.der-cli'; 2 | const GIT_ROOT_DIR = '.git'; 3 | const GIT_SERVER_FILE = '.git_server'; 4 | const GIT_TOKEN_FILE = '.git_token'; 5 | const GIT_LOGIN_FILE = '.git_login'; 6 | const GIT_OWN_FILE = '.git_own'; 7 | const GIT_PUBLISH_FILE = '.git_publish'; 8 | const GIT_IGNORE_FILE = '.gitignore'; 9 | const REPO_OWNER_USER = 'user'; // 用户仓库 10 | const REPO_OWNER_ORG = 'org'; // 组织仓库 11 | 12 | const GITHUB = 'github'; 13 | const GITEE = 'gitee'; 14 | 15 | const VERSION_RELEASE = 'release'; 16 | const VERSION_DEVELOP = 'dev'; 17 | const COMPONENT_FILE = '.componentrc'; 18 | 19 | const TEMPLATE_TEMP_DIR = 'oss'; 20 | 21 | const GIT_SERVER_TYPE = [{ 22 | name: 'Github', 23 | value: GITHUB, 24 | }, { 25 | name: 'Gitee(码云)', 26 | value: GITEE, 27 | }]; 28 | 29 | const GIT_OWNER_TYPE = [{ 30 | name: '个人', 31 | value: REPO_OWNER_USER, 32 | }, { 33 | name: '组织', 34 | value: REPO_OWNER_ORG, 35 | }]; 36 | 37 | const GIT_OWNER_TYPE_ONLY = [{ 38 | name: '个人', 39 | value: REPO_OWNER_USER, 40 | }]; 41 | 42 | const GIT_PUBLISH_TYPE = [{ 43 | name: 'OSS', 44 | value: 'oss', 45 | }]; 46 | 47 | const GIT_COMMIT_TYPE = [{ 48 | value: 'feat', 49 | name: 'feat: 新功能', 50 | }, 51 | { 52 | value: 'fix', 53 | name: 'fix: 修复', 54 | }, 55 | { 56 | value: 'docs', 57 | name: 'docs: 文档变更', 58 | }, 59 | { 60 | value: 'style', 61 | name: 'style: 代码格式(不影响代码运行的变动)', 62 | }, 63 | { 64 | value: 'refactor', 65 | name: 'refactor: 重构(既不是增加feature),也不是修复bug', 66 | }, 67 | { 68 | value: 'pref', 69 | name: 'pref: 性能优化', 70 | }, 71 | { 72 | value: 'test', 73 | name: 'test: 增加测试', 74 | }, 75 | { 76 | value: 'chore', 77 | name: 'chore: 构建过程或辅助工具的变动', 78 | }, 79 | { 80 | value: 'revert', 81 | name: 'revert: 回退', 82 | }, 83 | { 84 | value: 'build', 85 | name: 'build: 打包', 86 | }, 87 | ] 88 | 89 | module.exports = { 90 | DEFAULT_CLI_HOME, 91 | GIT_ROOT_DIR, 92 | GIT_SERVER_FILE, 93 | GIT_TOKEN_FILE, 94 | GIT_LOGIN_FILE, 95 | GIT_OWN_FILE, 96 | GIT_PUBLISH_FILE, 97 | GIT_IGNORE_FILE, 98 | REPO_OWNER_USER, 99 | REPO_OWNER_ORG, 100 | GITHUB, 101 | GITEE, 102 | VERSION_RELEASE, 103 | VERSION_DEVELOP, 104 | COMPONENT_FILE, 105 | TEMPLATE_TEMP_DIR, 106 | GIT_SERVER_TYPE, 107 | GIT_OWNER_TYPE, 108 | GIT_OWNER_TYPE_ONLY, 109 | GIT_PUBLISH_TYPE, 110 | GIT_COMMIT_TYPE 111 | } -------------------------------------------------------------------------------- /packages/models/git/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_CAN_NOT_FIND_USER_HOME = () => { 2 | throw new Error('[Git] 用户主目录获取失败!'); 3 | }; 4 | 5 | const Error_INIT_GIT_SERVER_FAILED = () => { 6 | throw new Error('[Git] GitServer初始化失败, 检查.git_server文件内容是否被修改, 或使用[-refreshServer]参数更新.git_server文件') 7 | } 8 | 9 | const Error_FAILED_GET_INFO = () => { 10 | throw new Error('[Git] 用户或组织信息获取失败'); 11 | } 12 | 13 | const Error_FAILED_CREATE_REMOTE_REPO = () => { 14 | throw new Error('[Git] 远程仓库创建失败'); 15 | } 16 | 17 | const Error_CODE_CONFLICTS = () => { 18 | throw new Error('[Git] 当前代码存在冲突, 请手动处理合并后再试!'); 19 | } 20 | 21 | const Error_BUIILD_FAILED = (buildPath) => { 22 | throw new Error(`[Git] 构建结果:${buildPath} 不存在!`); 23 | } 24 | 25 | const Error_BUIILD_PATH_NOT_FOUND = (buildPath) => { 26 | throw new Error(`[Git] package.json 中 files 属性未添加构建结果目录:[${buildPath}], 请在 package.json 中手动添加!`); 27 | } 28 | 29 | const Error_PACKAGE_JSON_NOT_FOUND = () => { 30 | throw new Error('[Git] package.json 不存在!'); 31 | } 32 | 33 | const Error_COMMIT_INFO_IS_EMPTY = () => { 34 | return '提交信息不能为空' 35 | } 36 | 37 | module.exports = { 38 | Error_CAN_NOT_FIND_USER_HOME, 39 | Error_INIT_GIT_SERVER_FAILED, 40 | Error_FAILED_GET_INFO, 41 | Error_FAILED_CREATE_REMOTE_REPO, 42 | Error_CODE_CONFLICTS, 43 | Error_BUIILD_FAILED, 44 | Error_BUIILD_PATH_NOT_FOUND, 45 | Error_PACKAGE_JSON_NOT_FOUND, 46 | Error_COMMIT_INFO_IS_EMPTY 47 | } -------------------------------------------------------------------------------- /packages/models/git/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/git", 3 | "version": "0.5.5", 4 | "description": "Git Flow models", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib", 15 | "Git" 16 | ], 17 | "publishConfig": { 18 | "access": "public" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/der-cli/der-cli.git" 23 | }, 24 | "scripts": { 25 | "test": "yarn test:git && yarn test:gitee && yarn test:github", 26 | "test:git": "mocha __tests__/git.test.js", 27 | "test:gitee": "mocha __tests__/gitee.test.js", 28 | "test:github": "mocha __tests__/github.test.js" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/der-cli/der-cli/issues" 32 | }, 33 | "dependencies": { 34 | "@der-cli/log": "^0.5.0", 35 | "@der-cli/utils": "^0.5.0", 36 | "axios": "^0.26.0", 37 | "colors": "^1.4.0", 38 | "fs-extra": "^10.0.0", 39 | "listr": "^0.14.3", 40 | "mocha": "^9.2.1", 41 | "rxjs": "^7.5.4", 42 | "semver": "^7.3.5", 43 | "should": "^13.2.3", 44 | "simple-git": "^3.2.6" 45 | }, 46 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 47 | } 48 | -------------------------------------------------------------------------------- /packages/models/package/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.5.5](https://github.com/der-cli/der-cli/compare/v0.5.4...v0.5.5) (2022-05-01) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * version bug ([dd07ef9](https://github.com/der-cli/der-cli/commit/dd07ef9928beb2a14d89cbf8babe25df8d9f3074)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.5.3](https://github.com/der-cli/der-cli/compare/v0.5.2...v0.5.3) (2022-04-30) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * 修复site star ([4dc7849](https://github.com/der-cli/der-cli/commit/4dc78496df0a3b723c23a06c09bbfb2af916a99c)) 23 | 24 | 25 | 26 | 27 | 28 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 29 | 30 | **Note:** Version bump only for package @der-cli/package 31 | 32 | 33 | 34 | 35 | 36 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 37 | 38 | **Note:** Version bump only for package @der-cli/package 39 | 40 | 41 | 42 | 43 | 44 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 45 | 46 | **Note:** Version bump only for package @der-cli/package 47 | -------------------------------------------------------------------------------- /packages/models/package/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/package` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const package = require('@der-cli/package'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/models/package/__tests__/package.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const fse = require('fs-extra'); 5 | const should = require('should'); 6 | const Package = require('../lib'); 7 | const { getNpmLatestVersion } = require('@der-cli/get-npm-info'); 8 | const { 9 | Error_CONST_EMPTY_OPTION, 10 | Error_CONST_OPTION_IS_NOT_OBJECT, 11 | } = require('../lib/error'); 12 | 13 | const TARGET_PATH = 'D:/repository/QuickStart/der-cli/commands/init' 14 | const TARGET_PATH2 = 'C:\\Users\\86136\\.der-cli\\dependencies' 15 | const STORE_DIR = 'C:\\Users\\86136\\.der-cli\\dependencies\\node_modules' 16 | const PACKAGE_NAME = '@der-cli/init' 17 | const PACKAGE_NAME_CONVERT = '@der-cli_init' 18 | const PACKAGE_VERSION = '1.0.0' 19 | const PACKAGE_LATEST_VERSION = 'latest' 20 | 21 | function createPackageInstance(options = { haveTargetPath: true }) { 22 | const packageVersion = options.latestVersion ? PACKAGE_LATEST_VERSION : PACKAGE_VERSION 23 | const { haveTargetPath } = options 24 | return haveTargetPath ? 25 | new Package({ 26 | targetPath: TARGET_PATH, 27 | storeDir: STORE_DIR, 28 | packageName: PACKAGE_NAME, 29 | packageVersion 30 | }) : 31 | new Package({ 32 | storeDir: STORE_DIR, 33 | packageName: PACKAGE_NAME, 34 | packageVersion 35 | }) 36 | } 37 | 38 | function createPackageInstanceWithoutTargetPath() { 39 | return createPackageInstance({ haveTargetPath: false }) 40 | } 41 | 42 | describe('Package 对象实例化', function () { 43 | it('Options参数为空', function () { 44 | try { 45 | new Package(); 46 | } catch (err) { 47 | err.message.should.equal(Error_CONST_EMPTY_OPTION) 48 | } 49 | }); 50 | it('Options参数不为对象', function () { 51 | try { 52 | new Package(1); 53 | } catch (err) { 54 | err.message.should.equal(Error_CONST_OPTION_IS_NOT_OBJECT) 55 | } 56 | try { 57 | new Package(function () {}); 58 | } catch (err) { 59 | err.message.should.equal(Error_CONST_OPTION_IS_NOT_OBJECT) 60 | } 61 | }); 62 | it('带targetPath的实例化', function () { 63 | const pkg_instance = createPackageInstance(); 64 | pkg_instance.should.have.property('targetPath', TARGET_PATH); 65 | pkg_instance.should.have.property('storeDir', STORE_DIR); 66 | pkg_instance.should.have.property('packageName', PACKAGE_NAME); 67 | pkg_instance.should.have.property('packageVersion', PACKAGE_VERSION); 68 | pkg_instance.should.have.property('cacheFilePathPrefix', PACKAGE_NAME_CONVERT); 69 | }); 70 | it('不带targetPath的实例化', function () { 71 | const pkg_instance = createPackageInstanceWithoutTargetPath() 72 | pkg_instance.should.have.property('targetPath', undefined); 73 | pkg_instance.should.have.property('storeDir', STORE_DIR); 74 | pkg_instance.should.have.property('packageName', PACKAGE_NAME); 75 | pkg_instance.should.have.property('packageVersion', PACKAGE_VERSION); 76 | pkg_instance.should.have.property('cacheFilePathPrefix', PACKAGE_NAME_CONVERT); 77 | }); 78 | }); 79 | 80 | describe('Package prepare', function () { 81 | before(function () { 82 | if (fs.existsSync(STORE_DIR)) { 83 | this.timeout(30000) 84 | fse.removeSync(STORE_DIR) 85 | } 86 | }) 87 | it('storeDir不存在时, 创建storeDir', async function () { 88 | fs.existsSync(STORE_DIR).should.be.false() 89 | const pkgInstance = createPackageInstance({ latestVersion: true }); 90 | await pkgInstance.prepare(); 91 | fs.existsSync(STORE_DIR).should.be.true() 92 | }) 93 | it('packageVersion为latest获取最新版本号', async function () { 94 | const pkgInstance = createPackageInstance({ latestVersion: true }); 95 | await pkgInstance.prepare(); 96 | this.packageVersion = await getNpmLatestVersion(PACKAGE_NAME); 97 | // console.log(this.packageVersion); 98 | pkgInstance.packageVersion.should.equal(this.packageVersion) 99 | }) 100 | }) 101 | 102 | describe('Package cacheFilePath属性测试', function () { 103 | it('获取cacheFilePath属性', function () { 104 | const intance = createPackageInstance(); 105 | const actulPath = `${STORE_DIR}\\_${PACKAGE_NAME_CONVERT}@${PACKAGE_VERSION}@@der-cli\\init` 106 | intance.cacheFilePath.should.equal(actulPath); 107 | }) 108 | }) 109 | 110 | describe('Package getSpecificCacheFilePath方法测试', function () { 111 | it('获取getSpecificCacheFilePath属性', function () { 112 | const intance = createPackageInstance(); 113 | const actulPath = `${STORE_DIR}\\_${PACKAGE_NAME_CONVERT}@${PACKAGE_VERSION}@@der-cli\\init` 114 | intance.getSpecificCacheFilePath('1.0.0').should.equal(actulPath); 115 | }) 116 | }) 117 | 118 | describe('Package exists方法测试', function () { 119 | it('有targetPath时, 正确判断package是否存在', async function () { 120 | const pkg_intance = createPackageInstance(); 121 | delete pkg_intance.storeDir; 122 | (await pkg_intance.exists()).should.be.true(); 123 | }) 124 | it('无targetPath时, 正确判断package是否存在', async function () { 125 | const pkg_intance = createPackageInstanceWithoutTargetPath(); 126 | (await pkg_intance.exists()).should.be.false(); 127 | }) 128 | }) 129 | 130 | describe('Package getRootFilePath方法测试', function () { 131 | it('有targetPath时, 正确获取入口文件', async function () { 132 | const pkg_intance = createPackageInstance(); 133 | delete pkg_intance.storeDir; 134 | (await pkg_intance.getRootFilePath()).should.equal(`${TARGET_PATH}/lib/index.js`); 135 | }) 136 | it('入口文件不存在时, 返回null', function () { 137 | const pkg_intance = createPackageInstanceWithoutTargetPath(); 138 | should.strictEqual(pkg_intance.getRootFilePath(), null) 139 | }) 140 | }) 141 | 142 | describe('Package install方法测试', function () { 143 | it('正确install Package', async function () { 144 | this.timeout(30000) 145 | // const pkg_intance = createPackageInstanceWithoutTargetPath(); 146 | const pkg_intance = new Package({ 147 | targetPath: TARGET_PATH2, 148 | storeDir: STORE_DIR, 149 | packageName: PACKAGE_NAME, 150 | packageVersion: PACKAGE_LATEST_VERSION, 151 | }) 152 | await pkg_intance.install(); 153 | (await pkg_intance.getRootFilePath()).should.equal('C:/Users/86136/.der-cli/dependencies/node_modules/_@der-cli_init@0.0.10@@der-cli/init/lib/index.js') 154 | }) 155 | after(function () { 156 | if (fs.existsSync(STORE_DIR)) { 157 | this.timeout(30000) 158 | fse.removeSync(STORE_DIR) 159 | } 160 | }) 161 | }) 162 | 163 | describe('Package update方法测试', function () { 164 | it('正确update Package', async function () { 165 | this.timeout(30000) 166 | const pkg_intance = new Package({ 167 | targetPath: TARGET_PATH2, 168 | storeDir: STORE_DIR, 169 | packageName: PACKAGE_NAME, 170 | packageVersion: PACKAGE_VERSION, 171 | }) 172 | await pkg_intance.update(); 173 | // console.log(await pkg_intance.getRootFilePath()); 174 | (await pkg_intance.getRootFilePath()).should.equal('C:/Users/86136/.der-cli/dependencies/node_modules/_@der-cli_init@0.0.10@@der-cli/init/lib/index.js') 175 | }) 176 | after(function () { 177 | if (fs.existsSync(STORE_DIR)) { 178 | this.timeout(30000) 179 | fse.removeSync(STORE_DIR) 180 | } 181 | }) 182 | }) -------------------------------------------------------------------------------- /packages/models/package/lib/const.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/packages/models/package/lib/const.js -------------------------------------------------------------------------------- /packages/models/package/lib/error.js: -------------------------------------------------------------------------------- 1 | const Error_CONST_EMPTY_OPTION = '[Package] Package类的options参数不能为空!' 2 | const Error_CONST_OPTION_IS_NOT_OBJECT = '[Package] Package类的options参数必须为对象!' 3 | 4 | const Error_EMPTY_OPTION = () => { 5 | throw new Error(Error_CONST_EMPTY_OPTION); 6 | } 7 | 8 | const Error_OPTION_IS_NOT_OBJECT = () => { 9 | throw new Error(Error_CONST_OPTION_IS_NOT_OBJECT); 10 | } 11 | 12 | module.exports = { 13 | Error_CONST_EMPTY_OPTION, 14 | Error_CONST_OPTION_IS_NOT_OBJECT, 15 | Error_EMPTY_OPTION, 16 | Error_OPTION_IS_NOT_OBJECT 17 | } -------------------------------------------------------------------------------- /packages/models/package/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fse = require('fs-extra'); 5 | const pkgDir = require('pkg-dir').sync; 6 | const pathExists = require('path-exists').sync; 7 | const npminstall = require('npminstall'); 8 | const { isObject } = require('@der-cli/utils'); 9 | const formatPath = require('@der-cli/format-path'); 10 | const log = require('@der-cli/log'); 11 | const { 12 | getDefaultRegistry, 13 | getNpmLatestVersion 14 | } = require('@der-cli/get-npm-info'); 15 | const { 16 | Error_EMPTY_OPTION, 17 | Error_OPTION_IS_NOT_OBJECT 18 | } = require('./error'); 19 | 20 | /** 21 | * 本地 Package 依赖下载、更新、缓存核心实现 22 | * 23 | * @class Package 24 | */ 25 | class Package { 26 | constructor(options) { 27 | if (!options) { 28 | Error_EMPTY_OPTION() 29 | } 30 | if (!isObject(options)) { 31 | Error_OPTION_IS_NOT_OBJECT() 32 | } 33 | 34 | // Init props 35 | const { targetPath, storeDir, packageName, packageVersion } = options; 36 | this.targetPath = targetPath; // package的目标路径(本地) 37 | this.storeDir = storeDir; // package node_modules 路径 38 | this.packageName = packageName; // package name 39 | this.packageVersion = packageVersion; // package version 40 | this.cacheFilePathPrefix = this.packageName.replace('/', '_'); // 解析package的缓存目录前缀 41 | } 42 | 43 | // 准备阶段 44 | async prepare() { 45 | if (this.storeDir && !pathExists(this.storeDir)) { 46 | // 创建本地缓存目录 47 | fse.mkdirpSync(this.storeDir); 48 | } 49 | if (this.packageVersion === 'latest') { 50 | // 获取最新版本 51 | this.packageVersion = await getNpmLatestVersion(this.packageName); 52 | } 53 | } 54 | 55 | get cacheFilePath() { 56 | return path.resolve(this.storeDir, `_${this.cacheFilePathPrefix}@${this.packageVersion}@${this.packageName}`); 57 | } 58 | 59 | getSpecificCacheFilePath(packageVersion) { 60 | return path.resolve(this.storeDir, `_${this.cacheFilePathPrefix}@${packageVersion}@${this.packageName}`); 61 | } 62 | 63 | // 判断本地缓存是否存在 64 | async exists() { 65 | if (this.storeDir) { 66 | await this.prepare(); 67 | return pathExists(this.cacheFilePath); 68 | // C:\Users\username\.der-cli\dependencies\node_modules\_@der-cli_init@1.0.1@@der-cli\init 69 | } else { 70 | return pathExists(this.targetPath); 71 | } 72 | } 73 | 74 | // 安装Package 75 | async install() { 76 | await this.prepare(); 77 | return npminstall({ 78 | root: this.targetPath, 79 | storeDir: this.storeDir, 80 | registry: getDefaultRegistry(true), 81 | pkgs: [{ 82 | name: this.packageName, 83 | version: this.packageVersion, 84 | }], 85 | }); 86 | } 87 | 88 | // 更新Package 89 | async update() { 90 | await this.prepare(); 91 | // 1. 获取最新的npm模块版本号 92 | const latestPackageVersion = await getNpmLatestVersion(this.packageName); 93 | // 2. 查询最新版本号对应的路径是否存在 94 | const latestFilePath = this.getSpecificCacheFilePath(latestPackageVersion); 95 | // 3. 如果不存在,则直接安装最新版本 96 | if (!pathExists(latestFilePath)) { 97 | await npminstall({ 98 | root: this.targetPath, 99 | storeDir: this.storeDir, 100 | registry: getDefaultRegistry(true), 101 | pkgs: [{ 102 | name: this.packageName, 103 | version: latestPackageVersion, 104 | }], 105 | }); 106 | } 107 | // TODO: downloadTemplate时此行未打印? 108 | // log.info(`[Package] 检测到更新: 已更新至 ${this.packageVersion} => ${latestPackageVersion}`); 109 | this.packageVersion = latestPackageVersion; 110 | } 111 | 112 | // 获取入口文件的路径 /commands/init/ 113 | getRootFilePath() { 114 | function _getRootFile(targetPath) { 115 | // 1. 获取 package.json 所在目录 116 | const _dir = pkgDir(targetPath); // Current terminal directory or '-targetPath' directory 117 | 118 | if (_dir) { 119 | // 2. 读取 package.json 120 | const pkgFile = require(path.resolve(_dir, 'package.json')); 121 | // 3. 寻找 main/lib -> path 122 | if (pkgFile && pkgFile.main) { 123 | // 4. 路径的兼容(macOS/windows, '\' -> '/') 124 | return formatPath(path.resolve(_dir, pkgFile.main)); 125 | } 126 | } 127 | return null; 128 | } 129 | 130 | if (this.storeDir) { 131 | return _getRootFile(this.cacheFilePath); 132 | } else { 133 | return _getRootFile(this.targetPath); 134 | } 135 | } 136 | } 137 | 138 | module.exports = Package; -------------------------------------------------------------------------------- /packages/models/package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/package", 3 | "version": "0.5.5", 4 | "description": "本地 Package 依赖下载、更新、缓存核心实现", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "mocha __tests__/package.test.js" 21 | }, 22 | "dependencies": { 23 | "@der-cli/format-path": "^0.5.0", 24 | "@der-cli/get-npm-info": "^0.5.0", 25 | "@der-cli/log": "^0.5.0", 26 | "@der-cli/utils": "^0.5.0", 27 | "fs-extra": "^10.0.0", 28 | "mocha": "^9.2.1", 29 | "npminstall": "^5.4.1", 30 | "path-exists": "^4.0.0", 31 | "pkg-dir": "^5.0.0", 32 | "should": "^13.2.3" 33 | }, 34 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 35 | } 36 | -------------------------------------------------------------------------------- /packages/utils/format-path/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/format-path 9 | 10 | 11 | 12 | 13 | 14 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 15 | 16 | **Note:** Version bump only for package @der-cli/format-path 17 | -------------------------------------------------------------------------------- /packages/utils/format-path/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/format-path` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const formatPath = require('@der-cli/format-path'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/format-path/__tests__/format-path.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const formatPath = require('..'); 4 | 5 | describe('@der-cli/format-path', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/utils/format-path/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | function formatPath(p) { 6 | if (p && typeof p === 'string') { 7 | const sep = path.sep; 8 | if (sep === '/') { 9 | return p; 10 | } else { 11 | // '\' -> '/' 12 | return p.replace(/\\/g, '/'); 13 | } 14 | } 15 | return p; 16 | } 17 | 18 | module.exports = formatPath; -------------------------------------------------------------------------------- /packages/utils/format-path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/format-path", 3 | "version": "0.5.0", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 23 | } 24 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/get-npm-info 9 | 10 | 11 | 12 | 13 | 14 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 15 | 16 | **Note:** Version bump only for package @der-cli/get-npm-info 17 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/README.md: -------------------------------------------------------------------------------- 1 | # `get-npm-info` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const getNpmInfo = require('get-npm-info'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/__tests__/get-npm-info.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getNpmInfo = require('..'); 4 | 5 | describe('get-npm-info', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/lib/const.js: -------------------------------------------------------------------------------- 1 | const REGISTRY_ORIGIN_NPM = 'https://registry.npmjs.org'; 2 | const REGISTRY_TAOBAO_NPM = 'https://registry.npm.taobao.org'; 3 | 4 | module.exports = { 5 | REGISTRY_TAOBAO_NPM, 6 | REGISTRY_ORIGIN_NPM 7 | } -------------------------------------------------------------------------------- /packages/utils/get-npm-info/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const axios = require('axios'); 4 | const urlJoin = require('url-join'); 5 | const semver = require('semver'); 6 | const { 7 | REGISTRY_TAOBAO_NPM, 8 | REGISTRY_ORIGIN_NPM 9 | } = require('./const'); 10 | 11 | /** 12 | * 13 | * 14 | * @param {*} npmName 包名 15 | * @param {*} registry 源 16 | * @return {*} 17 | */ 18 | function getNpmInfo(npmName, registry) { 19 | if (!npmName) { 20 | return null; 21 | } 22 | const registryUrl = registry || getDefaultRegistry(); 23 | // https://registry.npmjs.org/@der-cli-dev/core 24 | const npmInfoUrl = urlJoin(registryUrl, npmName); 25 | return axios.get(npmInfoUrl).then(response => { 26 | if (response.status === 200) { 27 | return response.data; 28 | } 29 | return null; 30 | }).catch(err => { 31 | // TODO log.fail(err); 32 | return Promise.reject(err); 33 | }); 34 | } 35 | 36 | function getDefaultRegistry(isOriginal = false) { 37 | return isOriginal ? REGISTRY_ORIGIN_NPM : REGISTRY_TAOBAO_NPM; 38 | } 39 | 40 | // 获取npm包的版本号,返回数组 41 | async function getNpmVersions(npmName, registry) { 42 | const data = await getNpmInfo(npmName, registry); 43 | if (data) { 44 | return Object.keys(data.versions); 45 | } else { 46 | return []; 47 | } 48 | } 49 | 50 | // 获取满足条件的版本号:过滤版本列表中大于当前版本号的版本 51 | function getSemverVersions(baseVersion, versions) { 52 | return versions 53 | .filter(version => semver.satisfies(version, `>${baseVersion}`)) 54 | .sort((a, b) => semver.gt(b, a) ? 1 : -1); // 降序排列 55 | } 56 | 57 | async function getNpmSemverVersion(baseVersion, npmName, _registry) { 58 | const versions = await getNpmVersions(npmName, _registry); 59 | const newVersions = getSemverVersions(baseVersion, versions); 60 | if (newVersions && newVersions.length > 0) { 61 | return newVersions[0]; 62 | } 63 | return null; 64 | } 65 | 66 | // 获取最新版本号 67 | async function getNpmLatestVersion(npmName, registry) { 68 | let versions = await getNpmVersions(npmName, registry); 69 | 70 | if (versions) { 71 | return versions.sort((a, b) => semver.gt(b, a))[versions.length - 1]; 72 | } 73 | return null; 74 | } 75 | 76 | module.exports = { 77 | getNpmInfo, 78 | getNpmVersions, 79 | getNpmSemverVersion, 80 | getDefaultRegistry, 81 | getNpmLatestVersion, 82 | }; -------------------------------------------------------------------------------- /packages/utils/get-npm-info/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/get-npm-info", 3 | "version": "0.5.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "axios": { 8 | "version": "0.26.0", 9 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", 10 | "integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==", 11 | "requires": { 12 | "follow-redirects": "^1.14.8" 13 | } 14 | }, 15 | "follow-redirects": { 16 | "version": "1.14.9", 17 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", 18 | "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" 19 | }, 20 | "lru-cache": { 21 | "version": "6.0.0", 22 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 23 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 24 | "requires": { 25 | "yallist": "^4.0.0" 26 | } 27 | }, 28 | "semver": { 29 | "version": "7.3.5", 30 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", 31 | "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", 32 | "requires": { 33 | "lru-cache": "^6.0.0" 34 | } 35 | }, 36 | "url-join": { 37 | "version": "4.0.1", 38 | "resolved": "https://registry.npmmirror.com/url-join/-/url-join-4.0.1.tgz", 39 | "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" 40 | }, 41 | "yallist": { 42 | "version": "4.0.0", 43 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 44 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/get-npm-info", 3 | "version": "0.5.0", 4 | "description": "get npm info", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "dependencies": { 23 | "axios": "^0.26.0", 24 | "semver": "^7.3.5", 25 | "url-join": "^4.0.1" 26 | }, 27 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 28 | } 29 | -------------------------------------------------------------------------------- /packages/utils/get-npm-info/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | axios@^0.26.0: 6 | version "0.26.0" 7 | resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" 8 | integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== 9 | dependencies: 10 | follow-redirects "^1.14.8" 11 | 12 | follow-redirects@^1.14.8: 13 | version "1.14.9" 14 | resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" 15 | integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== 16 | 17 | lru-cache@^6.0.0: 18 | version "6.0.0" 19 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" 20 | integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== 21 | dependencies: 22 | yallist "^4.0.0" 23 | 24 | semver@^7.3.5: 25 | version "7.3.5" 26 | resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" 27 | integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== 28 | dependencies: 29 | lru-cache "^6.0.0" 30 | 31 | url-join@^4.0.1: 32 | version "4.0.1" 33 | resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" 34 | integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== 35 | 36 | yallist@^4.0.0: 37 | version "4.0.0" 38 | resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" 39 | integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== 40 | -------------------------------------------------------------------------------- /packages/utils/locale/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/locale 9 | 10 | 11 | 12 | 13 | 14 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 15 | 16 | **Note:** Version bump only for package @der-cli/locale 17 | 18 | 19 | 20 | 21 | 22 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 23 | 24 | **Note:** Version bump only for package @der-cli/locale 25 | -------------------------------------------------------------------------------- /packages/utils/locale/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/locale` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const locale = require('@der-cli/locale'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/locale/__tests__/locale.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const locale = require('..'); 4 | 5 | describe('@der-cli/locale', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/utils/locale/lib/en_us.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | welcome: 'Welcome using der cli', 3 | } -------------------------------------------------------------------------------- /packages/utils/locale/lib/getEnvLocale.js: -------------------------------------------------------------------------------- 1 | function getEnvLocale(env) { 2 | env = env || process.env; 3 | return env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE; 4 | } 5 | 6 | module.exports = getEnvLocale(); 7 | -------------------------------------------------------------------------------- /packages/utils/locale/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const locale = require('./loadLocale'); 4 | module.exports = locale; -------------------------------------------------------------------------------- /packages/utils/locale/lib/loadLocale.js: -------------------------------------------------------------------------------- 1 | function loadLocale() { 2 | const locale = require('./getEnvLocale'); 3 | if (locale) { 4 | const localeShortName = locale.split('.')[0].toLocaleLowerCase(); 5 | return require(`./${localeShortName}`); 6 | } else { 7 | return require('./zh_cn'); 8 | } 9 | } 10 | 11 | module.exports = loadLocale(); 12 | -------------------------------------------------------------------------------- /packages/utils/locale/lib/zh_cn.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | welcome: '欢迎━(*`∀´*)ノ亻!', 3 | } -------------------------------------------------------------------------------- /packages/utils/locale/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/locale", 3 | "version": "0.5.0", 4 | "description": "der-cli locale util", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "ISC", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/der-cli/der-cli.git" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: run tests from root\" && exit 1" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/der-cli/der-cli/issues" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/utils/log/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | 9 | ### Features 10 | 11 | * 优化提示 ([d943f7d](https://github.com/der-cli/der-cli/commit/d943f7dcef9b145c79b68367a4252b4b428cdabc)) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.4.3](https://github.com/der-cli/der-cli/compare/v0.4.2...v0.4.3) (2022-03-05) 18 | 19 | **Note:** Version bump only for package @der-cli/log 20 | 21 | 22 | 23 | 24 | 25 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 26 | 27 | **Note:** Version bump only for package @der-cli/log 28 | -------------------------------------------------------------------------------- /packages/utils/log/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/log` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const log = require('@der-cli/log'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/log/__tests__/log.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const log = require('..'); 4 | 5 | describe('@der-cli/log', () => { 6 | it('needs tests'); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/utils/log/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const log = require('npmlog'); 4 | 5 | // 判断debug模式 6 | log.level = process.env.DER_CLI_LOG_LEVEL ? process.env.DER_CLI_LOG_LEVEL : 'info'; 7 | // 前缀 8 | log.heading = 'der'; 9 | log.headingStyle = { fg: 'white', bg: 'cyan' }; 10 | log.prefixStyle = { fg: 'cyan' }; 11 | 12 | // 添加自定义命令 13 | log.addLevel('success', 2000, { fg: 'green', bold: true }); 14 | log.addLevel('fail', 2000, { fg: 'red', bold: true }); 15 | 16 | module.exports = log; -------------------------------------------------------------------------------- /packages/utils/log/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli-dev/log", 3 | "version": "0.5.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "ansi-regex": { 8 | "version": "5.0.1", 9 | "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", 10 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" 11 | }, 12 | "aproba": { 13 | "version": "2.0.0", 14 | "resolved": "https://registry.npmmirror.com/aproba/-/aproba-2.0.0.tgz", 15 | "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" 16 | }, 17 | "are-we-there-yet": { 18 | "version": "3.0.0", 19 | "resolved": "https://registry.npmmirror.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz", 20 | "integrity": "sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw==", 21 | "requires": { 22 | "delegates": "^1.0.0", 23 | "readable-stream": "^3.6.0" 24 | } 25 | }, 26 | "color-support": { 27 | "version": "1.1.3", 28 | "resolved": "https://registry.npmmirror.com/color-support/-/color-support-1.1.3.tgz", 29 | "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==" 30 | }, 31 | "console-control-strings": { 32 | "version": "1.1.0", 33 | "resolved": "https://registry.npmmirror.com/console-control-strings/-/console-control-strings-1.1.0.tgz", 34 | "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" 35 | }, 36 | "delegates": { 37 | "version": "1.0.0", 38 | "resolved": "https://registry.npmmirror.com/delegates/-/delegates-1.0.0.tgz", 39 | "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" 40 | }, 41 | "emoji-regex": { 42 | "version": "8.0.0", 43 | "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", 44 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" 45 | }, 46 | "gauge": { 47 | "version": "4.0.0", 48 | "resolved": "https://registry.npmmirror.com/gauge/-/gauge-4.0.0.tgz", 49 | "integrity": "sha512-F8sU45yQpjQjxKkm1UOAhf0U/O0aFt//Fl7hsrNVto+patMHjs7dPI9mFOGUKbhrgKm0S3EjW3scMFuQmWSROw==", 50 | "requires": { 51 | "ansi-regex": "^5.0.1", 52 | "aproba": "^1.0.3 || ^2.0.0", 53 | "color-support": "^1.1.2", 54 | "console-control-strings": "^1.0.0", 55 | "has-unicode": "^2.0.1", 56 | "signal-exit": "^3.0.0", 57 | "string-width": "^4.2.3", 58 | "strip-ansi": "^6.0.1", 59 | "wide-align": "^1.1.2" 60 | } 61 | }, 62 | "has-unicode": { 63 | "version": "2.0.1", 64 | "resolved": "https://registry.npmmirror.com/has-unicode/-/has-unicode-2.0.1.tgz", 65 | "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" 66 | }, 67 | "inherits": { 68 | "version": "2.0.4", 69 | "resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz", 70 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 71 | }, 72 | "is-fullwidth-code-point": { 73 | "version": "3.0.0", 74 | "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 75 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" 76 | }, 77 | "npmlog": { 78 | "version": "6.0.1", 79 | "resolved": "https://registry.npmmirror.com/npmlog/-/npmlog-6.0.1.tgz", 80 | "integrity": "sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg==", 81 | "requires": { 82 | "are-we-there-yet": "^3.0.0", 83 | "console-control-strings": "^1.1.0", 84 | "gauge": "^4.0.0", 85 | "set-blocking": "^2.0.0" 86 | } 87 | }, 88 | "readable-stream": { 89 | "version": "3.6.0", 90 | "resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-3.6.0.tgz", 91 | "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", 92 | "requires": { 93 | "inherits": "^2.0.3", 94 | "string_decoder": "^1.1.1", 95 | "util-deprecate": "^1.0.1" 96 | } 97 | }, 98 | "safe-buffer": { 99 | "version": "5.2.1", 100 | "resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz", 101 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 102 | }, 103 | "set-blocking": { 104 | "version": "2.0.0", 105 | "resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz", 106 | "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" 107 | }, 108 | "signal-exit": { 109 | "version": "3.0.7", 110 | "resolved": "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz", 111 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 112 | }, 113 | "string-width": { 114 | "version": "4.2.3", 115 | "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", 116 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 117 | "requires": { 118 | "emoji-regex": "^8.0.0", 119 | "is-fullwidth-code-point": "^3.0.0", 120 | "strip-ansi": "^6.0.1" 121 | } 122 | }, 123 | "string_decoder": { 124 | "version": "1.3.0", 125 | "resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.3.0.tgz", 126 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 127 | "requires": { 128 | "safe-buffer": "~5.2.0" 129 | } 130 | }, 131 | "strip-ansi": { 132 | "version": "6.0.1", 133 | "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", 134 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 135 | "requires": { 136 | "ansi-regex": "^5.0.1" 137 | } 138 | }, 139 | "util-deprecate": { 140 | "version": "1.0.2", 141 | "resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz", 142 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 143 | }, 144 | "wide-align": { 145 | "version": "1.1.5", 146 | "resolved": "https://registry.npmmirror.com/wide-align/-/wide-align-1.1.5.tgz", 147 | "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", 148 | "requires": { 149 | "string-width": "^1.0.2 || 2 || 3 || 4" 150 | } 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /packages/utils/log/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/log", 3 | "version": "0.5.0", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from root\" && exit 1" 21 | }, 22 | "dependencies": { 23 | "npmlog": "^6.0.1" 24 | }, 25 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 26 | } 27 | -------------------------------------------------------------------------------- /packages/utils/log/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | ansi-regex@^5.0.1: 6 | version "5.0.1" 7 | resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" 8 | integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== 9 | 10 | "aproba@^1.0.3 || ^2.0.0": 11 | version "2.0.0" 12 | resolved "https://registry.yarnpkg.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc" 13 | integrity sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ== 14 | 15 | are-we-there-yet@^3.0.0: 16 | version "3.0.0" 17 | resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d" 18 | integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw== 19 | dependencies: 20 | delegates "^1.0.0" 21 | readable-stream "^3.6.0" 22 | 23 | color-support@^1.1.3: 24 | version "1.1.3" 25 | resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" 26 | integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== 27 | 28 | console-control-strings@^1.1.0: 29 | version "1.1.0" 30 | resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" 31 | integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= 32 | 33 | delegates@^1.0.0: 34 | version "1.0.0" 35 | resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" 36 | integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= 37 | 38 | emoji-regex@^8.0.0: 39 | version "8.0.0" 40 | resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" 41 | integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== 42 | 43 | gauge@^4.0.0: 44 | version "4.0.3" 45 | resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.3.tgz#286cf105c1962c659f0963058fb05116c1b82d3f" 46 | integrity sha512-ICw1DhAwMtb22rYFwEHgJcx1JCwJGv3x6G0OQUq56Nge+H4Q8JEwr8iveS0XFlsUNSI67F5ffMGK25bK4Pmskw== 47 | dependencies: 48 | aproba "^1.0.3 || ^2.0.0" 49 | color-support "^1.1.3" 50 | console-control-strings "^1.1.0" 51 | has-unicode "^2.0.1" 52 | signal-exit "^3.0.7" 53 | string-width "^4.2.3" 54 | strip-ansi "^6.0.1" 55 | wide-align "^1.1.5" 56 | 57 | has-unicode@^2.0.1: 58 | version "2.0.1" 59 | resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" 60 | integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= 61 | 62 | inherits@^2.0.3: 63 | version "2.0.4" 64 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 65 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 66 | 67 | is-fullwidth-code-point@^3.0.0: 68 | version "3.0.0" 69 | resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" 70 | integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== 71 | 72 | npmlog@^6.0.1: 73 | version "6.0.1" 74 | resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.1.tgz#06f1344a174c06e8de9c6c70834cfba2964bba17" 75 | integrity sha512-BTHDvY6nrRHuRfyjt1MAufLxYdVXZfd099H4+i1f0lPywNQyI4foeNXJRObB/uy+TYqUW0vAD9gbdSOXPst7Eg== 76 | dependencies: 77 | are-we-there-yet "^3.0.0" 78 | console-control-strings "^1.1.0" 79 | gauge "^4.0.0" 80 | set-blocking "^2.0.0" 81 | 82 | readable-stream@^3.6.0: 83 | version "3.6.0" 84 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" 85 | integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== 86 | dependencies: 87 | inherits "^2.0.3" 88 | string_decoder "^1.1.1" 89 | util-deprecate "^1.0.1" 90 | 91 | safe-buffer@~5.2.0: 92 | version "5.2.1" 93 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" 94 | integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== 95 | 96 | set-blocking@^2.0.0: 97 | version "2.0.0" 98 | resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" 99 | integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= 100 | 101 | signal-exit@^3.0.7: 102 | version "3.0.7" 103 | resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" 104 | integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== 105 | 106 | "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: 107 | version "4.2.3" 108 | resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" 109 | integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== 110 | dependencies: 111 | emoji-regex "^8.0.0" 112 | is-fullwidth-code-point "^3.0.0" 113 | strip-ansi "^6.0.1" 114 | 115 | string_decoder@^1.1.1: 116 | version "1.3.0" 117 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" 118 | integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== 119 | dependencies: 120 | safe-buffer "~5.2.0" 121 | 122 | strip-ansi@^6.0.1: 123 | version "6.0.1" 124 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" 125 | integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== 126 | dependencies: 127 | ansi-regex "^5.0.1" 128 | 129 | util-deprecate@^1.0.1: 130 | version "1.0.2" 131 | resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 132 | integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= 133 | 134 | wide-align@^1.1.5: 135 | version "1.1.5" 136 | resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3" 137 | integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg== 138 | dependencies: 139 | string-width "^1.0.2 || 2 || 3 || 4" 140 | -------------------------------------------------------------------------------- /packages/utils/request/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/request 9 | 10 | 11 | 12 | 13 | 14 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 15 | 16 | **Note:** Version bump only for package @der-cli/request 17 | -------------------------------------------------------------------------------- /packages/utils/request/README.md: -------------------------------------------------------------------------------- 1 | # `@der-cli/request` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const request = require('@der-cli/request'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/request/__tests__/request.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('../lib'); 4 | 5 | describe('@der-cli/request', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/utils/request/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const axios = require('axios'); 4 | 5 | const BASE_URL = process.env.DER_CLI_BASE_URL ? process.env.DER_CLI_BASE_URL : 6 | 'http://der.aoau.top/'; 7 | 8 | const request = axios.create({ 9 | baseURL: BASE_URL, 10 | timeout: 5000, 11 | }); 12 | 13 | request.interceptors.response.use( 14 | response => { 15 | return response.data; 16 | }, 17 | error => { 18 | return Promise.reject(error); 19 | } 20 | ); 21 | 22 | module.exports = request; -------------------------------------------------------------------------------- /packages/utils/request/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/request", 3 | "version": "0.5.0", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "https://github.com/der-cli/der-cli#readme", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "registry": "https://registry.npmjs.org", 18 | "access": "public" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/der-cli/der-cli.git" 23 | }, 24 | "scripts": { 25 | "test": "echo \"Error: run tests from root\" && exit 1" 26 | }, 27 | "bugs": { 28 | "url": "https://github.com/der-cli/der-cli/issues" 29 | }, 30 | "dependencies": { 31 | "axios": "^0.26.0" 32 | }, 33 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e" 34 | } 35 | -------------------------------------------------------------------------------- /packages/utils/request/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | axios@^0.26.0: 6 | version "0.26.0" 7 | resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" 8 | integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== 9 | dependencies: 10 | follow-redirects "^1.14.8" 11 | 12 | follow-redirects@^1.14.8: 13 | version "1.14.8" 14 | resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" 15 | integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== 16 | -------------------------------------------------------------------------------- /packages/utils/utils/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.5.0](https://github.com/der-cli/der-cli/compare/v0.4.7...v0.5.0) (2022-03-13) 7 | 8 | **Note:** Version bump only for package @der-cli/utils 9 | 10 | 11 | 12 | 13 | 14 | # [0.4.0](https://github.com/der-cli/der-cli/compare/v0.3.3...v0.4.0) (2022-03-03) 15 | 16 | **Note:** Version bump only for package @der-cli/utils 17 | -------------------------------------------------------------------------------- /packages/utils/utils/README.md: -------------------------------------------------------------------------------- 1 | # `utils` 2 | 3 | > TODO: description 4 | 5 | ## Usage 6 | 7 | ``` 8 | const utils = require('utils'); 9 | 10 | // TODO: DEMONSTRATE API 11 | ``` 12 | -------------------------------------------------------------------------------- /packages/utils/utils/__tests__/utils.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require('../lib'); 4 | 5 | describe('utils', () => { 6 | it('needs tests'); 7 | }); -------------------------------------------------------------------------------- /packages/utils/utils/lib/exec.js: -------------------------------------------------------------------------------- 1 | // 兼容windows 2 | function exec(command, args, options) { 3 | const win32 = process.platform === 'win32'; 4 | 5 | const cmd = win32 ? 'cmd' : command; 6 | const cmdArgs = win32 ? ['/c'].concat(command, args) : args; 7 | // windows: cp.spawn('cmd', ['/c', 'node', '-e', code]) 8 | 9 | return require('child_process').spawn(cmd, cmdArgs, options || {}); 10 | } 11 | 12 | // 异步执行 13 | function execAsync(command, args, options) { 14 | return new Promise((resolve, reject) => { 15 | const p = exec(command, args, options); 16 | p.on('error', e => { 17 | reject(e); 18 | }); 19 | p.on('exit', c => { 20 | resolve(c); 21 | }); 22 | }); 23 | } 24 | 25 | module.exports = { 26 | exec, 27 | execAsync 28 | } -------------------------------------------------------------------------------- /packages/utils/utils/lib/file.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function readFile(path, options = {}) { 4 | if (fs.existsSync(path)) { 5 | const buffer = fs.readFileSync(path) 6 | if (buffer) { 7 | if (options.toJson) { 8 | return buffer.toJSON() 9 | } else { 10 | return buffer.toString() 11 | } 12 | } 13 | } 14 | return null; 15 | } 16 | 17 | function writeFile(path, data, { rewrite = true } = {}) { 18 | if (fs.existsSync(path)) { 19 | if (rewrite) { 20 | fs.writeFileSync(path, data) 21 | return true 22 | } 23 | return false 24 | } else { 25 | fs.writeFileSync(path, data) 26 | return true 27 | } 28 | } 29 | 30 | module.exports = { 31 | readFile, 32 | writeFile 33 | }; -------------------------------------------------------------------------------- /packages/utils/utils/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { isObject } = require('./isObject'); 4 | const { spinnerStart } = require('./spinnerStart'); 5 | const { exec, execAsync } = require('./exec'); 6 | const { sleep } = require('./sleep'); 7 | const { readFile, writeFile } = require('./file'); 8 | const terminalLink = require('./terminalLink'); 9 | const inquirer = require('./inquirer'); 10 | 11 | module.exports = { 12 | isObject, 13 | spinnerStart, 14 | exec, 15 | execAsync, 16 | sleep, 17 | readFile, 18 | writeFile, 19 | inquirer, 20 | terminalLink 21 | } -------------------------------------------------------------------------------- /packages/utils/utils/lib/inquirer.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer') 2 | 3 | module.exports = function({ choices, defaultValue, message, type = 'list', require = true, mask = '*' }) { 4 | const options = { 5 | type, 6 | name: 'name', 7 | message, 8 | default: defaultValue, 9 | require, 10 | mask, 11 | } 12 | if (type === 'list') { 13 | options.choices = choices; 14 | } 15 | return inquirer.prompt(options).then((answer) => answer.name) 16 | } 17 | -------------------------------------------------------------------------------- /packages/utils/utils/lib/isObject.js: -------------------------------------------------------------------------------- 1 | function isObject(o) { 2 | return Object.prototype.toString.call(o) === '[object Object]'; 3 | } 4 | 5 | module.exports = { isObject }; -------------------------------------------------------------------------------- /packages/utils/utils/lib/sleep.js: -------------------------------------------------------------------------------- 1 | function sleep(timeout = 1000) { 2 | return new Promise(resolve => setTimeout(resolve, timeout)); 3 | } 4 | 5 | module.exports = { 6 | sleep 7 | } -------------------------------------------------------------------------------- /packages/utils/utils/lib/spinnerStart.js: -------------------------------------------------------------------------------- 1 | const Spinner = require('cli-spinner').Spinner; 2 | 3 | function spinnerStart(msg, spinnerString = '|/-\\') { 4 | const spinner = new Spinner(`${msg}.. %s`); 5 | spinner.setSpinnerString(spinnerString); 6 | spinner.start(); 7 | return spinner; 8 | } 9 | 10 | module.exports = { spinnerStart } -------------------------------------------------------------------------------- /packages/utils/utils/lib/terminalLink.js: -------------------------------------------------------------------------------- 1 | module.exports = function terminalLink(key, url) { 2 | if (!url) { 3 | return require('terminal-link')(key, key); 4 | } else { 5 | return require('terminal-link')(key, url); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/utils/utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@der-cli/utils", 3 | "version": "0.5.0", 4 | "description": "> TODO: description", 5 | "author": "song <3224266014@qq.com>", 6 | "homepage": "", 7 | "license": "GPL", 8 | "main": "lib/index.js", 9 | "directories": { 10 | "lib": "lib", 11 | "test": "__tests__" 12 | }, 13 | "files": [ 14 | "lib" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: run tests from utils\"" 21 | }, 22 | "gitHead": "ff83013d9331007eed4708356e166448ead08b0e", 23 | "dependencies": { 24 | "cli-spinner": "^0.2.10", 25 | "inquirer": "^8.2.0", 26 | "terminal-link": "^2.1.1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /scripts/tests.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/B-SOUL-Studio/cli/5b4c1afe5eed38947529010fa261424463641a50/scripts/tests.js --------------------------------------------------------------------------------