shell.ts 964 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import execa from "execa";
  5. export const shell = async (
  6. command: string,
  7. args?: string[],
  8. options?: execa.Options,
  9. log: boolean = false
  10. ) => {
  11. try {
  12. if (options && options.shell === true) {
  13. const stringCommand = [command, ...(!args ? [] : args)].join(" ");
  14. if (log) console.log(`[running]: ${stringCommand}`);
  15. return await execa(stringCommand, {
  16. stdio: "inherit",
  17. cwd: process.cwd(),
  18. env: process.env,
  19. ...options,
  20. });
  21. } else {
  22. if (log) console.log(`[running]: ${command}`);
  23. return await execa(command, args, {
  24. stdio: "inherit",
  25. cwd: process.cwd(),
  26. env: process.env,
  27. ...options,
  28. });
  29. }
  30. } catch (error) {
  31. console.error("Error with command: %s", command);
  32. throw new Error(error);
  33. }
  34. };