Skip to content

Commit

Permalink
fix(developer): kmc build ldml keyboard should create output folder
Browse files Browse the repository at this point in the history
Relates to #9948.
  • Loading branch information
mcdurdin committed Nov 8, 2023
1 parent 5e9056f commit 974bbd1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as kmcLdml from '@keymanapp/kmc-ldml';
import { KvkFileWriter, CompilerCallbacks, LDMLKeyboardXMLSourceFileReader, CompilerOptions, defaultCompilerOptions, KeymanFileTypes } from '@keymanapp/common-types';
import { BuildActivity } from './BuildActivity.js';
import { fileURLToPath } from 'url';
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';

export class BuildLdmlKeyboard extends BuildActivity {
public get name(): string { return 'LDML keyboard'; }
Expand All @@ -20,21 +21,32 @@ export class BuildLdmlKeyboard extends BuildActivity {
const outFileBase = path.basename(fileBaseName, path.extname(fileBaseName));
const outFileDir = path.dirname(fileBaseName);

try {
fs.mkdirSync(outFileDir, {recursive: true});
} catch(e) {
callbacks.reportMessage(InfrastructureMessages.Error_CannotCreateFolder({folderName:outFileDir, e}));
return false;
}

if(kmx && kvk) {
const outFileKmx = path.join(outFileDir, outFileBase + KeymanFileTypes.Binary.Keyboard);
// TODO: console needs to be replaced with InfrastructureMessages
console.log(`Writing compiled keyboard to ${outFileKmx}`);
fs.writeFileSync(outFileKmx, kmx);

const outFileKvk = path.join(outFileDir, outFileBase + KeymanFileTypes.Binary.VisualKeyboard);
// TODO: console needs to be replaced with InfrastructureMessages
console.log(`Writing compiled visual keyboard to ${outFileKvk}`);
fs.writeFileSync(outFileKvk, kvk);
} else {
// TODO: console needs to be replaced with InfrastructureMessages
console.error(`An error occurred compiling ${infile}`);
return false;
}

if(kmw) {
const outFileKmw = path.join(outFileDir, outFileBase + KeymanFileTypes.Binary.WebKeyboard);
// TODO: console needs to be replaced with InfrastructureMessages
console.log(`Writing compiled js keyboard to ${outFileKmw}`);
fs.writeFileSync(outFileKmw, kmw);
}
Expand Down

0 comments on commit 974bbd1

Please sign in to comment.