27 行
1.8 KiB
JavaScript
27 行
1.8 KiB
JavaScript
// Copy the canonical keyboard into another Glyphix sandbox; no cross-app data.
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import {fileURLToPath} from 'node:url'
|
|
const app=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..')
|
|
const target=path.resolve(process.argv[2]||'')
|
|
if(!process.argv[2]||!fs.existsSync(path.join(target,'src/manifest.json')))throw Error('Usage: node scripts/install.mjs <Glyphix project>')
|
|
const oldMeta=path.join(target,'src/assets/ime-dict/meta.json')
|
|
if(fs.existsSync(oldMeta)){
|
|
const current=JSON.parse(fs.readFileSync(path.join(app,'src/assets/ime-dict/meta.json'),'utf8')).shards
|
|
for(const name of JSON.parse(fs.readFileSync(oldMeta,'utf8')).shards){
|
|
if(!/^(short|s?[0-9]+|ds?[0-9a-d]+)$/.test(name))throw Error('Invalid generated shard name')
|
|
const old=path.join(target,'src/assets/ime-dict',name+'.json')
|
|
if(!current.includes(name)&&fs.existsSync(old))fs.unlinkSync(old)
|
|
}
|
|
}
|
|
for(const relative of ['keyboard/index.ux','common/ime-engine.js','common/ime-lifecycle.js','common/ime-theme.js','assets/ime-dict','assets/ime-icons']){
|
|
const destination=path.join(target,'src',relative);fs.mkdirSync(path.dirname(destination),{recursive:true});fs.cpSync(path.join(app,'src',relative),destination,{recursive:true})
|
|
}
|
|
const license=path.join(target,'src/assets/crab-keyboard-license.txt')
|
|
fs.copyFileSync(path.join(app,'third_party/crabKeyboard/LICENSE'),license)
|
|
fs.copyFileSync(path.join(app,'third_party/jieba/LICENSE'),path.join(target,'src/assets/jieba-license.txt'))
|
|
const manifestPath=path.join(target,'src/manifest.json'),manifest=JSON.parse(fs.readFileSync(manifestPath,'utf8'))
|
|
manifest.router.pages.keyboard={component:'index'}
|
|
fs.writeFileSync(manifestPath,JSON.stringify(manifest,null,2)+'\n')
|
|
console.log('Installed canonical offline keyboard:',manifest.package)
|