11//
2- // Version 1.0 of Keyman Developer Project .kpj file
2+ // Version 1.0 and 2.0 of Keyman Developer Project .kpj file
33//
44
55import { KeymanFileTypes } from '../main.js' ;
@@ -9,11 +9,17 @@ export class KeymanDeveloperProject {
99 options : KeymanDeveloperProjectOptions ;
1010 files : KeymanDeveloperProjectFile [ ] ;
1111 projectPath : string = '' ;
12+ readonly projectFile : KeymanDeveloperProjectFile ;
1213
13- constructor ( private projectFilename : string , version : KeymanDeveloperProjectVersion , private callbacks : CompilerCallbacks ) {
14- this . projectPath = this . callbacks . path . dirname ( this . projectFilename ) ;
14+ get projectFilename ( ) {
15+ return this . _projectFilename ;
16+ }
17+
18+ constructor ( private _projectFilename : string , version : KeymanDeveloperProjectVersion , private callbacks : CompilerCallbacks ) {
19+ this . projectPath = this . callbacks . path . dirname ( this . _projectFilename ) ;
1520 this . options = new KeymanDeveloperProjectOptions ( version ) ;
1621 this . files = [ ] ;
22+ this . projectFile = new KeymanDeveloperProjectFile20 ( _projectFilename , callbacks ) ;
1723 }
1824 /**
1925 * Adds .kmn, .xml, .kps to project based on options.sourcePath
@@ -38,8 +44,6 @@ export class KeymanDeveloperProject {
3844 this . files . push ( file ) ;
3945 }
4046 }
41-
42- this . addMetadataFile ( ) ;
4347 }
4448
4549 public isKeyboardProject ( ) {
@@ -50,26 +54,32 @@ export class KeymanDeveloperProject {
5054 return ! ! this . files . find ( file => file . fileType == KeymanFileTypes . Source . Model ) ;
5155 }
5256
53- public addMetadataFile ( ) {
54- const ext = this . isLexicalModelProject ( ) ? KeymanFileTypes . Source . ModelInfo : KeymanFileTypes . Source . KeyboardInfo ;
57+ private resolveProjectPath ( p : string ) : string {
58+ // Replace placeholders in the target path
59+ return p . replace ( '$PROJECTPATH' , this . projectPath ) ;
60+ }
61+
62+ getOutputFilePath ( type : KeymanFileTypes . Binary ) {
63+ // Roughly corresponds to Delphi TProject.GetTargetFileName
64+ let p = this . options . version == '1.0' ?
65+ this . options . buildPath || '$SOURCEPATH' :
66+ this . options . buildPath ;
5567
56- if ( this . files . find ( file => KeymanFileTypes . filenameIs ( file . filename , ext ) ) ) {
57- return ;
68+ // Replace placeholders in the target path
69+ if ( this . options . version == '1.0' ) {
70+ // TODO: do we need to support $VERSION?
71+ // $SOURCEPATH only supported in 1.0 projects
72+ p = p . replace ( '$SOURCEPATH' , this . callbacks . path . dirname ( this . _projectFilename ) ) ;
5873 }
5974
60- const infoFile =
61- this . callbacks . path . join ( this . projectPath ,
62- this . callbacks . path . basename ( this . projectFilename , KeymanFileTypes . Source . Project ) + ext ) ;
63- this . files . push ( new KeymanDeveloperProjectFile20 ( infoFile , this . callbacks ) ) ;
64- }
75+ p = this . resolveProjectPath ( p ) ;
6576
66- private resolveProjectPath ( p : string ) : string {
67- // Replace placeholders in the target path
68- return p . replace ( '$PROJECTPATH' , this . projectPath ) ;
77+ const f = this . callbacks . path . basename ( this . _projectFilename , KeymanFileTypes . Source . Project ) + type ;
78+ return this . callbacks . path . normalize ( this . callbacks . path . join ( p , f ) ) ;
6979 }
7080
7181 resolveInputFilePath ( file : KeymanDeveloperProjectFile ) : string {
72- return this . callbacks . resolveFilename ( this . projectFilename , file . filePath ) ;
82+ return this . callbacks . resolveFilename ( this . _projectFilename , file . filePath ) ;
7383 }
7484
7585 resolveOutputFilePath ( file : KeymanDeveloperProjectFile , sourceExt : string , targetExt : string ) : string {
0 commit comments