Skip to content

Commit

Permalink
build: 可指定編譯基於指定版本的語言包
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Feb 16, 2022
1 parent 093be5c commit 142c19d
Show file tree
Hide file tree
Showing 19 changed files with 435 additions and 329 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,7 @@ tsc-multi.json.tpl
!/original-plugin-raw/**/*
/.github/
!/.run/
/original-plugin/*-*.zip
/plugin-dev-out/*-*.zip
/original-plugin/*-*
/plugin-dev-out/*-*
/original-plugin-raw/*-*
/plugin-dev-raw/*-*
4 changes: 2 additions & 2 deletions .run/plugin_download_series.run.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="plugin:download:series" type="js.build_tools.npm" nameIsGenerated="true">
<configuration default="false" name="plugin:series:download" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="plugin:download:series" />
<script value="plugin:series:download" />
</scripts>
<node-interpreter value="project" />
<node-options value="--enable-source-maps" />
Expand Down
13 changes: 13 additions & 0 deletions .run/plugin_series_build.run.xml
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>
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ The Chinese Language Pack localizes the UI of IntelliJ IDEA, AppCode, CLion, Dat

- [GitHub Tags](https://github.com/bluelovers/idea-l10n-zht/tags)

- 或執行 `yarn run plugin:series:build` 即可以最新版的打包程式來自行選擇要打包哪一個版本系列

![img-001.png](docs/img-001.png)

![img_1.png](docs/img_1.png)

## dev

1. 執行 `yarn run ci:git:config`
Expand Down Expand Up @@ -78,7 +84,7 @@ The Chinese Language Pack localizes the UI of IntelliJ IDEA, AppCode, CLion, Dat

- ~~自動偵測抓取原版簡體最新下載網址~~
- 偵測檢查 zip / git / 檔案系統 上的檔案 是否存在大小寫不同的同名檔案
- 可指定編譯基於指定版本的語言包
- ~~可指定編譯基於指定版本的語言包~~
- 同時更新多個版本的語言包

## 已知問題
Expand Down
19 changes: 19 additions & 0 deletions bin/build-series.ts
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);

})
;
Binary file added docs/img-001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions lib/build/pack-plugin-jar.ts
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();
})
})
;
}
92 changes: 92 additions & 0 deletions lib/build/properties-replace.ts
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();
})
})
;
}
102 changes: 102 additions & 0 deletions lib/build/to-zht.ts
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();
})
})
}
Loading

0 comments on commit 142c19d

Please sign in to comment.