Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exe-type.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. const isWindows = require("is-windows")
  3. const path = require("path")
  4. function isCmd(file) {
  5. const comspec = path.basename(process.env.comspec || '').replace(/\.exe$/i, '')
  6. return isWindows() && (file === comspec || /^cmd(?:\.exe)?$/i.test(file))
  7. }
  8. function isNode(file) {
  9. const cmdname = path.basename(process.execPath).replace(/\.exe$/i, '')
  10. return file === 'node' || cmdname === file
  11. }
  12. function isNpm(file) {
  13. // XXX is this even possible/necessary?
  14. // wouldn't npm just be detected as a node shebang?
  15. return file === 'npm' && !isWindows()
  16. }
  17. function isSh(file) {
  18. return ['dash', 'sh', 'bash', 'zsh'].includes(file)
  19. }
  20. /**
  21. * Returns the basename of the executable.
  22. *
  23. * On Windows, strips the `.exe` extension (if any) and normalizes the name to
  24. * lowercase.
  25. *
  26. * @param exePath {string} Path of the executable as passed to spawned processes:
  27. * either command or a path to a file.
  28. * @return {string} Basename of the executable.
  29. */
  30. function getExeBasename(exePath) {
  31. const baseName = path.basename(exePath);
  32. if (isWindows()) {
  33. // Stripping `.exe` seems to be enough for our usage. We may eventually
  34. // want to handle all executable extensions (such as `.bat` or `.cmd`).
  35. return baseName.replace(/\.exe$/i, "").toLowerCase();
  36. } else {
  37. return baseName;
  38. }
  39. }
  40. module.exports = {
  41. isCmd,
  42. isNode,
  43. isNpm,
  44. isSh,
  45. getExeBasename,
  46. }