Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

command.js 726B

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