-
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
7564b5c
commit 1fbed03
Showing
7 changed files
with
9,592 additions
and
30 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
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
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 @@ | ||
/** | ||
* Created by user on 2022/1/10. | ||
*/ | ||
|
||
export default import('./download-original-plugin') | ||
.then(() => import('./unzip')) | ||
.then(() => import('./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
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,32 +1,66 @@ | ||
import JSZip from "jszip"; | ||
import { outputFile, readFile } from 'fs-extra'; | ||
import { outputFile, outputJSON, readFile } from 'fs-extra'; | ||
import { join } from 'upath2'; | ||
import { __root } from '../test/__root'; | ||
import Bluebird from 'bluebird'; | ||
import { cli_logger, createProgressEstimator } from '../lib/cli-progress'; | ||
import { __plugin_downloaded_dir, __plugin_downloaded_dir_unzip } from '../lib/const'; | ||
import { SingleBar } from 'cli-progress'; | ||
import { console } from 'debug-color2'; | ||
import { createMultiBar } from '../lib/cli-progress'; | ||
|
||
unzipLang('zh'); | ||
const multibar = createMultiBar(); | ||
|
||
export default unzipLang('zh') | ||
.finally(() => multibar.stop()) | ||
; | ||
|
||
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$/); | ||
console.cyan.log(`unzip ${lang}.zip`); | ||
|
||
return file[0].async('nodebuffer').then(JSZip.loadAsync) | ||
}) | ||
.then(zip => | ||
let bar: SingleBar; | ||
|
||
return Bluebird.resolve(readFile(join(__plugin_downloaded_dir, `${lang}.zip`))) | ||
.then<JSZip>(JSZip.loadAsync) | ||
.then(async (zip) => | ||
{ | ||
let file = zip.file(/\.jar$/); | ||
|
||
if (!file.length || file.length > 1) | ||
{ | ||
return Object.values(zip.files) | ||
}) | ||
.each(async (file) => | ||
throw new Error(`files of .jar should be only one file, but get ${file}`) | ||
} | ||
|
||
return file[0].async('nodebuffer').then(JSZip.loadAsync) | ||
}) | ||
.then(zip => | ||
{ | ||
return Object.values(zip.files) | ||
}) | ||
.tap((ls) => | ||
{ | ||
bar = multibar.create(ls.length, 0); | ||
}) | ||
.reduce(async (ls, file, index) => | ||
{ | ||
if (!file.dir) | ||
{ | ||
return !file.dir && outputFile(join(__plugin_downloaded_dir_unzip, lang, file.name), await file.async('nodebuffer')) | ||
bar.update(index + 1, { filename: file.name }); | ||
ls.push(file.name); | ||
await outputFile(join(__plugin_downloaded_dir_unzip, lang, file.name), await file.async('nodebuffer')) | ||
} | ||
return ls | ||
}, [] as string[]) | ||
.tap(ls => | ||
{ | ||
return outputJSON(join(__plugin_downloaded_dir_unzip, lang + '.list.json'), ls, { | ||
spaces: 2, | ||
}) | ||
}) | ||
.finally(() => | ||
{ | ||
bar?.update(bar.getTotal()); | ||
bar?.stop(); | ||
}) | ||
//.tap(console.dir) | ||
, `unzip ${lang}.zip`) | ||
; | ||
} |