forked from natuka/web.puabadge.com
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
const root = path.resolve('src/views/douyin/components/image-point-cloud')
|
|
|
|
function walk(d) {
|
|
for (const f of fs.readdirSync(d)) {
|
|
const p = path.join(d, f)
|
|
if (fs.statSync(p).isDirectory()) walk(p)
|
|
else if (f.endsWith('.js')) convert(p)
|
|
}
|
|
}
|
|
|
|
function convert(file) {
|
|
let s = fs.readFileSync(file, 'utf8')
|
|
|
|
s = s.replace(
|
|
/const\s+\{([^}]+)\}\s*=\s*require\((['"])(.*?)\2\)/g,
|
|
(_m, names, _q, mod) => `import {${names}} from '${mod}'`
|
|
)
|
|
s = s.replace(
|
|
/const\s+(\w+)\s*=\s*require\((['"])(.*?)\2\)/g,
|
|
(_m, name, _q, mod) => `import * as ${name} from '${mod}'`
|
|
)
|
|
|
|
// remove config perf require block
|
|
s = s.replace(
|
|
/try\s*\{[\s\S]*?POINT_CLOUD_PERF_LOG[\s\S]*?\}\s*catch[\s\S]*?\{[\s\S]*?\}/,
|
|
'let _perfLog = false'
|
|
)
|
|
|
|
s = s.replace(/module\.exports\s*=\s*\{([\s\S]*?)\}\s*$/m, (_m, body) => `export {${body}}`)
|
|
s = s.replace(/module\.exports\s*=\s*(\w+)\s*$/m, 'export default $1')
|
|
|
|
fs.writeFileSync(file, s)
|
|
console.log('converted', file)
|
|
}
|
|
|
|
walk(root)
|