feat: migrate static pages to native tabbar

This commit is contained in:
2026-04-23 21:25:24 +08:00
parent f3cd0c3a98
commit cd30f57f2c
116 changed files with 7143 additions and 311 deletions

View File

@@ -0,0 +1,83 @@
const fs = require('fs')
const path = require('path')
const PROJECT_ROOT = process.cwd()
const IGNORED_SEGMENTS = ['node_modules', 'miniprogram_npm', 'coverage', '.worktrees']
function shouldIgnore(filePath) {
return IGNORED_SEGMENTS.some(segment => filePath.includes(`${path.sep}${segment}${path.sep}`))
}
function getProjectFiles(extension) {
const pendingDirs = [PROJECT_ROOT]
const collectedFiles = []
while (pendingDirs.length) {
const currentDir = pendingDirs.pop()
const entries = fs.readdirSync(currentDir, { withFileTypes: true })
entries.forEach(entry => {
const absolutePath = path.join(currentDir, entry.name)
if (shouldIgnore(absolutePath)) {
return
}
if (entry.isDirectory()) {
pendingDirs.push(absolutePath)
return
}
if (entry.isFile() && absolutePath.endsWith(extension)) {
collectedFiles.push(absolutePath)
}
})
}
return collectedFiles
}
function getDirectoryImportViolations() {
const requirePattern = /require\((['"])(\.[^'"]+)\1\)/g
return getProjectFiles('.js').flatMap(filePath => {
const source = fs.readFileSync(filePath, 'utf8')
const violations = []
let match = requirePattern.exec(source)
while (match) {
const specifier = match[2]
const targetPath = path.resolve(path.dirname(filePath), specifier)
if (fs.existsSync(targetPath) && fs.statSync(targetPath).isDirectory()) {
violations.push({
filePath: path.relative(PROJECT_ROOT, filePath),
specifier
})
}
match = requirePattern.exec(source)
}
return violations
})
}
function getImportTarget(wxssPath, importPath) {
return path.resolve(path.dirname(wxssPath), importPath)
}
describe('miniprogram compatibility', () => {
test('avoids directory-level require paths that the miniprogram runtime cannot resolve reliably', () => {
expect(getDirectoryImportViolations()).toEqual([])
})
test('app.wxss imports the generated TDesign style entry that exists in the project', () => {
const appWxssPath = path.join(PROJECT_ROOT, 'app.wxss')
const appWxss = fs.readFileSync(appWxssPath, 'utf8')
const match = appWxss.match(/@import ['"]([^'"]+)['"];/)
expect(match).not.toBeNull()
expect(fs.existsSync(getImportTarget(appWxssPath, match[1]))).toBe(true)
})
})