forked from bluelovers/idea-l10n-zht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-latest-version-of-zh-cn.ts
70 lines (61 loc) · 1.68 KB
/
fetch-latest-version-of-zh-cn.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { outputFile } from 'fs-extra';
import { join } from 'upath2';
import { __root } from '../test/__root';
import fetch from 'cross-fetch';
import { __plugin_zh_cn_id } from '../lib/const/link-of-zh-cn';
import { console } from 'debug-color2';
import Bluebird from 'bluebird';
import type { IVersionApiResult } from '../lib/const/version-map';
import {
_getVersionDownloadByVersion,
_getVersionInfoBySeries,
generateVersionMap,
getLatestSeries,
} from '../lib/util/version-map';
export default Bluebird.resolve(fetch('https://plugins.jetbrains.com/api/plugins/13710/updates?channel=&size=5'))
.then((res) =>
{
return res.json() as any as IVersionApiResult;
})
.then(generateVersionMap)
.then((data) =>
{
const sv = getLatestSeries(data);
const row = _getVersionInfoBySeries(sv, data);
const id = row.id.toString();
const version = row.version.toString();
if (__plugin_zh_cn_id !== id)
{
console.success(`發現新版本 #${id} version: ${version}`);
const __plugin_zh_cn_download = _getVersionDownloadByVersion(version, data);
return outputFile(join(__root, 'lib/const/link-of-zh-cn.ts'), `
/**
* @default '${id}'
* @deprecated
*/
export const __plugin_zh_cn_id: string = '${id}';
/**
* @default '${sv}'
* @deprecated
*/
export const __plugin_zh_cn_series: string = '${sv}';
/**
* @default '${version}'
* @deprecated
*/
export const __plugin_zh_cn_version: string = '${version}';
/**
* @see ${__plugin_zh_cn_download}
* @deprecated
*/
export const __plugin_zh_cn_download: string = '${__plugin_zh_cn_download}';
`);
}
console.gray(`沒有發現新版本`);
})
.catch((e) =>
{
console.error(`嘗試偵測新版本時發生錯誤`);
console.error(e);
})
;