Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rewrite in unplugin #35

Open
wants to merge 41 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2c03124
feat: update `snippet.js`, formerly `main.js`
2nthony Nov 3, 2021
33bb18c
fix(snippet): `compareVersion`
2nthony Nov 3, 2021
7d25b8f
chore: remove useless files
2nthony Nov 6, 2021
770b50a
chore(deps): unplugin init
2nthony Nov 6, 2021
443047e
chore: unplugin init
2nthony Nov 6, 2021
db289d8
chore(tsconfig): init
2nthony Nov 6, 2021
de7a8ce
test(jestconfig): update
2nthony Nov 6, 2021
a219f89
feat(unplugin): rewrite
2nthony Nov 6, 2021
e74fbaf
test: update files
2nthony Nov 6, 2021
2f501a7
chore(pkg): verbose test script
2nthony Nov 6, 2021
04b08b5
chore(pkg): rollback scripts
2nthony Nov 6, 2021
dc3f4f5
chore: nuxt worked!
2nthony Nov 6, 2021
a6922b9
chore: remove `index.js`
2nthony Nov 6, 2021
5f856a0
chore(deps): clean
2nthony Nov 6, 2021
d6c125a
feat(types): interface `PupaOptions`
2nthony Nov 6, 2021
a3e0182
Revert "feat(types): interface `PupaOptions`"
2nthony Nov 6, 2021
3e3326e
chore(readme): update
2nthony Nov 6, 2021
4e44dbb
chore(readme): center the preview
2nthony Nov 6, 2021
86608a4
chore(readme): include zh
2nthony Nov 7, 2021
9051975
chore(readme): update migrate
2nthony Nov 7, 2021
d6a5e8f
build: add script
2nthony Nov 7, 2021
cc913e9
chore: add funding
2nthony Nov 8, 2021
9ae9261
refactor: snippet.ts
2nthony Nov 8, 2021
2787e30
feat: support modify the popup text or message
2nthony Nov 8, 2021
343fc7e
chore(readme): update
2nthony Nov 8, 2021
6311b2a
fix: missing ','
2nthony Nov 8, 2021
9277bef
chore: update lint-staged match
2nthony Nov 8, 2021
9bb3973
fix: move arguments
2nthony Nov 8, 2021
74f72da
revert: snippet.ts
2nthony Nov 8, 2021
cce5e16
chore(readme): new preview
2nthony Dec 24, 2021
03cd92f
chore(readme): add chinese doc
2nthony Dec 24, 2021
cde32f9
chore(snippet): update
2nthony Dec 26, 2021
0e242f1
refactor: resolved id
2nthony Dec 26, 2021
47f98ad
chore: update
2nthony Dec 26, 2021
49fc0da
chore(readme-zh): fix contributors and code syntax
2nthony Dec 29, 2021
ce7b367
fix(utils): drop `ftp` path resolve
2nthony Dec 30, 2021
83d4848
refactor: move assert
2nthony Mar 13, 2022
ab2f5c0
chore: classic yarn
2nthony Oct 20, 2023
103dff6
remove funding
2nthony Oct 20, 2023
34b6912
revert options to legacy
2nthony Oct 20, 2023
b69c1f3
update readme
2nthony Oct 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .babelrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: 2nthony
218 changes: 122 additions & 96 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/FEMessage/update-popup/pulls)
[![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/)

![](https://user-images.githubusercontent.com/53422750/88611099-eb654b00-d0ba-11ea-89b9-ca92afc1078c.gif)
<p align="center">
<img src="https://user-images.githubusercontent.com/19513289/147315981-e64ac6ed-85d9-4c3c-ae18-cb066f25863c.gif" />
</p>

## Table of Contents

- [Features](#features)
- [Install](#install)
- [Usage](#usage)
- [Options](#options)
- [Notice](#notice)
- [Contributing](#contributing)
- [Contributors](#contributors)
- [License](#license)
Expand All @@ -32,132 +32,156 @@
yarn add @femessage/update-popup
```

[⬆ Back to Top](#table-of-contents)

## Usage
<details>
<summary>Vite</summary>

你需要通过环境变量 `UPDATE_POPUP_VERSION` 来传入版本号,后续每次迭代更新只需要修改比当前大的版本号即可。
```ts
// src/main.js
import '@update-popup'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有点不太明白,为什么一些地方可以直接 @update-popup,有些地方又需要添加 scope @femessage/update-popup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xxx.config.js 中视为包名,在 client 中 @update-popup 视为虚拟文件,https://cn.vitejs.dev/guide/api-plugin.html#importing-a-virtual-file


环境变量
// vite.config.ts
import UpdatePopup from '@femessage/update-popup/vite'

```bash
# .env
UPDATE_POPUP_VERSION=1.0.0 # 如果有必要,可以支持更多位数。如:1.0.0.1,1.0.0.1.1
export default defineConfig({
plugins: [
UpdatePopup({
/* options */
}),
],
})
```

也可以使用 [options.auto](#options.auto) 来实现自动更新版本。
</details><br/>

工程配置文件
<details>
<summary>Webpack</summary>

```js
// nuxt.config.js
const config = {
modules: ['@femessage/update-popup/nuxt', {options}]
}
```ts
// src/main.js
import '@update-popup'

// vue.config.js 或者 poi.config.js
const UpdatePopup = require('@femessage/update-popup')
const config = {
chainWebpack: config => {
config.plugin('femessage-update-popup').use(UpdatePopup, [{options}])
}
// webpack.config.ts
module.exports = {
plugins: [
require('@femessage/update-popup/webpack')({
/* options */
}),
],
}
```

就这么简单!
</details><br/>

<details>
<summary>Nuxt2</summary>

```ts
// plugins/update-popup.js
import '@update-popup'

// nuxt.config.ts
export default {
plugins: [
{
src: '~/plugins/update-popup',
mode: 'client',
},
],
buildModules: [
[
'@femessage/update-popup/nuxt',
{
/* options */
},
],
],
}
```

[⬆ Back to Top](#table-of-contents)
</details><br/>

## Options
<details>
<summary>Vue CLI</summary>

### options.publicPath
```ts
// src/main.js
import '@update-popup'

- Type: `string`
- Default: `webpackConfig.output.publicPath`
- Reference: [webpack publicPath](https://webpack.docschina.org/configuration/output/#outputpublicpath)
// vue.config.ts
module.exports = {
configureWebpack: {
plugins: [
require('@femessage/update-popup/webpack')({
/* options */
}),
],
},
}
```

使用独立的 publicPath,一般情况下不需要设置此参数。
</details><br/>

[⬆ Back to Top](#table-of-contents)

### options.auto

- Type: `boolean`
- Default: `false`

是否需要自动更新版本,需要配合 `options.versionType` 一起使用。

**注意**:开启此功能,环境变量 `UPDATE_POPUP_VERSION` 则不会再生效。

### options.versionType

- Type: `'timestamp' | 未来支持更多`
- Default: `timestamp`

自动生成的 version 的方式,可选值:

- `timestamp`:

使用当前时间戳,它看上去是这样的:`1603184005919.0.0`,把时间戳放在版本号的第一位,是为了保证无论如何都会大于已有的版本。

**注意**:这将失去版本语义化的控制。

### options.inject

- Type: `boolean`
- Default: `true`

是否自动添加到 webpack 入口文件,一般情况下不需要设置此参数。
如果设置为 `false` 需要手动将 `@femessage/update-popup/app/main` 注入到你的代码中。
何时需要设置此参数请参阅 [Notice.QianKun(乾坤)](#qiankun乾坤)。

### options.envKey

- Type: `string`
- Default: `'UPDATE_POPUP_VERSION'`
## Options

指定获取环境变量的 key 。e.g. `process.env.UPDATE_POPUP_VERSION=1.0.0`
这里显示默认值及其介绍。

### options.versionFileName
````ts
UpdatePopup({
// 与 vite 的 `publicDir` 和 webpack 的 `publicPath` 相似.
publicBasePath: '',

- Type: `string`
- Default: `'update_popup_version.txt'`
// 环境变量的 key
// 例如:`process.env.UPDATE_POPUP_VERSION = 1.0.0`
envKey: 'UPDATE_POPUP_VERSION',

版本号文件名。
// 生成 `update_popup_version.txt` 到输出目录
versionFileName: 'update_popup_version.txt',

## Notice
// 生成版本号的方式
// `auto`:
// 使用当前时间戳,看上去会是这个样子 `1603184005919.0.0`
// 因此第一个值总是会大于上一次的值
//
// `env`:
// 你需要设置一个环境变量 `UPDATE_POPUP_VERSION`
// 当需要迭代更新时,修改这个值大于当前值即可
// ```.env
// UPDATE_POPUP_VERSION = 1.0.0
// 例如: `1.0.1`, `1.0.0.1.1`
// ```
versionType: 'auto',

### QianKun(乾坤)
// 弹出框信息文本
popupMessage: '发现新版本可用',

此插件会自动生成一个普通的 js 文件并添加到 webpack 入口文件中,
但由于子应用的入口文件需要 **[导出生命周期钩子](https://qiankun.umijs.org/zh/guide/getting-started#1-%E5%AF%BC%E5%87%BA%E7%9B%B8%E5%BA%94%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90)** 的要求,
因此需要禁止自动添加入口文件,则做如下的调整:
// 弹出框刷新按钮文本
popupActionText: '刷新',
})
````

#### 在子应用中使用
## 从 `v1.1.3` 迁移

调整工程配置文件
`src/main.js`

```diff
# nuxt.config.js
const config = {
- modules: ['@femessage/update-popup/nuxt']
+ modules: [['@femessage/update-popup/nuxt'], { inject: false }]
}

# vue.config.js 或者 poi.config.js
const config = {
chainWebpack: config => {
config.plugin('update-popup').use(UpdatePopup, [{
+ inject: false
}])
}
}
- import '@femessage/update-popup/app/main'
+ import '@update-popup'
```

最后在你的**子应用**入口文件添加
`xxx.config.js` 请参照 [Install](#install).

```diff
+ import '@femessage/update-popup/app/main'
UpdatePopup({
- publicPath: '/',
+ publicBasePath: '/',

- auto: true,
+ versionType: 'auto',

- inject: false,
})
```

[⬆ Back to Top](#table-of-contents)
Expand All @@ -184,7 +208,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://evila.me/"><img src="https://avatars3.githubusercontent.com/u/19513289?v=4?s=100" width="100px;" alt=""/><br /><sub><b>EVILLT</b></sub></a><br /><a href="https://github.com/FEMessage/update-popup/commits?author=evillt" title="Code">💻</a> <a href="https://github.com/FEMessage/update-popup/commits?author=evillt" title="Tests">⚠️</a> <a href="#ideas-evillt" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/FEMessage/update-popup/commits?author=evillt" title="Documentation">📖</a> <a href="#maintenance-evillt" title="Maintenance">🚧</a></td>
<td align="center"><a href="https://github.com/2nthony/"><img src="https://avatars3.githubusercontent.com/u/19513289?v=4?s=100" width="100px;" alt=""/><br /><sub><b>2nthony(formerly evillt)</b></sub></a><br /><a href="https://github.com/FEMessage/update-popup/commits?author=2nthony" title="Code">💻</a> <a href="https://github.com/FEMessage/update-popup/commits?author=evillt" title="Tests">⚠️</a> <a href="#ideas-evillt" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/FEMessage/update-popup/commits?author=evillt" title="Documentation">📖</a> <a href="#maintenance-evillt" title="Maintenance">🚧</a></td>
<td align="center"><a href="https://4ark.me"><img src="https://avatars0.githubusercontent.com/u/27952659?v=4?s=100" width="100px;" alt=""/><br /><sub><b>4Ark</b></sub></a><br /><a href="https://github.com/FEMessage/update-popup/commits?author=gd4Ark" title="Documentation">📖</a> <a href="#translation-gd4Ark" title="Translation">🌍</a> <a href="https://github.com/FEMessage/update-popup/commits?author=gd4Ark" title="Code">💻</a> <a href="https://github.com/FEMessage/update-popup/issues?q=author%3Agd4Ark" title="Bug reports">🐛</a></td>
<td align="center"><a href="http://aa"><img src="https://avatars.githubusercontent.com/u/10540920?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ynwshy</b></sub></a><br /><a href="https://github.com/FEMessage/update-popup/issues?q=author%3Aynwshy" title="Bug reports">🐛</a></td>
</tr>
</table>

Expand Down
Loading