@bams-app/work-cli 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -157,58 +157,30 @@ cd work/configs && npm publish --registry=https://registry.npmjs.org/
157
157
 
158
158
  `work-cli` 与 `create` 生成的项目均以 `"*"` 声明 `@bams-app/ui-dev-server`:仓库内直接链接到
159
159
  本地包,发布后自动解析为 registry 上最新的已发布版本,无需手动改版本号。
160
+ 用户项目升级时使用 `npm i @bams-app/ui-dev-server@latest`,该命令会把声明改写为 `^x.y.z`。
160
161
 
161
162
  ## 用户项目升级
162
163
 
163
- 用户项目的 `devDependencies` 只声明 `@bams-app/ui-dev-server` 一个(`"*"`),能力包与
164
- 运行时依赖全部作为它的传递依赖解析到同一份包,提升到项目根 `node_modules`。
164
+ 用户项目只声明 `@bams-app/ui-dev-server` 一个依赖,能力包与运行时依赖全部作为它的传递依赖解析到
165
+ 同一份包,提升到项目根 `node_modules`。
165
166
 
166
- ### 为什么直接用 npm 命令带不动这些依赖
167
-
168
- 能力包在 ui-dev-server 里声明为 `"*"`,运行时依赖是普通版本范围,而项目
169
- `package-lock.json` 已把它们逐个钉死在具体版本、且仍满足声明范围,npm 便不再重新解析:
170
- `npm install` 与 `npm update @bams-app/ui-dev-server` 都不会动它们;裸 `npm update` 虽能带上,
171
- 但会重解析整棵依赖树、顺带升级其它第三方依赖。所以只能清掉它们在 lockfile 里的记录,
172
- 让 npm 重新解析。
173
-
174
- ### 升级步骤
167
+ ui-dev-server 对能力包声明的是显式版本范围(`^x.y.z`),范围随 ui-dev-server 每次发布同步更新,
168
+ 因此升级就是一条命令:
175
169
 
176
170
  ```bash
177
- # 1. ui-dev-server 的依赖清单清理 package-lock.json
178
- node -e "
179
- const fs = require('fs');
180
- const dev = JSON.parse(fs.readFileSync('node_modules/@bams-app/ui-dev-server/package.json', 'utf8'));
181
- const names = new Set([...Object.keys(dev.dependencies || {}), '@bams-app/ui-dev-server']);
182
- const lock = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'));
183
- let removed = 0;
184
- for (const section of ['packages', 'dependencies']) {
185
- const container = lock[section];
186
- if (!container) continue;
187
- for (const key of Object.keys(container)) {
188
- const name = key.replace(/^.*node_modules\//, '');
189
- if (names.has(name)) { delete container[key]; removed++; }
190
- }
191
- }
192
- fs.writeFileSync('package-lock.json', JSON.stringify(lock, null, 2) + '\n');
193
- console.log('已清理', removed, '条由 ui-dev-server 提供的依赖记录');
194
- "
195
-
196
- # 2. 这些包按 ui-dev-server 声明的版本重新解析,其余依赖保持锁定不动
197
- npm install
171
+ npm i @bams-app/ui-dev-server@latest
198
172
  ```
199
173
 
200
- 清理范围必须覆盖 ui-dev-server 声明的**全部**依赖:只删 `@bams-app/*` 的话,能力包会刷新,
201
- vue / axios 等运行时依赖仍停在 lockfile 里的旧版本。
174
+ 新版本的依赖范围与 `package-lock.json` 中钉住的旧版本不再匹配,npm 会自动重新解析整套能力包,
175
+ 无需手工清理 lockfile(历史版本遗留的 `*` 范围才需要旧办法,见 git 历史)。
202
176
 
203
- 只想升 ui-dev-server 本身、不在意它带的依赖时,直接 `npm i @bams-app/ui-dev-server@latest`。
204
- 跨大版本(0.1 → 0.2)先改 `package.json` 为 `"^0.2.0"`,再执行上面的两步。
177
+ 跨大版本(0.1 0.2)同理,直接执行上面的命令即可。
205
178
 
206
179
  ### 前提
207
180
 
208
- - 升级前确保对应版本已发布:`"*"` 只解析 registry 上已发布的版本。
181
+ - 升级前确保对应版本已发布:能力包与 ui-dev-server 由 `yarn publish-all` 同批次发布。
209
182
  - registry 指向:`create` 不生成项目 `.npmrc`,`@bams-app/*` 默认走官方 npm
210
- (registry.npmjs.org);仅在内网隔离、必须走私服时,才在项目 `.npmrc` 手动加
211
- `@bams-app:registry=https://npm.hedpy.cn/`(私服若存在同名旧版本,会遮蔽官方新版)。
183
+ (切私服需在执行 `create` 时指定 registry)。
212
184
 
213
185
  ## 环境要求
214
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bams-app/work-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "BAMS-Work 全局开发工具:复用 work 已发布的包(create-env / create-ui-*)提供项目初始化、组件创建与环境配置能力,开发调试由用户项目本地的 ui-dev-server 承担",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,12 +13,12 @@
13
13
  "templates"
14
14
  ],
15
15
  "dependencies": {
16
- "@bams-app/create-env": "*",
17
- "@bams-app/create-pages-entry": "*",
18
- "@bams-app/create-pages-from-components": "*",
19
- "@bams-app/create-ui-base": "*",
20
- "@bams-app/create-ui-component": "*",
21
- "@bams-app/create-ui-page": "*"
16
+ "@bams-app/create-env": "^0.1.3",
17
+ "@bams-app/create-pages-entry": "^0.1.3",
18
+ "@bams-app/create-pages-from-components": "^0.1.3",
19
+ "@bams-app/create-ui-base": "^0.1.3",
20
+ "@bams-app/create-ui-component": "^0.1.3",
21
+ "@bams-app/create-ui-page": "^0.1.3"
22
22
  },
23
23
  "engines": {
24
24
  "node": ">=16.7.0"
@@ -13,6 +13,14 @@ demo-ui/ui-component-demo # 示例组件
13
13
  <scope>-ui/ui-xxx # 业务组件(add 时创建)
14
14
  ```
15
15
 
16
+ ## 前置条件(必需)
17
+
18
+ 必须先全局安装 CLI,否则 `work` 命令(`work add` / `work env` / `work pages-entry`)不可用:
19
+
20
+ ```bash
21
+ npm i -g @bams-app/work-cli
22
+ ```
23
+
16
24
  ## 开始
17
25
 
18
26
  ```bash
@@ -32,40 +40,26 @@ npm run dev:ui demo -- --port 8080 # `--` 之后透传给 vue-cli-servi
32
40
 
33
41
  ## 命令
34
42
 
35
- | 命令 | 作用 |
36
- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
37
- | `npm run dev:ui <环境标识> [组件名]` | 启动开发服务 |
43
+ | 命令 | 作用 |
44
+ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
45
+ | `npm run dev:ui <环境标识> [组件名]` | 启动开发服务 |
38
46
  | `work add --dir <scope> --name <name> [--type component\|page\|base] [--desc ...]` | 新建组件/页面/基础组件;scope 目录不存在会自动创建并注册到根 `package.json` |
39
- | `work env` | 交互式生成 `.envs/.env.dev-<标识>` |
40
- | `work pages-entry --dir <scope> --type page\|component` | 生成构建用动态入口(内部使用) |
41
- | `work pages-from-components --dir <scope>` | 把 `ui-*` 批量复制为 `page-*` |
47
+ | `work env` | 交互式生成 `.envs/.env.dev-<标识>` |
48
+ | `work pages-entry --dir <scope> --type page\|component` | 生成构建用动态入口(内部使用) |
49
+ | `work pages-from-components --dir <scope>` | 把 `ui-*` 批量复制为 `page-*` |
42
50
 
43
51
  环境文件字段:`PORT`、`PROXY_TARGET`、`BASE_URL`、`VUE_APP_*` 等,见模板文件;改完重跑 `dev:ui` 生效。
44
52
 
45
53
  ## 依赖升级
46
54
 
47
55
  项目只声明 `@bams-app/ui-dev-server`,能力包与 vue、devextreme 等运行时依赖都由它提供并提升到根 `node_modules`。
56
+ ui-dev-server 对能力包声明的是显式版本范围(`^x.y.z`),范围随它每次发布同步更新,因此升级就是一条命令:
48
57
 
49
58
  ```bash
50
- npm i @bams-app/ui-dev-server@latest # 只换 ui-dev-server
59
+ npm i @bams-app/ui-dev-server@latest
51
60
  ```
52
61
 
53
- lockfile 会把 ui-dev-server 提供的包逐个钉死;要连带刷新这些包,先清理记录再安装:
54
-
55
- ```bash
56
- node -e "
57
- const fs=require('fs');
58
- const dev=JSON.parse(fs.readFileSync('node_modules/@bams-app/ui-dev-server/package.json','utf8'));
59
- const names=new Set([...Object.keys(dev.dependencies||{}),'@bams-app/ui-dev-server']);
60
- const lock=JSON.parse(fs.readFileSync('package-lock.json','utf8'));
61
- let n=0;
62
- for(const s of ['packages','dependencies']){const c=lock[s];if(!c)continue;
63
- for(const k of Object.keys(c))if(names.has(k.replace(/^.*node_modules\//,''))){delete c[k];n++}}
64
- fs.writeFileSync('package-lock.json',JSON.stringify(lock,null,2)+'\n');
65
- console.log('已清理',n,'条');
66
- "
67
- npm install
68
- ```
62
+ 新范围与 `package-lock.json` 中钉住的旧版本不再匹配,npm 会自动重新解析整套能力包,无需手工清理 lockfile。
69
63
 
70
64
  全局 CLI 升级:`npm i -g @bams-app/work-cli@latest`。
71
65