This commit is contained in:
52
scripts/sync-sdk-engine.cjs
Normal file
52
scripts/sync-sdk-engine.cjs
Normal file
@@ -0,0 +1,52 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const projectRoot = path.resolve(__dirname, '..')
|
||||
const repoRoot = path.resolve(projectRoot, '..')
|
||||
const sourceDir = path.join(repoRoot, 'sgs-map-sdk-release', 'engine')
|
||||
const targetDir = path.join(projectRoot, 'public', 'engine')
|
||||
|
||||
if (!fs.existsSync(sourceDir)) {
|
||||
throw new Error(`SDK Engine source not found: ${sourceDir}`)
|
||||
}
|
||||
|
||||
const publicDir = path.join(projectRoot, 'public')
|
||||
const resolvedTarget = path.resolve(targetDir)
|
||||
if (!resolvedTarget.startsWith(path.resolve(publicDir) + path.sep)) {
|
||||
throw new Error(`Refusing to write outside public directory: ${resolvedTarget}`)
|
||||
}
|
||||
|
||||
const rewriteTextFiles = (dir) => {
|
||||
const replacements = [
|
||||
['http://1.92.206.90:9000/museum-assets', '/museum-assets'],
|
||||
['http://1.92.206.90:9000/tts-audio', '/tts-audio'],
|
||||
['http://1.92.206.90:9000', 'http://legacy-minio.local:9000'],
|
||||
['https://1.92.206.90:9000', 'https://legacy-minio.local:9000'],
|
||||
['https://guide.whaoyue.com/museum-assets', '/museum-assets'],
|
||||
['https://guide.whaoyue.com/tts-audio', '/tts-audio'],
|
||||
['https://guide.whaoyue.com/app-api', '/app-api']
|
||||
]
|
||||
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const filePath = path.join(dir, entry.name)
|
||||
if (entry.isDirectory()) {
|
||||
rewriteTextFiles(filePath)
|
||||
continue
|
||||
}
|
||||
if (!entry.isFile() || !/\.(?:html|js|mjs|json|css|map)$/i.test(entry.name)) continue
|
||||
|
||||
let text = fs.readFileSync(filePath, 'utf8')
|
||||
const original = text
|
||||
for (const [from, to] of replacements) {
|
||||
text = text.split(from).join(to)
|
||||
}
|
||||
if (text !== original) fs.writeFileSync(filePath, text, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
fs.rmSync(targetDir, { recursive: true, force: true })
|
||||
fs.mkdirSync(path.dirname(targetDir), { recursive: true })
|
||||
fs.cpSync(sourceDir, targetDir, { recursive: true })
|
||||
rewriteTextFiles(targetDir)
|
||||
|
||||
console.log(`Synced SDK Engine: ${sourceDir} -> ${targetDir}`)
|
||||
Reference in New Issue
Block a user