create.js
This file
Path
lib/methods/create.js
63 lines · 2.3 KiB · JavaScript
Last changed by
Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–5why, one step back1import isPlainObject from 'is-plain-obj';2import {normalizeParameters} from './parameters.js';3import {isTemplateString, parseTemplates} from './template.js';4import {execaCoreSync} from './main-sync.js';5import {execaCoreAsync} from './main-async.js';Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
line 6why, one step back6import {mergeOptions} from './bind.js';Rename files (#977)ehmickybefore adoption4b2e316
line 7why, one step back7Add more code comments (#984)ehmickybefore adoptionfdd8a9f
lines 8–12why, one step back8// Wraps every exported methods to provide the following features:9// - template string syntax: execa`command argument`10// - options binding: boundExeca = execa(options)11// - optional argument/options: execa(file), execa(file, args), execa(file, options), execa(file, args, options)12// `mapArguments()` and `setBoundExeca()` allows for method-specific logic.Rename files (#977)ehmickybefore adoption4b2e316
lines 13–14why, one step back13export const createExeca = (mapArguments, boundOptions, deepOptions, setBoundExeca) => {14 const createNested = (mapArguments, boundOptions, setBoundExeca) => createExeca(mapArguments, boundOptions, deepOptions, setBoundExeca);Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 15–21why, one step back15 const boundExeca = (...execaArguments) => callBoundExeca({16 mapArguments,17 deepOptions,18 boundOptions,19 setBoundExeca,20 createNested,21 }, ...execaArguments);Rename files (#977)ehmickybefore adoption4b2e316
lines 22–34why, one step back2223 if (setBoundExeca !== undefined) {24 setBoundExeca(boundExeca, createNested, boundOptions);25 }2627 return boundExeca;28};2930const callBoundExeca = ({mapArguments, deepOptions = {}, boundOptions = {}, setBoundExeca, createNested}, firstArgument, ...nextArguments) => {31 if (isPlainObject(firstArgument)) {32 return createNested(mapArguments, mergeOptions(boundOptions, firstArgument), setBoundExeca);33 }34Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 35–41why, one step back35 const {file, commandArguments, options, isSync} = parseArguments({36 mapArguments,37 firstArgument,38 nextArguments,39 deepOptions,40 boundOptions,41 });Rename files (#977)ehmickybefore adoption4b2e316
line 42why, one step back42 return isSyncUpgrade xo (#980)ehmickybefore adoptionccfa412
lines 43–44why, one step back43 ? execaCoreSync(file, commandArguments, options)44 : execaCoreAsync(file, commandArguments, options, createNested);Rename files (#977)ehmickybefore adoption4b2e316
lines 45–50why, one step back45};4647const parseArguments = ({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions}) => {48 const callArguments = isTemplateString(firstArgument)49 ? parseTemplates(firstArgument, nextArguments)50 : [firstArgument, ...nextArguments];Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 51–52why, one step back51 const [initialFile, initialArguments, initialOptions] = normalizeParameters(...callArguments);52 const mergedOptions = mergeOptions(mergeOptions(deepOptions, boundOptions), initialOptions);Rename files (#977)ehmickybefore adoption4b2e316
lines 53–55why, one step back53 const {54 options = mergedOptions,55 isSync = false,Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
line 56why, one step back56 } = mapArguments({options: mergedOptions});Upgrade xo (#980)ehmickybefore adoptionccfa412
line 57why, one step back57 return {Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
lines 58–59why, one step back58 file: initialFile,59 commandArguments: initialArguments,Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 60–62why, one step back60 options,61 isSync,62 };Rename files (#977)ehmickybefore adoption4b2e316
line 63why, one step back63};