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.

ConfigParser.js 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const fs_1 = __importDefault(require("fs"));
  7. const path_1 = __importDefault(require("path"));
  8. const glob_1 = __importDefault(require("glob"));
  9. const deepmerge_1 = __importDefault(require("deepmerge"));
  10. const logger_1 = __importDefault(require("@wdio/logger"));
  11. const utils_1 = require("../utils");
  12. const constants_1 = require("../constants");
  13. const log = logger_1.default('@wdio/config:ConfigParser');
  14. const MERGE_OPTIONS = { clone: false };
  15. class ConfigParser {
  16. constructor() {
  17. this._config = constants_1.DEFAULT_CONFIGS();
  18. this._capabilities = [];
  19. }
  20. addConfigFile(filename) {
  21. if (typeof filename !== 'string') {
  22. throw new Error('addConfigFile requires filepath');
  23. }
  24. const filePath = path_1.default.resolve(process.cwd(), filename);
  25. try {
  26. utils_1.loadTypeScriptCompiler();
  27. const fileConfig = deepmerge_1.default(require(filePath).config, {}, MERGE_OPTIONS);
  28. const defaultTo = Array.isArray(this._capabilities) ? [] : {};
  29. this._capabilities = deepmerge_1.default(this._capabilities, fileConfig.capabilities || defaultTo, MERGE_OPTIONS);
  30. delete fileConfig.capabilities;
  31. this.addService(fileConfig);
  32. for (let hookName of constants_1.SUPPORTED_HOOKS) {
  33. delete fileConfig[hookName];
  34. }
  35. this._config = deepmerge_1.default(this._config, fileConfig, MERGE_OPTIONS);
  36. this._config = deepmerge_1.default(utils_1.detectBackend(this._config), this._config, MERGE_OPTIONS);
  37. delete this._config.watch;
  38. }
  39. catch (e) {
  40. log.error(`Failed loading configuration file: ${filePath}:`, e.message);
  41. throw e;
  42. }
  43. }
  44. merge(object = {}) {
  45. const spec = Array.isArray(object.spec) ? object.spec : [];
  46. const exclude = Array.isArray(object.exclude) ? object.exclude : [];
  47. this._config = deepmerge_1.default(this._config, object, MERGE_OPTIONS);
  48. if (object.specs && object.specs.length > 0) {
  49. this._config.specs = object.specs;
  50. }
  51. else if (object.exclude && object.exclude.length > 0) {
  52. this._config.exclude = object.exclude;
  53. }
  54. this._capabilities = utils_1.validObjectOrArray(this._config.capabilities) ? this._config.capabilities : this._capabilities;
  55. if (this._config.spec && utils_1.isCucumberFeatureWithLineNumber(this._config.spec)) {
  56. this._config.cucumberFeaturesWithLineNumbers = Array.isArray(this._config.spec) ? [...this._config.spec] : [this._config.spec];
  57. }
  58. if (spec.length > 0) {
  59. this._config.specs = this.setFilePathToFilterOptions(spec, this._config.specs);
  60. }
  61. if (exclude.length > 0) {
  62. this._config.exclude = this.setFilePathToFilterOptions(exclude, this._config.exclude);
  63. }
  64. this._config = deepmerge_1.default(utils_1.detectBackend(this._config), this._config, MERGE_OPTIONS);
  65. }
  66. addService(service) {
  67. const addHook = (hookName, hook) => {
  68. const existingHooks = this._config[hookName];
  69. if (!existingHooks) {
  70. this._config[hookName] = hook.bind(service);
  71. }
  72. else if (typeof existingHooks === 'function') {
  73. this._config[hookName] = [existingHooks, hook.bind(service)];
  74. }
  75. else {
  76. this._config[hookName] = [...existingHooks, hook.bind(service)];
  77. }
  78. };
  79. for (const hookName of constants_1.SUPPORTED_HOOKS) {
  80. const hooksToBeAdded = service[hookName];
  81. if (!hooksToBeAdded) {
  82. continue;
  83. }
  84. if (typeof hooksToBeAdded === 'function') {
  85. addHook(hookName, hooksToBeAdded);
  86. }
  87. else if (Array.isArray(hooksToBeAdded)) {
  88. for (const hookToAdd of hooksToBeAdded) {
  89. if (typeof hookToAdd === 'function') {
  90. addHook(hookName, hookToAdd);
  91. }
  92. }
  93. }
  94. }
  95. }
  96. getSpecs(capSpecs, capExclude) {
  97. var _a;
  98. let specs = ConfigParser.getFilePaths(this._config.specs);
  99. let spec = Array.isArray(this._config.spec) ? this._config.spec : [];
  100. let exclude = ConfigParser.getFilePaths(this._config.exclude);
  101. let suites = Array.isArray(this._config.suite) ? this._config.suite : [];
  102. if (suites.length > 0) {
  103. let suiteSpecs = [];
  104. for (let suiteName of suites) {
  105. let suite = (_a = this._config.suites) === null || _a === void 0 ? void 0 : _a[suiteName];
  106. if (!suite) {
  107. log.warn(`No suite was found with name "${suiteName}"`);
  108. }
  109. if (Array.isArray(suite)) {
  110. suiteSpecs = suiteSpecs.concat(ConfigParser.getFilePaths(suite));
  111. }
  112. }
  113. if (suiteSpecs.length === 0) {
  114. throw new Error(`The suite(s) "${suites.join('", "')}" you specified don't exist ` +
  115. 'in your config file or doesn\'t contain any files!');
  116. }
  117. let tmpSpecs = spec.length > 0 ? [...specs, ...suiteSpecs] : suiteSpecs;
  118. if (Array.isArray(capSpecs)) {
  119. tmpSpecs = ConfigParser.getFilePaths(capSpecs);
  120. }
  121. if (Array.isArray(capExclude)) {
  122. exclude = ConfigParser.getFilePaths(capExclude);
  123. }
  124. specs = [...new Set(tmpSpecs)];
  125. return specs.filter(spec => !exclude.includes(spec));
  126. }
  127. if (Array.isArray(capSpecs)) {
  128. specs = ConfigParser.getFilePaths(capSpecs);
  129. }
  130. if (Array.isArray(capExclude)) {
  131. exclude = ConfigParser.getFilePaths(capExclude);
  132. }
  133. return specs.filter(spec => !exclude.includes(spec));
  134. }
  135. setFilePathToFilterOptions(cliArgFileList, config) {
  136. const filesToFilter = new Set();
  137. const fileList = ConfigParser.getFilePaths(config);
  138. cliArgFileList.forEach(filteredFile => {
  139. filteredFile = utils_1.removeLineNumbers(filteredFile);
  140. let globMatchedFiles = ConfigParser.getFilePaths(glob_1.default.sync(filteredFile));
  141. if (fs_1.default.existsSync(filteredFile) && fs_1.default.lstatSync(filteredFile).isFile()) {
  142. filesToFilter.add(path_1.default.resolve(process.cwd(), filteredFile));
  143. }
  144. else if (globMatchedFiles.length) {
  145. globMatchedFiles.forEach(file => filesToFilter.add(file));
  146. }
  147. else {
  148. fileList.forEach(file => {
  149. if (file.match(filteredFile)) {
  150. filesToFilter.add(file);
  151. }
  152. });
  153. }
  154. });
  155. if (filesToFilter.size === 0) {
  156. throw new Error(`spec file(s) ${cliArgFileList.join(', ')} not found`);
  157. }
  158. return [...filesToFilter];
  159. }
  160. getConfig() {
  161. return this._config;
  162. }
  163. getCapabilities(i) {
  164. if (typeof i === 'number' && Array.isArray(this._capabilities) && this._capabilities[i]) {
  165. return this._capabilities[i];
  166. }
  167. return this._capabilities;
  168. }
  169. static getFilePaths(patterns, omitWarnings) {
  170. let files = [];
  171. if (typeof patterns === 'string') {
  172. patterns = [patterns];
  173. }
  174. if (!Array.isArray(patterns)) {
  175. throw new Error('specs or exclude property should be an array of strings');
  176. }
  177. patterns = patterns.map(pattern => utils_1.removeLineNumbers(pattern));
  178. for (let pattern of patterns) {
  179. let filenames = glob_1.default.sync(pattern);
  180. filenames = filenames.filter((filename) => constants_1.SUPPORTED_FILE_EXTENSIONS.find((ext) => filename.endsWith(ext)));
  181. filenames = filenames.map(filename => path_1.default.isAbsolute(filename) ? path_1.default.normalize(filename) : path_1.default.resolve(process.cwd(), filename));
  182. if (filenames.length === 0 && !omitWarnings) {
  183. log.warn('pattern', pattern, 'did not match any file');
  184. }
  185. files = deepmerge_1.default(files, filenames, MERGE_OPTIONS);
  186. }
  187. return files;
  188. }
  189. }
  190. exports.default = ConfigParser;