Skip to content

Commit

Permalink
feat: build plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jan 9, 2022
1 parent aa28b9e commit c26f836
Show file tree
Hide file tree
Showing 7 changed files with 8,076 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ 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');
export const __plugin_dev_raw_dir = join(__root, 'plugin-dev-raw');
export const __plugin_dev_output_dir = join(__root, 'plugin-dev-out');
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"main": "index.js",
"scripts": {
"plugin:handle-source": "ts-node scripts/plugin-handle-source.ts",
"build": "ts-node scripts/puglin-build-install-file.ts",
"review": "yarn run review:coverage",
"review:coverage": "yarn run lint && yarn run coverage",
"review:test": "yarn run lint && yarn run test",
Expand Down
Binary file added plugin-dev-out/zh.jar
Binary file not shown.
7,971 changes: 7,971 additions & 0 deletions plugin-dev-out/zh.list.json

Large diffs are not rendered by default.

Binary file added plugin-dev-out/zh.zip
Binary file not shown.
96 changes: 96 additions & 0 deletions scripts/puglin-build-install-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { async as FastGlob } from '@bluelovers/fast-glob/bluebird';
import { __plugin_dev_output_dir, __plugin_dev_raw_dir, __plugin_downloaded_dir_unzip } from '../lib/const';
import { console } from 'debug-color2';
import { outputFile, outputJSON, pathExists, readFile, readJSON } from 'fs-extra';
import { join } from 'upath2';
import JSZip from "jszip";
import Bluebird from 'bluebird';
import { createMultiBar } from '../lib/cli-progress';
import { gray, cyan } from 'ansi-colors';

const multibar = createMultiBar();

export default FastGlob<string>([
'*',
'!*.list.json',
], {
cwd: __plugin_downloaded_dir_unzip,
onlyDirectories: true,
}).mapSeries(async (lang) =>
{
console.cyan.log(`build ${lang}`);

const cwd = join(__plugin_downloaded_dir_unzip, lang);
const cacheList: string[] = await readJSON(join(__plugin_downloaded_dir_unzip, lang + '.list.json'));

const zip = new JSZip();
const jar = new JSZip();

const bar = multibar.create(cacheList.length, 0);

return Bluebird.reduce(cacheList, async (ls, file, index) =>
{

bar.update(index, { filename: file });

const fullpath = join(cwd, file);
const fullpath_new = join(__plugin_dev_raw_dir, lang, file);
let buf: string | Buffer;

if (/^(search|postfixTemplates|intentionDescriptions)\//.test(file))
{
bar.update(index, { filename: gray(file) });
return ls;
}
else if (await pathExists(fullpath_new))
{
buf = await readFile(fullpath_new);
}
else
{
buf = await readFile(fullpath);
}

jar.file(file, buf);

ls.push(file);

return ls;
}, [] as string[])
.then(async (ls) =>
{
bar.update(bar.getTotal() - 1, { filename: cyan(lang + '.jar') });

const buf = await jar.generateAsync({
type: "nodebuffer" ,
mimeType: 'application/java-archive',
});

zip.file('lib/zh.jar', buf);

return Promise.all([
zip.generateAsync({
type: "nodebuffer",
mimeType: 'application/java-archive',
}),
outputJSON(join(__plugin_dev_output_dir, lang + '.list.json'), ls, {
spaces: 2,
}),
outputFile(join(__plugin_dev_output_dir, lang + '.jar'), buf)
]).then(ls => ls[0] as Buffer);
})
.tap((buf) =>
{
return outputFile(join(__plugin_dev_output_dir, lang + '.zip'), buf)
})
.finally(() =>
{
bar.update(bar.getTotal());
bar.stop();
})
})
.finally(() =>
{
multibar.stop();
})
;
12 changes: 6 additions & 6 deletions scripts/to-zht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { async as FastGlob } from '@bluelovers/fast-glob/bluebird';
import { __plugin_dev_dir, __plugin_downloaded_dir_unzip } from '../lib/const';
import { __plugin_dev_raw_dir, __plugin_downloaded_dir_unzip } from '../lib/const';
import { outputFile, outputJSON, pathExists, readFile, readJSON, unlink } from 'fs-extra';
import { join } from 'upath2';
import { console } from 'debug-color2';
Expand Down Expand Up @@ -44,9 +44,9 @@ export default FastGlob<string>([
})
.each(async (file: string, index) =>
{
bar.update(index + 1, { filename: file });
bar.update(index, { filename: file });
const fullpath = join(cwd, file);
const fullpath_new = join(__plugin_dev_dir, lang, file);
const fullpath_new = join(__plugin_dev_raw_dir, lang, file);

if (cacheList.includes(file))
{
Expand Down Expand Up @@ -80,7 +80,7 @@ export default FastGlob<string>([
}
else
{
bar.update(index + 1, { filename: red(file) });
bar.update(index, { filename: red(file) });

if (await pathExists(fullpath))
{
Expand All @@ -90,15 +90,15 @@ export default FastGlob<string>([

if (await pathExists(fullpath_new))
{
bar.update(index + 1, { filename: gray(file) });
bar.update(index, { filename: gray(file) });

await unlink(fullpath_new);
}

})
.tap(() =>
{
return outputJSON(join(__plugin_dev_dir, lang + '.list.json'), cacheListNew, {
return outputJSON(join(__plugin_dev_raw_dir, lang + '.list.json'), cacheListNew, {
spaces: 2,
})
})
Expand Down

0 comments on commit c26f836

Please sign in to comment.