Skip to content

Commit

Permalink
feat: save CA file to savePath
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweiGL committed Jan 31, 2023
1 parent 6174c31 commit 6b29fe4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const writeFile = async (
}

export const exec = async (cmd: string, options?: ExecOptions) => {
return await util.promisify(child_process.exec)(cmd, options)
return util.promisify(child_process.exec)(cmd, options)
}

/**
Expand Down
23 changes: 14 additions & 9 deletions plugin/mkcert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import path from 'path'
import process from 'process'

import pc from 'picocolors'
import { PLUGIN_DATA_DIR } from 'plugin/lib/constant'
import { Logger } from 'vite'

import { PLUGIN_DATA_DIR } from '../lib/constant'
import { debug } from '../lib/logger'
import {
ensureDirExist,
Expand Down Expand Up @@ -74,14 +74,15 @@ export type MkcertOptions = MkcertBaseOptions & {
class Mkcert {
private force?: boolean
private autoUpgrade?: boolean
private mkcertLocalPath?: string
private keyFilePath: string
private certFilePath: string
private source: BaseSource
private sourceType: SourceType
private savePath: string
private logger: Logger

private source: BaseSource
private mkcertLocalPath?: string
private mkcertSavedPath: string
private sourceType: SourceType
private keyFilePath: string
private certFilePath: string

private config: Config

Expand All @@ -104,6 +105,7 @@ class Mkcert {
this.force = force
this.logger = logger
this.autoUpgrade = autoUpgrade
this.savePath = savePath
this.mkcertLocalPath = mkcertPath
this.keyFilePath = path.resolve(savePath, keyFileName)
this.certFilePath = path.resolve(savePath, certFileName)
Expand Down Expand Up @@ -141,7 +143,7 @@ class Mkcert {
if (!exists) {
this.logger.error(
pc.red(
`${this.mkcertLocalPath} does not exist, please check the mkcertPath paramter`
`${this.mkcertLocalPath} does not exist, please check the mkcertPath parameter`
)
)
}
Expand Down Expand Up @@ -172,8 +174,10 @@ class Mkcert {
)
}

await ensureDirExist(this.keyFilePath)
await ensureDirExist(this.certFilePath)
await Promise.all([
ensureDirExist(this.keyFilePath),
ensureDirExist(this.certFilePath)
])

const cmd = `${escape(mkcertBinnary)} -install -key-file ${escape(
this.keyFilePath
Expand All @@ -182,6 +186,7 @@ class Mkcert {
await exec(cmd, {
env: {
...process.env,
CAROOT: this.savePath,
JAVA_HOME: undefined
}
})
Expand Down

0 comments on commit 6b29fe4

Please sign in to comment.