Skip to content

Commit

Permalink
fix: Update getSuffix to properly work in pipeline (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksentak authored Aug 26, 2024
1 parent 51de8d9 commit 16b4e6e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,33 @@ function generateMethods(json = {}, examples = {}, templates = {}, languages = [
event: isEventMethod(methodObj)
}

const suffix = state.destination && config.templateExtensionMap ? state.destination.split(state.destination.includes('_') ? '_' : '.').pop() : ''

/**
* Extracts the suffix from a given file path.
*
* The suffix is determined by the last underscore or period in the filename.
* If the filename contains an underscore, the portion after the last underscore
* is considered the suffix. If no underscore is found but there is a period,
* the portion after the last period (typically the file extension) is considered the suffix.
* If neither an underscore nor a period is found, an empty string is returned.
*
* @param {string} path - The full file path from which to extract the suffix.
* @returns {string} - The extracted suffix or an empty string if no suffix is found.
*/
const getSuffix = (path) => {
// Extract the last part of the path (the filename)
const filename = path.split('/').pop() // Get the last part of the path
// Check for underscores or periods in the filename and handle accordingly
if (filename.includes('_')) {
return filename.split('_').pop() // Return the last part after the last underscore
} else if (filename.includes('.')) {
return filename.split('.').pop() // Return the extension after the last period
} else {
return '' // Return empty if no suffix can be determined
}
}

const suffix = state.destination && config.templateExtensionMap ? getSuffix(state.destination) : ''

// Generate implementation of methods/events for both dynamic and static configured templates
Array.from(new Set(['methods'].concat(config.additionalMethodTemplates))).filter(dir => dir).forEach(dir => {
Expand Down

0 comments on commit 16b4e6e

Please sign in to comment.