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.

cmd.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const path = require("path")
  3. const whichOrUndefined = require("../which-or-undefined")
  4. /**
  5. * Intercepts Node and npm processes spawned through Windows' `cmd.exe`.
  6. *
  7. * @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
  8. * @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
  9. * @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
  10. */
  11. function mungeCmd(workingDir, options) {
  12. const cmdi = options.args.indexOf('/c')
  13. if (cmdi === -1) {
  14. return {...options}
  15. }
  16. const re = /^\s*("*)([^"]*?\bnode(?:\.exe|\.EXE)?)("*)( .*)?$/
  17. const npmre = /^\s*("*)([^"]*?\b(?:npm))("*)( |$)/
  18. const command = options.args[cmdi + 1]
  19. if (command === undefined) {
  20. return {...options}
  21. }
  22. let newArgs = [...options.args];
  23. // Remember the original Node command to use it in the shim
  24. let originalNode;
  25. let m = command.match(re)
  26. let replace
  27. if (m) {
  28. originalNode = m[2]
  29. // TODO: Remove `replace`: seems unused
  30. replace = m[1] + path.join(workingDir, 'node.cmd') + m[3] + m[4]
  31. newArgs[cmdi + 1] = m[1] + m[2] + m[3] +
  32. ' "' + path.join(workingDir, 'node') + '"' + m[4]
  33. } else {
  34. // XXX probably not a good idea to rewrite to the first npm in the
  35. // path if it's a full path to npm. And if it's not a full path to
  36. // npm, then the dirname will not work properly!
  37. m = command.match(npmre)
  38. if (m === null) {
  39. return {...options}
  40. }
  41. let npmPath = whichOrUndefined('npm') || 'npm'
  42. npmPath = path.join(path.dirname(npmPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')
  43. replace = m[1] + '"' + path.join(workingDir, 'node.cmd') + '"' +
  44. ' "' + npmPath + '"' +
  45. m[3] + m[4]
  46. newArgs[cmdi + 1] = command.replace(npmre, replace)
  47. }
  48. return {...options, args: newArgs, originalNode};
  49. }
  50. module.exports = mungeCmd