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.

printer.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ConfigPrinter = exports.ChainFormatter = void 0;
  6. function _gensync() {
  7. const data = require("gensync");
  8. _gensync = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. const ChainFormatter = {
  14. Programmatic: 0,
  15. Config: 1
  16. };
  17. exports.ChainFormatter = ChainFormatter;
  18. const Formatter = {
  19. title(type, callerName, filepath) {
  20. let title = "";
  21. if (type === ChainFormatter.Programmatic) {
  22. title = "programmatic options";
  23. if (callerName) {
  24. title += " from " + callerName;
  25. }
  26. } else {
  27. title = "config " + filepath;
  28. }
  29. return title;
  30. },
  31. loc(index, envName) {
  32. let loc = "";
  33. if (index != null) {
  34. loc += `.overrides[${index}]`;
  35. }
  36. if (envName != null) {
  37. loc += `.env["${envName}"]`;
  38. }
  39. return loc;
  40. },
  41. *optionsAndDescriptors(opt) {
  42. const content = Object.assign({}, opt.options);
  43. delete content.overrides;
  44. delete content.env;
  45. const pluginDescriptors = [...(yield* opt.plugins())];
  46. if (pluginDescriptors.length) {
  47. content.plugins = pluginDescriptors.map(d => descriptorToConfig(d));
  48. }
  49. const presetDescriptors = [...(yield* opt.presets())];
  50. if (presetDescriptors.length) {
  51. content.presets = [...presetDescriptors].map(d => descriptorToConfig(d));
  52. }
  53. return JSON.stringify(content, undefined, 2);
  54. }
  55. };
  56. function descriptorToConfig(d) {
  57. var _d$file;
  58. let name = (_d$file = d.file) == null ? void 0 : _d$file.request;
  59. if (name == null) {
  60. if (typeof d.value === "object") {
  61. name = d.value;
  62. } else if (typeof d.value === "function") {
  63. name = `[Function: ${d.value.toString().substr(0, 50)} ... ]`;
  64. }
  65. }
  66. if (name == null) {
  67. name = "[Unknown]";
  68. }
  69. if (d.options === undefined) {
  70. return name;
  71. } else if (d.name == null) {
  72. return [name, d.options];
  73. } else {
  74. return [name, d.options, d.name];
  75. }
  76. }
  77. class ConfigPrinter {
  78. constructor() {
  79. this._stack = [];
  80. }
  81. configure(enabled, type, {
  82. callerName,
  83. filepath
  84. }) {
  85. if (!enabled) return () => {};
  86. return (content, index, envName) => {
  87. this._stack.push({
  88. type,
  89. callerName,
  90. filepath,
  91. content,
  92. index,
  93. envName
  94. });
  95. };
  96. }
  97. static *format(config) {
  98. let title = Formatter.title(config.type, config.callerName, config.filepath);
  99. const loc = Formatter.loc(config.index, config.envName);
  100. if (loc) title += ` ${loc}`;
  101. const content = yield* Formatter.optionsAndDescriptors(config.content);
  102. return `${title}\n${content}`;
  103. }
  104. *output() {
  105. if (this._stack.length === 0) return "";
  106. const configs = yield* _gensync().all(this._stack.map(s => ConfigPrinter.format(s)));
  107. return configs.join("\n\n");
  108. }
  109. }
  110. exports.ConfigPrinter = ConfigPrinter;