nomadro/apps/miniprogram/tt/scripts/validate-size.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

62 lines
1.6 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.

/**
* 抖音官方分包限制(developer.open-douyin.com 分包简介):
* - 主包 ≤ 4MB
* - 单个分包 ≤ 2MB
* - 全部包合计 ≤ 16MB
* 校验 dist(已 strip .map);上传前请先 copy-static。
*/
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const dist = path.join(root, 'dist')
const MAIN_LIMIT = 4 * 1024 * 1024
const SUB_LIMIT = 2 * 1024 * 1024
const TOTAL_LIMIT = 16 * 1024 * 1024
function dirSize(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 += dirSize(p)
else if (!name.endsWith('.map')) n += st.size
}
return n
}
function mb(n) {
return (n / 1024 / 1024).toFixed(2)
}
if (!fs.existsSync(dist)) {
console.error('missing dist/')
process.exit(1)
}
const packageBook = path.join(dist, 'packageBook')
const sub = dirSize(packageBook)
const total = dirSize(dist)
const main = total - sub
console.log(`tt size check (official: main≤4 / sub≤2 / total≤16 MB)`)
console.log(` main≈${mb(main)} MB packageBook=${mb(sub)} MB total=${mb(total)} MB`)
let fail = 0
if (main > MAIN_LIMIT) {
console.error(`FAIL main ${mb(main)} > 4 MB`)
fail = 1
}
if (sub > SUB_LIMIT) {
console.error(`FAIL packageBook ${mb(sub)} > 2 MB`)
fail = 1
}
if (total > TOTAL_LIMIT) {
console.error(`FAIL total ${mb(total)} > 16 MB`)
fail = 1
}
if (!fail) console.log('OK')
process.exit(fail)