Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const os = require('os');
  3. const execa = require('execa');
  4. // Reference: https://www.gaijin.at/en/lstwinver.php
  5. const names = new Map([
  6. ['10.0', '10'],
  7. ['6.3', '8.1'],
  8. ['6.2', '8'],
  9. ['6.1', '7'],
  10. ['6.0', 'Vista'],
  11. ['5.2', 'Server 2003'],
  12. ['5.1', 'XP'],
  13. ['5.0', '2000'],
  14. ['4.9', 'ME'],
  15. ['4.1', '98'],
  16. ['4.0', '95']
  17. ]);
  18. const windowsRelease = release => {
  19. const version = /\d+\.\d/.exec(release || os.release());
  20. if (release && !version) {
  21. throw new Error('`release` argument doesn\'t match `n.n`');
  22. }
  23. const ver = (version || [])[0];
  24. // Server 2008, 2012, 2016, and 2019 versions are ambiguous with desktop versions and must be detected at runtime.
  25. // If `release` is omitted or we're on a Windows system, and the version number is an ambiguous version
  26. // then use `wmic` to get the OS caption: https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx
  27. // If `wmic` is obsoloete (later versions of Windows 10), use PowerShell instead.
  28. // If the resulting caption contains the year 2008, 2012, 2016 or 2019, it is a server version, so return a server OS name.
  29. if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) {
  30. let stdout;
  31. try {
  32. stdout = execa.sync('wmic', ['os', 'get', 'Caption']).stdout || '';
  33. } catch (_) {
  34. stdout = execa.sync('powershell', ['(Get-CimInstance -ClassName Win32_OperatingSystem).caption']).stdout || '';
  35. }
  36. const year = (stdout.match(/2008|2012|2016|2019/) || [])[0];
  37. if (year) {
  38. return `Server ${year}`;
  39. }
  40. }
  41. return names.get(ver);
  42. };
  43. module.exports = windowsRelease;