52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
|
|
const projectRoot = path.resolve(__dirname, '..')
|
|
const h5Root = path.join(projectRoot, 'dist', 'build', 'h5')
|
|
const faviconSource = path.join(projectRoot, 'public', 'favicon.svg')
|
|
const faviconTarget = path.join(h5Root, 'favicon.svg')
|
|
|
|
if (!fs.existsSync(h5Root)) {
|
|
throw new Error(`H5 build output not found: ${h5Root}`)
|
|
}
|
|
|
|
const copyDirectory = (source, target) => {
|
|
fs.mkdirSync(target, { recursive: true })
|
|
|
|
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
|
const sourcePath = path.join(source, entry.name)
|
|
const targetPath = path.join(target, entry.name)
|
|
|
|
if (entry.isDirectory()) {
|
|
copyDirectory(sourcePath, targetPath)
|
|
continue
|
|
}
|
|
|
|
if (entry.isFile()) {
|
|
fs.copyFileSync(sourcePath, targetPath)
|
|
}
|
|
}
|
|
}
|
|
|
|
const copyStaticSubtree = (subtree) => {
|
|
const sourceDir = path.join(projectRoot, 'static', subtree)
|
|
const targetDir = path.join(h5Root, 'static', subtree)
|
|
|
|
if (!fs.existsSync(sourceDir)) {
|
|
throw new Error(`Static assets not found: ${sourceDir}`)
|
|
}
|
|
|
|
fs.rmSync(targetDir, { recursive: true, force: true })
|
|
copyDirectory(sourceDir, targetDir)
|
|
console.log(`Copied ${subtree} assets to ${path.relative(projectRoot, targetDir)}`)
|
|
}
|
|
|
|
copyStaticSubtree('nav-assets')
|
|
copyStaticSubtree('guide-data')
|
|
copyStaticSubtree('sgs-map-sdk')
|
|
copyStaticSubtree('three')
|
|
|
|
if (fs.existsSync(faviconSource)) {
|
|
fs.copyFileSync(faviconSource, faviconTarget)
|
|
}
|