Skip to content
Myr

create.js

This file

Path

lib/methods/create.js

81 lines · 2.7 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–9why, one step back
1import isPlainObject from 'is-plain-obj';
2import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';3import {normalizeParameters} from './parameters.js';4import {isTemplateString, parseTemplates} from './template.js';5import {execaCoreSync} from './main-sync.js';6import {execaCoreAsync} from './main-async.js';78export const createExeca = (mapArguments, boundOptions, deepOptions, setBoundExeca) => {9 const createNested = (mapArguments, boundOptions, setBoundExeca) => createExeca(mapArguments, boundOptions, deepOptions, setBoundExeca);

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 10–16why, one step back
10 const boundExeca = (...execaArguments) => callBoundExeca({
11 mapArguments,12 deepOptions,13 boundOptions,14 setBoundExeca,15 createNested,16 }, ...execaArguments);

Rename files (#977)ehmickybefore adoption4b2e316

lines 17–29why, one step back
17
18 if (setBoundExeca !== undefined) {19 setBoundExeca(boundExeca, createNested, boundOptions);20 }2122 return boundExeca;23};2425const callBoundExeca = ({mapArguments, deepOptions = {}, boundOptions = {}, setBoundExeca, createNested}, firstArgument, ...nextArguments) => {26 if (isPlainObject(firstArgument)) {27 return createNested(mapArguments, mergeOptions(boundOptions, firstArgument), setBoundExeca);28 }29

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 30–36why, one step back
30 const {file, commandArguments, options, isSync} = parseArguments({
31 mapArguments,32 firstArgument,33 nextArguments,34 deepOptions,35 boundOptions,36 });

Rename files (#977)ehmickybefore adoption4b2e316

line 37why, one step back
37 return isSync

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 38–39why, one step back
38 ? execaCoreSync(file, commandArguments, options)
39 : execaCoreAsync(file, commandArguments, options, createNested);

Rename files (#977)ehmickybefore adoption4b2e316

lines 40–45why, one step back
40};
4142const parseArguments = ({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions}) => {43 const callArguments = isTemplateString(firstArgument)44 ? parseTemplates(firstArgument, nextArguments)45 : [firstArgument, ...nextArguments];

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 46–47why, one step back
46 const [initialFile, initialArguments, initialOptions] = normalizeParameters(...callArguments);
47 const mergedOptions = mergeOptions(mergeOptions(deepOptions, boundOptions), initialOptions);

Rename files (#977)ehmickybefore adoption4b2e316

line 48why, one step back
48 const {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 49–50why, one step back
49 file = initialFile,
50 commandArguments = initialArguments,

Rename files (#977)ehmickybefore adoption4b2e316

lines 51–52why, one step back
51 options = mergedOptions,
52 isSync = false,

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 53–59why, one step back
53 } = mapArguments({file: initialFile, commandArguments: initialArguments, options: mergedOptions});
54 return {55 file,56 commandArguments,57 options,58 isSync,59 };

Rename files (#977)ehmickybefore adoption4b2e316

lines 60–81why, one step back
60};
6162// Deep merge specific options like `env`. Shallow merge the other ones.63const mergeOptions = (boundOptions, options) => {64 const newOptions = Object.fromEntries(65 Object.entries(options).map(([optionName, optionValue]) => [66 optionName,67 mergeOption(optionName, boundOptions[optionName], optionValue),68 ]),69 );70 return {...boundOptions, ...newOptions};71};7273const mergeOption = (optionName, boundOptionValue, optionValue) => {74 if (DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue)) {75 return {...boundOptionValue, ...optionValue};76 }7778 return optionValue;79};8081const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);