Skip to content
Merged
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
57 changes: 4 additions & 53 deletions _scripts/patchShaka.mjs
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
// This script fixes shaka not exporting its type definitions and referencing the Roboto font on google fonts in its CSS
// by adding an export line to the type definitions and updating the CSS to point to the local Roboto font
// This script fixes shaka-player referencing the Roboto font on google fonts in its CSS
// by updating the CSS to point to the local Roboto font
// this script only makes changes if they are needed, so running it multiple times doesn't cause any problems

import { appendFileSync, closeSync, ftruncateSync, openSync, readFileSync, writeSync } from 'fs'
import { closeSync, ftruncateSync, openSync, readFileSync, writeSync } from 'fs'
import { resolve } from 'path'

const SHAKA_DIST_DIR = resolve(import.meta.dirname, '../node_modules/shaka-player/dist')

function fixTypes() {
let fixedTypes = false

let fileHandleNormal
try {
fileHandleNormal = openSync(`${SHAKA_DIST_DIR}/shaka-player.ui.d.ts`, 'a+')

const contents = readFileSync(fileHandleNormal, 'utf-8')

// This script is run after every `yarn install`, even if shaka-player wasn't updated
// So we want to check first, if we actually need to make any changes
// or if the ones from the previous run are still intact
if (!contents.includes('export default shaka')) {
appendFileSync(fileHandleNormal, 'export default shaka;\n')

fixedTypes = true
}
} finally {
if (typeof fileHandleNormal !== 'undefined') {
closeSync(fileHandleNormal)
}
}

let fileHandleDebug
try {
fileHandleDebug = openSync(`${SHAKA_DIST_DIR}/shaka-player.ui.debug.d.ts`, 'a+')

const contents = readFileSync(fileHandleDebug, 'utf-8')

// This script is run after every `yarn install`, even if shaka-player wasn't updated
// So we want to check first, if we actually need to make any changes
// or if the ones from the previous run are still intact
if (!contents.includes('export default shaka')) {
appendFileSync(fileHandleDebug, 'export default shaka;\n')

fixedTypes = true
}
} finally {
if (typeof fileHandleDebug !== 'undefined') {
closeSync(fileHandleDebug)
}
}

if (fixedTypes) {
console.log('Fixed shaka-player types')
}
}

function removeRobotoFont() {
let cssFileHandle
try {
Expand All @@ -72,11 +24,10 @@ function removeRobotoFont() {
console.log('Removed shaka-player Roboto font, so it uses ours')
}
} finally {
if (typeof cssFileHandle !== 'undefined') {
if (cssFileHandle !== undefined) {
closeSync(cssFileHandle)
}
}
}

fixTypes()
removeRobotoFont()