command.js
 1  'use strict';
 2  const SPACES_REGEXP = / +/g;
 3  
 4  const joinCommand = (file, args = []) => {
 5  	if (!Array.isArray(args)) {
 6  		return file;
 7  	}
 8  
 9  	return [file, ...args].join(' ');
10  };
11  
12  // Handle `execa.command()`
13  const parseCommand = command => {
14  	const tokens = [];
15  	for (const token of command.trim().split(SPACES_REGEXP)) {
16  		// Allow spaces to be escaped by a backslash if not meant as a delimiter
17  		const previousToken = tokens[tokens.length - 1];
18  		if (previousToken && previousToken.endsWith('\\')) {
19  			// Merge previous token with current one
20  			tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
21  		} else {
22  			tokens.push(token);
23  		}
24  	}
25  
26  	return tokens;
27  };
28  
29  module.exports = {
30  	joinCommand,
31  	parseCommand
32  };