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.

utils.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @license Copyright 2017 Google Inc. All Rights Reserved.
  3. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  4. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  5. */
  6. 'use strict';
  7. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  8. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  9. return new (P || (P = Promise))(function (resolve, reject) {
  10. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  11. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  12. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  13. step((generator = generator.apply(thisArg, _arguments || [])).next());
  14. });
  15. };
  16. Object.defineProperty(exports, "__esModule", { value: true });
  17. exports.getLocalAppDataPath = exports.toWinDirFormat = exports.makeTmpDir = exports.getPlatform = exports.ChromeNotInstalledError = exports.UnsupportedPlatformError = exports.InvalidUserDataDirectoryError = exports.ChromePathNotSetError = exports.LauncherError = exports.delay = exports.defaults = void 0;
  18. const path_1 = require("path");
  19. const child_process_1 = require("child_process");
  20. const mkdirp = require("mkdirp");
  21. const isWsl = require('is-wsl');
  22. function defaults(val, def) {
  23. return typeof val === 'undefined' ? def : val;
  24. }
  25. exports.defaults = defaults;
  26. function delay(time) {
  27. return __awaiter(this, void 0, void 0, function* () {
  28. return new Promise(resolve => setTimeout(resolve, time));
  29. });
  30. }
  31. exports.delay = delay;
  32. class LauncherError extends Error {
  33. constructor(message = 'Unexpected error', code) {
  34. super();
  35. this.message = message;
  36. this.code = code;
  37. this.stack = new Error().stack;
  38. return this;
  39. }
  40. }
  41. exports.LauncherError = LauncherError;
  42. class ChromePathNotSetError extends LauncherError {
  43. constructor() {
  44. super(...arguments);
  45. this.message = 'The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.';
  46. this.code = "ERR_LAUNCHER_PATH_NOT_SET" /* ERR_LAUNCHER_PATH_NOT_SET */;
  47. }
  48. }
  49. exports.ChromePathNotSetError = ChromePathNotSetError;
  50. class InvalidUserDataDirectoryError extends LauncherError {
  51. constructor() {
  52. super(...arguments);
  53. this.message = 'userDataDir must be false or a path.';
  54. this.code = "ERR_LAUNCHER_INVALID_USER_DATA_DIRECTORY" /* ERR_LAUNCHER_INVALID_USER_DATA_DIRECTORY */;
  55. }
  56. }
  57. exports.InvalidUserDataDirectoryError = InvalidUserDataDirectoryError;
  58. class UnsupportedPlatformError extends LauncherError {
  59. constructor() {
  60. super(...arguments);
  61. this.message = `Platform ${getPlatform()} is not supported.`;
  62. this.code = "ERR_LAUNCHER_UNSUPPORTED_PLATFORM" /* ERR_LAUNCHER_UNSUPPORTED_PLATFORM */;
  63. }
  64. }
  65. exports.UnsupportedPlatformError = UnsupportedPlatformError;
  66. class ChromeNotInstalledError extends LauncherError {
  67. constructor() {
  68. super(...arguments);
  69. this.message = 'No Chrome installations found.';
  70. this.code = "ERR_LAUNCHER_NOT_INSTALLED" /* ERR_LAUNCHER_NOT_INSTALLED */;
  71. }
  72. }
  73. exports.ChromeNotInstalledError = ChromeNotInstalledError;
  74. function getPlatform() {
  75. return isWsl ? 'wsl' : process.platform;
  76. }
  77. exports.getPlatform = getPlatform;
  78. function makeTmpDir() {
  79. switch (getPlatform()) {
  80. case 'darwin':
  81. case 'linux':
  82. return makeUnixTmpDir();
  83. case 'wsl':
  84. // We populate the user's Windows temp dir so the folder is correctly created later
  85. process.env.TEMP = getLocalAppDataPath(`${process.env.PATH}`);
  86. case 'win32':
  87. return makeWin32TmpDir();
  88. default:
  89. throw new UnsupportedPlatformError();
  90. }
  91. }
  92. exports.makeTmpDir = makeTmpDir;
  93. function toWinDirFormat(dir = '') {
  94. const results = /\/mnt\/([a-z])\//.exec(dir);
  95. if (!results) {
  96. return dir;
  97. }
  98. const driveLetter = results[1];
  99. return dir.replace(`/mnt/${driveLetter}/`, `${driveLetter.toUpperCase()}:\\`)
  100. .replace(/\//g, '\\');
  101. }
  102. exports.toWinDirFormat = toWinDirFormat;
  103. function getLocalAppDataPath(path) {
  104. const userRegExp = /\/mnt\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
  105. const results = userRegExp.exec(path) || [];
  106. return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`;
  107. }
  108. exports.getLocalAppDataPath = getLocalAppDataPath;
  109. function makeUnixTmpDir() {
  110. return child_process_1.execSync('mktemp -d -t lighthouse.XXXXXXX').toString().trim();
  111. }
  112. function makeWin32TmpDir() {
  113. const winTmpPath = process.env.TEMP || process.env.TMP ||
  114. (process.env.SystemRoot || process.env.windir) + '\\temp';
  115. const randomNumber = Math.floor(Math.random() * 9e7 + 1e7);
  116. const tmpdir = path_1.join(winTmpPath, 'lighthouse.' + randomNumber);
  117. mkdirp.sync(tmpdir);
  118. return tmpdir;
  119. }
  120. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7R0FJRztBQUNILFlBQVksQ0FBQzs7Ozs7Ozs7Ozs7O0FBRWIsK0JBQTBCO0FBQzFCLGlEQUF1QztBQUN2QyxpQ0FBaUM7QUFDakMsTUFBTSxLQUFLL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