Skip to content

Commit

Permalink
0.8.0: replace plum with micro plum
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Jul 14, 2023
1 parent 534370a commit bf64783
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
node-version: 18.x
node-version: 20.x
- name: Install node dependencies
run: |
npm i -g pnpm
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
node-version: 18.x
node-version: 20.x
- name: Install node dependencies
run: |
npm i -g pnpm
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "boost"]
path = boost
url = https://github.com/boostorg/boost
[submodule "plum"]
path = plum
url = https://github.com/rime/plum
[submodule "lua"]
path = lua
url = https://github.com/lua/lua
Expand Down
4 changes: 2 additions & 2 deletions doc/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ However, you are more than welcomed to host a customized version of My RIME to d
Those steps work on Ubuntu latest stable and LTS release.
It's highly recommended to be done BEFORE your customization, in order to locate problems.
* Customize [schemas.json](../schemas.json).
* If your IME uses lua, place your `rime.lua` and `lua` directory under [rime-config](../rime-config/).
* If your IME has `*.custom.yaml`, place them under [rime-config](../rime-config/).
* Run `pnpm run schema`.
* Run `pnpm run wasm` if the end of previous step's output asks you to do, or if your IME uses lua.
* Run `pnpm run wasm` (given `pnpm run lib` has already been executed).
* Test by `pnpm run dev`.
* Once everything works fine, run `pnpm run build`.
* The artifact is in `dist`, and you may deploy it to a static web server.
Expand Down
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@libreservice/my-rime",
"version": "0.7.4",
"version": "0.8.0",
"files": [
"dist"
],
Expand Down Expand Up @@ -35,44 +35,45 @@
"devDependencies": {
"@codemirror/legacy-modes": "^6.3.2",
"@libreservice/lazy-cache": "^0.1.0",
"@libreservice/micro-plum": "^0.1.1",
"@libreservice/micro-plum": "^0.1.5",
"@libreservice/my-widget": "^0.1.4",
"@libreservice/my-worker": "^0.4.0",
"@libreservice/wasm-code": "^0.1.1",
"@playwright/test": "^1.35.1",
"@playwright/test": "^1.36.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"@types/js-yaml": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vicons/fa": "^0.12.0",
"@vicons/fluent": "^0.12.0",
"@vicons/material": "^0.12.0",
"@vitejs/plugin-vue": "^4.2.3",
"client-zip": "^2.4.4",
"emoji-regex": "^10.2.1",
"esbuild": "^0.18.6",
"eslint": "^8.43.0",
"esbuild": "^0.18.12",
"eslint": "^8.45.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.15.0",
"eslint-plugin-vue": "^9.15.1",
"idb": "^7.1.1",
"js-yaml": "^4.1.0",
"luaparse": "^0.3.1",
"naive-ui": "^2.34.4",
"rollup": "^3.25.1",
"rollup": "^3.26.2",
"rollup-plugin-esbuild": "^5.0.0",
"textarea-caret": "^3.1.0",
"tslib": "^2.5.3",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"tslib": "^2.6.0",
"typescript": "^5.1.6",
"vite": "^4.4.4",
"vite-plugin-pwa": "^0.16.4",
"vite-plugin-run": "^0.4.1",
"vooks": "^0.2.12",
"vue": "^3.3.4",
"vue-router": "^4.2.2",
"vue-tsc": "^1.8.1"
"vue-router": "^4.2.4",
"vue-tsc": "^1.8.5"
}
}
1 change: 0 additions & 1 deletion plum
Submodule plum deleted from 3d0643
13 changes: 10 additions & 3 deletions scripts/build_wasm.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { spawnSync } from 'child_process'
import { exit } from 'process'
import { readFileSync } from 'fs'
import { existsSync, readFileSync } from 'fs'
import { ensure } from './util.mjs'

const OPENCC_TARGET = '/usr/local/share/opencc'
const OPENCC_HOST = `build/sysroot/${OPENCC_TARGET}`
const LIB_PATH = 'build/sysroot/usr/local/lib'
const RIME_PATH = 'build/librime_native/bin'

const preloadFiles = []
function preload (file) {
Expand Down Expand Up @@ -39,8 +40,7 @@ const compileArgs = [
'-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', 'EXPORTED_FUNCTIONS=_init,_set_schema_name,_set_option,_set_ime,_process,_select_candidate_on_current_page,_deploy',
'-s', 'EXPORTED_RUNTIME_METHODS=["ccall","FS"]',
'--preload-file', 'rime-config@rime',
'--preload-file', 'build/librime_native/bin/build/default.yaml@rime/build/default.yaml',
'--preload-file', `${RIME_PATH}/build/default.yaml@rime/build/default.yaml`,
'-I', 'build/sysroot/usr/local/include',
'-o', 'public/rime.js'
]
Expand All @@ -49,6 +49,13 @@ for (const file of preloadFiles) {
compileArgs.push('--preload-file', `${OPENCC_HOST}/${file}@${OPENCC_TARGET}/${file}`)
}

for (const file of ['rime.lua', 'lua']) {
const path = `${RIME_PATH}/${file}`
if (existsSync(path)) {
compileArgs.push('--preload-file', `${path}@rime/${file}`)
}
}

const linkArgs = [
'-fexceptions',
'-L', LIB_PATH,
Expand Down
129 changes: 67 additions & 62 deletions scripts/install_schemas.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { spawnSync } from 'child_process'
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, existsSync, readdirSync } from 'fs'
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, readdirSync, cpSync } from 'fs'
import { cwd, chdir, exit } from 'process'
import yaml from 'js-yaml'
import { Recipe } from '@libreservice/micro-plum'
import { utf8, ensure, md5sum } from './util.mjs'

const root = cwd()
Expand All @@ -22,19 +23,24 @@ const dependencyMap = {} // maps schema to dependent schemas
const openccConfigs = ['t2s.json']

// temp data structures
const targetSchemas = {} // maps target to a list of schemas
const targetManifest = {} // maps target to files downloaded from it
const targetLicense = {}
const ids = []
const disabledIds = []

function install (target) {
ensure(spawnSync('plum/rime-install', [target], {
stdio: 'inherit',
env: {
...process.env,
rime_dir: RIME_DIR
async function install (recipe, target) {
const manifest = await recipe.load()
for (const { file, content } of manifest) {
if (content) {
const path = `${RIME_DIR}/${file}`
mkdirSync(path.slice(0, path.lastIndexOf('/')), { recursive: true })
writeFileSync(path, content)
if (target && !targetManifest[target].includes(file)) {
targetManifest[target].push(file)
}
console.log(`Installed ${file}`)
}
}))
}
}

function loadOpenCC (config) {
Expand All @@ -43,10 +49,6 @@ function loadOpenCC (config) {
}
}

function isOfficialIME (target) {
return !target.includes('/')
}

function parseYaml (schemaId) {
const content = yaml.load(readFileSync(`${RIME_DIR}/build/${schemaId}.schema.yaml`, utf8))
for (const [key, value] of Object.entries(content)) {
Expand All @@ -67,7 +69,33 @@ function parseYaml (schemaId) {
}
}

['prelude', 'essay', 'emoji'].forEach(install)
function getPackageDir (target) {
return `public/ime/${target}`
}

function readJson (path, defaultValue) {
try {
return JSON.parse(readFileSync(path, 'utf-8'))
} catch (e) {
return defaultValue
}
}

function bumpVersion (oldVersion) {
if (!oldVersion) {
return version
}
const [major, minor, patch] = oldVersion.split('.')
return [major, minor, Number(patch) + 1].join('.')
}

// Main

mkdirSync(`${RIME_DIR}/opencc`, { recursive: true })
for (const fileName of readdirSync('rime-config')) {
cpSync(`rime-config/${fileName}`, `${RIME_DIR}/${fileName}`, { recursive: true })
}
await Promise.all(['prelude', 'essay', 'emoji'].map(target => install(new Recipe(target))))

// remove emoji_category as I don't want to visit a zoo when I type 东吴
const emojiJson = `${RIME_DIR}/opencc/emoji.json`
Expand All @@ -77,12 +105,12 @@ emojiDict.dicts = emojiDict.dicts.filter(({ file }) => file !== 'emoji_category.
writeFileSync(emojiJson, JSON.stringify(emojiContent))

for (const schema of schemas) {
const { target } = schema
if (!(target in targetSchemas)) {
targetSchemas[target] = []
const recipe = new Recipe(schema.target, { schemaIds: [schema.id] })
const target = recipe.repo.match(/(rime\/rime-)?(.*)/)[2]
if (!(target in targetManifest)) {
targetManifest[target] = []
targetFiles[target] = []
targetLicense[target] = schema.license
install(target)
}
ids.push(schema.id)
if (schema.disabled) {
Expand All @@ -91,15 +119,14 @@ for (const schema of schemas) {
schemaName[schema.id] = schema.name
}
schemaTarget[schema.id] = target
targetSchemas[target].push(schema.id)
if (schema.dependencies) {
dependencyMap[schema.id] = schema.dependencies
}
if (schema.family) {
for (const { id, name, disabled } of schema.family) {
recipe.schemaIds.push(id)
ids.push(id)
schemaTarget[id] = target
targetSchemas[target].push(id)
if (disabled) {
disabledIds.push(id)
} else if (schema.dependencies) {
Expand All @@ -108,9 +135,14 @@ for (const schema of schemas) {
}
}
}
await install(recipe, target)
if (schema.emoji) {
loadOpenCC('emoji.json')
install(`emoji:customize:schema=${schema.id}`)
writeFileSync(`${RIME_DIR}/${schema.id}.custom.yaml`,
`__patch:
- patch/+:
__include: emoji_suggestion:/patch
`)
}
}

Expand Down Expand Up @@ -138,24 +170,23 @@ ensure(spawnSync('./rime_console', [], {
chdir(root)
ids.forEach(parseYaml)

function getPackageDir (target) {
return `public/ime/${target}`
}

for (const [target, schemaIds] of Object.entries(targetSchemas)) {
// find all files that belongs to a target('s npm package)
// wtf https://github.com/rime/plum/blob/6f502ff6fa87789847fa18200415318e705bffa4/scripts/resolver.sh#L22
const repoDir = `plum/package/${isOfficialIME(target) ? 'rime/' : ''}${target}`.replace('rime-', '')
for (const [target, manifest] of Object.entries(targetManifest)) {
// find all built files that belongs to a target('s npm package)
const fileNames = []
for (const schemaId of schemaIds) {
fileNames.push(`${schemaId}.schema.yaml`)
const schemaPostfix = '.schema.yaml'
for (const file of manifest) {
if (!file.endsWith(schemaPostfix)) {
continue
}
const schemaId = file.slice(0, -schemaPostfix.length)
fileNames.push(file)
const { dict, prism } = schemaFiles[schemaId]
const dictionary = dict || schemaId
const dictYaml = `${dictionary}.dict.yaml`
const tableBin = `${dictionary}.table.bin`
const reverseBin = `${dictionary}.reverse.bin`
const prismBin = `${prism || dictionary}.prism.bin`
if (!fileNames.includes(tableBin) && existsSync(`${repoDir}/${dictYaml}`)) {
if (!fileNames.includes(tableBin) && manifest.includes(dictYaml)) {
fileNames.push(tableBin, reverseBin)
}
if (!fileNames.includes(prismBin)) {
Expand All @@ -177,22 +208,6 @@ for (const [target, schemaIds] of Object.entries(targetSchemas)) {
}
}

function readJson (path, defaultValue) {
try {
return JSON.parse(readFileSync(path, 'utf-8'))
} catch (e) {
return defaultValue
}
}

function bumpVersion (oldVersion) {
if (!oldVersion) {
return version
}
const [major, minor, patch] = oldVersion.split('.')
return [major, minor, Number(patch) + 1].join('.')
}

const oldTargetFiles = readJson('target-files.json', {})

const updatedTargets = []
Expand All @@ -205,7 +220,7 @@ for (const [target, files] of Object.entries(targetFiles)) {
updatedTargets.push(target)
newVersion = bumpVersion(oldVersion)
const packageJson = {
name: `@${isOfficialIME(target) ? 'rime-contrib' : ''}/${target}`,
name: `@${target.includes('/') ? '' : 'rime-contrib/'}${target}`,
version: newVersion,
files: targetFiles[target].map(({ name }) => name),
license: targetLicense[target]
Expand Down Expand Up @@ -234,20 +249,10 @@ writeFileSync('schema-files.json', JSON.stringify(schemaFiles))
writeFileSync('schema-target.json', JSON.stringify(schemaTarget))
writeFileSync('dependency-map.json', JSON.stringify(dependencyMap))
writeFileSync('target-version.json', JSON.stringify(targetVersion))

let oldOpenccConfigs
try {
oldOpenccConfigs = readFileSync('opencc-configs.json', 'utf-8')
} catch (e) {
oldOpenccConfigs = ''
}

const sortedOpenccConfig = JSON.stringify(openccConfigs.sort())
if (oldOpenccConfigs !== sortedOpenccConfig) {
writeFileSync('opencc-configs.json', sortedOpenccConfig)
console.log("opencc-configs.json is updated. You need to run 'pnpm run wasm' again.")
}
writeFileSync('opencc-configs.json', JSON.stringify(openccConfigs.sort()))

for (const fileName of readdirSync(`${RIME_DIR}/opencc`)) {
copyFileSync(`${RIME_DIR}/opencc/${fileName}`, `build/sysroot/usr/local/share/opencc/${fileName}`)
}

console.log("Run 'pnpm run wasm' before 'pnpm run dev' to update rime.data.")
1 change: 0 additions & 1 deletion scripts/update_submodule.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
set -e

git submodule update --init --recursive -f librime
git submodule update --init plum
git submodule update --init lua
git submodule update --init librime-lua
git submodule update --init boost
Expand Down

0 comments on commit bf64783

Please sign in to comment.