diff --git a/gulpfile.js b/gulpfile.js index 3619962289..9bf44231f8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,6 +21,10 @@ const resourceSyncGlobs = [ const outputFilePath = path.join(outputPath, '**') const rawCopySrc = (globs, options = {}) => gulp.src(globs, { encoding: false, ...options }) +const removeWoff2FontSources = (cssText) => + cssText. + replace(/@font-face\s*{[^{}]*url\(["']?web\/Inter-[^{}]*?\.woff2[^{}]*}\s*/g, ''). + replace(/url\((["']?)[^)"']+?\.woff2(?:\?[^)"']*)?\1\)\s*format\((["'])woff2\2\),?/g, '') const staticCleanKeep = new Set([ 'entitlements.plist', 'node_modules', @@ -53,6 +57,7 @@ const css = { buildMobileCSS (...params) { return gulp.series( () => exec(`pnpm css:mobile-build`, {}), + css._removeUnsupportedIOSFonts, )(...params) }, @@ -60,6 +65,19 @@ const css = { return gulp.src(path.join(outputPath, 'css', 'style.css')). pipe(gulp.dest(path.join(outputPath, 'css'))) }, + + _removeUnsupportedIOSFonts () { + const mobileCssPath = path.join(mobilePath, 'css') + for (const file of ['inter.css', 'style.css']) { + const filePath = path.join(mobileCssPath, file) + if (fs.existsSync(filePath)) { + fs.writeFileSync( + filePath, + removeWoff2FontSources(fs.readFileSync(filePath, 'utf8'))) + } + } + return Promise.resolve() + }, } const common = { @@ -151,10 +169,9 @@ const common = { () => rawCopySrc([ 'node_modules/inter-ui/inter.css', ]).pipe(gulp.dest(path.join(outputPath, 'mobile', 'css'))), - () => rawCopySrc('node_modules/inter-ui/web/*.*'). - pipe(gulp.dest(path.join(outputPath, 'mobile', 'css', 'web'))), () => rawCopySrc([ - 'node_modules/katex/dist/fonts/*.woff2', + 'node_modules/katex/dist/fonts/*.woff', + 'node_modules/katex/dist/fonts/*.ttf', ]).pipe(gulp.dest(path.join(outputPath, 'mobile', 'css', 'fonts'))), )(...params) }, diff --git a/package.json b/package.json index 45f3a0a400..e100ae8f38 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "sync-ios-release": "pnpm clean && pnpm release-mobile && rm -rf ./static/mobile/**/*.map && pnpm exec cap sync ios", "clean": "gulp clean", "test": "run-s cljs:test cljs:run-test", + "test:ios-web-fonts": "node ./scripts/check-ios-web-fonts.mjs", "test:node-adapter": "pnpm --dir deps/db-sync run test:node-adapter", "report": "run-s cljs:report", "style:lint": "stylelint \"src/**/*.css\"", @@ -227,4 +228,4 @@ "keytar" ] } -} \ No newline at end of file +} diff --git a/scripts/check-ios-web-fonts.mjs b/scripts/check-ios-web-fonts.mjs new file mode 100644 index 0000000000..a27b3ffa0c --- /dev/null +++ b/scripts/check-ios-web-fonts.mjs @@ -0,0 +1,52 @@ +import fs from 'node:fs' +import path from 'node:path' + +const repoRoot = path.resolve(import.meta.dirname, '..') +const assetRoots = [ + path.join(repoRoot, 'static', 'mobile'), + path.join(repoRoot, 'ios', 'App', 'App', 'public'), +] + +const existingAssetRoots = assetRoots.filter((root) => fs.existsSync(root)) + +if (existingAssetRoots.length === 0) { + throw new Error('No iOS web assets found. Run pnpm release-mobile or pnpm sync-ios-release first.') +} + +const walk = (dir) => { + const entries = fs.readdirSync(dir, { withFileTypes: true }) + return entries.flatMap((entry) => { + const fullPath = path.join(dir, entry.name) + return entry.isDirectory() ? walk(fullPath) : fullPath + }) +} + +const relativePath = (filePath) => path.relative(repoRoot, filePath) +const files = existingAssetRoots.flatMap(walk) +const woff2Files = files + .filter((filePath) => filePath.endsWith('.woff2')) + .map(relativePath) + .sort() +const cssWoff2References = files + .filter((filePath) => filePath.endsWith('.css')) + .flatMap((filePath) => { + const css = fs.readFileSync(filePath, 'utf8') + return css.includes('.woff2') ? [relativePath(filePath)] : [] + }) + .sort() + +if (woff2Files.length > 0) { + console.error('iOS web assets must not include .woff2 font files:') + for (const filePath of woff2Files) { + console.error(`- ${filePath}`) + } + process.exit(1) +} + +if (cssWoff2References.length > 0) { + console.error('iOS web CSS must not reference .woff2 font files:') + for (const filePath of cssWoff2References) { + console.error(`- ${filePath}`) + } + process.exit(1) +}