@@ -13,21 +13,12 @@ import {
1313 AACSemanticCategory ,
1414 AACSemanticIntent ,
1515} from '../core/treeStructure' ;
16- // Removed unused import: FileProcessor
1716import plist , { PlistValue } from 'plist' ;
1817import {
1918 ValidationFailureError ,
2019 buildValidationResultFromMessage ,
2120} from '../validation/validationTypes' ;
22- import {
23- ProcessorInput ,
24- getBasename ,
25- getFs ,
26- getPath ,
27- readBinaryFromInput ,
28- readTextFromInput ,
29- writeTextToPath ,
30- } from '../utils/io' ;
21+ import { ProcessorInput , getBasename } from '../utils/io' ;
3122
3223interface ApplePanelsActionParameters {
3324 CharString ?: string ;
@@ -227,24 +218,24 @@ class ApplePanelsProcessor extends BaseProcessor {
227218 }
228219
229220 async loadIntoTree ( filePathOrBuffer : ProcessorInput ) : Promise < AACTree > {
221+ const { readBinaryFromInput, readTextFromInput, pathExists, getFileSize, join } =
222+ this . options . fileAdapter ;
230223 await Promise . resolve ( ) ;
231224 const filename =
232225 typeof filePathOrBuffer === 'string' ? getBasename ( filePathOrBuffer ) : 'upload.plist' ;
233226 let buffer : Uint8Array ;
234227
235228 try {
236229 if ( typeof filePathOrBuffer === 'string' ) {
237- const fs = getFs ( ) ;
238- const path = getPath ( ) ;
239230 if ( filePathOrBuffer . endsWith ( '.ascconfig' ) ) {
240- const panelDefsPath = path . join (
231+ const panelDefsPath = join (
241232 filePathOrBuffer ,
242233 'Contents' ,
243234 'Resources' ,
244235 'PanelDefinitions.plist'
245236 ) ;
246- if ( fs . existsSync ( panelDefsPath ) ) {
247- buffer = fs . readFileSync ( panelDefsPath ) ;
237+ if ( pathExists ( panelDefsPath ) ) {
238+ buffer = readBinaryFromInput ( panelDefsPath ) ;
248239 } else {
249240 const validation = buildValidationResultFromMessage ( {
250241 filename,
@@ -257,7 +248,7 @@ class ApplePanelsProcessor extends BaseProcessor {
257248 throw new ValidationFailureError ( 'Apple Panels file not found' , validation ) ;
258249 }
259250 } else {
260- buffer = fs . readFileSync ( filePathOrBuffer ) ;
251+ buffer = readBinaryFromInput ( filePathOrBuffer ) ;
261252 }
262253 } else {
263254 buffer = readBinaryFromInput ( filePathOrBuffer ) ;
@@ -403,8 +394,7 @@ class ApplePanelsProcessor extends BaseProcessor {
403394 filesize :
404395 typeof filePathOrBuffer === 'string'
405396 ? ( ( ) => {
406- const fs = getFs ( ) ;
407- return fs . existsSync ( filePathOrBuffer ) ? fs . statSync ( filePathOrBuffer ) . size : 0 ;
397+ return pathExists ( filePathOrBuffer ) ? getFileSize ( filePathOrBuffer ) : 0 ;
408398 } ) ( )
409399 : readBinaryFromInput ( filePathOrBuffer ) . byteLength ,
410400 format : 'applepanels' ,
@@ -421,6 +411,7 @@ class ApplePanelsProcessor extends BaseProcessor {
421411 translations : Map < string , string > ,
422412 outputPath : string
423413 ) : Promise < Uint8Array > {
414+ const { readBinaryFromInput, join } = this . options . fileAdapter ;
424415 // Load the tree, apply translations, and save to new file
425416 const tree = await this . loadIntoTree ( filePathOrBuffer ) ;
426417
@@ -477,13 +468,13 @@ class ApplePanelsProcessor extends BaseProcessor {
477468 if ( outputPath . endsWith ( '.plist' ) ) {
478469 return readBinaryFromInput ( outputPath ) ;
479470 }
480- const path = getPath ( ) ;
481471 const configPath = outputPath . endsWith ( '.ascconfig' ) ? outputPath : `${ outputPath } .ascconfig` ;
482- const panelDefsPath = path . join ( configPath , 'Contents' , 'Resources' , 'PanelDefinitions.plist' ) ;
472+ const panelDefsPath = join ( configPath , 'Contents' , 'Resources' , 'PanelDefinitions.plist' ) ;
483473 return readBinaryFromInput ( panelDefsPath ) ;
484474 }
485475
486476 async saveFromTree ( tree : AACTree , outputPath : string ) : Promise < void > {
477+ const { writeTextToPath, pathExists, mkDir, join, dirname } = this . options . fileAdapter ;
487478 await Promise . resolve ( ) ;
488479 // Support two output modes:
489480 // 1) Single-file .plist (PanelDefinitions.plist content written directly)
@@ -495,15 +486,13 @@ class ApplePanelsProcessor extends BaseProcessor {
495486 let contentsPath = '' ;
496487 let resourcesPath = '' ;
497488 if ( ! isSinglePlist ) {
498- const fs = getFs ( ) ;
499- const path = getPath ( ) ;
500489 configPath = outputPath . endsWith ( '.ascconfig' ) ? outputPath : `${ outputPath } .ascconfig` ;
501- contentsPath = path . join ( configPath , 'Contents' ) ;
502- resourcesPath = path . join ( contentsPath , 'Resources' ) ;
490+ contentsPath = join ( configPath , 'Contents' ) ;
491+ resourcesPath = join ( contentsPath , 'Resources' ) ;
503492
504- if ( ! fs . existsSync ( configPath ) ) fs . mkdirSync ( configPath , { recursive : true } ) ;
505- if ( ! fs . existsSync ( contentsPath ) ) fs . mkdirSync ( contentsPath , { recursive : true } ) ;
506- if ( ! fs . existsSync ( resourcesPath ) ) fs . mkdirSync ( resourcesPath , { recursive : true } ) ;
493+ if ( ! pathExists ( configPath ) ) mkDir ( configPath , { recursive : true } ) ;
494+ if ( ! pathExists ( contentsPath ) ) mkDir ( contentsPath , { recursive : true } ) ;
495+ if ( ! pathExists ( resourcesPath ) ) mkDir ( resourcesPath , { recursive : true } ) ;
507496
508497 // Create Info.plist (bundle mode only)
509498 const infoPlist = {
@@ -521,11 +510,11 @@ class ApplePanelsProcessor extends BaseProcessor {
521510 `Generated by AAC Processors${ tree . metadata ?. author ? ` - Author: ${ tree . metadata . author } ` : '' } ` ,
522511 } ;
523512 const infoPlistContent = plist . build ( infoPlist ) ;
524- writeTextToPath ( path . join ( contentsPath , 'Info.plist' ) , infoPlistContent ) ;
513+ writeTextToPath ( join ( contentsPath , 'Info.plist' ) , infoPlistContent ) ;
525514
526515 // Create AssetIndex.plist (empty)
527516 const assetIndexContent = plist . build ( { } ) ;
528- writeTextToPath ( path . join ( resourcesPath , 'AssetIndex.plist' ) , assetIndexContent ) ;
517+ writeTextToPath ( join ( resourcesPath , 'AssetIndex.plist' ) , assetIndexContent ) ;
529518 }
530519
531520 // Build PanelDefinitions content from tree
@@ -666,15 +655,12 @@ class ApplePanelsProcessor extends BaseProcessor {
666655
667656 if ( isSinglePlist ) {
668657 // Write single PanelDefinitions.plist file directly
669- const fs = getFs ( ) ;
670- const path = getPath ( ) ;
671- const dir = path . dirname ( outputPath ) ;
672- if ( ! fs . existsSync ( dir ) ) fs . mkdirSync ( dir , { recursive : true } ) ;
658+ const dir = dirname ( outputPath ) ;
659+ if ( ! pathExists ( dir ) ) mkDir ( dir , { recursive : true } ) ;
673660 writeTextToPath ( outputPath , panelDefsContent ) ;
674661 } else {
675662 // Write into bundle structure
676- const path = getPath ( ) ;
677- writeTextToPath ( path . join ( resourcesPath , 'PanelDefinitions.plist' ) , panelDefsContent ) ;
663+ writeTextToPath ( join ( resourcesPath , 'PanelDefinitions.plist' ) , panelDefsContent ) ;
678664 }
679665 }
680666
0 commit comments