list-files-plugin.ts 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:off */
  3. import path from 'path';
  4. import {glob} from 'glob';
  5. import SignedFileGenerator from './signed-file-generator';
  6. type GlobPattern = Parameters<typeof glob>[0];
  7. type Options = {
  8. cwd: string;
  9. output: string;
  10. pattern: GlobPattern;
  11. };
  12. class ListFilesPlugin extends SignedFileGenerator<string[]> {
  13. constructor(options: Options) {
  14. super('ListFilesPlugin', options);
  15. }
  16. generateData(files: string[]) {
  17. return Promise.resolve(files);
  18. }
  19. sourceTemplate(data: string[], signingToken: string) {
  20. return `
  21. // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
  22. //
  23. // Generated by ${this.name} (${path.basename(__filename)})
  24. // ${signingToken}
  25. //
  26. // This script contains a list of story files to be dynamically loaded by our
  27. // component library.
  28. const FilesList: string[] = ${JSON.stringify(data)}
  29. export {FilesList}
  30. `;
  31. }
  32. }
  33. export default ListFilesPlugin;