@liuli-util/cli 3.16.0 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +30 -42
- package/README.zh-CN.md +86 -0
- package/dist/bin.js +72 -72
- package/dist/bin.js.map +3 -3
- package/dist/commands/deploy/DeployService.d.ts +26 -7
- package/dist/commands/deploy/DeployService.d.ts.map +1 -1
- package/dist/commands/deploy/index.d.ts.map +1 -1
- package/dist/commands/deploy/util/validate.d.ts +8 -0
- package/dist/commands/deploy/util/validate.d.ts.map +1 -0
- package/package.json +74 -72
- package/src/commands/deploy/DeployService.ts +103 -46
- package/src/commands/deploy/__tests__/DeployService.test.ts +52 -19
- package/src/commands/deploy/__tests__/simpleGit.test.ts +26 -1
- package/src/commands/deploy/index.ts +2 -1
- package/src/commands/deploy/util/validate.ts +18 -0
- package/src/commands/sync/__tests__/.temp/package.json +16 -0
- package/templates/cli/package.json +1 -5
- package/templates/cli/src/bin.ts +1 -1
- package/templates/cli/tsconfig.json +28 -28
- package/templates/lib/package.json +3 -10
- package/templates/lib/tsconfig.json +28 -28
- package/tsconfig.json +34 -34
- package/src/commands/esbuild/__tests__/.temp/getDeps/package.json +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/CHANGELOG.md +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/README.md +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/bin.js +0 -3
- package/src/commands/generate/__tests__/.temp/test-cli/package.json +0 -44
- package/src/commands/generate/__tests__/.temp/test-cli/src/bin.ts +0 -13
- package/src/commands/generate/__tests__/.temp/test-cli/src/index.ts +0 -1
- package/src/commands/generate/__tests__/.temp/test-cli/tsconfig.json +0 -28
package/CHANGELOG.md
CHANGED
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 rxliuli
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1,49 +1,51 @@
|
|
1
1
|
# @liuli-util/cli
|
2
2
|
|
3
|
-
|
3
|
+
> [中文](https://github.com/rxliuli/liuli-tools/tree/master/apps/liuli-cli/README.zh-CN.md)
|
4
4
|
|
5
|
-
|
5
|
+
A zero-configuration CLI packaged for libraries and CLI applications.
|
6
6
|
|
7
|
-
|
7
|
+
## Getting started
|
8
|
+
|
9
|
+
### Install
|
8
10
|
|
9
11
|
```sh
|
10
|
-
yarn add -D @liuli-util/cli #
|
11
|
-
npm i -g @liuli-util/cli #
|
12
|
+
yarn add -D @liuli-util/cli # local installation
|
13
|
+
npm i -g @liuli-util/cli # install globally
|
12
14
|
```
|
13
15
|
|
14
|
-
###
|
16
|
+
### Bale
|
15
17
|
|
16
18
|
```sh
|
17
|
-
yarn liuli-cli build lib #
|
18
|
-
yarn liuli-cli build cli #
|
19
|
+
yarn liuli-cli build lib # package library
|
20
|
+
yarn liuli-cli build cli # package cli reference program
|
19
21
|
```
|
20
22
|
|
21
|
-
>
|
23
|
+
> Add the `-w` option to start the watch mode of rollup, the packaged dist/ will not be compressed and the dependencies will not be included in the bundle.
|
22
24
|
|
23
|
-
![
|
25
|
+
![Monitor Mode](https://liuli.dev/images/liuli-cli%20%E7%9B%91%E8%A7%86%E6%A8%A1%E5%BC%8F.gif)
|
24
26
|
|
25
|
-
###
|
27
|
+
### Generate
|
26
28
|
|
27
29
|
```sh
|
28
|
-
yarn liuli-cli generate <name> --template lib #
|
29
|
-
yarn liuli-cli generate <name> --template cli #
|
30
|
+
yarn liuli-cli generate <name> --template lib # Generate ts-lib project
|
31
|
+
yarn liuli-cli generate <name> --template cli # Generate cli project
|
30
32
|
```
|
31
33
|
|
32
|
-
util
|
34
|
+
util also supports interactive project creation
|
33
35
|
|
34
36
|
```shell
|
35
37
|
yarn liuli-cli generate
|
36
38
|
```
|
37
39
|
|
38
|
-
![
|
40
|
+
![Liuli-cli interactively create screenshots](https://liuli.dev/images/liuli-cli%20%E4%BA%A4%E4%BA%92%E5%BC%8F%E5%88%9B %E5%BB%BA%E6%88%AA%E5%9B%BE.gif)
|
39
41
|
|
40
|
-
###
|
42
|
+
### Sync configuration
|
41
43
|
|
42
44
|
```shell
|
43
45
|
yarn liuli-cli sync
|
44
46
|
```
|
45
47
|
|
46
|
-
|
48
|
+
Which configuration needs to be synced in package.json
|
47
49
|
|
48
50
|
```json
|
49
51
|
{
|
@@ -51,7 +53,7 @@ yarn liuli-cli sync
|
|
51
53
|
}
|
52
54
|
```
|
53
55
|
|
54
|
-
|
56
|
+
Currently supported configuration items
|
55
57
|
|
56
58
|
- prettier
|
57
59
|
- commitlint
|
@@ -62,39 +64,25 @@ yarn liuli-cli sync
|
|
62
64
|
- eslint-vue-ts
|
63
65
|
- jest
|
64
66
|
|
65
|
-
|
67
|
+
Future goals: By default will include checking the synchronization of the cli itself (if it needs to be used outside of a monorepo), eslint/style-lint etc., and implementing an interactive cli when not configured
|
66
68
|
|
67
|
-
>
|
69
|
+
> Note: Currently only the dependencies are synced and no installation is performed
|
68
70
|
|
69
|
-
|
71
|
+
Interactive initialization synchronization configuration is also supported
|
70
72
|
|
71
73
|
```shell
|
72
74
|
yarn liuli-cli sync init
|
73
75
|
```
|
74
76
|
|
75
|
-
##
|
77
|
+
## design concept
|
76
78
|
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
79
|
+
- Convention over configuration, configuration should not be provided if possible. VitePress does this too, reference: https://vitepress.vuejs.org/#lighter-page-weight This leads to some constraints, including the following
|
80
|
+
- When packaging the library, the entry file must be `src/index.ts`, and the export file must be `dist/index.esm.js` and `dist/index.js`
|
81
|
+
- When packaging the CLI, the entry file must be `src/bin.ts`, and the exit file must be `dist/bin.js`
|
82
|
+
- All dependencies will be treated as external dependencies when packaging lib, and all dependencies will be bundled when packaging cli
|
81
83
|
|
82
84
|
## FAQ
|
83
85
|
|
84
|
-
###
|
85
|
-
|
86
|
-
事实上,esbuild 本身非常非常非常快(重要的事情说三遍),但如果使用 js 封装 CLI,则性能会迅速降低。
|
87
|
-
|
88
|
-
打包这个项目使用 esbuild、cli 封装、rollup 的时间对比如下
|
89
|
-
|
90
|
-
| 打包方式 | 时间 |
|
91
|
-
| -------- | ----- |
|
92
|
-
| esbuild | 0.49s |
|
93
|
-
| cli 封装 | 3.2s |
|
94
|
-
| rollup | 3.65s |
|
95
|
-
|
96
|
-
> 现在 [vscode 插件打包官方推荐使用 esbuild](https://code.visualstudio.com/api/working-with-extensions/bundling-extension) ,吾辈在生产项目中也有过实践,长期而言吾辈比较看好这类更高性能的打包工具。
|
97
|
-
|
98
|
-
### 为什么不捆绑外部依赖项
|
86
|
+
### Why not bundle external dependencies
|
99
87
|
|
100
|
-
|
88
|
+
The main reason is that you want to leave the bundling work to the final application, avoid bundling the same dependencies repeatedly, and also avoid dealing with the problem of using `worker_threads` directly based on the file system in nodejs.
|
package/README.zh-CN.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# @liuli-util/cli
|
2
|
+
|
3
|
+
一个针对于库和 CLI 应用程序打包的零配置 CLI。
|
4
|
+
|
5
|
+
## 起步
|
6
|
+
|
7
|
+
### 安装
|
8
|
+
|
9
|
+
```sh
|
10
|
+
yarn add -D @liuli-util/cli # 局部安装
|
11
|
+
npm i -g @liuli-util/cli # 全局安装
|
12
|
+
```
|
13
|
+
|
14
|
+
### 打包
|
15
|
+
|
16
|
+
```sh
|
17
|
+
yarn liuli-cli build lib # 打包库
|
18
|
+
yarn liuli-cli build cli # 打包 cli 引用程序
|
19
|
+
```
|
20
|
+
|
21
|
+
> 添加 `-w` 选项则启动 rollup 的监视模式,打包出来的 dist/ 不会压缩且不会将依赖项打进 bundle。
|
22
|
+
|
23
|
+
![监视模式](https://liuli.dev/images/liuli-cli%20%E7%9B%91%E8%A7%86%E6%A8%A1%E5%BC%8F.gif)
|
24
|
+
|
25
|
+
### 生成
|
26
|
+
|
27
|
+
```sh
|
28
|
+
yarn liuli-cli generate <name> --template lib # 生成 ts-lib 项目
|
29
|
+
yarn liuli-cli generate <name> --template cli # 生成 cli 项目
|
30
|
+
```
|
31
|
+
|
32
|
+
util 也支持交互式的创建项目
|
33
|
+
|
34
|
+
```shell
|
35
|
+
yarn liuli-cli generate
|
36
|
+
```
|
37
|
+
|
38
|
+
![liuli-cli 交互式创建截图](https://liuli.dev/images/liuli-cli%20%E4%BA%A4%E4%BA%92%E5%BC%8F%E5%88%9B%E5%BB%BA%E6%88%AA%E5%9B%BE.gif)
|
39
|
+
|
40
|
+
### 同步配置
|
41
|
+
|
42
|
+
```shell
|
43
|
+
yarn liuli-cli sync
|
44
|
+
```
|
45
|
+
|
46
|
+
需要在 package.json 中指定同步哪些配置
|
47
|
+
|
48
|
+
```json
|
49
|
+
{
|
50
|
+
"sync": ["prettier", "workspaces", "commitlint", "simplehooks"]
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
54
|
+
目前支持的配置项
|
55
|
+
|
56
|
+
- prettier
|
57
|
+
- commitlint
|
58
|
+
- simplehooks
|
59
|
+
- workspaces
|
60
|
+
- gitignore
|
61
|
+
- eslint-ts
|
62
|
+
- eslint-vue-ts
|
63
|
+
- jest
|
64
|
+
|
65
|
+
未来的目标:默认将包括检查 cli 自身的同步(如果需要在 monorepo 之外使用的话),eslint/style-lint 之类,还有在没有配置时实现交互式 cli
|
66
|
+
|
67
|
+
> 注:目前仅同步依赖而不会执行安装
|
68
|
+
|
69
|
+
也支持交互式的初始化同步配置
|
70
|
+
|
71
|
+
```shell
|
72
|
+
yarn liuli-cli sync init
|
73
|
+
```
|
74
|
+
|
75
|
+
## 设计理念
|
76
|
+
|
77
|
+
- 约定大于配置,如果可能应该不提供配置。VitePress 也是这样做的,参考:https://vitepress.vuejs.org/#lighter-page-weight 这会导致一些约束,包括以下内容
|
78
|
+
- 打包库时入口文件必须是 `src/index.ts`,出口文件则是 `dist/index.esm.js` 与 `dist/index.js`
|
79
|
+
- 打包 CLI 时入口文件必须是 `src/bin.ts`,出口文件则是 `dist/bin.js`
|
80
|
+
- 在打包 lib 时会将所有的依赖作为外部依赖处理,而在打包 cli 时会将所有依赖项打进 bundle
|
81
|
+
|
82
|
+
## FAQ
|
83
|
+
|
84
|
+
### 为什么不捆绑外部依赖项
|
85
|
+
|
86
|
+
主要原因是希望将捆绑的工作交由最终应用完成,避免重复捆绑相同的依赖,而且还可以避免处理 nodejs 中直接基于文件系统使用 `worker_threads` 的问题。
|