zip.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. import JSZip from 'jszip';
  4. import {glob} from 'glob';
  5. async function main() {
  6. const zip = new JSZip();
  7. const filesToInclude = [
  8. './index.html',
  9. './dist/**',
  10. './*/*.md'
  11. ];
  12. if (fs.existsSync('./lib')) filesToInclude.push('./lib/**');
  13. if (fs.existsSync('./images')) filesToInclude.push('./images/**');
  14. if (fs.existsSync('./slides')) filesToInclude.push('./slides/**');
  15. for (const pattern of filesToInclude) {
  16. const files = glob.sync(pattern, {
  17. nodir: true,
  18. dot: true,
  19. ignore: ['./examples/**', './test/**']
  20. });
  21. for (const file of files) {
  22. const filePath = path.resolve(file);
  23. const relativePath = path.relative(process.cwd(), filePath);
  24. const fileData = fs.readFileSync(filePath);
  25. zip.file(relativePath, fileData);
  26. }
  27. }
  28. const content = await zip.generateAsync({ type: 'nodebuffer' });
  29. fs.writeFileSync('reveal-js-presentation.zip', content);
  30. console.log('Presentation packaged successfully: reveal-js-presentation.zip');
  31. }
  32. main().catch(error => {
  33. console.error('Error packaging presentation:', error);
  34. process.exit(1);
  35. });