process-argv.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getProcessArgvBin = exports.getProcessArgvWithoutBin = void 0;
  4. function getProcessArgvBinIndex() {
  5. // The binary name is the first command line argument for:
  6. // - bundled Electron apps: bin argv1 argv2 ... argvn
  7. if (isBundledElectronApp())
  8. return 0;
  9. // or the second one (default) for:
  10. // - standard node apps: node bin.js argv1 argv2 ... argvn
  11. // - unbundled Electron apps: electron bin.js argv1 arg2 ... argvn
  12. return 1;
  13. }
  14. function isBundledElectronApp() {
  15. // process.defaultApp is either set by electron in an electron unbundled app, or undefined
  16. // see https://github.com/electron/electron/blob/master/docs/api/process.md#processdefaultapp-readonly
  17. return isElectronApp() && !process.defaultApp;
  18. }
  19. function isElectronApp() {
  20. // process.versions.electron is either set by electron, or undefined
  21. // see https://github.com/electron/electron/blob/master/docs/api/process.md#processversionselectron-readonly
  22. return !!process.versions.electron;
  23. }
  24. function getProcessArgvWithoutBin() {
  25. return process.argv.slice(getProcessArgvBinIndex() + 1);
  26. }
  27. exports.getProcessArgvWithoutBin = getProcessArgvWithoutBin;
  28. function getProcessArgvBin() {
  29. return process.argv[getProcessArgvBinIndex()];
  30. }
  31. exports.getProcessArgvBin = getProcessArgvBin;