fix: localize skin site UI and renew JWT on startup
Catalog missing skin-site messages and check source IDs during i18n validation. Renew the saved JWT before loading session data, guard overlapping login/logout requests, and reload announcements after authentication with a retry action.
This commit is contained in:
1 parent
2d7683b0bb
commit
7f3a1cdf5c
11 files changed
+4744
-2341
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { createRequire } from 'node:module'
|
||||
|
||||
const require = createRequire(new URL('../../apps/app-frontend/package.json', import.meta.url))
|
||||
const ts = require('typescript')
|
||||
const { parse } = require('vue/compiler-sfc')
|
||||
|
||||
/** Read the message IDs actually used by skin-site UI, including uncatalogued messages. */
|
||||
export function collectSkinSiteMessages(root = 'apps/app-frontend/src') {
|
||||
const messages = new Map()
|
||||
function walk(directory) {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const file = path.join(directory, entry.name)
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name !== 'locales') walk(file)
|
||||
continue
|
||||
}
|
||||
if (!/\.(vue|ts)$/.test(file) || file.endsWith('.test.ts')) continue
|
||||
let source = fs.readFileSync(file, 'utf8')
|
||||
if (file.endsWith('.vue')) {
|
||||
const { descriptor } = parse(source)
|
||||
source = [descriptor.script?.content, descriptor.scriptSetup?.content]
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
}
|
||||
const ast = ts.createSourceFile(`${file}.ts`, source, ts.ScriptTarget.Latest, true)
|
||||
function visit(node) {
|
||||
if (ts.isObjectLiteralExpression(node)) {
|
||||
const properties = Object.fromEntries(
|
||||
node.properties
|
||||
.filter(ts.isPropertyAssignment)
|
||||
.map((property) => [
|
||||
property.name.getText(ast).replace(/^['"]|['"]$/g, ''),
|
||||
property.initializer,
|
||||
]),
|
||||
)
|
||||
if (
|
||||
properties.id &&
|
||||
properties.defaultMessage &&
|
||||
ts.isStringLiteralLike(properties.id) &&
|
||||
ts.isStringLiteralLike(properties.defaultMessage) &&
|
||||
properties.id.text.startsWith('app.skin-site.')
|
||||
) {
|
||||
messages.set(properties.id.text, {
|
||||
id: properties.id.text,
|
||||
defaultMessage: properties.defaultMessage.text,
|
||||
file,
|
||||
})
|
||||
}
|
||||
}
|
||||
ts.forEachChild(node, visit)
|
||||
}
|
||||
visit(ast)
|
||||
}
|
||||
}
|
||||
walk(root)
|
||||
return [...messages.values()]
|
||||
}
|
||||
Reference in new issue
Block a user