Skip to content

Commit ca8bc5c

Browse files
committed
feat: pushPlugin function
1 parent 8675f6d commit ca8bc5c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/main.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,29 @@ export function createPlugins(
280280
},
281281
}),
282282
)
283+
284+
// utility function that pushes a plugin
285+
function pushPlugin(
286+
nameTriggers: string[],
287+
[moduleName, prop]: [modulesname: string, prop?: string],
288+
pluginDefaultOptions: object = {},
289+
includeByDefault: boolean = false
290+
) {
291+
const index = includesAny(inputPluginsNames, [...nameTriggers, moduleName])
292+
if (index !== null) {
293+
const modul = require(moduleName)
294+
const pluginFunction = typeof prop === "string" ? modul[prop] : modul
295+
if (typeof inputPluginsNames[index] === "string") {
296+
// plugin name only
297+
plugins.push(pluginFunction(pluginDefaultOptions))
298+
} else {
299+
// plugin with options
300+
plugins.push(pluginFunction(inputPluginsNames[index][1]))
301+
}
302+
} else if (includeByDefault) {
303+
const modul = require(moduleName)
304+
const pluginFunction = typeof prop === "string" ? modul[prop] : modul
305+
plugins.push(pluginFunction(pluginDefaultOptions))
283306
}
284307
}
285308

0 commit comments

Comments
 (0)