设计
This commit is contained in:
51
templates/front_sample/standard/scripts/audit-check.mjs
Normal file
51
templates/front_sample/standard/scripts/audit-check.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
function walk(dir, acc = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory() && entry.name !== 'node_modules') {
|
||||
walk(full, acc);
|
||||
} else if (/\.(ts|vue)$/.test(entry.name)) {
|
||||
acc.push(full);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
const srcFiles = walk('src');
|
||||
const badPlaceholder = [];
|
||||
const zhLocales = srcFiles.filter((f) => f.includes(`${path.sep}locale${path.sep}zh-CN.ts`));
|
||||
|
||||
for (const file of srcFiles) {
|
||||
const text = fs.readFileSync(file, 'utf8');
|
||||
if (text.includes("'???'") || /'(\?\?[^']*)'/.test(text)) {
|
||||
badPlaceholder.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
let zhOk = 0;
|
||||
for (const file of zhLocales) {
|
||||
if (/[\u4e00-\u9fff]/.test(fs.readFileSync(file, 'utf8'))) zhOk += 1;
|
||||
}
|
||||
|
||||
let mockInDist = false;
|
||||
if (fs.existsSync('dist/assets')) {
|
||||
for (const name of fs.readdirSync('dist/assets')) {
|
||||
if (!name.endsWith('.js')) continue;
|
||||
const chunk = fs.readFileSync(path.join('dist/assets', name), 'utf8');
|
||||
if (chunk.includes('mockjs') || chunk.includes('Mock.mock')) {
|
||||
mockInDist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({
|
||||
badPlaceholder: badPlaceholder.length,
|
||||
zhLocales: `${zhOk}/${zhLocales.length}`,
|
||||
mockInDist,
|
||||
hasGit: fs.existsSync('.env.development') && fs.readFileSync('.env.development', 'utf8').includes('VITE_API_BASE_URL=http'),
|
||||
settingsHttp: fs.readFileSync('src/locale/zh-CN/settings.ts', 'utf8').includes('http.logout.title'),
|
||||
rootMenu: fs.readFileSync('src/locale/zh-CN.ts', 'utf8').includes('仪表盘'),
|
||||
}, null, 2));
|
||||
67
templates/front_sample/standard/scripts/restore-p0-vue.mjs
Normal file
67
templates/front_sample/standard/scripts/restore-p0-vue.mjs
Normal file
@@ -0,0 +1,67 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const BASE =
|
||||
'https://raw.githubusercontent.com/arco-design/arco-design-pro-vue/main/arco-design-pro-vite/src';
|
||||
|
||||
const vueFiles = [
|
||||
'views/visualization/multi-dimension-data-analysis/components/content-publishing-source.vue',
|
||||
'views/user/info/components/my-project.vue',
|
||||
'views/user/info/components/my-team.vue',
|
||||
'views/user/setting/components/enterprise-certification.vue',
|
||||
];
|
||||
|
||||
async function download(relPath) {
|
||||
const res = await fetch(`${BASE}/${relPath}`);
|
||||
if (!res.ok) throw new Error(`${relPath}: HTTP ${res.status}`);
|
||||
return res.text();
|
||||
}
|
||||
|
||||
function patchForProject(content, relPath) {
|
||||
let text = content;
|
||||
|
||||
if (relPath.includes('my-project.vue')) {
|
||||
text = text.replace(
|
||||
"import { queryMyProjectList, MyProjectRecord } from '@/api/user-center';",
|
||||
"import { type MyProjectRecord, queryMyProjectList } from '@/api/user';",
|
||||
);
|
||||
text = text.replace(/\{\{ project\.contributors \}\}\s*/g, '');
|
||||
}
|
||||
|
||||
if (relPath.includes('my-team.vue')) {
|
||||
text = text.replace(
|
||||
"import { queryMyTeamList, MyTeamRecord } from '@/api/user-center';",
|
||||
"import { type MyTeamRecord, queryMyTeamList } from '@/api/user';",
|
||||
);
|
||||
}
|
||||
|
||||
if (relPath.includes('enterprise-certification.vue')) {
|
||||
text = text.replace(
|
||||
"import { EnterpriseCertificationModel } from '@/api/user-center';",
|
||||
"import type { EnterpriseCertificationModel } from '@/api/user';",
|
||||
);
|
||||
text = text.replace(
|
||||
/type: Object as PropType<EnterpriseCertificationModel>/,
|
||||
'type: Object as PropType<EnterpriseCertificationModel>,',
|
||||
);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
for (const relPath of vueFiles) {
|
||||
let content = await download(relPath);
|
||||
content = patchForProject(content, relPath);
|
||||
const fullPath = path.join('src', relPath);
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
fs.writeFileSync(fullPath, content, 'utf8');
|
||||
const hasCn = /[\u4e00-\u9fff]/.test(content);
|
||||
console.log(`OK ${relPath} (cn=${hasCn})`);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const BASE =
|
||||
'https://raw.githubusercontent.com/arco-design/arco-design-pro-vue/main/arco-design-pro-vite/src';
|
||||
|
||||
const localeFiles = [
|
||||
'locale/zh-CN/settings.ts',
|
||||
'views/login/locale/zh-CN.ts',
|
||||
'views/form/group/locale/zh-CN.ts',
|
||||
'views/form/step/locale/zh-CN.ts',
|
||||
'views/dashboard/workplace/locale/zh-CN.ts',
|
||||
'views/dashboard/monitor/locale/zh-CN.ts',
|
||||
'views/list/card/locale/zh-CN.ts',
|
||||
'views/list/search-table/locale/zh-CN.ts',
|
||||
'views/profile/basic/locale/zh-CN.ts',
|
||||
'views/result/success/locale/zh-CN.ts',
|
||||
'views/result/error/locale/zh-CN.ts',
|
||||
'views/exception/403/locale/zh-CN.ts',
|
||||
'views/exception/404/locale/zh-CN.ts',
|
||||
'views/user/info/locale/zh-CN.ts',
|
||||
'views/user/setting/locale/zh-CN.ts',
|
||||
'views/visualization/data-analysis/locale/zh-CN.ts',
|
||||
'views/visualization/multi-dimension-data-analysis/locale/zh-CN.ts',
|
||||
];
|
||||
|
||||
const rootZhCN = `import { mergeLocaleModules } from './merge-locales';
|
||||
import localeSettings from './zh-CN/settings';
|
||||
|
||||
const componentLocales = mergeLocaleModules(
|
||||
import.meta.glob('@/components/**/locale/zh-CN.ts', { eager: true }),
|
||||
);
|
||||
const viewLocales = mergeLocaleModules(
|
||||
import.meta.glob('@/views/**/locale/zh-CN.ts', { eager: true }),
|
||||
);
|
||||
|
||||
export default {
|
||||
'menu.dashboard': '仪表盘',
|
||||
'menu.server.dashboard': '仪表盘-服务端',
|
||||
'menu.server.workplace': '工作台-服务端',
|
||||
'menu.server.monitor': '实时监控-服务端',
|
||||
'menu.list': '列表页',
|
||||
'menu.result': '结果页',
|
||||
'menu.exception': '异常页',
|
||||
'menu.form': '表单页',
|
||||
'menu.profile': '详情页',
|
||||
'menu.visualization': '数据可视化',
|
||||
'menu.user': '个人中心',
|
||||
'menu.arcoWebsite': 'Arco Design',
|
||||
'menu.faq': '常见问题',
|
||||
'navbar.docs': '文档中心',
|
||||
'navbar.action.locale': '切换为中文',
|
||||
...localeSettings,
|
||||
...componentLocales,
|
||||
...viewLocales,
|
||||
};
|
||||
`;
|
||||
|
||||
async function download(relPath) {
|
||||
const url = `${BASE}/${relPath}`;
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) {
|
||||
throw new Error(`${relPath}: HTTP ${res.status}`);
|
||||
}
|
||||
return res.text();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
for (const relPath of localeFiles) {
|
||||
const content = await download(relPath);
|
||||
const dest = path.join('src', relPath.replace(/^locale\//, 'locale/'));
|
||||
const fullPath = path.join('src', relPath);
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
fs.writeFileSync(fullPath, content, 'utf8');
|
||||
const hasCn = /[\u4e00-\u9fff]/.test(content);
|
||||
console.log(`OK ${relPath} (cn=${hasCn})`);
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join('src', 'locale/zh-CN.ts'), rootZhCN, 'utf8');
|
||||
console.log('OK locale/zh-CN.ts (cn=true)');
|
||||
|
||||
// search-table column setting label
|
||||
const stPath = path.join('src', 'views/list/search-table/index.vue');
|
||||
let st = fs.readFileSync(stPath, 'utf8');
|
||||
st = st.replace(
|
||||
"{{ item.title === '#' ? '???' : item.title }}",
|
||||
"{{ item.title === '#' ? '序列号' : item.title }}",
|
||||
);
|
||||
fs.writeFileSync(stPath, st, 'utf8');
|
||||
console.log('OK search-table/index.vue');
|
||||
|
||||
// verify
|
||||
let bad = 0;
|
||||
for (const relPath of ['locale/zh-CN.ts', ...localeFiles]) {
|
||||
const fullPath = path.join('src', relPath);
|
||||
const text = fs.readFileSync(fullPath, 'utf8');
|
||||
if (text.includes("'???'") || text.includes("'??'")) {
|
||||
console.error('STILL BAD:', relPath);
|
||||
bad += 1;
|
||||
}
|
||||
}
|
||||
if (bad) process.exit(1);
|
||||
console.log('All locale files verified');
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user