| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /**
- * Batch normalize saas-adminui list page labels and button types.
- * Usage: node scripts/normalize-list-labels.js
- */
- const fs = require('fs')
- const path = require('path')
- const viewsDir = path.join(__dirname, '../src/views')
- const replacements = [
- ['label="\u516c\u53f8\u540d"', 'label="\u516c\u53f8\u540d\u79f0"'],
- ['label="\u516c\u53f8\u540d:"', 'label="\u516c\u53f8\u540d\u79f0:"'],
- ['placeholder="\u8bf7\u9009\u62e9\u516c\u53f8\u540d"', 'placeholder="\u8bf7\u9009\u62e9\u516c\u53f8\u540d\u79f0"'],
- ['placeholder="\u8bf7\u8f93\u5165\u516c\u53f8\u540d"', 'placeholder="\u8bf7\u8f93\u5165\u516c\u53f8\u540d\u79f0"'],
- ['placeholder="\u5168\u90e8\u516c\u53f8"', 'placeholder="\u5168\u90e8"'],
- ['label="\u624b\u673a" prop="mobile"', 'label="\u624b\u673a\u53f7\u7801" prop="mobile"'],
- ['label="\u624b\u673a"', 'label="\u624b\u673a\u53f7\u7801"'],
- ['placeholder="\u8bf7\u8f93\u5165\u624b\u673a"', 'placeholder="\u8bf7\u8f93\u5165\u624b\u673a\u53f7\u7801"'],
- ['type="cyan"', 'type="primary"'],
- ['label-width="68px"', 'label-width="88px"'],
- ['label-width="85px"', 'label-width="88px"'],
- ['label-width="90px"', 'label-width="88px"'],
- ['label-width="100px"', 'label-width="88px"'],
- ['style="width: 205.4px"', 'style="width: 100%"'],
- ['style="width:205.4px"', 'style="width: 100%"'],
- ['style="width: 220px"', 'style="width: 100%"'],
- ['style="width:220px"', 'style="width: 100%"']
- ]
- function walk(dir, files = []) {
- for (const name of fs.readdirSync(dir)) {
- const full = path.join(dir, name)
- const stat = fs.statSync(full)
- if (stat.isDirectory()) {
- walk(full, files)
- } else if (name.endsWith('.vue')) {
- files.push(full)
- }
- }
- return files
- }
- let changedFiles = 0
- let totalReplacements = 0
- for (const file of walk(viewsDir)) {
- let content = fs.readFileSync(file, 'utf8')
- const original = content
- let fileCount = 0
- for (const [from, to] of replacements) {
- if (content.includes(from)) {
- const parts = content.split(from)
- fileCount += parts.length - 1
- content = parts.join(to)
- }
- }
- if (content !== original) {
- fs.writeFileSync(file, content, 'utf8')
- changedFiles++
- totalReplacements += fileCount
- console.log('updated: ' + path.relative(viewsDir, file) + ' (' + fileCount + ')')
- }
- }
- console.log('\nDone. ' + changedFiles + ' files, ' + totalReplacements + ' replacements.')
|