forked from bluelovers/idea-l10n-zht
-
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.
feat(cache): 將版本資訊保存至
lib/const/version-map.json
- Loading branch information
1 parent
a888e26
commit 88fc62e
Showing
9 changed files
with
346 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
|
||
/** | ||
* @default '156292' | ||
*/ | ||
export const __plugin_zh_cn_id: string = '156292'; | ||
|
||
export const __plugin_zh_cn_id = '156292'; | ||
/** | ||
* @default '221' | ||
*/ | ||
export const __plugin_zh_cn_series: string = '221'; | ||
/** | ||
* @default '221.114' | ||
*/ | ||
export const __plugin_zh_cn_version: string = '221.114'; | ||
|
||
export const __plugin_zh_cn_version = '221.114'; | ||
|
||
export const __plugin_zh_cn_download = 'https://plugins.jetbrains.com/plugin/download?rel=true&updateId=156292'; | ||
/** | ||
* @see https://plugins.jetbrains.com/plugin/download?rel=true&updateId=156292 | ||
*/ | ||
export const __plugin_zh_cn_download: string = 'https://plugins.jetbrains.com/plugin/download?rel=true&updateId=156292'; | ||
|
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,63 @@ | ||
declare namespace version_map { | ||
type IVersionApiResultRow = { | ||
id: string; | ||
link: string; | ||
version: string; | ||
|
||
approve: boolean; | ||
listed: boolean; | ||
recalculateCompatibilityAllowed: boolean; | ||
cdate: string; | ||
file: string; | ||
notes: string; | ||
since: string; | ||
until: string; | ||
sinceUntil: string; | ||
channel: string; | ||
size: number; | ||
downloads: number; | ||
pluginId: number; | ||
compatibleVersions: { | ||
GOLAND: string; | ||
PHPSTORM: string; | ||
DATASPELL: string; | ||
WEBSTORM: string; | ||
GATEWAY: string; | ||
IDEA_COMMUNITY: string; | ||
CLION: string; | ||
IDEA: string; | ||
PYCHARM_EDUCATIONAL: string; | ||
PYCHARM_COMMUNITY: string; | ||
PYCHARM: string; | ||
DBE: string; | ||
CWMGUEST: string; | ||
RUBYMINE: string; | ||
APPCODE: string; | ||
IDEA_EDUCATIONAL: string; | ||
JBCLIENT: string; | ||
}; | ||
author: { | ||
id: string; | ||
name: string; | ||
link: string; | ||
hubLogin: string; | ||
isJetBrains: boolean; | ||
icon: string; | ||
}; | ||
modules: any[]; | ||
} | ||
type IVersionApiResult = IVersionApiResultRow[]; | ||
type IVersionDownloadMap = Record<string, string>; | ||
type IVersionMapRecord = Record<string, IVersionApiResultRow>; | ||
interface IVersionMap { | ||
version_map_record: IVersionMapRecord; | ||
series: string[]; | ||
version_download_map: IVersionDownloadMap; | ||
series_latest_map: IVersionDownloadMap; | ||
} | ||
const version_map_record: IVersionMap["version_map_record"]; | ||
const series: IVersionMap["series"]; | ||
const version_download_map: IVersionMap["version_download_map"]; | ||
const series_latest_map: IVersionMap["series_latest_map"]; | ||
} | ||
export = version_map; |
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,78 @@ | ||
import type { IVersionMap } from '../const/version-map'; | ||
import { readJSON, readJSONSync} from 'fs-extra'; | ||
import { __file_version_map_json } from '../const'; | ||
|
||
let versionMap: IVersionMap; | ||
|
||
export function _loadVersionMapSync(): IVersionMap | ||
{ | ||
return readJSONSync(__file_version_map_json) | ||
} | ||
|
||
export function _loadVersionMapAsync(): Promise<IVersionMap> | ||
{ | ||
return readJSON(__file_version_map_json) | ||
} | ||
|
||
export function _versionMap(): IVersionMap | ||
{ | ||
return versionMap ??= _loadVersionMapSync() | ||
} | ||
|
||
export function getLatestSeries(data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return data.series[0] | ||
} | ||
|
||
export function getLatestVersion(data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return _getVersion(getLatestSeries(data), data) | ||
} | ||
|
||
export function _getVersion(series: string, data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return data.series_latest_map[series] | ||
} | ||
|
||
export function getVersionLatestInfo(data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return _getVersionInfoByVersion(getLatestVersion(data), data) | ||
} | ||
|
||
export function _getVersionInfoByVersion(version: string, data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return data.version_map_record[version] | ||
} | ||
|
||
export function _getVersionInfoBySeries(series: string, data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return _getVersionInfoByVersion(_getVersion(series, data), data) | ||
} | ||
|
||
export function getVersionLatestDownload(data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return _getVersionDownloadByVersion(getLatestSeries(data), data) | ||
} | ||
|
||
export function _getVersionDownloadByVersion(version: string, data?: IVersionMap) | ||
{ | ||
data ??= _versionMap(); | ||
return data.version_download_map[version] | ||
} | ||
|
||
/** | ||
* @example | ||
* generateDownloadLink(156292) | ||
* // => https://plugins.jetbrains.com/plugin/download?rel=true&updateId=156292 | ||
*/ | ||
export function generateDownloadLink(id: string | number) | ||
{ | ||
return `https://plugins.jetbrains.com/plugin/download?rel=true&updateId=${id}` | ||
} |
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,8 @@ | ||
|
||
import { __root } from '../../test/__root'; | ||
|
||
export const opts = { | ||
cwd: __root, | ||
throwError: true, | ||
printStderr: true, | ||
} as const; |
Oops, something went wrong.