Skip to content

Commit

Permalink
feat: make directives and output formats extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKruckenberg committed Mar 8, 2021
1 parent c26be86 commit c4198f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default function imagetools(userOptions: Partial<PluginOptions> = {}): Pl
const pluginOptions = { ...defaultOptions, ...userOptions }


const directives = [...Object.values(builtinDiretcives), ...pluginOptions.customDirectives]

const outputFormats = [...Object.values(builtinOutputFormats), ...pluginOptions.customOutputFormats]

return {
name: 'imagetools',
enforce: 'pre',
Expand All @@ -43,8 +47,8 @@ export default function imagetools(userOptions: Partial<PluginOptions> = {}): Pl
}

if (!data) {
// build transformation pipeline
const { transforms, metadata: _metadata, parametersUsed } = buildTransforms(config,directives)
// build the transformation pipeline
const { transforms, metadata: _metadata, parametersUsed } = buildTransforms(config, directives)

metadata = { src: src.pathname, ..._metadata }

Expand Down Expand Up @@ -83,8 +87,9 @@ export default function imagetools(userOptions: Partial<PluginOptions> = {}): Pl
return metadata
}))

const output = Object.values(outputFormats)
.map(f => f(src,outputMetadatas))
// go through all output formats to find the one to use
const output = outputFormats
.map(f => f(src, outputMetadatas))
.find(res => !!res)

return dataToEsm(output)
Expand Down

0 comments on commit c4198f4

Please sign in to comment.