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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function path() {
  7. const data = _interopRequireWildcard(require('path'));
  8. path = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _chalk() {
  14. const data = _interopRequireDefault(require('chalk'));
  15. _chalk = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function fs() {
  21. const data = _interopRequireWildcard(require('graceful-fs'));
  22. fs = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _prompts() {
  28. const data = _interopRequireDefault(require('prompts'));
  29. _prompts = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _jestConfig() {
  35. const data = require('jest-config');
  36. _jestConfig = function () {
  37. return data;
  38. };
  39. return data;
  40. }
  41. function _jestUtil() {
  42. const data = require('jest-util');
  43. _jestUtil = function () {
  44. return data;
  45. };
  46. return data;
  47. }
  48. var _errors = require('./errors');
  49. var _generateConfigFile = _interopRequireDefault(
  50. require('./generateConfigFile')
  51. );
  52. var _modifyPackageJson = _interopRequireDefault(require('./modifyPackageJson'));
  53. var _questions = _interopRequireWildcard(require('./questions'));
  54. function _interopRequireDefault(obj) {
  55. return obj && obj.__esModule ? obj : {default: obj};
  56. }
  57. function _getRequireWildcardCache(nodeInterop) {
  58. if (typeof WeakMap !== 'function') return null;
  59. var cacheBabelInterop = new WeakMap();
  60. var cacheNodeInterop = new WeakMap();
  61. return (_getRequireWildcardCache = function (nodeInterop) {
  62. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  63. })(nodeInterop);
  64. }
  65. function _interopRequireWildcard(obj, nodeInterop) {
  66. if (!nodeInterop && obj && obj.__esModule) {
  67. return obj;
  68. }
  69. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  70. return {default: obj};
  71. }
  72. var cache = _getRequireWildcardCache(nodeInterop);
  73. if (cache && cache.has(obj)) {
  74. return cache.get(obj);
  75. }
  76. var newObj = {};
  77. var hasPropertyDescriptor =
  78. Object.defineProperty && Object.getOwnPropertyDescriptor;
  79. for (var key in obj) {
  80. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  81. var desc = hasPropertyDescriptor
  82. ? Object.getOwnPropertyDescriptor(obj, key)
  83. : null;
  84. if (desc && (desc.get || desc.set)) {
  85. Object.defineProperty(newObj, key, desc);
  86. } else {
  87. newObj[key] = obj[key];
  88. }
  89. }
  90. }
  91. newObj.default = obj;
  92. if (cache) {
  93. cache.set(obj, newObj);
  94. }
  95. return newObj;
  96. }
  97. /**
  98. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  99. *
  100. * This source code is licensed under the MIT license found in the
  101. * LICENSE file in the root directory of this source tree.
  102. */
  103. const {
  104. JEST_CONFIG_BASE_NAME,
  105. JEST_CONFIG_EXT_MJS,
  106. JEST_CONFIG_EXT_JS,
  107. JEST_CONFIG_EXT_TS,
  108. JEST_CONFIG_EXT_ORDER,
  109. PACKAGE_JSON
  110. } = _jestConfig().constants;
  111. const getConfigFilename = ext => JEST_CONFIG_BASE_NAME + ext;
  112. var _default = async (
  113. rootDir = (0, _jestUtil().tryRealpath)(process.cwd())
  114. ) => {
  115. // prerequisite checks
  116. const projectPackageJsonPath = path().join(rootDir, PACKAGE_JSON);
  117. if (!fs().existsSync(projectPackageJsonPath)) {
  118. throw new _errors.NotFoundPackageJsonError(rootDir);
  119. }
  120. const questions = _questions.default.slice(0);
  121. let hasJestProperty = false;
  122. let projectPackageJson;
  123. try {
  124. projectPackageJson = JSON.parse(
  125. fs().readFileSync(projectPackageJsonPath, 'utf-8')
  126. );
  127. } catch {
  128. throw new _errors.MalformedPackageJsonError(projectPackageJsonPath);
  129. }
  130. if (projectPackageJson.jest) {
  131. hasJestProperty = true;
  132. }
  133. const existingJestConfigExt = JEST_CONFIG_EXT_ORDER.find(ext =>
  134. fs().existsSync(path().join(rootDir, getConfigFilename(ext)))
  135. );
  136. if (hasJestProperty || existingJestConfigExt) {
  137. const result = await (0, _prompts().default)({
  138. initial: true,
  139. message:
  140. 'It seems that you already have a jest configuration, do you want to override it?',
  141. name: 'continue',
  142. type: 'confirm'
  143. });
  144. if (!result.continue) {
  145. console.log();
  146. console.log('Aborting...');
  147. return;
  148. }
  149. } // Add test script installation only if needed
  150. if (
  151. !projectPackageJson.scripts ||
  152. projectPackageJson.scripts.test !== 'jest'
  153. ) {
  154. questions.unshift(_questions.testScriptQuestion);
  155. } // Start the init process
  156. console.log();
  157. console.log(
  158. _chalk().default.underline(
  159. `The following questions will help Jest to create a suitable configuration for your project\n`
  160. )
  161. );
  162. let promptAborted = false; // @ts-expect-error: Return type cannot be object - faulty typings
  163. const results = await (0, _prompts().default)(questions, {
  164. onCancel: () => {
  165. promptAborted = true;
  166. }
  167. });
  168. if (promptAborted) {
  169. console.log();
  170. console.log('Aborting...');
  171. return;
  172. } // Determine if Jest should use JS or TS for the config file
  173. const jestConfigFileExt = results.useTypescript
  174. ? JEST_CONFIG_EXT_TS
  175. : projectPackageJson.type === 'module'
  176. ? JEST_CONFIG_EXT_MJS
  177. : JEST_CONFIG_EXT_JS; // Determine Jest config path
  178. const jestConfigPath = existingJestConfigExt
  179. ? getConfigFilename(existingJestConfigExt)
  180. : path().join(rootDir, getConfigFilename(jestConfigFileExt));
  181. const shouldModifyScripts = results.scripts;
  182. if (shouldModifyScripts || hasJestProperty) {
  183. const modifiedPackageJson = (0, _modifyPackageJson.default)({
  184. projectPackageJson,
  185. shouldModifyScripts
  186. });
  187. fs().writeFileSync(projectPackageJsonPath, modifiedPackageJson);
  188. console.log('');
  189. console.log(
  190. `✏️ Modified ${_chalk().default.cyan(projectPackageJsonPath)}`
  191. );
  192. }
  193. const generatedConfig = (0, _generateConfigFile.default)(
  194. results,
  195. projectPackageJson.type === 'module' ||
  196. jestConfigPath.endsWith(JEST_CONFIG_EXT_MJS)
  197. );
  198. fs().writeFileSync(jestConfigPath, generatedConfig);
  199. console.log('');
  200. console.log(
  201. `📝 Configuration file created at ${_chalk().default.cyan(jestConfigPath)}`
  202. );
  203. };
  204. exports.default = _default;