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 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  3. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  6. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
  8. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  9. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  10. const prompts = require('./prompts');
  11. const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender', 'type'];
  12. const noop = () => {};
  13. /**
  14. * Prompt for a series of questions
  15. * @param {Array|Object} questions Single question object or Array of question objects
  16. * @param {Function} [onSubmit] Callback function called on prompt submit
  17. * @param {Function} [onCancel] Callback function called on cancel/abort
  18. * @returns {Object} Object with values from user input
  19. */
  20. function prompt() {
  21. return _prompt.apply(this, arguments);
  22. }
  23. function _prompt() {
  24. _prompt = _asyncToGenerator(function* (questions = [], {
  25. onSubmit = noop,
  26. onCancel = noop
  27. } = {}) {
  28. const answers = {};
  29. const override = prompt._override || {};
  30. questions = [].concat(questions);
  31. let answer, question, quit, name, type, lastPrompt;
  32. const getFormattedAnswer = /*#__PURE__*/function () {
  33. var _ref = _asyncToGenerator(function* (question, answer, skipValidation = false) {
  34. if (!skipValidation && question.validate && question.validate(answer) !== true) {
  35. return;
  36. }
  37. return question.format ? yield question.format(answer, answers) : answer;
  38. });
  39. return function getFormattedAnswer(_x, _x2) {
  40. return _ref.apply(this, arguments);
  41. };
  42. }();
  43. var _iterator = _createForOfIteratorHelper(questions),
  44. _step;
  45. try {
  46. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  47. question = _step.value;
  48. var _question = question;
  49. name = _question.name;
  50. type = _question.type;
  51. // evaluate type first and skip if type is a falsy value
  52. if (typeof type === 'function') {
  53. type = yield type(answer, _objectSpread({}, answers), question);
  54. question['type'] = type;
  55. }
  56. if (!type) continue; // if property is a function, invoke it unless it's a special function
  57. for (let key in question) {
  58. if (passOn.includes(key)) continue;
  59. let value = question[key];
  60. question[key] = typeof value === 'function' ? yield value(answer, _objectSpread({}, answers), lastPrompt) : value;
  61. }
  62. lastPrompt = question;
  63. if (typeof question.message !== 'string') {
  64. throw new Error('prompt message is required');
  65. } // update vars in case they changed
  66. var _question2 = question;
  67. name = _question2.name;
  68. type = _question2.type;
  69. if (prompts[type] === void 0) {
  70. throw new Error(`prompt type (${type}) is not defined`);
  71. }
  72. if (override[question.name] !== undefined) {
  73. answer = yield getFormattedAnswer(question, override[question.name]);
  74. if (answer !== undefined) {
  75. answers[name] = answer;
  76. continue;
  77. }
  78. }
  79. try {
  80. // Get the injected answer if there is one or prompt the user
  81. answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : yield prompts[type](question);
  82. answers[name] = answer = yield getFormattedAnswer(question, answer, true);
  83. quit = yield onSubmit(question, answer, answers);
  84. } catch (err) {
  85. quit = !(yield onCancel(question, answers));
  86. }
  87. if (quit) return answers;
  88. }
  89. } catch (err) {
  90. _iterator.e(err);
  91. } finally {
  92. _iterator.f();
  93. }
  94. return answers;
  95. });
  96. return _prompt.apply(this, arguments);
  97. }
  98. function getInjectedAnswer(injected, deafultValue) {
  99. const answer = injected.shift();
  100. if (answer instanceof Error) {
  101. throw answer;
  102. }
  103. return answer === undefined ? deafultValue : answer;
  104. }
  105. function inject(answers) {
  106. prompt._injected = (prompt._injected || []).concat(answers);
  107. }
  108. function override(answers) {
  109. prompt._override = Object.assign({}, answers);
  110. }
  111. module.exports = Object.assign(prompt, {
  112. prompt,
  113. prompts,
  114. inject,
  115. override
  116. });