Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const plugins = [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-transform-runtime'],
['@babel/plugin-transform-object-rest-spread'],
['babel-plugin-react-compiler'],
['babel-plugin-react-compiler']
]

module.exports = {
Expand All @@ -12,20 +12,20 @@ module.exports = {
'@babel/preset-env',
{
targets: {
browsers: ['> 1%', 'last 2 versions', 'not ie <= 8'],
browsers: ['> 1%', 'last 2 versions', 'not ie <= 8']
},
modules: false,
useBuiltIns: 'entry',
corejs: 3,
},
corejs: 3
}
],
[
'@babel/preset-react',
{
runtime: 'automatic',
},
runtime: 'automatic'
}
],
'@babel/preset-typescript',
'@babel/preset-typescript'
],
compact: true,
comments: true,
Expand All @@ -35,7 +35,7 @@ module.exports = {
: plugins,
env: {
development: {
plugins: ['react-refresh/babel'],
},
},
plugins: ['react-refresh/babel']
}
}
}
32 changes: 16 additions & 16 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default [
'coverage/',
'**/*.d.ts',
'CHANGELOG.md',
'package-lock.json',
],
'package-lock.json'
]
},

// 基础推荐规则
Expand All @@ -40,29 +40,29 @@ export default [
plugins: {
'react-hooks': reactHooks,
import: importPlugin,
unicorn: unicorn,
react: react,
'@typescript-eslint': typescriptEslint,
unicorn,
react,
'@typescript-eslint': typescriptEslint
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
React: 'readonly',
React: 'readonly'
},
parser: typescriptParser,
ecmaVersion: 'latest',
sourceType: 'module',
sourceType: 'module'
},
settings: {
react: {
version: 'detect',
version: 'detect'
},
'import/resolver': {
typescript: true,
node: true,
},
node: true
}
},
rules: {
// React Hooks 严格检查
Expand All @@ -84,20 +84,20 @@ export default [
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],

// avoid hard failure on empty blocks
'no-empty': 'warn',
},
'no-empty': 'warn'
}
},

// Jest globals for test files
{
files: ['**/*.test.{js,jsx,ts,tsx}', '**/*.spec.{js,jsx,ts,tsx}'],
languageOptions: {
globals: {
...globals.jest,
},
},
...globals.jest
}
}
},

// Prettier 放在最后(Flat 兼容入口)
prettierConfig,
prettierConfig
]
32 changes: 16 additions & 16 deletions scripts/optimize-media.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const MP4_AUDIO_BITRATE = process.env.MP4_AUDIO_BITRATE || '128k'
const MIN_SAVINGS_PCT = Number(process.env.MEDIA_MIN_SAVINGS_PCT || '5')
const SKIP_SMALL_KB = Number(process.env.MEDIA_SKIP_SMALL_KB || '256')

function bytesToMiB(bytes) {
function bytesToMiB (bytes) {
return (bytes / 1024 / 1024).toFixed(2)
}

function runFfmpeg(args) {
function runFfmpeg (args) {
const result = spawnSync('ffmpeg', args, {
stdio: 'inherit',
windowsHide: true,
windowsHide: true
})
if (result.error) {
throw result.error
Expand All @@ -43,7 +43,7 @@ function runFfmpeg(args) {
}
}

function isFileExists(filePath) {
function isFileExists (filePath) {
try {
fsSync.accessSync(filePath)
return true
Expand All @@ -52,29 +52,29 @@ function isFileExists(filePath) {
}
}

async function ensureDir(dirPath) {
async function ensureDir (dirPath) {
await fs.mkdir(dirPath, { recursive: true })
}

async function cleanDir(dirPath) {
async function cleanDir (dirPath) {
await fs.rm(dirPath, { recursive: true, force: true })
await ensureDir(dirPath)
}

async function* walkFiles(dirPath) {
async function * walkFiles (dirPath) {
if (!isFileExists(dirPath)) return
const entries = await fs.readdir(dirPath, { withFileTypes: true })
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name)
if (entry.isDirectory()) {
yield* walkFiles(fullPath)
yield * walkFiles(fullPath)
} else if (entry.isFile()) {
yield fullPath
}
}
}

async function copyAll({ fromDir, toDir }) {
async function copyAll ({ fromDir, toDir }) {
if (!isFileExists(fromDir)) return { scanned: 0, copied: 0 }
await ensureDir(toDir)
let scanned = 0
Expand All @@ -90,7 +90,7 @@ async function copyAll({ fromDir, toDir }) {
return { scanned, copied }
}

async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
async function optimizeOne ({ inputPath, inputBaseDir, outputBaseDir }) {
const relPath = path.relative(inputBaseDir, inputPath)
const outputPath = path.join(outputBaseDir, relPath)

Expand Down Expand Up @@ -132,7 +132,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
MP3_BITRATE,
'-id3v2_version',
'3',
tmpPath,
tmpPath
])
} else {
// Re-encode MP4 (H.264 + AAC) and enable faststart
Expand All @@ -154,7 +154,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
MP4_AUDIO_BITRATE,
'-movflags',
'+faststart',
tmpPath,
tmpPath
])
}

Expand Down Expand Up @@ -188,12 +188,12 @@ if (SKIP_OPTIMIZE_MEDIA) {
process.exit(0)
}

function checkFfmpegAvailable() {
function checkFfmpegAvailable () {
const result = spawnSync('ffmpeg', ['-version'], { stdio: 'ignore', windowsHide: true })
return result.status === 0
}

async function main() {
async function main () {
if (!checkFfmpegAvailable()) {
console.error('[optimize:media] ffmpeg not found in PATH.')
console.error('Install ffmpeg and ensure `ffmpeg` is available in your terminal, then re-run.')
Expand All @@ -204,7 +204,7 @@ async function main() {
const targets = [
{ inputDir: SRC_AUDIO_DIR, outputDir: OUT_AUDIO_DIR },
{ inputDir: SRC_VIDEO_DIR, outputDir: OUT_VIDEO_DIR },
{ inputDir: SRC_PUBLIC_AUDIO_DIR, outputDir: OUT_PUBLIC_AUDIO_DIR },
{ inputDir: SRC_PUBLIC_AUDIO_DIR, outputDir: OUT_PUBLIC_AUDIO_DIR }
]

let changedCount = 0
Expand All @@ -225,7 +225,7 @@ async function main() {
const result = await optimizeOne({
inputPath,
inputBaseDir: target.inputDir,
outputBaseDir: target.outputDir,
outputBaseDir: target.outputDir
})
if (result.changed) {
changedCount += 1
Expand Down
6 changes: 3 additions & 3 deletions scripts/run-lighthouse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const fetchOk = async (url) => {
signal: controller.signal,
headers: {
// Some dev servers behave differently for default fetch UA.
'User-Agent': 'wui-react-lighthouse-probe',
},
'User-Agent': 'wui-react-lighthouse-probe'
}
})
if (!res.ok) return false
const text = await res.text()
Expand Down Expand Up @@ -107,7 +107,7 @@ const runLighthouse = (url) => {
const args = ['--view', url, '--preset=desktop']
const result = spawnSync('lighthouse', args, {
stdio: 'inherit',
shell: process.platform === 'win32',
shell: process.platform === 'win32'
})

process.exit(result.status ?? 1)
Expand Down
4 changes: 2 additions & 2 deletions scripts/run-sonar-scanner.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { spawnSync } = require('node:child_process')
const path = require('node:path')
const fs = require('node:fs')

function main() {
function main () {
const token = process.env.SONAR_TOKEN

if (!token) {
Expand Down Expand Up @@ -41,7 +41,7 @@ function main() {
const result = spawnSync(localScanner, args, {
stdio: 'inherit',
shell: false,
windowsHide: true,
windowsHide: true
})

process.exit(result.status ?? 1)
Expand Down
Loading
Loading