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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. 'use strict';
  2. function _child_process() {
  3. const data = require('child_process');
  4. _child_process = function () {
  5. return data;
  6. };
  7. return data;
  8. }
  9. function path() {
  10. const data = _interopRequireWildcard(require('path'));
  11. path = function () {
  12. return data;
  13. };
  14. return data;
  15. }
  16. function fs() {
  17. const data = _interopRequireWildcard(require('graceful-fs'));
  18. fs = function () {
  19. return data;
  20. };
  21. return data;
  22. }
  23. function _constants() {
  24. const data = _interopRequireDefault(require('../constants'));
  25. _constants = function () {
  26. return data;
  27. };
  28. return data;
  29. }
  30. function fastPath() {
  31. const data = _interopRequireWildcard(require('../lib/fast_path'));
  32. fastPath = function () {
  33. return data;
  34. };
  35. return data;
  36. }
  37. function _interopRequireDefault(obj) {
  38. return obj && obj.__esModule ? obj : {default: obj};
  39. }
  40. function _getRequireWildcardCache(nodeInterop) {
  41. if (typeof WeakMap !== 'function') return null;
  42. var cacheBabelInterop = new WeakMap();
  43. var cacheNodeInterop = new WeakMap();
  44. return (_getRequireWildcardCache = function (nodeInterop) {
  45. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  46. })(nodeInterop);
  47. }
  48. function _interopRequireWildcard(obj, nodeInterop) {
  49. if (!nodeInterop && obj && obj.__esModule) {
  50. return obj;
  51. }
  52. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  53. return {default: obj};
  54. }
  55. var cache = _getRequireWildcardCache(nodeInterop);
  56. if (cache && cache.has(obj)) {
  57. return cache.get(obj);
  58. }
  59. var newObj = {};
  60. var hasPropertyDescriptor =
  61. Object.defineProperty && Object.getOwnPropertyDescriptor;
  62. for (var key in obj) {
  63. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  64. var desc = hasPropertyDescriptor
  65. ? Object.getOwnPropertyDescriptor(obj, key)
  66. : null;
  67. if (desc && (desc.get || desc.set)) {
  68. Object.defineProperty(newObj, key, desc);
  69. } else {
  70. newObj[key] = obj[key];
  71. }
  72. }
  73. }
  74. newObj.default = obj;
  75. if (cache) {
  76. cache.set(obj, newObj);
  77. }
  78. return newObj;
  79. }
  80. /**
  81. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  82. *
  83. * This source code is licensed under the MIT license found in the
  84. * LICENSE file in the root directory of this source tree.
  85. */
  86. async function hasNativeFindSupport(forceNodeFilesystemAPI) {
  87. if (forceNodeFilesystemAPI) {
  88. return false;
  89. }
  90. try {
  91. return await new Promise(resolve => {
  92. // Check the find binary supports the non-POSIX -iname parameter wrapped in parens.
  93. const args = [
  94. '.',
  95. '-type',
  96. 'f',
  97. '(',
  98. '-iname',
  99. '*.ts',
  100. '-o',
  101. '-iname',
  102. '*.js',
  103. ')'
  104. ];
  105. const child = (0, _child_process().spawn)('find', args, {
  106. cwd: __dirname
  107. });
  108. child.on('error', () => {
  109. resolve(false);
  110. });
  111. child.on('exit', code => {
  112. resolve(code === 0);
  113. });
  114. });
  115. } catch {
  116. return false;
  117. }
  118. }
  119. function find(roots, extensions, ignore, enableSymlinks, callback) {
  120. const result = [];
  121. let activeCalls = 0;
  122. function search(directory) {
  123. activeCalls++;
  124. fs().readdir(
  125. directory,
  126. {
  127. withFileTypes: true
  128. },
  129. (err, entries) => {
  130. activeCalls--;
  131. if (err) {
  132. callback(result);
  133. return;
  134. } // node < v10.10 does not support the withFileTypes option, and
  135. // entry will be a string.
  136. entries.forEach(entry => {
  137. const file = path().join(
  138. directory,
  139. typeof entry === 'string' ? entry : entry.name
  140. );
  141. if (ignore(file)) {
  142. return;
  143. }
  144. if (typeof entry !== 'string') {
  145. if (entry.isSymbolicLink()) {
  146. return;
  147. }
  148. if (entry.isDirectory()) {
  149. search(file);
  150. return;
  151. }
  152. }
  153. activeCalls++;
  154. const stat = enableSymlinks ? fs().stat : fs().lstat;
  155. stat(file, (err, stat) => {
  156. activeCalls--; // This logic is unnecessary for node > v10.10, but leaving it in
  157. // since we need it for backwards-compatibility still.
  158. if (!err && stat && !stat.isSymbolicLink()) {
  159. if (stat.isDirectory()) {
  160. search(file);
  161. } else {
  162. const ext = path().extname(file).substr(1);
  163. if (extensions.indexOf(ext) !== -1) {
  164. result.push([file, stat.mtime.getTime(), stat.size]);
  165. }
  166. }
  167. }
  168. if (activeCalls === 0) {
  169. callback(result);
  170. }
  171. });
  172. });
  173. if (activeCalls === 0) {
  174. callback(result);
  175. }
  176. }
  177. );
  178. }
  179. if (roots.length > 0) {
  180. roots.forEach(search);
  181. } else {
  182. callback(result);
  183. }
  184. }
  185. function findNative(roots, extensions, ignore, enableSymlinks, callback) {
  186. const args = Array.from(roots);
  187. if (enableSymlinks) {
  188. args.push('(', '-type', 'f', '-o', '-type', 'l', ')');
  189. } else {
  190. args.push('-type', 'f');
  191. }
  192. if (extensions.length) {
  193. args.push('(');
  194. }
  195. extensions.forEach((ext, index) => {
  196. if (index) {
  197. args.push('-o');
  198. }
  199. args.push('-iname');
  200. args.push('*.' + ext);
  201. });
  202. if (extensions.length) {
  203. args.push(')');
  204. }
  205. const child = (0, _child_process().spawn)('find', args);
  206. let stdout = '';
  207. if (child.stdout === null) {
  208. throw new Error(
  209. 'stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/jest'
  210. );
  211. }
  212. child.stdout.setEncoding('utf-8');
  213. child.stdout.on('data', data => (stdout += data));
  214. child.stdout.on('close', () => {
  215. const lines = stdout
  216. .trim()
  217. .split('\n')
  218. .filter(x => !ignore(x));
  219. const result = [];
  220. let count = lines.length;
  221. if (!count) {
  222. callback([]);
  223. } else {
  224. lines.forEach(path => {
  225. fs().stat(path, (err, stat) => {
  226. // Filter out symlinks that describe directories
  227. if (!err && stat && !stat.isDirectory()) {
  228. result.push([path, stat.mtime.getTime(), stat.size]);
  229. }
  230. if (--count === 0) {
  231. callback(result);
  232. }
  233. });
  234. });
  235. }
  236. });
  237. }
  238. module.exports = async function nodeCrawl(options) {
  239. const {
  240. data,
  241. extensions,
  242. forceNodeFilesystemAPI,
  243. ignore,
  244. rootDir,
  245. enableSymlinks,
  246. roots
  247. } = options;
  248. const useNativeFind = await hasNativeFindSupport(forceNodeFilesystemAPI);
  249. return new Promise(resolve => {
  250. const callback = list => {
  251. const files = new Map();
  252. const removedFiles = new Map(data.files);
  253. list.forEach(fileData => {
  254. const [filePath, mtime, size] = fileData;
  255. const relativeFilePath = fastPath().relative(rootDir, filePath);
  256. const existingFile = data.files.get(relativeFilePath);
  257. if (
  258. existingFile &&
  259. existingFile[_constants().default.MTIME] === mtime
  260. ) {
  261. files.set(relativeFilePath, existingFile);
  262. } else {
  263. // See ../constants.js; SHA-1 will always be null and fulfilled later.
  264. files.set(relativeFilePath, ['', mtime, size, 0, '', null]);
  265. }
  266. removedFiles.delete(relativeFilePath);
  267. });
  268. data.files = files;
  269. resolve({
  270. hasteMap: data,
  271. removedFiles
  272. });
  273. };
  274. if (useNativeFind) {
  275. findNative(roots, extensions, ignore, enableSymlinks, callback);
  276. } else {
  277. find(roots, extensions, ignore, enableSymlinks, callback);
  278. }
  279. });
  280. };