create-vue-workspace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/index.mjs +910 -0
- package/package.json +41 -0
- package/templates/app-web/_env.development +2 -0
- package/templates/app-web/_env.production +2 -0
- package/templates/app-web/index.html +12 -0
- package/templates/app-web/package.json +25 -0
- package/templates/app-web/src/App.vue +18 -0
- package/templates/app-web/src/api/request.ts +15 -0
- package/templates/app-web/src/main.ts +7 -0
- package/templates/app-web/src/router/index.ts +16 -0
- package/templates/app-web/src/stores/app.ts +7 -0
- package/templates/app-web/src/styles/index.scss +8 -0
- package/templates/app-web/src/views/home-view.vue +16 -0
- package/templates/app-web/src/vite-env.d.ts +12 -0
- package/templates/app-web/tsconfig.json +7 -0
- package/templates/app-web/vite.config.ts +17 -0
- package/templates/base/README.md +53 -0
- package/templates/base/_changeset/config.json +11 -0
- package/templates/base/_editorconfig +12 -0
- package/templates/base/_gitignore +12 -0
- package/templates/base/eslint.config.mjs +25 -0
- package/templates/base/package.json +38 -0
- package/templates/base/pnpm-workspace.yaml +3 -0
- package/templates/base/prettier.config.mjs +8 -0
- package/templates/base/stylelint.config.mjs +8 -0
- package/templates/base/tsconfig.base.json +17 -0
- package/templates/base/tsconfig.json +4 -0
- package/templates/base/vitest.config.ts +10 -0
- package/templates/component/__tests__/{{fileName}}.component.spec.tsx +17 -0
- package/templates/component/components/{{fileName}}-sub.component.tsx +9 -0
- package/templates/component/composition/use-{{fileName}}.ts +46 -0
- package/templates/component/index.ts +12 -0
- package/templates/component/package.json +31 -0
- package/templates/component/tsconfig.json +5 -0
- package/templates/component/types.ts +5 -0
- package/templates/component/vite.config.ts +17 -0
- package/templates/component/{{fileName}}.component.tsx +22 -0
- package/templates/component/{{fileName}}.props.ts +12 -0
- package/templates/component/{{fileName}}.scss +11 -0
- package/templates/hook/use-{{kebab}}.ts +26 -0
- package/templates/pkg-lib/package.json +24 -0
- package/templates/pkg-lib/src/index.ts +5 -0
- package/templates/pkg-lib/tsconfig.json +4 -0
- package/templates/pkg-lib/vite.config.ts +17 -0
- package/templates/pkg-ui/package.json +31 -0
- package/templates/pkg-ui/src/index.ts +7 -0
- package/templates/pkg-ui/src/styles/index.scss +6 -0
- package/templates/pkg-ui/tsconfig.json +4 -0
- package/templates/pkg-ui/vite.config.ts +17 -0
- package/templates/pkg-utils/package.json +24 -0
- package/templates/pkg-utils/src/index.ts +20 -0
- package/templates/pkg-utils/tsconfig.json +4 -0
- package/templates/pkg-utils/vite.config.ts +13 -0
- package/templates/util/{{kebab}}.ts +4 -0
- package/templates/view/{{fileName}}.vue +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 create-vue-workspace contributors
|
|
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
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# create-vue-workspace
|
|
2
|
+
|
|
3
|
+
一个可发布到 npm 的 CLI,用于生成 **Vue 3 + Vite + TypeScript 的 pnpm monorepo 工作区**,并以 Angular CLI 风格的 `new` + `generate` 命令持续生成代码。
|
|
4
|
+
|
|
5
|
+
命令别名:`cvw`(对应 create-vue-workspace)
|
|
6
|
+
|
|
7
|
+
## 命令模型
|
|
8
|
+
|
|
9
|
+
对齐 Angular CLI 的两段式:`new` 建工作区,`generate` 跑生成器。
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
cvw new [name] # 创建工作区
|
|
13
|
+
cvw generate <type> [name] # 运行生成器,别名 cvw g
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### 生成器
|
|
17
|
+
|
|
18
|
+
| type | 别名 | 产物 | 关键选项 |
|
|
19
|
+
| --- | --- | --- | --- |
|
|
20
|
+
| `component` | `c` | `packages/<name>/` 独立组件包,并自动接线聚合包 | `--aggregator`(默认 `ui`)、`--with-sub`、`--skip-tests` |
|
|
21
|
+
| `package` | `pkg` | `packages/<name>/` 通用包骨架 | `--vue`(附带 vue 依赖) |
|
|
22
|
+
| `hook` | `h` | `<pkg>/src/composition/use-<name>.ts`,并追加 re-export | `--pkg`(默认 `hooks`) |
|
|
23
|
+
| `view` | `v` | `apps/<app>/src/views/<name>.vue`,并自动注册路由 | `--app`(默认 `web`)、`--route`、`--skip-route` |
|
|
24
|
+
| `util` | `u` | `<pkg>/src/<name>.ts`,并追加 re-export | `--pkg`(默认 `utils`) |
|
|
25
|
+
| `app` | `a` / `application` | `apps/<name>/` 新应用,并维护根 scripts 与 changeset ignore | `--port`、`--template`(默认 `web`)、`--ui` |
|
|
26
|
+
|
|
27
|
+
所有生成器通用:`--dry-run`(只打印将生成的文件,不落盘)、`-y/--yes`(非交互)。
|
|
28
|
+
|
|
29
|
+
### 快速开始
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 创建工作区
|
|
33
|
+
pnpm create vue-workspace my-app
|
|
34
|
+
# 或
|
|
35
|
+
npx create-vue-workspace@latest my-app
|
|
36
|
+
|
|
37
|
+
cd my-app
|
|
38
|
+
pnpm install
|
|
39
|
+
pnpm dev
|
|
40
|
+
|
|
41
|
+
# 生成代码
|
|
42
|
+
cvw g c button # 独立组件包,自动接线 packages/ui
|
|
43
|
+
cvw g pkg hooks --vue # 通用包
|
|
44
|
+
cvw g h theme --pkg hooks # composable
|
|
45
|
+
cvw g u array # 工具函数模块
|
|
46
|
+
cvw g v user/list # 页面 + 自动注册路由
|
|
47
|
+
cvw g app admin --port 5174
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### `cvw new` 选项
|
|
51
|
+
|
|
52
|
+
| 参数 | 说明 | 默认值 |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `--scope <@xxx>` | 生成物的包 scope | 由目录名推导,如 `@my-app` |
|
|
55
|
+
| `--packages <list>` | 初始创建的 packages,逗号分隔 | `ui,utils` |
|
|
56
|
+
| `--ui <farris\|none>` | 是否引入 `@farris/ui-vue` | `farris` |
|
|
57
|
+
| `--port <port>` | 应用开发端口 | `5173` |
|
|
58
|
+
| `--skip-install` | 跳过依赖安装 | — |
|
|
59
|
+
| `--skip-git` | 跳过 git 初始化 | — |
|
|
60
|
+
| `--dry-run` | 只打印将生成的文件,不落盘 | — |
|
|
61
|
+
| `-y, --yes` | 全部使用默认值,非交互(适合 CI) | — |
|
|
62
|
+
|
|
63
|
+
### 交互式
|
|
64
|
+
|
|
65
|
+
省略参数时会像 Angular CLI 一样追问,`-y` 下则直接报错:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cvw g # 追问:选择生成器
|
|
69
|
+
cvw g c # 追问:组件名称
|
|
70
|
+
cvw new # 追问:工程信息
|
|
71
|
+
cvw g list # 打印生成器清单
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 名称归一化
|
|
75
|
+
|
|
76
|
+
输入 `Button` / `button` / `input_group` 都会被归一化:目录 `button`、组件名 `FButton`、选择器 `f-button`、文件 `button.component.tsx`。
|
|
77
|
+
|
|
78
|
+
`cvw g h use-theme` 与 `cvw g h theme` 等价(自动去掉 `use` 前缀)。
|
|
79
|
+
|
|
80
|
+
### 错误处理
|
|
81
|
+
|
|
82
|
+
- 生成器目标已存在 → 报错并退出(退出码 1)
|
|
83
|
+
- `hook` / `util` 的目标包不存在 → 报错并提示先执行 `cvw g pkg <name>`
|
|
84
|
+
- `view` 找不到 `// cvw:routes` 锚点 → 跳过路由注册并提示手写
|
|
85
|
+
|
|
86
|
+
## 生成物结构
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
my-app/
|
|
90
|
+
├── apps/
|
|
91
|
+
│ └── web/ # @my-app/web,private,永不发包
|
|
92
|
+
│ └── src/
|
|
93
|
+
├── packages/
|
|
94
|
+
│ ├── ui/ # @my-app/ui,组件聚合包
|
|
95
|
+
│ ├── utils/ # @my-app/utils,纯 TS 工具
|
|
96
|
+
│ └── button/ # cvw g c 生成,独立组件包
|
|
97
|
+
│ ├── index.ts
|
|
98
|
+
│ ├── button.component.tsx
|
|
99
|
+
│ ├── button.props.ts
|
|
100
|
+
│ ├── composition/
|
|
101
|
+
│ ├── __tests__/
|
|
102
|
+
│ ├── package.json
|
|
103
|
+
│ └── vite.config.ts
|
|
104
|
+
├── pnpm-workspace.yaml
|
|
105
|
+
├── tsconfig.base.json
|
|
106
|
+
└── .changeset/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
组件骨架遵循《Farris UI Vue 组件开发规范》:`index.ts` + `<name>.component.tsx` + `<name>.props.ts` + `composition/` + `__tests__/`,组件名 `F` 前缀、选择器 `f-` 前缀。
|
|
110
|
+
|
|
111
|
+
## 开发约定
|
|
112
|
+
|
|
113
|
+
- 内部包引用一律使用 `workspace:*`,不要写死版本号
|
|
114
|
+
- 应用通过 Vite alias 直连 `packages/*/src` 源码,改库无需重新构建
|
|
115
|
+
- 依赖方向单向:`utils -> 组件包 -> ui -> apps`,禁止反向依赖
|
|
116
|
+
- `apps/*` 已在 `.changeset/config.json` 中 `ignore`,不会参与发布
|
|
117
|
+
|
|
118
|
+
## 版本管理与发布
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pnpm changeset # 记录变更
|
|
122
|
+
pnpm version-packages # 升版本、生成 CHANGELOG
|
|
123
|
+
pnpm release # 构建并发布到 npm
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 本地开发(本仓库)
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pnpm install
|
|
130
|
+
pnpm dev # 直接运行 CLI(tsx)
|
|
131
|
+
pnpm play # 生成一份真实产物到 playground/ 预览(覆盖全部生成器)
|
|
132
|
+
pnpm test # 单元测试
|
|
133
|
+
pnpm typecheck # 类型检查
|
|
134
|
+
pnpm build # unbuild -> dist
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 发布本 CLI
|
|
138
|
+
|
|
139
|
+
采用「构建 + 收集」两段式:`npm run build` 先产出 CLI,再把发包所需文件收集到 `dist/create-vue-workspace/`,形成一个**自包含的可发布包**。
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
dist/create-vue-workspace/
|
|
143
|
+
├── package.json # 已裁剪:无 scripts / devDependencies / private
|
|
144
|
+
├── README.md
|
|
145
|
+
├── LICENSE
|
|
146
|
+
├── dist/index.mjs # CLI 产物
|
|
147
|
+
└── templates/ # 全部模板
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
发布:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm login # 首次发布需先登录
|
|
154
|
+
npm run build # unbuild + 收集到 dist/create-vue-workspace/
|
|
155
|
+
cd dist/create-vue-workspace
|
|
156
|
+
npm pack --dry-run # 自检:应只含 dist/ + templates/ + README + LICENSE + package.json
|
|
157
|
+
npm publish
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
或一步到位(先构建再发布):
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm run publish:dist
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
约定与注意事项:
|
|
167
|
+
|
|
168
|
+
- 仓库根 `package.json` 标记了 `private: true`,表明它本身不是对外发布的包;请始终从 `dist/create-vue-workspace/` 发布
|
|
169
|
+
- 升版本在仓库根执行 `npm version patch|minor|major`,再重新 `npm run build`
|
|
170
|
+
- 暂存目录由每次 `npm run build` 重建(`unbuild` 会先清空 `dist/`),因此发布前务必先 build,避免发出陈旧产物
|
|
171
|
+
- 若改为 scoped 包名,需保留 `publishConfig.access: "public"`
|
|
172
|
+
|
|
173
|
+
> 本 CLI 仓库自身未接入 changesets(changesets 只出现在生成物模板中),版本号由 `npm version` 手动维护。
|