create.js
This file
Path
lib/arguments/create.js
42 lines · 1.8 KiB · JavaScript
Last changed by
Allow template strings with all methods (#933)ehmickybefore adoption8074d85
History of this fileTake it
Allow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 1–42why, one step back1import isPlainObject from 'is-plain-obj';2import {execaCoreAsync} from '../async.js';3import {execaCoreSync} from '../sync.js';4import {normalizeArguments} from './normalize.js';5import {isTemplateString, parseTemplates} from './template.js';67export const createExeca = (mapArguments, boundOptions, deepOptions, setBoundExeca) => {8 const createNested = (mapArguments, boundOptions, setBoundExeca) => createExeca(mapArguments, boundOptions, deepOptions, setBoundExeca);9 const boundExeca = (...args) => callBoundExeca({mapArguments, deepOptions, boundOptions, setBoundExeca, createNested}, ...args);1011 if (setBoundExeca !== undefined) {12 setBoundExeca(boundExeca, createNested, boundOptions);13 }1415 return boundExeca;16};1718const callBoundExeca = ({mapArguments, deepOptions = {}, boundOptions = {}, setBoundExeca, createNested}, firstArgument, ...nextArguments) => {19 if (isPlainObject(firstArgument)) {20 return createNested(mapArguments, {...boundOptions, ...firstArgument}, setBoundExeca);21 }2223 const {file, args, options, isSync} = parseArguments({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions});24 return isSync25 ? execaCoreSync(file, args, options)26 : execaCoreAsync(file, args, options, createNested);27};2829const parseArguments = ({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions}) => {30 const callArguments = isTemplateString(firstArgument)31 ? parseTemplates(firstArgument, nextArguments)32 : [firstArgument, ...nextArguments];33 const [rawFile, rawArgs, rawOptions] = normalizeArguments(...callArguments);34 const mergedOptions = {...deepOptions, ...boundOptions, ...rawOptions};35 const {36 file = rawFile,37 args = rawArgs,38 options = mergedOptions,39 isSync = false,40 } = mapArguments({file: rawFile, args: rawArgs, options: mergedOptions});41 return {file, args, options, isSync};42};