From 5e40d912bb479b9711cbfcfb12e58d7f4a457f88 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Mon, 28 Aug 2023 00:35:39 -0400 Subject: [PATCH] purge keeps binary --- .github/workflows/build.yml | 2 +- .github/workflows/ci.yml | 2 +- package.json | 2 +- scripts/install_schemas.ts | 21 +++++++++------------ src/components/micro-plum/DeployPane.vue | 19 ++++++++++++++++++- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fdd84d..cc721b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,7 +39,7 @@ jobs: pip install ninja echo "$env:ProgramFiles\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Use Node.js latest - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 20.x - name: Install node dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25f6e66..ac2113f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Use Node.js latest - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 20.x - name: Install node dependencies diff --git a/package.json b/package.json index 2119b74..5e418d0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "devDependencies": { "@codemirror/legacy-modes": "^6.3.3", "@libreservice/lazy-cache": "^0.1.1", - "@libreservice/micro-plum": "^0.2.0", + "@libreservice/micro-plum": "^0.2.1", "@libreservice/my-widget": "^0.1.4", "@libreservice/my-worker": "^0.4.2", "@libreservice/wasm-code": "^0.1.3", diff --git a/scripts/install_schemas.ts b/scripts/install_schemas.ts index 5eb953c..b5335fa 100644 --- a/scripts/install_schemas.ts +++ b/scripts/install_schemas.ts @@ -5,6 +5,7 @@ import { cwd, chdir, exit } from 'process' import yaml from 'js-yaml' import { Recipe, + getBinaryNames, GitHubDownloader } from '@libreservice/micro-plum' import { rf, utf8, ensure, md5sum } from './util.js' @@ -47,18 +48,14 @@ async function install (recipe: Recipe, target?: string) { function parseYaml (schemaId: string) { const content = yaml.load(readFileSync(`${RIME_DIR}/build/${schemaId}.schema.yaml`, utf8)) as { [key: string]: any } - for (const [key, value] of Object.entries(content)) { - if (key === 'translator') { - const { dictionary, prism } = value as { dictionary: string, prism?: string } - schemaFiles[schemaId] = {} - // By default, dictionary equals to schemaId, and prism equals to dictionary (not schemaId, see luna_pinyin_fluency) - if (dictionary !== schemaId) { - schemaFiles[schemaId].dict = dictionary - } - if (prism && prism !== dictionary) { - schemaFiles[schemaId].prism = prism - } - } + schemaFiles[schemaId] = {} + const { dict, prism } = getBinaryNames(content) + // By default, dictionary equals to schemaId, and prism equals to dictionary (not schemaId, see luna_pinyin_fluency) + if (dict !== schemaId) { + schemaFiles[schemaId].dict = dict + } + if (prism !== dict) { + schemaFiles[schemaId].prism = prism } } diff --git a/src/components/micro-plum/DeployPane.vue b/src/components/micro-plum/DeployPane.vue index eac51a2..b49c115 100644 --- a/src/components/micro-plum/DeployPane.vue +++ b/src/components/micro-plum/DeployPane.vue @@ -9,6 +9,7 @@ import { import yaml from 'js-yaml' import { u2s, + getBinaryNames, Recipe, FileLoader } from '@libreservice/micro-plum' @@ -98,12 +99,28 @@ async function onTrash () { if (content && !keptFiles.includes(file)) { keptFiles.push(file) } + if (file.endsWith('.schema.yaml')) { + const schemaYaml = `build/${file}` + try { + const obj = yaml.load(u2s(await FS.readFile(`${RIME_PATH}/${schemaYaml}`))) as object + const { dict, prism } = getBinaryNames(obj) + if (dict) { + const defaultYaml = 'build/default.yaml' + const tableBin = `build/${dict}.table.bin` + const reverseBin = `build/${dict}.reverse.bin` + const prismBin = `build/${prism}.prism.bin` + for (const bin of [defaultYaml, schemaYaml, tableBin, reverseBin, prismBin]) { + keptFiles.includes(bin) || keptFiles.push(bin) + } + } + } catch {} + } } } await Promise.all(prerequisites.map(prerequisite => add(new LocalLoader(prerequisite, [])))) await add(new LocalLoader('', selected.value)) await traverseFS(FS, undefined, async (path: string) => { - const file = path.slice(6) + const file = path.slice(6) // Trim /rime/ prefix const match = file.match(/^(\S+)\.userdb\/\S+$/) if (!keptFiles.includes(file) && (!match || !keptFiles.includes(`${match[1]}.dict.yaml`))) { await FS.unlink(path)