-
Notifications
You must be signed in to change notification settings - Fork 19
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
1 parent
ceef5ed
commit 4c5a909
Showing
6 changed files
with
91 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { join } from 'upath2'; | ||
import { __root } from '../test/__root'; | ||
|
||
export const __plugin_downloaded_dir = join(__root, 'original-plugin'); | ||
export const __plugin_downloaded_dir_unzip = join(__root, 'original-plugin-raw'); | ||
|
||
export const __plugin_dev_dir = join(__root, 'plugin-dev-raw'); |
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,15 +1,14 @@ | ||
import fetch from 'cross-fetch'; | ||
import { Response } from 'node-fetch'; | ||
import { outputFile } from 'fs-extra'; | ||
import { join } from 'path'; | ||
import { join } from 'upath2'; | ||
import { __root } from '../test/__root'; | ||
import { createProgressEstimator } from '../lib/cli-progress'; | ||
import { cli_logger, createProgressEstimator } from '../lib/cli-progress'; | ||
import { __plugin_downloaded_dir } from '../lib/const'; | ||
|
||
const logger = createProgressEstimator(__root); | ||
|
||
logger(fetch('https://plugins.jetbrains.com/plugin/download?rel=true&updateId=149295') | ||
cli_logger(fetch('https://plugins.jetbrains.com/plugin/download?rel=true&updateId=149295') | ||
.then((res) => (res as any as Response).buffer()) | ||
.then(buf => { | ||
return outputFile(join(__root, 'original-plugin', 'zh.zip'), buf) | ||
return outputFile(join(__plugin_downloaded_dir, 'zh.zip'), buf) | ||
}), `download Chinese (Simplified) Language Pack / 中文语言包`) | ||
; |
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,50 @@ | ||
/** | ||
* Created by user on 2022/1/9. | ||
*/ | ||
|
||
import { cn2tw_min } from '@lazy-cjk/zh-convert/min'; | ||
import { async as FastGlob } from '@bluelovers/fast-glob/bluebird'; | ||
import { __plugin_dev_dir, __plugin_downloaded_dir_unzip } from '../lib/const'; | ||
import { outputFile, pathExists, readFile, unlink } from 'fs-extra'; | ||
import { join } from 'upath2'; | ||
import { console } from 'debug-color2'; | ||
import { cli_logger } from '../lib/cli-progress'; | ||
|
||
cli_logger(FastGlob([ | ||
'**/*', | ||
], { | ||
cwd: __plugin_downloaded_dir_unzip, | ||
}) | ||
.each(async (file: string) => | ||
{ | ||
let fullpath_new = join(__plugin_dev_dir, file); | ||
|
||
if (!/\.(png)$/i.test(file)) | ||
{ | ||
let fullpath = join(__plugin_downloaded_dir_unzip, file); | ||
|
||
const content_old = await readFile(fullpath).then(content => content.toString()); | ||
let content_new = cn2tw_min(content_old); | ||
|
||
if (/META-INF\/plugin\.xml$/i.test(file)) | ||
{ | ||
content_new = content_new.replace(/<name>.+<\/name>/, `<name>Chinese (Traditional) Language Pack / 中文語言包</name>`); | ||
} | ||
|
||
if (content_new !== content_old) | ||
{ | ||
console.success(file); | ||
await outputFile(fullpath_new, content_new); | ||
return; | ||
} | ||
} | ||
|
||
if (await pathExists(fullpath_new)) | ||
{ | ||
console.warn(file); | ||
return unlink(fullpath_new); | ||
} | ||
}), `convert to zht`) | ||
; | ||
|
||
|
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,26 +1,32 @@ | ||
import JSZip from "jszip"; | ||
import { outputFile, readFile } from 'fs-extra'; | ||
import { join } from 'path'; | ||
import { join } from 'upath2'; | ||
import { __root } from '../test/__root'; | ||
import Bluebird from 'bluebird'; | ||
import { createProgressEstimator } from '../lib/cli-progress'; | ||
import { cli_logger, createProgressEstimator } from '../lib/cli-progress'; | ||
import { __plugin_downloaded_dir, __plugin_downloaded_dir_unzip } from '../lib/const'; | ||
|
||
const logger = createProgressEstimator(__root); | ||
unzipLang('zh'); | ||
|
||
logger(Bluebird.resolve(readFile(join(__root, 'original-plugin', 'zh.zip'))) | ||
.then<JSZip>(JSZip.loadAsync) | ||
.then(async (zip) => { | ||
let file = zip.file(/\.jar$/); | ||
|
||
return file[0].async('nodebuffer').then(JSZip.loadAsync) | ||
}) | ||
.then(zip => { | ||
return Object.values(zip.files) | ||
}) | ||
.each(async (file) => { | ||
return !file.dir && outputFile(join(__root, 'original-plugin-raw', 'zh', file.name), await file.async('nodebuffer')) | ||
}) | ||
//.tap(console.dir) | ||
, `unzip zh.zip`) | ||
; | ||
function unzipLang(lang: string | 'zh') | ||
{ | ||
return cli_logger(Bluebird.resolve(readFile(join(__plugin_downloaded_dir, `${lang}.zip`))) | ||
.then<JSZip>(JSZip.loadAsync) | ||
.then(async (zip) => | ||
{ | ||
let file = zip.file(/\.jar$/); | ||
|
||
return file[0].async('nodebuffer').then(JSZip.loadAsync) | ||
}) | ||
.then(zip => | ||
{ | ||
return Object.values(zip.files) | ||
}) | ||
.each(async (file) => | ||
{ | ||
return !file.dir && outputFile(join(__plugin_downloaded_dir_unzip, lang, file.name), await file.async('nodebuffer')) | ||
}) | ||
//.tap(console.dir) | ||
, `unzip ${lang}.zip`) | ||
; | ||
} |