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.

make.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. const fs = require('fs');
  3. const path = require('path');
  4. const babylon = require('babylon');
  5. const generate = require('babel-generator').default;
  6. const traverse = require('babel-traverse').default;
  7. const defaultsTemplate = body => `
  8. // Generated with \`lib/make.js\`
  9. 'use strict';
  10. const os = require('os');
  11. const path = require('path');
  12. const temp = os.tmpdir();
  13. const uidOrPid = process.getuid ? process.getuid() : process.pid;
  14. const hasUnicode = () => true;
  15. const isWindows = process.platform === 'win32';
  16. const osenv = {
  17. editor: () => process.env.EDITOR || process.env.VISUAL || (isWindows ? 'notepad.exe' : 'vi'),
  18. shell: () => isWindows ? (process.env.COMSPEC || 'cmd.exe') : (process.env.SHELL || '/bin/bash')
  19. };
  20. const umask = {
  21. fromString: () => process.umask()
  22. };
  23. let home = os.homedir();
  24. if (home) {
  25. process.env.HOME = home;
  26. } else {
  27. home = path.resolve(temp, 'npm-' + uidOrPid);
  28. }
  29. const cacheExtra = process.platform === 'win32' ? 'npm-cache' : '.npm';
  30. const cacheRoot = process.platform === 'win32' ? process.env.APPDATA : home;
  31. const cache = path.resolve(cacheRoot, cacheExtra);
  32. let defaults;
  33. let globalPrefix;
  34. ${body}
  35. `;
  36. const typesTemplate = body => `
  37. // Generated with \`lib/make.js\`
  38. 'use strict';
  39. const path = require('path');
  40. const Stream = require('stream').Stream;
  41. const url = require('url');
  42. const Umask = () => {};
  43. const getLocalAddresses = () => [];
  44. const semver = () => {};
  45. ${body}
  46. `;
  47. const defaults = require.resolve('npm/lib/config/defaults');
  48. const ast = babylon.parse(fs.readFileSync(defaults, 'utf8'));
  49. const isDefaults = node =>
  50. node.callee.type === 'MemberExpression' &&
  51. node.callee.object.name === 'Object' &&
  52. node.callee.property.name === 'defineProperty' &&
  53. node.arguments.some(x => x.name === 'exports');
  54. const isTypes = node =>
  55. node.type === 'MemberExpression' &&
  56. node.object.name === 'exports' &&
  57. node.property.name === 'types';
  58. let defs;
  59. let types;
  60. traverse(ast, {
  61. CallExpression(path) {
  62. if (isDefaults(path.node)) {
  63. defs = path.node;
  64. }
  65. },
  66. AssignmentExpression(path) {
  67. if (path.node.left && isTypes(path.node.left)) {
  68. types = path.node;
  69. }
  70. }
  71. });
  72. fs.writeFileSync(path.join(__dirname, 'defaults.js'), defaultsTemplate(generate(defs, {}, ast).code));
  73. fs.writeFileSync(path.join(__dirname, 'types.js'), typesTemplate(generate(types, {}, ast).code));