refactor: remove duplicate miniapp page sources
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { existsSync, readdirSync } from 'node:fs'
|
||||
import { extname, join, relative, resolve } from 'node:path'
|
||||
|
||||
const root = resolve(import.meta.dirname, '..')
|
||||
const pagesRoot = resolve(root, 'miniapp/pages')
|
||||
|
||||
function walk(directory) {
|
||||
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
||||
const absolutePath = join(directory, entry.name)
|
||||
return entry.isDirectory() ? walk(absolutePath) : [absolutePath]
|
||||
})
|
||||
}
|
||||
|
||||
const duplicatePageSources = walk(pagesRoot)
|
||||
.filter((file) => extname(file) === '.ts')
|
||||
.filter((file) => existsSync(file.replace(/\.ts$/, '.js')))
|
||||
.map((file) => relative(root, file).replace(/\\/g, '/'))
|
||||
|
||||
assert.deepEqual(
|
||||
duplicatePageSources,
|
||||
[],
|
||||
`小程序页面存在 TS/JS 双源,可能导致微信开发者工具加载旧实现:\n${duplicatePageSources.join('\n')}`,
|
||||
)
|
||||
|
||||
console.log('Miniapp page source uniqueness contracts passed')
|
||||
Reference in New Issue
Block a user