-
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
093be5c
commit 142c19d
Showing
19 changed files
with
435 additions
and
329 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
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,13 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="plugin:series:build" type="js.build_tools.npm"> | ||
<package-json value="$PROJECT_DIR$/package.json" /> | ||
<command value="run" /> | ||
<scripts> | ||
<script value="plugin:series:build" /> | ||
</scripts> | ||
<node-interpreter value="project" /> | ||
<node-options value="--enable-source-maps" /> | ||
<envs /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,19 @@ | ||
import { _lazyImportCore } from '../lib/util/import'; | ||
import { unzipLang } from '../lib/build/unzip'; | ||
import { basename } from 'upath2'; | ||
import { convertLang } from '../lib/build/to-zht'; | ||
import { replaceProperties } from '../lib/build/properties-replace'; | ||
import { packPluginJar } from '../lib/build/pack-plugin-jar'; | ||
|
||
export default _lazyImportCore(import('./download-series')) | ||
.then(async (result) => { | ||
|
||
const name = basename(result.file, '.zip'); | ||
|
||
await unzipLang(name); | ||
await convertLang(name); | ||
await replaceProperties(name); | ||
await packPluginJar(name); | ||
|
||
}) | ||
; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,82 @@ | ||
import Bluebird from 'bluebird'; | ||
import { console } from 'debug-color2'; | ||
import { join } from 'upath2'; | ||
import { | ||
__plugin_dev_output_dir, | ||
__plugin_dev_overwrite_dir, | ||
__plugin_dev_raw_dir, | ||
__plugin_downloaded_dir_unzip, | ||
} from '../const'; | ||
import { getBuildFileList } from '../get-build-file-list'; | ||
import JSZip from 'jszip'; | ||
import { mergePaths } from '../merge-paths'; | ||
import { cyan } from 'ansi-colors'; | ||
import { fixedJSZipDate } from 'jszip-fixed-date'; | ||
import { outputFile, outputJSON } from 'fs-extra'; | ||
import { createSingleBar } from '../cli-progress'; | ||
|
||
export function packPluginJar(lang: string | 'zh') | ||
{ | ||
return Bluebird.resolve() | ||
.then(async () => | ||
{ | ||
console.cyan.log(`pack plugin jar ${lang}`); | ||
|
||
const cwd = join(__plugin_downloaded_dir_unzip, lang); | ||
const cacheList: string[] = await getBuildFileList(lang); | ||
|
||
const jar = new JSZip(); | ||
|
||
const bar = createSingleBar(cacheList.length, 0); | ||
|
||
const { | ||
readPathFile, | ||
} = mergePaths([ | ||
join(__plugin_dev_overwrite_dir, lang), | ||
join(__plugin_dev_overwrite_dir, lang.split('-')[0]), | ||
join(__plugin_dev_raw_dir, lang), | ||
cwd, | ||
]); | ||
|
||
return Bluebird.reduce(cacheList, async (ls, file, index) => | ||
{ | ||
|
||
bar?.update(index, { filename: file }); | ||
|
||
let buf: Buffer = await readPathFile(file); | ||
|
||
if (buf) | ||
{ | ||
jar.file(file, buf); | ||
ls.push(file); | ||
} | ||
|
||
return ls; | ||
}, [] as string[]) | ||
.then(async (ls) => | ||
{ | ||
bar?.update(bar.getTotal() - 1, { filename: cyan(lang + '.jar') }); | ||
|
||
fixedJSZipDate(jar, new Date('2022-01-1 00:00:00Z')); | ||
|
||
const buf = await jar.generateAsync({ | ||
type: "nodebuffer", | ||
mimeType: 'application/java-archive', | ||
}); | ||
|
||
return Promise.all([ | ||
buf, | ||
outputJSON(join(__plugin_dev_output_dir, lang + '.list.json'), ls, { | ||
spaces: 2, | ||
}), | ||
outputFile(join(__plugin_dev_output_dir, lang + '.jar'), buf), | ||
] as const).then(ls => ls[0] as Buffer); | ||
}) | ||
.finally(() => | ||
{ | ||
bar?.update(bar.getTotal()); | ||
bar?.stop(); | ||
}) | ||
}) | ||
; | ||
} |
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,92 @@ | ||
import DotProperties from 'dot-properties-loader'; | ||
import { __dict_properties_lazy, __plugin_dev_raw_dir } from '../const'; | ||
import Bluebird from 'bluebird'; | ||
import { SingleBar } from 'cli-progress'; | ||
import { console } from 'debug-color2'; | ||
import { join } from 'upath2'; | ||
import { async as FastGlob } from '@bluelovers/fast-glob/bluebird'; | ||
import { outputJSON } from 'fs-extra'; | ||
import { createSingleBar } from '../cli-progress'; | ||
|
||
export const LAZY_PROPERTIES = new DotProperties({ | ||
file: __dict_properties_lazy, | ||
}); | ||
|
||
export const LAZY_PROPERTIES_KEYS = Object.keys(LAZY_PROPERTIES.tree); | ||
|
||
export function replaceProperties(lang: string | 'zh') | ||
{ | ||
return Bluebird.resolve() | ||
.then(async () => { | ||
let bar: SingleBar; | ||
|
||
console.cyan.log(`update ${lang} properties`); | ||
|
||
const cwd = join(__plugin_dev_raw_dir, lang); | ||
|
||
bar = createSingleBar(100, 0); | ||
|
||
const changedList = [] as string[]; | ||
|
||
return FastGlob([ | ||
'**/*.properties', | ||
], { | ||
cwd, | ||
}) | ||
.tap((ls) => | ||
{ | ||
bar?.setTotal(ls.length); | ||
}) | ||
.mapSeries(async (file: string, index) => | ||
{ | ||
bar?.update(index, { filename: file }); | ||
const fullpath = join(cwd, file); | ||
|
||
const dp = new DotProperties({ | ||
file: fullpath, | ||
}); | ||
|
||
let _changed = false; | ||
|
||
const tree = dp.tree; | ||
|
||
LAZY_PROPERTIES_KEYS | ||
.forEach(key => | ||
{ | ||
|
||
if (key in tree) | ||
{ | ||
dp.set(key, LAZY_PROPERTIES.get(key) as any); | ||
|
||
_changed = true; | ||
} | ||
|
||
}) | ||
; | ||
|
||
if (_changed) | ||
{ | ||
changedList.push(file); | ||
dp.save({ | ||
file: fullpath, | ||
options: { | ||
latin1: false, | ||
keySep: '=', | ||
}, | ||
}); | ||
} | ||
}) | ||
.tap(() => | ||
{ | ||
return outputJSON(join(__plugin_dev_raw_dir, lang + '.list.properties.changed.json'), changedList, { | ||
spaces: 2, | ||
}) | ||
}) | ||
.finally(() => | ||
{ | ||
bar?.update(bar.getTotal()); | ||
bar?.stop(); | ||
}) | ||
}) | ||
; | ||
} |
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,102 @@ | ||
import { SingleBar } from 'cli-progress'; | ||
import { console } from 'debug-color2'; | ||
import { join } from 'upath2'; | ||
import { __plugin_dev_raw_dir, __plugin_downloaded_dir_unzip } from '../const'; | ||
import { outputFile, outputJSON, pathExists, readFile, readJSON, unlink } from 'fs-extra'; | ||
import { async as FastGlob } from '@bluelovers/fast-glob/bluebird'; | ||
import { array_unique_overwrite } from 'array-hyper-unique'; | ||
import { handleText } from '../handleText'; | ||
import { gray, red } from 'ansi-colors'; | ||
import { createMultiBar, createSingleBar } from '../cli-progress'; | ||
import Bluebird from 'bluebird'; | ||
|
||
//export const multibar = createMultiBar(); | ||
|
||
export function convertLang(lang: string | 'zh') | ||
{ | ||
return Bluebird.resolve() | ||
.then(async () => | ||
{ | ||
let bar: SingleBar; | ||
|
||
console.cyan.log(`convert ${lang} to zht`); | ||
|
||
const cwd = join(__plugin_downloaded_dir_unzip, lang); | ||
const cacheList: string[] = await readJSON(join(__plugin_downloaded_dir_unzip, lang + '.list.json')); | ||
const cacheListNew: string[] = []; | ||
|
||
bar = createSingleBar(cacheList.length, 0); | ||
|
||
return FastGlob([ | ||
'**/*', | ||
], { | ||
cwd, | ||
}) | ||
.then(ls => | ||
{ | ||
return array_unique_overwrite([ | ||
...cacheList, | ||
...ls, | ||
]) | ||
}) | ||
.tap((ls) => | ||
{ | ||
bar?.setTotal(ls.length); | ||
}) | ||
.mapSeries(async (file: string, index) => | ||
{ | ||
bar?.update(index, { filename: file }); | ||
const fullpath = join(cwd, file); | ||
const fullpath_new = join(__plugin_dev_raw_dir, lang, file); | ||
|
||
if (cacheList.includes(file)) | ||
{ | ||
if (!/\.(png|svg)$|MANIFEST\.MF/i.test(file)) | ||
{ | ||
const content_old = await readFile(fullpath).then(content => content.toString()); | ||
|
||
let content_new = await handleText(content_old, { | ||
file, | ||
}); | ||
|
||
if (content_new !== content_old) | ||
{ | ||
cacheListNew.push(file); | ||
//console.success(file); | ||
await outputFile(fullpath_new, content_new); | ||
return; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
bar?.update(index, { filename: red(file) }); | ||
|
||
if (await pathExists(fullpath)) | ||
{ | ||
await unlink(fullpath); | ||
} | ||
} | ||
|
||
if (await pathExists(fullpath_new)) | ||
{ | ||
bar?.update(index, { filename: gray(file) }); | ||
|
||
await unlink(fullpath_new); | ||
} | ||
|
||
}) | ||
.tap(() => | ||
{ | ||
return outputJSON(join(__plugin_dev_raw_dir, lang + '.list.json'), cacheListNew, { | ||
spaces: 2, | ||
}) | ||
}) | ||
.finally(() => | ||
{ | ||
bar?.update(bar.getTotal()); | ||
bar?.stop(); | ||
//multibar?.stop(); | ||
}) | ||
}) | ||
} |
Oops, something went wrong.