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.

worker.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.worker = worker;
  6. exports.getSha1 = getSha1;
  7. function _crypto() {
  8. const data = require('crypto');
  9. _crypto = function () {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function path() {
  15. const data = _interopRequireWildcard(require('path'));
  16. path = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. function fs() {
  22. const data = _interopRequireWildcard(require('graceful-fs'));
  23. fs = function () {
  24. return data;
  25. };
  26. return data;
  27. }
  28. var _blacklist = _interopRequireDefault(require('./blacklist'));
  29. var _constants = _interopRequireDefault(require('./constants'));
  30. var dependencyExtractor = _interopRequireWildcard(
  31. require('./lib/dependencyExtractor')
  32. );
  33. function _interopRequireDefault(obj) {
  34. return obj && obj.__esModule ? obj : {default: obj};
  35. }
  36. function _getRequireWildcardCache(nodeInterop) {
  37. if (typeof WeakMap !== 'function') return null;
  38. var cacheBabelInterop = new WeakMap();
  39. var cacheNodeInterop = new WeakMap();
  40. return (_getRequireWildcardCache = function (nodeInterop) {
  41. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  42. })(nodeInterop);
  43. }
  44. function _interopRequireWildcard(obj, nodeInterop) {
  45. if (!nodeInterop && obj && obj.__esModule) {
  46. return obj;
  47. }
  48. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  49. return {default: obj};
  50. }
  51. var cache = _getRequireWildcardCache(nodeInterop);
  52. if (cache && cache.has(obj)) {
  53. return cache.get(obj);
  54. }
  55. var newObj = {};
  56. var hasPropertyDescriptor =
  57. Object.defineProperty && Object.getOwnPropertyDescriptor;
  58. for (var key in obj) {
  59. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  60. var desc = hasPropertyDescriptor
  61. ? Object.getOwnPropertyDescriptor(obj, key)
  62. : null;
  63. if (desc && (desc.get || desc.set)) {
  64. Object.defineProperty(newObj, key, desc);
  65. } else {
  66. newObj[key] = obj[key];
  67. }
  68. }
  69. }
  70. newObj.default = obj;
  71. if (cache) {
  72. cache.set(obj, newObj);
  73. }
  74. return newObj;
  75. }
  76. /**
  77. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  78. *
  79. * This source code is licensed under the MIT license found in the
  80. * LICENSE file in the root directory of this source tree.
  81. */
  82. const PACKAGE_JSON = path().sep + 'package.json';
  83. let hasteImpl = null;
  84. let hasteImplModulePath = null;
  85. function sha1hex(content) {
  86. return (0, _crypto().createHash)('sha1').update(content).digest('hex');
  87. }
  88. async function worker(data) {
  89. if (
  90. data.hasteImplModulePath &&
  91. data.hasteImplModulePath !== hasteImplModulePath
  92. ) {
  93. if (hasteImpl) {
  94. throw new Error('jest-haste-map: hasteImplModulePath changed');
  95. }
  96. hasteImplModulePath = data.hasteImplModulePath;
  97. hasteImpl = require(hasteImplModulePath);
  98. }
  99. let content;
  100. let dependencies;
  101. let id;
  102. let module;
  103. let sha1;
  104. const {computeDependencies, computeSha1, rootDir, filePath} = data;
  105. const getContent = () => {
  106. if (content === undefined) {
  107. content = fs().readFileSync(filePath, 'utf8');
  108. }
  109. return content;
  110. };
  111. if (filePath.endsWith(PACKAGE_JSON)) {
  112. // Process a package.json that is returned as a PACKAGE type with its name.
  113. try {
  114. const fileData = JSON.parse(getContent());
  115. if (fileData.name) {
  116. const relativeFilePath = path().relative(rootDir, filePath);
  117. id = fileData.name;
  118. module = [relativeFilePath, _constants.default.PACKAGE];
  119. }
  120. } catch (err) {
  121. throw new Error(`Cannot parse ${filePath} as JSON: ${err.message}`);
  122. }
  123. } else if (
  124. !_blacklist.default.has(filePath.substr(filePath.lastIndexOf('.')))
  125. ) {
  126. // Process a random file that is returned as a MODULE.
  127. if (hasteImpl) {
  128. id = hasteImpl.getHasteName(filePath);
  129. }
  130. if (computeDependencies) {
  131. const content = getContent();
  132. dependencies = Array.from(
  133. data.dependencyExtractor
  134. ? require(data.dependencyExtractor).extract(
  135. content,
  136. filePath,
  137. dependencyExtractor.extract
  138. )
  139. : dependencyExtractor.extract(content)
  140. );
  141. }
  142. if (id) {
  143. const relativeFilePath = path().relative(rootDir, filePath);
  144. module = [relativeFilePath, _constants.default.MODULE];
  145. }
  146. } // If a SHA-1 is requested on update, compute it.
  147. if (computeSha1) {
  148. sha1 = sha1hex(getContent() || fs().readFileSync(filePath));
  149. }
  150. return {
  151. dependencies,
  152. id,
  153. module,
  154. sha1
  155. };
  156. }
  157. async function getSha1(data) {
  158. const sha1 = data.computeSha1
  159. ? sha1hex(fs().readFileSync(data.filePath))
  160. : null;
  161. return {
  162. dependencies: undefined,
  163. id: undefined,
  164. module: undefined,
  165. sha1
  166. };
  167. }