@@ -9,11 +9,14 @@ import { KeymanFileTypes, CompilerCallbacks, KmpJsonFile, KmxFileReader, KMX, Ke
99import { KeyboardInfoCompilerMessages } from "./messages.js" ;
1010import langtags from "./imports/langtags.js" ;
1111import { validateMITLicense } from "./validate-mit-license.js" ;
12+ import { KmpCompiler } from "@keymanapp/kmc-package" ;
1213
1314const regionNames = new Intl . DisplayNames ( [ 'en' ] , { type : "region" } ) ;
1415const scriptNames = new Intl . DisplayNames ( [ 'en' ] , { type : "script" } ) ;
1516const langtagsByTag = { } ;
1617
18+ const HelpRoot = 'https://help.keyman.com/keyboard/' ;
19+
1720/**
1821 * Build a dictionary of language tags from langtags.json
1922 */
@@ -37,20 +40,11 @@ function init(): void {
3740}
3841
3942export interface KeyboardInfoSources {
40- /** The identifier for the keyboard */
41- keyboard_id : string ;
42-
43- /** The data from the .kps file, transformed to kmp.json */
44- kmpJsonData : KmpJsonFile . KmpJsonFile ;
45-
46- /** The path in the keymanapp/keyboards repo where this keyboard may be found (optional) */
47- sourcePath ?: string ;
48-
49- /** The full URL to the keyboard help, starting with https://help.keyman.com/keyboard/ (optional) */
50- helpLink ?: string ;
43+ /** The path in the keymanapp/keyboards repo where this keyboard may be found */
44+ sourcePath : string ;
5145
5246 /** The compiled keyboard filename and relative path (.js only) */
53- keyboardFilenameJs ?: string ;
47+ jsFilename ?: string ;
5448
5549 /** The compiled package filename and relative path (.kmp) */
5650 kmpFilename : string ;
@@ -78,7 +72,16 @@ export class KeyboardInfoCompiler {
7872 sources : KeyboardInfoSources
7973 ) : Uint8Array {
8074
81- // TODO: work from .kpj and nothing else as input
75+ // TODO(lowpri): work from .kpj and nothing else as input. Blocked because
76+ // .kpj work is largely in kmc at present, so that would need to move to
77+ // a separate module.
78+
79+ const kmpCompiler = new KmpCompiler ( this . callbacks ) ;
80+ const kmpJsonData = kmpCompiler . transformKpsToKmpObject ( sources . kpsFilename ) ;
81+ if ( ! kmpJsonData ) {
82+ // Errors will have been emitted by KmpCompiler
83+ return null ;
84+ }
8285
8386 if ( ! sources . kmpFilename ) {
8487 // We can't build any metadata without a .kmp file
@@ -90,8 +93,8 @@ export class KeyboardInfoCompiler {
9093
9194 let jsFile : string = null ;
9295
93- if ( sources . keyboardFilenameJs ) {
94- jsFile = this . loadJsFile ( sources . keyboardFilenameJs ) ;
96+ if ( sources . jsFilename ) {
97+ jsFile = this . loadJsFile ( sources . jsFilename ) ;
9598 if ( ! jsFile ) {
9699 return null ;
97100 }
@@ -100,7 +103,7 @@ export class KeyboardInfoCompiler {
100103 const kmxFiles : {
101104 filename : string ,
102105 data : KMX . KEYBOARD
103- } [ ] = this . loadKmxFiles ( sources . kpsFilename , sources . kmpJsonData ) ;
106+ } [ ] = this . loadKmxFiles ( sources . kpsFilename , kmpJsonData ) ;
104107
105108 //
106109 // Build .keyboard_info file
@@ -109,16 +112,16 @@ export class KeyboardInfoCompiler {
109112 //
110113
111114 keyboard_info . id = this . callbacks . path . basename ( sources . kmpFilename , '.kmp' ) ;
112- keyboard_info . name = sources . kmpJsonData . info . name . description ;
115+ keyboard_info . name = kmpJsonData . info . name . description ;
113116
114117 // License
115118
116- if ( ! sources . kmpJsonData . options ?. licenseFile ) {
119+ if ( ! kmpJsonData . options ?. licenseFile ) {
117120 this . callbacks . reportMessage ( KeyboardInfoCompilerMessages . Error_NoLicenseFound ( ) ) ;
118121 return null ;
119122 }
120123
121- if ( ! this . isLicenseMIT ( this . callbacks . resolveFilename ( sources . kpsFilename , sources . kmpJsonData . options . licenseFile ) ) ) {
124+ if ( ! this . isLicenseMIT ( this . callbacks . resolveFilename ( sources . kpsFilename , kmpJsonData . options . licenseFile ) ) ) {
122125 return null ;
123126 }
124127
@@ -132,7 +135,7 @@ export class KeyboardInfoCompiler {
132135
133136 // author
134137
135- const author = sources . kmpJsonData . info . author ;
138+ const author = kmpJsonData . info . author ;
136139 if ( author ?. description || author ?. url ) {
137140 keyboard_info . authorName = author . description ;
138141
@@ -151,15 +154,15 @@ export class KeyboardInfoCompiler {
151154
152155 // description
153156
154- if ( sources . kmpJsonData . info . description ?. description ) {
155- keyboard_info . description = sources . kmpJsonData . info . description ?. description . trim ( ) ;
157+ if ( kmpJsonData . info . description ?. description ) {
158+ keyboard_info . description = kmpJsonData . info . description ?. description . trim ( ) ;
156159 }
157160
158161 // extract the language identifiers from the language metadata arrays for
159162 // each of the keyboards in the kmp.json file, and merge into a single array
160163 // of identifiers in the .keyboard_info file.
161164
162- this . fillLanguages ( keyboard_info , sources . kmpJsonData ) ;
165+ this . fillLanguages ( keyboard_info , kmpJsonData ) ;
163166
164167 // TODO: use: TZ=UTC0 git log -1 --no-merges --date=format:%Y-%m-%dT%H:%M:%SZ --format=%ad
165168 keyboard_info . lastModifiedDate = ( new Date ) . toISOString ( ) ;
@@ -173,19 +176,19 @@ export class KeyboardInfoCompiler {
173176 return null ;
174177 }
175178
176- if ( sources . keyboardFilenameJs ) {
177- keyboard_info . jsFilename = this . callbacks . path . basename ( sources . keyboardFilenameJs ) ;
179+ if ( sources . jsFilename ) {
180+ keyboard_info . jsFilename = this . callbacks . path . basename ( sources . jsFilename ) ;
178181 // Always overwrite with actual file size
179- keyboard_info . jsFileSize = this . callbacks . fileSize ( sources . keyboardFilenameJs ) ;
182+ keyboard_info . jsFileSize = this . callbacks . fileSize ( sources . jsFilename ) ;
180183 if ( keyboard_info . jsFileSize === undefined ) {
181- this . callbacks . reportMessage ( KeyboardInfoCompilerMessages . Error_FileDoesNotExist ( { filename :sources . keyboardFilenameJs } ) ) ;
184+ this . callbacks . reportMessage ( KeyboardInfoCompilerMessages . Error_FileDoesNotExist ( { filename :sources . jsFilename } ) ) ;
182185 return null ;
183186 }
184187 }
185188
186189 const includes = new Set < KeyboardInfoFileIncludes > ( ) ;
187190 keyboard_info . packageIncludes = [ ] ;
188- for ( const file of sources . kmpJsonData . files ) {
191+ for ( const file of kmpJsonData . files ) {
189192 if ( file . name . match ( / \. ( o t f | t t f | t t c ) $ / ) ) {
190193 includes . add ( 'fonts' ) ;
191194 } else if ( file . name . match ( / w e l c o m e \. h t m $ / ) ) {
@@ -198,7 +201,7 @@ export class KeyboardInfoCompiler {
198201 }
199202 keyboard_info . packageIncludes = [ ...includes ] ;
200203
201- keyboard_info . version = sources . kmpJsonData . info . version . description ;
204+ keyboard_info . version = kmpJsonData . info . version . description ;
202205
203206 let minVersion = minKeymanVersion ;
204207 const m = jsFile ?. match ( / t h i s .K M I N V E R \s * = \s * ( [ ' " ] ) ( .* ?) \1/ ) ;
@@ -235,7 +238,7 @@ export class KeyboardInfoCompiler {
235238 // and if the .js is in the package, that it is mobile native as well,
236239 // because the targets metadata is not available in the .js.
237240 platforms . add ( 'mobileWeb' ) . add ( 'desktopWeb' ) ;
238- if ( sources . kmpJsonData . files . find ( file => file . name . match ( / \. j s $ / ) ) ) {
241+ if ( kmpJsonData . files . find ( file => file . name . match ( / \. j s $ / ) ) ) {
239242 platforms . add ( 'android' ) . add ( 'ios' ) ;
240243 }
241244 }
@@ -262,15 +265,12 @@ export class KeyboardInfoCompiler {
262265
263266 keyboard_info . minKeymanVersion = minVersion ;
264267 keyboard_info . sourcePath = sources . sourcePath ;
265-
266- if ( sources . helpLink ) {
267- keyboard_info . helpLink = sources . helpLink ;
268- }
268+ keyboard_info . helpLink = HelpRoot + keyboard_info . id ;
269269
270270 // Related packages
271- if ( sources . kmpJsonData . relatedPackages ?. length ) {
271+ if ( kmpJsonData . relatedPackages ?. length ) {
272272 keyboard_info . related = { } ;
273- for ( const p of sources . kmpJsonData . relatedPackages ) {
273+ for ( const p of kmpJsonData . relatedPackages ) {
274274 keyboard_info . related [ p . id ] = {
275275 deprecates : p . relationship == 'deprecates'
276276 } ;
0 commit comments