Skip to content

Commit

Permalink
feat: Support more platforms and architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweiGL committed Jun 28, 2023
1 parent a5bd23f commit 0cb9571
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
33 changes: 11 additions & 22 deletions plugin/mkcert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,17 @@ class Mkcert {
const sourceInfo = await this.source.getSourceInfo()

if (!sourceInfo) {
if (typeof this.sourceType === 'string') {
this.logger.error(
'Failed to request mkcert information, please check your network'
)
if (this.sourceType === 'github') {
this.logger.info(
'If you are a user in china, maybe you should set "source" paramter to "coding"'
)
}
} else {
this.logger.info(
'Please check your custom "source", it seems to return invalid result'
)
}
return undefined
const message =
typeof this.sourceType === 'string'
? `Unsupported platform. Unable to find a binary file for ${
process.platform
} platform with ${process.arch} arch on ${
this.sourceType === 'github'
? 'https://github.com/FiloSottile/mkcert/releases'
: 'https://liuweigl.coding.net/p/github/artifacts?hash=8d4dd8949af543159c1b5ac71ff1ff72'
}`
: 'Please check your custom "source", it seems to return invalid result'
throw new Error(message)
}

return sourceInfo
Expand All @@ -278,13 +274,6 @@ class Mkcert {

debug('The mkcert does not exist, download it now')

if (!sourceInfo) {
this.logger.error(
'Can not obtain download information of mkcert, init skipped'
)
return
}

await this.downloadMkcert(sourceInfo.downloadUrl, this.savedMkcert)
}

Expand Down
22 changes: 6 additions & 16 deletions plugin/mkcert/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ export abstract class BaseSource {
abstract getSourceInfo(): Promise<SourceInfo | undefined>

protected getPlatformIdentifier() {
switch (process.platform) {
case 'win32':
return 'windows-amd64.exe'
case 'linux':
return process.arch === 'arm64'
? 'linux-arm64'
: process.arch === 'arm'
? 'linux-arm'
: 'linux-amd64'
case 'darwin':
return process.arch === 'arm64' ? 'darwin-arm64' : 'darwin-amd64'
default:
throw new Error('Unsupported platform')
}
const arch = process.arch === 'x64' ? 'amd64' : process.arch
return process.platform === 'win32'
? `windows-${arch}.exe`
: `${process.platform}-${arch}`
}
}

Expand Down Expand Up @@ -67,7 +57,7 @@ export class GithubSource extends BaseSource {
/**
* Download mkcert from coding.net
*
* @see {https://help.coding.net/openapi}
* @see https://help.coding.net/openapi
*/
export class CodingSource extends BaseSource {
public static CODING_API = 'https://e.coding.net/open-api'
Expand Down Expand Up @@ -118,7 +108,7 @@ export class CodingSource extends BaseSource {
PageSize: 1
})

const version = VersionData.Response.Data.InstanceSet[0]?.Version
const version = VersionData.Response.Data?.InstanceSet[0]?.Version

if (!version) {
return undefined
Expand Down

0 comments on commit 0cb9571

Please sign in to comment.