nomadro/apps/miniprogram/tt/scripts/copy-static.mjs
eric 1d3e513ae2 Ship Douyin tt/ miniprogram: offline reader, clipboard privacy, README.
Add apps/miniprogram/tt as a standalone Douyin app with official usePrivacyCheck + tt.showModal/setClipboardData flow, single-chapter offline reader, and document console privacy setup for clipboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 15:17:52 +08:00

71 lines
1.7 KiB
JavaScript

/**
* Taro copy.patterns 偶发不落盘;构建后强制把 icons / assets 拷进 dist。
*/
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const out = 'dist'
function rmrf(p) {
if (!fs.existsSync(p)) return
fs.rmSync(p, { recursive: true, force: true })
}
function copyDir(from, to, { wipe = false } = {}) {
if (!fs.existsSync(from)) {
console.warn(`[copy-static] skip missing: ${from}`)
return 0
}
if (wipe) rmrf(to)
fs.mkdirSync(to, { recursive: true })
let n = 0
for (const name of fs.readdirSync(from)) {
const src = path.join(from, name)
const dest = path.join(to, name)
const st = fs.statSync(src)
if (st.isDirectory()) n += copyDir(src, dest)
else {
fs.copyFileSync(src, dest)
n += 1
}
}
return n
}
function stripMaps(dir) {
if (!fs.existsSync(dir)) return 0
let n = 0
for (const name of fs.readdirSync(dir)) {
const p = path.join(dir, name)
const st = fs.statSync(p)
if (st.isDirectory()) n += stripMaps(p)
else if (name.endsWith('.map')) {
fs.unlinkSync(p)
n += 1
}
}
return n
}
const icons = copyDir(
path.join(root, 'src/public/icons'),
path.join(root, out, 'icons'),
{ wipe: true },
)
const assets = copyDir(
path.join(root, 'src/assets'),
path.join(root, out, 'assets'),
{ wipe: true },
)
const bookImgs = copyDir(
path.join(root, 'src/packageBook/assets/book-images'),
path.join(root, out, 'packageBook/assets/book-images'),
{ wipe: true },
)
const maps = stripMaps(path.join(root, out))
console.log(
`[copy-static] ${out}: icons=${icons} assets=${assets} bookImgs=${bookImgs} mapsRemoved=${maps}`,
)