forked from liuweiGL/vite-plugin-mkcert
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,030 additions
and
3,517 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,6 @@ | |
"rollup": "^2.44.0", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.3", | ||
"vite": "^2.1.4" | ||
"vite": "^2.1.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Octokit } from '@octokit/rest' | ||
import log from '../lib/log' | ||
import request from '../lib/request' | ||
|
||
export type SourceInfo = { | ||
version: string | ||
downloadUrl: string | ||
} | ||
|
||
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 'darwin-amd64' | ||
default: | ||
throw new Error('Unsupported platform') | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Download mkcert from github repo | ||
*/ | ||
export class GithubSource extends BaseSource { | ||
public static create() { | ||
return new GithubSource() | ||
} | ||
|
||
private constructor() { | ||
super() | ||
} | ||
|
||
public async getSourceInfo(): Promise<SourceInfo | undefined> { | ||
let version: string | undefined | ||
let downloadUrl: string | undefined | ||
|
||
const octokit = new Octokit() | ||
const { data } = await octokit.repos.getLatestRelease({ | ||
owner: 'FiloSottile', | ||
repo: 'mkcert' | ||
}) | ||
const platformIdentifier = this.getPlatformIdentifier() | ||
|
||
version = data.tag_name | ||
downloadUrl = data.assets.find(item => | ||
item.name.includes(platformIdentifier) | ||
)?.browser_download_url | ||
|
||
if (!(version && downloadUrl)) { | ||
log('Github assets do not match') | ||
return | ||
} | ||
|
||
return { | ||
downloadUrl, | ||
version | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Download mkcert from coding repo | ||
* | ||
* @see {https://help.coding.net/openapi} | ||
*/ | ||
export class CodingSource extends BaseSource { | ||
private static CODING_OPEN_API = 'https://liuweigl.coding.net/open-api' | ||
|
||
public static create() { | ||
return new CodingSource() | ||
} | ||
|
||
private constructor() { | ||
super() | ||
} | ||
|
||
async getSourceInfo(): Promise<SourceInfo | undefined> { | ||
const { data } = await request({ | ||
method: 'POST', | ||
url: CodingSource.CODING_OPEN_API, | ||
params: { | ||
Action: 'DescribeArtifactRepositoryFileList' | ||
}, | ||
data: { | ||
Action: 'DescribeArtifactRepositoryFileList', | ||
Repository: 'mkcert', | ||
Project: 'github', | ||
PageSize: 10 | ||
} | ||
}) | ||
|
||
console.log(data) | ||
|
||
return data | ||
} | ||
} |
Oops, something went wrong.