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.

FileCache.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. const debug = require('debug')('stylelint:file-cache');
  3. const fileEntryCache = require('file-entry-cache');
  4. const getCacheFile = require('./getCacheFile');
  5. const path = require('path');
  6. const DEFAULT_CACHE_LOCATION = './.stylelintcache';
  7. const DEFAULT_HASH = '';
  8. /** @typedef {import('file-entry-cache').FileDescriptor["meta"] & { hashOfConfig?: string }} CacheMetadata */
  9. /**
  10. * @param {string} [cacheLocation]
  11. * @param {string} [hashOfConfig]
  12. * @constructor
  13. */
  14. class FileCache {
  15. constructor(cacheLocation = DEFAULT_CACHE_LOCATION, hashOfConfig = DEFAULT_HASH) {
  16. const cacheFile = path.resolve(getCacheFile(cacheLocation, process.cwd()));
  17. debug(`Cache file is created at ${cacheFile}`);
  18. this._fileCache = fileEntryCache.create(cacheFile);
  19. this._hashOfConfig = hashOfConfig;
  20. }
  21. /**
  22. * @param {string} absoluteFilepath
  23. * @return {boolean}
  24. */
  25. hasFileChanged(absoluteFilepath) {
  26. // Get file descriptor compares current metadata against cached
  27. // one and stores the result to "changed" prop.w
  28. const descriptor = this._fileCache.getFileDescriptor(absoluteFilepath);
  29. /** @type {CacheMetadata} */
  30. const meta = descriptor.meta || {};
  31. const changed = descriptor.changed || meta.hashOfConfig !== this._hashOfConfig;
  32. if (!changed) {
  33. debug(`Skip linting ${absoluteFilepath}. File hasn't changed.`);
  34. }
  35. // Mutate file descriptor object and store config hash to each file.
  36. // Running lint with different config should invalidate the cache.
  37. if (meta.hashOfConfig !== this._hashOfConfig) {
  38. meta.hashOfConfig = this._hashOfConfig;
  39. }
  40. return changed;
  41. }
  42. reconcile() {
  43. this._fileCache.reconcile();
  44. }
  45. destroy() {
  46. this._fileCache.destroy();
  47. }
  48. /**
  49. * @param {string} absoluteFilepath
  50. */
  51. removeEntry(absoluteFilepath) {
  52. this._fileCache.removeEntry(absoluteFilepath);
  53. }
  54. }
  55. module.exports = FileCache;