1
- import { existsSync , PathLike , readdirSync , readFileSync } from 'fs' ;
1
+ import { existsSync , readdirSync , readFileSync , type PathLike } from 'fs' ;
2
2
import path , { basename , extname } from 'path' ;
3
3
import type {
4
4
AppConfig ,
@@ -13,7 +13,7 @@ import type {
13
13
import jsdom from 'jsdom' ;
14
14
import { convertMarkdownsToHTML } from './convertMarkdown' ;
15
15
import { splitVersion } from './stringUtils' ;
16
- import { Task , TaskOutput } from './Task' ;
16
+ import { Task , type TaskOutput } from './Task' ;
17
17
18
18
const fontFamilies : string [ ] = [ ] ;
19
19
@@ -26,13 +26,13 @@ function decodeFromXml(input: string): string {
26
26
. replace ( '&' , '&' ) ;
27
27
}
28
28
29
- function parseConfigValue ( value : any ) {
29
+ export function parseConfigValue ( value : any ) {
30
30
if ( ! value . includes ( ':' ) && ! isNaN ( parseInt ( value ) ) ) value = parseInt ( value ) ;
31
31
else if ( [ 'true' , 'false' ] . includes ( value ) ) value = value === 'true' ? true : false ;
32
32
// else {} // " " split array, string, enum or time
33
33
return value ;
34
34
}
35
- function parseAdditionalNames ( namesTag : Element , verbose : number ) {
35
+ export function parseAdditionalNames ( namesTag : Element , verbose : number ) {
36
36
const additionalNames = [ ] ;
37
37
const nameTags = namesTag ?. getElementsByTagName ( 'name' ) ;
38
38
for ( const tag of nameTags ) {
@@ -46,7 +46,7 @@ function parseAdditionalNames(namesTag: Element, verbose: number) {
46
46
}
47
47
return additionalNames ;
48
48
}
49
- function parseStyles ( stylesTag : Element , verbose : number ) {
49
+ export function parseStyles ( stylesTag : Element , verbose : number ) {
50
50
const styles = [ ] ;
51
51
const styleTags = stylesTag ?. getElementsByTagName ( 'style' ) ;
52
52
if ( ! styleTags ) throw new Error ( 'Styles tag not found in xml' ) ;
@@ -77,7 +77,7 @@ function parseStyles(stylesTag: Element, verbose: number) {
77
77
78
78
return styles ;
79
79
}
80
- function parseStylesInfo ( stylesInfoTag : Element , verbose : number ) : StyleConfig {
80
+ export function parseStylesInfo ( stylesInfoTag : Element , verbose : number ) : StyleConfig {
81
81
return {
82
82
font : stylesInfoTag . getElementsByTagName ( 'text-font' ) [ 0 ] . attributes . getNamedItem ( 'family' ) !
83
83
. value ,
@@ -101,7 +101,7 @@ function parseStylesInfo(stylesInfoTag: Element, verbose: number): StyleConfig {
101
101
} ;
102
102
}
103
103
104
- function parseTrait ( tag : Element , name : string ) : string {
104
+ export function parseTrait ( tag : Element , name : string ) : string {
105
105
const traitTags = tag . getElementsByTagName ( 'trait' ) ;
106
106
for ( const tag of traitTags ) {
107
107
if ( tag . attributes . getNamedItem ( 'name' ) ! . value === name ) {
@@ -161,7 +161,7 @@ function changeAndroidToRem(propValue: string) {
161
161
}
162
162
}
163
163
164
- function convertFooter ( markdown : string | undefined , appdef : Document ) : string | undefined {
164
+ export function convertFooter ( markdown : string | undefined , appdef : Document ) : string | undefined {
165
165
const footer = markdown ?. length ? convertMarkdownsToHTML ( removeCData ( markdown ) ) : undefined ;
166
166
const appName = appdef . getElementsByTagName ( 'app-name' ) [ 0 ] . innerHTML ;
167
167
const versionName = appdef . getElementsByTagName ( 'version' ) [ 0 ] . getAttribute ( 'name' ) ;
@@ -176,7 +176,7 @@ function convertFooter(markdown: string | undefined, appdef: Document): string |
176
176
?. replace ( / % p r o g r a m - v e r s i o n % / g, programVersion ?? '' ) ;
177
177
}
178
178
179
- function convertCollectionFooter ( collectionTag : Element , document : Document ) {
179
+ export function convertCollectionFooter ( collectionTag : Element , document : Document ) {
180
180
const footerTags = Array . from ( collectionTag . children ) . filter (
181
181
( child ) => child . tagName === 'footer'
182
182
) ;
@@ -360,7 +360,7 @@ function convertConfig(dataDir: string, verbose: number) {
360
360
return filterFeaturesNotReady ( data ) ;
361
361
}
362
362
363
- function parseFeatures ( document : Document , verbose : number ) {
363
+ export function parseFeatures ( document : Document , verbose : number ) {
364
364
const mainFeatureTags = document
365
365
. querySelector ( 'features[type=main]' )
366
366
?. getElementsByTagName ( 'e' ) ;
@@ -384,7 +384,7 @@ function parseFeatures(document: Document, verbose: number) {
384
384
return mainFeatures ;
385
385
}
386
386
387
- function parseFonts ( document : Document , verbose : number ) {
387
+ export function parseFonts ( document : Document , verbose : number ) {
388
388
const fontTags = document . getElementsByTagName ( 'fonts' ) [ 0 ] . getElementsByTagName ( 'font' ) ;
389
389
const fonts = [ ] ;
390
390
@@ -407,7 +407,7 @@ function parseFonts(document: Document, verbose: number) {
407
407
return fonts ;
408
408
}
409
409
410
- function parseColorThemes ( document : Document , verbose : number ) {
410
+ export function parseColorThemes ( document : Document , verbose : number ) {
411
411
const colorThemeTags = document
412
412
. getElementsByTagName ( 'color-themes' ) [ 0 ]
413
413
. getElementsByTagName ( 'color-theme' ) ;
@@ -468,7 +468,7 @@ function parseColorThemes(document: Document, verbose: number) {
468
468
return { themes, defaultTheme } ;
469
469
}
470
470
471
- function parseTraits ( document : Document , dataDir : string , verbose : number ) {
471
+ export function parseTraits ( document : Document , dataDir : string , verbose : number ) {
472
472
const traitTags = document . getElementsByTagName ( 'traits' ) [ 0 ] ?. getElementsByTagName ( 'trait' ) ;
473
473
const traits : { [ key : string ] : any } = { } ;
474
474
@@ -488,7 +488,7 @@ function parseTraits(document: Document, dataDir: string, verbose: number) {
488
488
return traits ;
489
489
}
490
490
491
- function parseBookCollections ( document : Document , verbose : number ) {
491
+ export function parseBookCollections ( document : Document , verbose : number ) {
492
492
const booksTags = document . getElementsByTagName ( 'books' ) ;
493
493
const bookCollections = [ ] ;
494
494
@@ -701,7 +701,7 @@ function parseBookCollections(document: Document, verbose: number) {
701
701
return bookCollections ;
702
702
}
703
703
704
- function parseInterfaceLanguages ( document : Document , data : AppConfig , verbose : number ) {
704
+ export function parseInterfaceLanguages ( document : Document , data : AppConfig , verbose : number ) {
705
705
const interfaceLanguagesTag = document . getElementsByTagName ( 'interface-languages' ) [ 0 ] ;
706
706
const useSystemLanguage = parseTrait ( interfaceLanguagesTag , 'use-system-language' ) === 'true' ;
707
707
const interfaceLanguages : {
@@ -729,7 +729,7 @@ function parseInterfaceLanguages(document: Document, data: AppConfig, verbose: n
729
729
return interfaceLanguages ;
730
730
}
731
731
732
- function parseWritingSystem ( element : Element , verbose : number ) : WritingSystemConfig {
732
+ export function parseWritingSystem ( element : Element , verbose : number ) : WritingSystemConfig {
733
733
const type = element . attributes . getNamedItem ( 'type' ) ! . value ;
734
734
const fontFamily = element . getElementsByTagName ( 'font-family' ) [ 0 ] . innerHTML ;
735
735
const textDirection = parseTrait ( element , 'text-direction' ) ;
@@ -747,7 +747,7 @@ function parseWritingSystem(element: Element, verbose: number): WritingSystemCon
747
747
748
748
return writingSystem ;
749
749
}
750
- function parseDictionaryWritingSystem (
750
+ export function parseDictionaryWritingSystem (
751
751
element : Element ,
752
752
verbose : number
753
753
) : DictionaryWritingSystemConfig {
@@ -799,7 +799,7 @@ function parseDictionaryWritingSystem(
799
799
} ;
800
800
}
801
801
802
- function parseMenuLocalizations ( document : Document , verbose : number ) {
802
+ export function parseMenuLocalizations ( document : Document , verbose : number ) {
803
803
const translationMappingsTags = document . getElementsByTagName ( 'translation-mappings' ) ;
804
804
let translationMappings : {
805
805
defaultLang : string ;
@@ -832,7 +832,7 @@ function parseMenuLocalizations(document: Document, verbose: number) {
832
832
return translationMappings ;
833
833
}
834
834
835
- function parseKeys ( document : Document , verbose : number ) {
835
+ export function parseKeys ( document : Document , verbose : number ) {
836
836
if ( document . getElementsByTagName ( 'keys' ) . length > 0 ) {
837
837
const keys = Array . from (
838
838
document . getElementsByTagName ( 'keys' ) [ 0 ] . getElementsByTagName ( 'key' )
@@ -844,7 +844,7 @@ function parseKeys(document: Document, verbose: number) {
844
844
return [ ] ;
845
845
}
846
846
847
- function parseAnalytics ( document : Document , verbose : number ) {
847
+ export function parseAnalytics ( document : Document , verbose : number ) {
848
848
const analyticsElements = document . getElementsByTagName ( 'analytics' ) ;
849
849
850
850
const analytics : { enabled : boolean ; providers : any [ ] } = {
@@ -893,7 +893,7 @@ function parseAnalytics(document: Document, verbose: number) {
893
893
return analytics ;
894
894
}
895
895
896
- function parseFirebase ( document : Document , verbose : number ) {
896
+ export function parseFirebase ( document : Document , verbose : number ) {
897
897
const firebaseElements = document . getElementsByTagName ( 'firebase' ) ;
898
898
let firebase : { features : { [ key : string ] : any } } = { features : { } } ;
899
899
@@ -920,7 +920,7 @@ function parseFirebase(document: Document, verbose: number) {
920
920
return firebase ;
921
921
}
922
922
923
- function parseAudioSources ( document : Document , verbose : number ) {
923
+ export function parseAudioSources ( document : Document , verbose : number ) {
924
924
const audioSources = document
925
925
. getElementsByTagName ( 'audio-sources' ) [ 0 ]
926
926
?. getElementsByTagName ( 'audio-source' ) ;
@@ -987,7 +987,7 @@ function parseAudioSources(document: Document, verbose: number) {
987
987
return { sources, files } ;
988
988
}
989
989
990
- function parseVideos ( document : Document , verbose : number ) {
990
+ export function parseVideos ( document : Document , verbose : number ) {
991
991
const videoTags = document . getElementsByTagName ( 'videos' ) [ 0 ] ?. getElementsByTagName ( 'video' ) ;
992
992
const videos : any [ ] = [ ] ;
993
993
if ( videoTags ?. length > 0 ) {
@@ -1030,7 +1030,7 @@ function parseVideos(document: Document, verbose: number) {
1030
1030
return videos ;
1031
1031
}
1032
1032
1033
- function parseIllustrations ( document : Document , verbose : number ) {
1033
+ export function parseIllustrations ( document : Document , verbose : number ) {
1034
1034
const imagesTags = document . getElementsByTagName ( 'images' ) ;
1035
1035
const illustrations : any [ ] = [ ] ;
1036
1036
if ( imagesTags ?. length > 0 ) {
@@ -1067,7 +1067,7 @@ function parseIllustrations(document: Document, verbose: number) {
1067
1067
return illustrations ;
1068
1068
}
1069
1069
1070
- function parseLayouts ( document : Document , bookCollections : any , verbose : number ) {
1070
+ export function parseLayouts ( document : Document , bookCollections : any , verbose : number ) {
1071
1071
const layoutRoot = document . getElementsByTagName ( 'layouts' ) [ 0 ] ;
1072
1072
let defaultLayout = layoutRoot ?. getAttribute ( 'default' ) ;
1073
1073
const layouts = [ ] ;
@@ -1109,7 +1109,7 @@ function parseLayouts(document: Document, bookCollections: any, verbose: number)
1109
1109
return { layouts, defaultLayout } ;
1110
1110
}
1111
1111
1112
- function parseBackgroundImages ( document : Document , verbose : number ) {
1112
+ export function parseBackgroundImages ( document : Document , verbose : number ) {
1113
1113
const backgroundImageTags = document
1114
1114
. querySelector ( 'images[type=background]' )
1115
1115
?. getElementsByTagName ( 'image' ) ;
@@ -1127,7 +1127,7 @@ function parseBackgroundImages(document: Document, verbose: number) {
1127
1127
return backgroundImages ;
1128
1128
}
1129
1129
1130
- function parseWatermarkImages ( document : Document , verbose : number ) {
1130
+ export function parseWatermarkImages ( document : Document , verbose : number ) {
1131
1131
const watermarkImageTags = document
1132
1132
. querySelector ( 'images[type=watermark]' )
1133
1133
?. getElementsByTagName ( 'image' ) ;
@@ -1145,7 +1145,7 @@ function parseWatermarkImages(document: Document, verbose: number) {
1145
1145
return watermarkImages ;
1146
1146
}
1147
1147
1148
- function parseMenuItems ( document : Document , type : string , verbose : number ) {
1148
+ export function parseMenuItems ( document : Document , type : string , verbose : number ) {
1149
1149
const firstMenuItemsByType = document . querySelector ( `menu-items[type="${ type } "]` ) ;
1150
1150
const menuItemTags = firstMenuItemsByType ?. getElementsByTagName ( 'menu-item' ) ;
1151
1151
const menuItems = [ ] ;
@@ -1208,7 +1208,7 @@ function parseMenuItems(document: Document, type: string, verbose: number) {
1208
1208
return menuItems ;
1209
1209
}
1210
1210
1211
- function parsePlans ( document : Document , verbose : number ) {
1211
+ export function parsePlans ( document : Document , verbose : number ) {
1212
1212
const features : { [ key : string ] : string } = { } ;
1213
1213
const plans : {
1214
1214
id : string ;
0 commit comments