Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
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.

index.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. const {promisify} = require('util');
  3. const path = require('path');
  4. const childProcess = require('child_process');
  5. const isWsl = require('is-wsl');
  6. const pExecFile = promisify(childProcess.execFile);
  7. // Convert a path from WSL format to Windows format:
  8. // `/mnt/c/Program Files/Example/MyApp.exe` → `C:\Program Files\Example\MyApp.exe``
  9. const wslToWindowsPath = async path => {
  10. const {stdout} = await pExecFile('wslpath', ['-w', path]);
  11. return stdout.trim();
  12. };
  13. module.exports = async (target, options) => {
  14. if (typeof target !== 'string') {
  15. throw new TypeError('Expected a `target`');
  16. }
  17. options = {
  18. wait: false,
  19. ...options
  20. };
  21. let command;
  22. let appArguments = [];
  23. const cliArguments = [];
  24. const childProcessOptions = {};
  25. if (Array.isArray(options.app)) {
  26. appArguments = options.app.slice(1);
  27. options.app = options.app[0];
  28. }
  29. if (process.platform === 'darwin') {
  30. command = 'open';
  31. if (options.wait) {
  32. cliArguments.push('-W');
  33. }
  34. if (options.app) {
  35. cliArguments.push('-a', options.app);
  36. }
  37. } else if (process.platform === 'win32' || isWsl) {
  38. command = 'cmd' + (isWsl ? '.exe' : '');
  39. cliArguments.push('/c', 'start', '""', '/b');
  40. target = target.replace(/&/g, '^&');
  41. if (options.wait) {
  42. cliArguments.push('/wait');
  43. }
  44. if (options.app) {
  45. if (isWsl && options.app.startsWith('/mnt/')) {
  46. const windowsPath = await wslToWindowsPath(options.app);
  47. options.app = windowsPath;
  48. }
  49. cliArguments.push(options.app);
  50. }
  51. if (appArguments.length > 0) {
  52. cliArguments.push(...appArguments);
  53. }
  54. } else {
  55. if (options.app) {
  56. command = options.app;
  57. } else {
  58. const useSystemXdgOpen = process.versions.electron || process.platform === 'android';
  59. command = useSystemXdgOpen ? 'xdg-open' : path.join(__dirname, 'xdg-open');
  60. }
  61. if (appArguments.length > 0) {
  62. cliArguments.push(...appArguments);
  63. }
  64. if (!options.wait) {
  65. // `xdg-open` will block the process unless stdio is ignored
  66. // and it's detached from the parent even if it's unref'd.
  67. childProcessOptions.stdio = 'ignore';
  68. childProcessOptions.detached = true;
  69. }
  70. }
  71. cliArguments.push(target);
  72. if (process.platform === 'darwin' && appArguments.length > 0) {
  73. cliArguments.push('--args', ...appArguments);
  74. }
  75. const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
  76. if (options.wait) {
  77. return new Promise((resolve, reject) => {
  78. subprocess.once('error', reject);
  79. subprocess.once('close', exitCode => {
  80. if (exitCode > 0) {
  81. reject(new Error(`Exited with code ${exitCode}`));
  82. return;
  83. }
  84. resolve(subprocess);
  85. });
  86. });
  87. }
  88. subprocess.unref();
  89. return subprocess;
  90. };