Skip to content

Commit 0e6b262

Browse files
committed
add EXTERNAL
1 parent 64a25e6 commit 0e6b262

File tree

7 files changed

+116
-45
lines changed

7 files changed

+116
-45
lines changed

CHANGELOG.en-US.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
---
88

9+
## 1.6.0
10+
11+
`2023-02-04`
12+
13+
[#22](https://github.com/guMcrey/version-rocket/issues/22)
14+
- 🆕 generate-version-file add EXTERNAL env,can be used to display richer content when customizing the popup UI. Such as current version updates or other information
15+
- 💄 update README.md and README.zh-CN.md
16+
917
## 1.5.0
1018

1119
`2023-01-17`

CHANGELOG.zh-CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
---
88

9+
## 1.6.0
10+
11+
`2023-02-04`
12+
13+
[#22](https://github.com/guMcrey/version-rocket/issues/22)
14+
- 🆕 generate-version-file 新增 EXTERNAL 坏境变量,可用于在自定义弹窗 UI 时展示更丰富内容。如当前版本更新内容或其他信息
15+
- 💄 更新 README.md 和 README.zh-CN.md 文档
16+
917
## 1.5.0
1018

1119
`2023-01-17`

README.md

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Step 2: after executing the `generate-version-file` custom command, generate the
115115

116116
- File output directory (optional): **user defined version.json output directory**, which is the dist directory by default
117117

118+
- `EXTERNAL` (optional): when you want to save more information to `version.json`, such as the modified content of the current version or other things that need to be displayed on the pop-up (used in onVersionUpdate custom UI) `v1.6.0`
119+
118120
```javascript
119121
// package.json
120122

@@ -137,6 +139,35 @@ Step 2: after executing the `generate-version-file` custom command, generate the
137139

138140
```
139141

142+
**EXTERNAL usage** `v1.6.0`
143+
144+
JSON format please use this tool to escape [click here](https://codebeautify.org/json-encode-online)
145+
146+
```javascript
147+
// package.json
148+
149+
{
150+
"name": "test",
151+
"description": "test",
152+
"private": true,
153+
"version": "0.0.1",
154+
"scripts": {
155+
...
156+
// Mac or Linux (simple text)
157+
"generate:version": "EXTERNAL='some text' generate-version-file dist public"
158+
// Mac or Linux (JSON text)
159+
"generate:version": "EXTERNAL='{\"update\":\"fix bugs\",\"content\":\"some tips\"}' generate-version-file dist public"
160+
// Windows (simple text)
161+
"generate:version": "set EXTERNAL=some text && generate-version-file dist public"
162+
// Windows (JSON text)
163+
"generate:version": "set EXTERNAL={\"update\":\"fix bugs\",\"content\":\"some tips\"} && generate-version-file dist public"
164+
...
165+
},
166+
...
167+
}
168+
169+
```
170+
140171
<details>
141172
<summary>⚠️ Notice:</summary>
142173
If your project is connected to CDN, it is strongly recommended that you set the `version.json` file is set to always no caching (configure in nginx or turn off the function of CDN ignoring the parameter cache)
@@ -311,17 +342,16 @@ If your card copy will be generated according to conditions, you can pass in `ME
311342
...
312343
// Mac or Linux system
313344
"send-lark-message:test": "MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-lark-message"
314-
// Windows system: install cross-env first
315-
// npm install cross-env -D
316-
"send-lark-message:test": "cross-env MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-lark-message"
345+
// Windows system
346+
"send-lark-message:test": "set MESSAGE_JSON={\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true} && send-lark-message"
317347
...
318348
},
319349
...
320350
}
321351
322352
```
323353
324-
Or after export variables, quote in package.json
354+
Or after export variables, quote in package.json (not support Windows)
325355
326356
```javascript
327357
@@ -340,11 +370,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
340370
"version": "0.0.1",
341371
"scripts": {
342372
...
343-
// Mac or Linux system
344373
"send-lark-message:test": "MESSAGE_JSON=${messageJSON} send-lark-message"
345-
// Windows system: install cross-env first
346-
// npm install cross-env -D
347-
"send-lark-message:test": "cross-env MESSAGE_JSON=${messageJSON} send-lark-message"
348374
...
349375
},
350376
...
@@ -467,16 +493,15 @@ If your card copy will be generated according to conditions, you can pass in `ME
467493
...
468494
// Mac or Linux system
469495
"send-wecom-message:test": "MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-wecom-message"
470-
// Windows system: install cross-env first
471-
// npm install cross-env -D
472-
"send-wecom-message:test": "cross-env MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-wecom-message"
496+
// Windows system
497+
"send-wecom-message:test": "set MESSAGE_JSON={\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true} && send-wecom-message"
473498
...
474499
},
475500
...
476501
}
477502
```
478503
479-
Or after export variables, quote in package.json
504+
Or after export variables, quote in package.json (not support Windows)
480505
481506
```javascript
482507
@@ -493,11 +518,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
493518
"version": "0.0.1",
494519
"scripts": {
495520
...
496-
// Mac or Linux system
497521
"send-wecom-message:test": "MESSAGE_JSON=${messageJSON} send-wecom-message"
498-
// Windows system: install cross-env first
499-
// npm install cross-env -D
500-
"send-wecom-message:test": "cross-env MESSAGE_JSON=${messageJSON} send-wecom-message"
501522
...
502523
},
503524
...
@@ -541,17 +562,17 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
541562
| config.originVersionFileUrl | string | The path to the version.json file on the remote server | | Yes |
542563
| config.localPackageVersion | string | The version of the current application usually takes the version field of package.json for comparison with the version.json file of the remote server | | Yes |
543564
| config.pollingTime | number | Time interval for polling monitoring, in ms | 5000 | No |
544-
| config.immediate | boolean | On the first visit, version monitoring will be triggered immediately, and then polling will be conducted at a customized time interval **`V 1.5.0`** | false | No |
565+
| config.immediate | boolean | On the first visit, version monitoring will be triggered immediately, and then polling will be conducted at a customized time interval **`v1.5.0`** | false | No |
545566
| config.onVersionUpdate | function(data) | Callback function for custom version hint UI (if you want to customize the popup UI, you can get the return value through the callback function to control the appearance of the popup) | | No |
546-
| config.onRefresh | function(data) | Confirm update: the callback function of the custom refresh event, where data is the latest version **`V 1.5.0`** | | No |
547-
| config.onCancel | function(data) | Cancel update: the callback function of the custom cancel event, where data is the latest version **`V 1.5.0`** | | No |
567+
| config.onRefresh | function(data) | Confirm update: the callback function of the custom refresh event, where data is the latest version **`v1.5.0`** | | No |
568+
| config.onCancel | function(data) | Cancel update: the callback function of the custom cancel event, where data is the latest version **`v1.5.0`** | | No |
548569
| options | object | Configuration items for popup text and themes (not customize the popup UI, but use it if you need to modify the text and themes) | | No |
549570
| options.title | string | Popup title | Update | No |
550571
| options.description | string | Popup description | V xxx is available | No |
551572
| options.buttonText | string | Popup button text | Refresh | No |
552-
| options.cancelButtonText | string | Text to close pop-up button (add this option, if you want the pop-up to be allowed to be close) **`V 1.5.0`** | | No |
553-
| options.cancelMode | ignore-current-version / ignore-today / ignore-current-window | Close pop-up mode (It takes effect when cancelButtonText is set) **`V 1.5.0`** | ignore-current-version | No |
554-
| options.cancelUpdateAndStopWorker | boolean | When the popup is cancelled, the worker is also stopped (It takes effect when cancelButtonText is set) **`V 1.5.0`** | false | 否 |
573+
| options.cancelButtonText | string | Text to close pop-up button (add this option, if you want the pop-up to be allowed to be close) **`v1.5.0`** | | No |
574+
| options.cancelMode | ignore-current-version / ignore-today / ignore-current-window | Close pop-up mode (It takes effect when cancelButtonText is set) **`v1.5.0`** | ignore-current-version | No |
575+
| options.cancelUpdateAndStopWorker | boolean | When the popup is cancelled, the worker is also stopped (It takes effect when cancelButtonText is set) **`v1.5.0`** | false | 否 |
555576
| options.imageUrl | string | Popup image | | No |
556577
| options.rocketColor | string | The popup picture's theme color of the rocket, after setting Options.imageUrl is invalid | | No |
557578
| options.primaryColor | string | The theme color of the popup, it will affect the hint image background color and button background color, after setting imageUrl is invalid | | No |

README.zh-CN.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ unCheckVersion({closeDialog: false})
112112
第二步: 执行 `generate-version-file` 自定义命令后,在 dist 目录生成 `version.json` 文件, 用于部署到远程服务器
113113
- `VERSION` (参数可选): 需要**自定义 version** 时传入, 默认取 package.json 的 version 字段
114114
- 文件输出目录 (参数可选): 需要**自定义 version.json 输出目录**时传入, 默认为 dist 目录
115+
- `EXTERNAL` (参数可选):希望将更多信息存到 `version.json` 中时传入,如当前版本的修改内容或其他需要展示在提示弹窗上时 (用于 onVersionUpdate 自定义 UI 时)`v1.6.0`
115116

116117
```javascript
117118
// package.json
@@ -135,6 +136,35 @@ unCheckVersion({closeDialog: false})
135136

136137
```
137138

139+
**EXTERNAL 环境变量设置方式** `v1.6.0`
140+
141+
JSON 格式可以通过 [这里](https://codebeautify.org/json-encode-online) 转义后再使用
142+
143+
```javascript
144+
// package.json
145+
146+
{
147+
"name": "test",
148+
"description": "test",
149+
"private": true,
150+
"version": "0.0.1",
151+
"scripts": {
152+
...
153+
// Mac 或 Linux 系统 (简单文本)
154+
"generate:version": "EXTERNAL='some text' generate-version-file dist public"
155+
// Mac 或 Linux 系统 (JSON 文本)
156+
"generate:version": "EXTERNAL='{\"update\":\"fix bugs\",\"content\":\"some tips\"}' generate-version-file dist public"
157+
// Windows 系统 (简单文本)
158+
"generate:version": "set EXTERNAL=some text && generate-version-file dist public"
159+
// Windows 系统 (JSON 文本)
160+
"generate:version": "set EXTERNAL={\"update\":\"fix bugs\",\"content\":\"some tips\"} && generate-version-file dist public"
161+
...
162+
},
163+
...
164+
}
165+
166+
```
167+
138168
<details>
139169
<summary>⚠️ 注意事项</summary>
140170
如果你的项目接入了 CDN, 强烈建议你将 version.json 文件设置为强制不缓存 (在 nginx 中配置或关闭 CDN 忽略参数缓存的功能)
@@ -310,17 +340,16 @@ checkVersion(
310340
...
311341
// Mac 或 Linux 系统
312342
"send-lark-message:test": "MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-lark-message"
313-
// Windows 系统先安装 cross-env
314-
// npm install cross-env -D
315-
"send-lark-message:test": "cross-env MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-lark-message"
343+
// Windows 系统
344+
"send-lark-message:test": "set MESSAGE_JSON={\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true} && send-lark-message"
316345
...
317346
},
318347
...
319348
}
320349

321350
```
322351
323-
export 变量后, 在 package.json 中引用
352+
export 变量后, 在 package.json 中引用 (不支持 Windows)
324353
325354
```javascript
326355

@@ -339,11 +368,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
339368
"version": "0.0.1",
340369
"scripts": {
341370
...
342-
// Mac 或 Linux 系统
343371
"send-lark-message:test": "MESSAGE_JSON=${messageJSON} send-lark-message"
344-
// Windows 系统先安装 cross-env
345-
// npm install cross-env -D
346-
"send-lark-message:test": "cross-env MESSAGE_JSON=${messageJSON} send-lark-message"
347372
...
348373
},
349374
...
@@ -462,16 +487,15 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
462487
...
463488
// Mac 或 Linux 系统
464489
"send-wecom-message:test": "MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-wecom-message"
465-
// Windows 系统先安装 cross-env
466-
// npm install cross-env -D
467-
"send-wecom-message:test": "cross-env MESSAGE_JSON='{\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true}' send-wecom-message"
490+
// Windows 系统
491+
"send-wecom-message:test": "set MESSAGE_JSON={\"title\":\"This is a dynamically generated title\",\"version\":\"1.1.0-beta\",\"accessUrl\":\"http://test.example.com\",\"isNotifyAll\":true} && send-wecom-message"
468492
...
469493
},
470494
...
471495
}
472496
```
473497
474-
export 变量后, 在 `package.json` 中引用
498+
export 变量后, 在 `package.json` 中引用 (不支持 Windows)
475499
476500
```javascript
477501

@@ -488,11 +512,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
488512
"version": "0.0.1",
489513
"scripts": {
490514
...
491-
// Mac 或 Linux 系统
492515
"send-wecom-message:test": "MESSAGE_JSON=${messageJSON} send-wecom-message"
493-
// Windows 系统先安装 cross-env
494-
// npm install cross-env -D
495-
"send-wecom-message:test": "cross-env MESSAGE_JSON=${messageJSON} send-wecom-message"
496516
...
497517
},
498518
...
@@ -534,17 +554,17 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
534554
| config.originVersionFileUrl | string | 远程服务器上的 version.json 文件路径 | ||
535555
| config.localPackageVersion | string | 当前应用版本号, 通常取 package.json 的 version 字段, 用于与远程服务器的 version.json 文件比较 | ||
536556
| config.pollingTime | number | 轮询监测的时间间隔, 单位 ms | 5000 ||
537-
| config.immediate | boolean | 第一次访问时, 立即触发版本监测, 之后按自定义时间间隔轮询 **`V 1.5.0`** | false ||
557+
| config.immediate | boolean | 第一次访问时, 立即触发版本监测, 之后按自定义时间间隔轮询 **`v1.5.0`** | false ||
538558
| config.onVersionUpdate | function(data) | 自定义版本提示 UI 的回调函数 (如果你想自定义弹窗 UI, 通过回调函数可以拿到返回值来控制弹窗的显隐 ) | ||
539-
| config.onRefresh | function(data) | 确认更新: 自定义 refresh 事件的回调函数, data 为最新版本号 **`V 1.5.0`** | ||
540-
| config.onCancel | function(data) | 取消更新: 自定义 cancel 事件的回调函数, data 为最新版本号 **`V 1.5.0`** | ||
559+
| config.onRefresh | function(data) | 确认更新: 自定义 refresh 事件的回调函数, data 为最新版本号 **`v1.5.0`** | ||
560+
| config.onCancel | function(data) | 取消更新: 自定义 cancel 事件的回调函数, data 为最新版本号 **`v1.5.0`** | ||
541561
| options | object | 弹窗文案和主题的配置项 (不自定义弹窗 UI, 但有修改文案和主题的需求时使用) | ||
542562
| options.title | string | 弹窗的标题 | Update ||
543563
| options.description | string | 弹窗的描述 | V xxx is available ||
544564
| options.buttonText | string | 弹窗按钮的文案 | Refresh ||
545-
| options.cancelButtonText | string | 关闭弹窗按钮的文案 (如果你希望弹窗允许被关闭, 请添加此选项) **`V 1.5.0`** | ||
546-
| options.cancelMode | ignore-current-version (当前版本不再提示) / ignore-today (今天不再提示) / ignore-current-window (当前窗口不再提示) | 关闭弹窗的模式 (当 cancelButtonText 设置后生效) **`V 1.5.0`** | ignore-current-version ||
547-
| options.cancelUpdateAndStopWorker | boolean | 关闭弹窗时, 也关闭 worker (当 cancelButtonText 设置后生效) **`V 1.5.0`** | false ||
565+
| options.cancelButtonText | string | 关闭弹窗按钮的文案 (如果你希望弹窗允许被关闭, 请添加此选项) **`v1.5.0`** | ||
566+
| options.cancelMode | ignore-current-version (当前版本不再提示) / ignore-today (今天不再提示) / ignore-current-window (当前窗口不再提示) | 关闭弹窗的模式 (当 cancelButtonText 设置后生效) **`v1.5.0`** | ignore-current-version ||
567+
| options.cancelUpdateAndStopWorker | boolean | 关闭弹窗时, 也关闭 worker (当 cancelButtonText 设置后生效) **`v1.5.0`** | false ||
548568
| options.imageUrl | string | 弹窗的提示图片 | ||
549569
| options.rocketColor | string | 弹窗提示图片中火箭的主题色, 设置后 options.imageUrl 无效 | ||
550570
| options.primaryColor | string | 弹窗的主题色, 会作用到提示图片背景色和按钮背景色, 设置后 imageUrl 无效 | ||

scripts/createVersionFile.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@
88
const fs = require('fs');
99
const path = require('path');
1010
const outputDir = process.argv.length > 2 ? process.argv.splice(2) : ['dist']
11+
12+
const getExternal = () => {
13+
const external = process.env.EXTERNAL || ''
14+
try {
15+
JSON.parse(external)
16+
return external
17+
} catch (error) {
18+
return `"${external.trim()}"`
19+
}
20+
}
21+
1122
outputDir.forEach((val) => {
1223
const outputVersionPath = path.join(process.cwd(), `${val}/version.json`);
1324
const packageJsonPath = path.join(process.cwd(), 'package.json');
1425
const packageJsonObject = JSON.parse(fs.readFileSync(packageJsonPath).toString());
15-
fs.writeFile(outputVersionPath, `{ "version": "${process.env.VERSION || packageJsonObject.version}" }`, () => {
26+
27+
fs.writeFile(outputVersionPath, `{ "version": "${process.env.VERSION || packageJsonObject.version}", "external": ${getExternal()} }`, () => {
1628
console.log(`created ${val}/version file`, process.env.VERSION || packageJsonObject.version);
1729
})
1830
})

utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const createWorkerFunc = () => {
2525
if (oldVersion !== versionJsonFile.version) {
2626
temp.postMessage({
2727
refreshPageVersion: `${versionJsonFile.version}`,
28+
external: versionJsonFile.external,
2829
});
2930
}
3031
});

utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const createWorkerFunc = () => {
2727
if (oldVersion !== versionJsonFile.version) {
2828
temp.postMessage({
2929
refreshPageVersion: `${versionJsonFile.version}`,
30+
external: versionJsonFile.external,
3031
})
3132
}
3233
})

0 commit comments

Comments
 (0)