Skip to content

Commit

Permalink
feat: allow force to generate certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweiGL committed Feb 25, 2022
1 parent 306f844 commit ce4c4e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

![localhost](docs/assets/screenshot/localhost.png)

![127.0.0.1](docs/assets/screenshot/127.0.0.1.png)
![127.0.0.1](docs/assets/screenshot/127.0.0.1.png)

![localhost](docs/assets/screenshot/localip.png)

![localhost](docs/assets/screenshot/localip.png)
</details>

## 快速开始
Expand Down Expand Up @@ -44,6 +45,10 @@ export default defineConfig({

## 参数

### force

是否强制重新生成证书。

### autoUpgrade

是否自动升级 `mkcert`
Expand All @@ -65,6 +70,7 @@ export default defineConfig({
设置环境变量 `DEBUG`=`vite:plugin:mkcert`

## 更新日志

[CHANGELOG](CHANGELOG.md)

## 原理
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export default defineConfig({
```

## Parameters
### force

Whether to force generate.
### autoUpgrade

Whether to automatically upgrade `mkcert`.
Expand Down
15 changes: 14 additions & 1 deletion packages/plugin/src/mkcert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import Record from './record'
export type SourceType = 'github' | 'coding' | BaseSource

export type MkcertOptions = {
/**
* Whether to force generate
*/
force?: boolean

/**
* Automatically upgrade mkcert
*
Expand Down Expand Up @@ -55,6 +60,7 @@ const KEY_FILE_PATH = resolvePath('certs/dev.key')
const CERT_FILE_PATH = resolvePath('certs/dev.pem')

class Mkcert {
private force?: boolean
private autoUpgrade?: boolean
private mkcertLocalPath?: string
private source: BaseSource
Expand All @@ -70,8 +76,9 @@ class Mkcert {
}

private constructor(options: MkcertProps) {
const { autoUpgrade, source, mkcertPath, logger } = options
const { force, autoUpgrade, source, mkcertPath, logger } = options

this.force = force
this.logger = logger
this.autoUpgrade = autoUpgrade
this.mkcertLocalPath = mkcertPath
Expand Down Expand Up @@ -274,6 +281,12 @@ class Mkcert {
public async renew(hosts: string[]) {
const record = new Record({ config: this.config })

if (this.force) {
debug(`Certificate is forced to regenerate`)

await this.regenerate(record, hosts)
}

if (!record.contains(hosts)) {
debug(
`The hosts changed from [${record.getHosts()}] to [${hosts}], start regenerate certificate`
Expand Down

0 comments on commit ce4c4e0

Please sign in to comment.