UNPKG

@roots/bud

Version:

Configurable, extensible build tools for modern single and multi-page web applications

23 lines (22 loc) 851 B
import { isset } from '@roots/bud/cli/helpers/isset'; import get from '@roots/bud-support/get'; import noop from '@roots/bud-support/noop'; export default async function override(bud, arg, env, manifestPath, fn, children = true) { if (!isset(arg) && manifestPath && bud.context.manifest?.bud && manifestPath in bud.context.manifest?.bud) { arg = get(bud.context.manifest.bud, manifestPath); } if (!isset(arg) && bud.env.has(env)) { arg = bud.env.get(env); } if (!isset(arg)) return; await fn(bud)(arg); children && bud.hasChildren && (await withChildren(bud, arg, fn)); } export const withChildren = async (bud, value, fn) => { bud.hasChildren && (await Promise.all([bud, ...Object.values(bud.children)].map(async (bud) => await fn(bud)(value).catch(noop)))); };