find-stylesheets.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.findStylesheetFiles = findStylesheetFiles;
  11. const core_1 = require("@angular-devkit/core");
  12. /** Regular expression that matches stylesheet paths */
  13. const STYLESHEET_REGEX = /.*\.(css|scss)$/;
  14. /**
  15. * Finds stylesheets in the given directory from within the specified tree.
  16. * @param tree Devkit tree where stylesheet files can be found in.
  17. * @param startDirectory Optional start directory where stylesheets should be searched in.
  18. * This can be useful if only stylesheets within a given folder are relevant (to avoid
  19. * unnecessary iterations).
  20. */
  21. function findStylesheetFiles(tree, startDirectory = '/') {
  22. const result = [];
  23. const visitDir = (dirPath) => {
  24. const { subfiles, subdirs } = tree.getDir(dirPath);
  25. subfiles.forEach(fileName => {
  26. if (STYLESHEET_REGEX.test(fileName)) {
  27. result.push((0, core_1.join)(dirPath, fileName));
  28. }
  29. });
  30. // Visit directories within the current directory to find other stylesheets.
  31. subdirs.forEach(fragment => {
  32. // Do not visit directories or files inside node modules or `dist/` folders.
  33. if (fragment !== 'node_modules' && fragment !== 'dist') {
  34. visitDir((0, core_1.join)(dirPath, fragment));
  35. }
  36. });
  37. };
  38. visitDir(startDirectory);
  39. return result;
  40. }
  41. //# sourceMappingURL=find-stylesheets.js.map