rollup-util.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const { readFileSync } = require('fs')
  2. const path = require('path')
  3. const glob = require('glob')
  4. const cleanup = require('rollup-plugin-cleanup')
  5. const sourcemaps = require('rollup-plugin-sourcemaps')
  6. const replace = require('@rollup/plugin-replace')
  7. const handleBars = require('handlebars')
  8. const rootPkgJsonData = require('../../package.json')
  9. exports.EXTERNAL_BROWSER_GLOBALS = {
  10. fullcalendar: 'FullCalendar', // if this gets updated, update codebase...
  11. 'fullcalendar-scheduler': 'FullCalendar',
  12. luxon: 'luxon',
  13. rrule: 'rrule',
  14. moment: 'moment',
  15. 'moment-timezone/builds/moment-timezone-with-data': 'moment' // see moment-timezone/src/main.ts
  16. }
  17. exports.WATCH_OPTIONS = {
  18. chokidar: { // better than default watch util. doesn't fire change events on stat changes (like last opened)
  19. awaitWriteFinish: { // because tsc/rollup sometimes takes a long time to write and triggers two recompiles
  20. stabilityThreshold: 500,
  21. pollInterval: 100
  22. }
  23. },
  24. clearScreen: false // let tsc do the screan clearing
  25. }
  26. exports.SOURCEMAP_PLUGINS = [
  27. sourcemaps(),
  28. // HACK: there's a bug with sourcemap reading and watching: the first rebuild includes the intermediate
  29. // sourceMappingURL comments, confusing consumers of the generated sourcemap. Forcefully remove these comments.
  30. cleanup({ comments: 'none' })
  31. ]
  32. exports.TEMPLATE_PLUGIN = replace({
  33. delimiters: [ '<%= ', ' %>' ],
  34. values: {
  35. version: rootPkgJsonData.version,
  36. releaseDate: new Date().toISOString().replace(/T.*/, '')
  37. // ^TODO: store this in package.json for easier old-release recreation
  38. }
  39. })
  40. exports.renderBanner = handleBars.compile(
  41. readFileSync(
  42. path.join(__dirname, '../../packages/banner.tpl'),
  43. { encoding: 'utf8' }
  44. )
  45. )
  46. const REL_PATH_RE = /^\./
  47. const SCSS_PATH_RE = /\.scss$/i
  48. const TILDE_PATH_RE = /^~/
  49. exports.onwarn = function(warning, warn) {
  50. // ignore circ dep warnings. too numerous and hard to fix right now
  51. if (warning.code !== 'CIRCULAR_DEPENDENCY') {
  52. warn(warning)
  53. }
  54. }
  55. exports.isRelPath = function(path) {
  56. return REL_PATH_RE.test(path)
  57. }
  58. exports.isAbsPath = function(path) { // not x-OS-friendly
  59. return /^\//.test(path)
  60. }
  61. exports.isNamedPkg = function(path) {
  62. return !exports.isRelPath(path) && !exports.isAbsPath(path)
  63. }
  64. exports.isScssPath = function(path) {
  65. return SCSS_PATH_RE.test(path)
  66. }
  67. exports.isStylePath = function(path) {
  68. return /\.s?css$/i.test(path)
  69. }