31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
/**
|
|
* scripts/strip-i18n-auth.mjs
|
|
* 从 i18n.ts 内联 messages 中移除已外置至 locales 下 auth.json 的键。
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const i18nPath = path.resolve(__dirname, '../src/i18n.ts');
|
|
|
|
const content = fs.readFileSync(i18nPath, 'utf8');
|
|
const start = content.indexOf('const messages = {') + 'const messages = '.length;
|
|
const end = content.indexOf('const i18n = createI18n');
|
|
const messagesStr = content.slice(start, end).trim().replace(/,\s*$/, '');
|
|
const messages = new Function(`return ${messagesStr}`)();
|
|
|
|
for (const loc of ['en', 'zh-CN', 'zh-TW', 'th']) {
|
|
delete messages[loc].title;
|
|
delete messages[loc].login;
|
|
delete messages[loc].landing;
|
|
delete messages[loc].register;
|
|
}
|
|
|
|
const header = content.slice(0, content.indexOf('const messages = {'));
|
|
const footer = content.slice(end);
|
|
const serialized = JSON.stringify(messages, null, 2);
|
|
const newContent = `${header}const messages = ${serialized};\n\n${footer}`;
|
|
fs.writeFileSync(i18nPath, newContent, 'utf8');
|
|
console.log('Stripped auth keys from i18n.ts');
|