import { join , dirname } from 'path' ; import { readdir } from 'fs/promises' ; import { Dirent } from 'fs' ; const ALLOWED_VERSIONED_DIRNAME_LENGTH = [ 2 , 3 ] ; function isVersionedDirname ( dirent ) { if ( ! dirent . isDirectory ( ) ) return false ; return ( ALLOWED_VERSIONED_DIRNAME_LENGTH . includes ( dirent . name . length ) && dirent . name . toLowerCase ( ) . startsWith ( 'v' ) ) ; } async function getMaxVersion ( from ) { const entries = await readdir ( from , { withFileTypes : true } ) ; const dirnames = entries . reduce < string [ ] > ( ( acc , cur ) => { if ( isVersionedDirname ( cur ) ) acc . push ( cur . name ) ; return acc ; } , [ ] ) ; if ( ! dirnames . length ) return null ; return Math . max ( ... dirnames . map ( ( d ) => parseInt ( d . charAt ( 1 ) , 10 ) ) ) ; } /**
 * Get the full path to a node translation file in `/dist`.
 */ export async function getNodeTranslationPath ( { nodeSourcePath , longNodeType , locale , } ) { const nodeDir = dirname ( nodeSourcePath ) ; const maxVersion = await getMaxVersion ( nodeDir ) ; const nodeType = longNodeType . replace ( 'n8n-nodes-base.' , '' ) ; return maxVersion ? join ( nodeDir , `v${ maxVersion }` , 'translations' , locale , `${ nodeType }.json` ) : join ( nodeDir , 'translations' , locale , `${ nodeType }.json` ) ; } /**
 * Get the full path to a credential translation file in `/dist`.
 */ export function getCredentialTranslationPath ( { locale , credentialType , } ) { const packagesPath = join ( __dirname , '..' , '..' , '..' ) ; const credsPath = join ( packagesPath , 'nodes-base' , 'dist' , 'credentials' ) ; return join ( credsPath , 'translations' , locale , `${ credentialType }.json` ) ; }