1- // This script fixes shaka not exporting its type definitions and referencing the Roboto font on google fonts in its CSS
2- // by adding an export line to the type definitions and updating the CSS to point to the local Roboto font
1+ // This script fixes shaka-player referencing the Roboto font on google fonts in its CSS
2+ // by updating the CSS to point to the local Roboto font
33// this script only makes changes if they are needed, so running it multiple times doesn't cause any problems
44
5- import { appendFileSync , closeSync , ftruncateSync , openSync , readFileSync , writeSync } from 'fs'
5+ import { closeSync , ftruncateSync , openSync , readFileSync , writeSync } from 'fs'
66import { resolve } from 'path'
77
88const SHAKA_DIST_DIR = resolve ( import . meta. dirname , '../node_modules/shaka-player/dist' )
99
10- function fixTypes ( ) {
11- let fixedTypes = false
12-
13- let fileHandleNormal
14- try {
15- fileHandleNormal = openSync ( `${ SHAKA_DIST_DIR } /shaka-player.ui.d.ts` , 'a+' )
16-
17- const contents = readFileSync ( fileHandleNormal , 'utf-8' )
18-
19- // This script is run after every `yarn install`, even if shaka-player wasn't updated
20- // So we want to check first, if we actually need to make any changes
21- // or if the ones from the previous run are still intact
22- if ( ! contents . includes ( 'export default shaka' ) ) {
23- appendFileSync ( fileHandleNormal , 'export default shaka;\n' )
24-
25- fixedTypes = true
26- }
27- } finally {
28- if ( typeof fileHandleNormal !== 'undefined' ) {
29- closeSync ( fileHandleNormal )
30- }
31- }
32-
33- let fileHandleDebug
34- try {
35- fileHandleDebug = openSync ( `${ SHAKA_DIST_DIR } /shaka-player.ui.debug.d.ts` , 'a+' )
36-
37- const contents = readFileSync ( fileHandleDebug , 'utf-8' )
38-
39- // This script is run after every `yarn install`, even if shaka-player wasn't updated
40- // So we want to check first, if we actually need to make any changes
41- // or if the ones from the previous run are still intact
42- if ( ! contents . includes ( 'export default shaka' ) ) {
43- appendFileSync ( fileHandleDebug , 'export default shaka;\n' )
44-
45- fixedTypes = true
46- }
47- } finally {
48- if ( typeof fileHandleDebug !== 'undefined' ) {
49- closeSync ( fileHandleDebug )
50- }
51- }
52-
53- if ( fixedTypes ) {
54- console . log ( 'Fixed shaka-player types' )
55- }
56- }
57-
5810function removeRobotoFont ( ) {
5911 let cssFileHandle
6012 try {
@@ -72,11 +24,10 @@ function removeRobotoFont() {
7224 console . log ( 'Removed shaka-player Roboto font, so it uses ours' )
7325 }
7426 } finally {
75- if ( typeof cssFileHandle !== ' undefined' ) {
27+ if ( cssFileHandle !== undefined ) {
7628 closeSync ( cssFileHandle )
7729 }
7830 }
7931}
8032
81- fixTypes ( )
8233removeRobotoFont ( )
0 commit comments