From 974bbd1ee38d041eff69cbf6dc63cb3c210a647c Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 8 Nov 2023 10:38:35 +0700 Subject: [PATCH] fix(developer): kmc build ldml keyboard should create output folder Relates to #9948. --- .../src/commands/buildClasses/BuildLdmlKeyboard.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts b/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts index 1b0c2b22e5c..e12295c7873 100644 --- a/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts +++ b/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts @@ -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'; } @@ -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); }