nomadro/apps/miniprogram/scripts/copy-weapp-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

65 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Taro copy.patterns 偶发不落盘;构建后强制把 icons / assets 拷进 dist/weapp。
* 分享开关由 markPageShare 挂到 Page 组件(勿写入 page.json,基础库会报「无效的 page.json」)。
* 仅微信;抖音见 tt/scripts/copy-static.mjs,小红书见 xhs/。
*/
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/weapp'
function copyDir(from, to) {
if (!fs.existsSync(from)) {
console.warn(`[copy-weapp-static] skip missing: ${from}`)
return 0
}
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
}
/** 清掉历史误写入的 enableShare*,避免开发者工具刷黄字警告 */
function stripInvalidShareKeys(pagesRoot) {
if (!fs.existsSync(pagesRoot)) return 0
let n = 0
for (const name of fs.readdirSync(pagesRoot)) {
const jsonPath = path.join(pagesRoot, name, 'index.json')
if (!fs.existsSync(jsonPath)) continue
try {
const raw = fs.readFileSync(jsonPath, 'utf8').replace(/^\uFEFF/, '')
const j = JSON.parse(raw)
if (!('enableShareAppMessage' in j) && !('enableShareTimeline' in j)) continue
delete j.enableShareAppMessage
delete j.enableShareTimeline
fs.writeFileSync(jsonPath, JSON.stringify(j))
n += 1
} catch (e) {
console.warn(`[copy-weapp-static] strip share fail ${jsonPath}:`, e.message)
}
}
return n
}
const icons = copyDir(
path.join(root, 'src/public/icons'),
path.join(root, out, 'icons'),
)
const assets = copyDir(
path.join(root, 'src/assets'),
path.join(root, out, 'assets'),
)
const stripped = stripInvalidShareKeys(path.join(root, out, 'pages'))
console.log(`[copy-weapp-static] ${out}: icons=${icons} assets=${assets} strippedShareJson=${stripped}`)