add-banner.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env node
  2. 'use strict'
  3. import { readFileSync, writeFileSync } from 'node:fs';
  4. import { join, dirname, basename } from 'node:path';
  5. import { fileURLToPath } from 'node:url'
  6. import { sync } from 'glob';
  7. import banner from '@repo/banner';
  8. const __dirname = dirname(fileURLToPath(import.meta.url))
  9. const styles = sync(join(__dirname, '..', 'dist', 'css', '*.css'))
  10. const plugins = {
  11. 'tabler-flags': 'Flags',
  12. 'tabler-flags.rtl': 'Flags RTL',
  13. 'tabler-marketing': 'Marketing',
  14. 'tabler-marketing.rtl': 'Marketing RTL',
  15. 'tabler-payments': 'Payments',
  16. 'tabler-payments.rtl': 'Payments RTL',
  17. 'tabler-socials': 'Socials',
  18. 'tabler-socials.rtl': 'Socials RTL',
  19. 'tabler-vendors': 'Vendors',
  20. 'tabler-vendors.rtl': 'Vendors RTL',
  21. }
  22. styles.forEach((file, i) => {
  23. const content = readFileSync(file, 'utf8')
  24. const filename = basename(file)
  25. const pluginKey = Object.keys(plugins).find(plugin => filename.includes(plugin))
  26. const plugin = plugins[pluginKey]
  27. const regex = /^(@charset ['"][a-zA-Z0-9-]+['"];?)\n?/i
  28. let newContent = ''
  29. if (content.match(regex)) {
  30. newContent = content.replace(regex, (m, m1) => {
  31. return `${m1}\n${banner(plugin)}\n`
  32. })
  33. } else {
  34. newContent = `${banner(plugin)}\n${content}`
  35. }
  36. writeFileSync(file, newContent, 'utf8')
  37. })