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.

index.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const path = require('path');
  3. const Module = require('module');
  4. const fs = require('fs');
  5. const resolveFrom = (fromDirectory, moduleId, silent) => {
  6. if (typeof fromDirectory !== 'string') {
  7. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDirectory}\``);
  8. }
  9. if (typeof moduleId !== 'string') {
  10. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  11. }
  12. try {
  13. fromDirectory = fs.realpathSync(fromDirectory);
  14. } catch (error) {
  15. if (error.code === 'ENOENT') {
  16. fromDirectory = path.resolve(fromDirectory);
  17. } else if (silent) {
  18. return;
  19. } else {
  20. throw error;
  21. }
  22. }
  23. const fromFile = path.join(fromDirectory, 'noop.js');
  24. const resolveFileName = () => Module._resolveFilename(moduleId, {
  25. id: fromFile,
  26. filename: fromFile,
  27. paths: Module._nodeModulePaths(fromDirectory)
  28. });
  29. if (silent) {
  30. try {
  31. return resolveFileName();
  32. } catch (error) {
  33. return;
  34. }
  35. }
  36. return resolveFileName();
  37. };
  38. module.exports = (fromDirectory, moduleId) => resolveFrom(fromDirectory, moduleId);
  39. module.exports.silent = (fromDirectory, moduleId) => resolveFrom(fromDirectory, moduleId, true);