-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathexport-tailwind-safelist.js
65 lines (57 loc) · 2.04 KB
/
export-tailwind-safelist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
This command should only be run when updating one of the dynamic components or when we add a suport for a custom class on the docs.
EX: - Avo::ButtonComponent
*/
/* eslint-disable no-template-curly-in-string */
const fs = require('fs')
const kebabCase = require('lodash/kebabCase')
const colors = require('tailwindcss/colors')
// Dynamically-built buttons need these classes in prod.
const buttonClasses = [
'bg-${color}-50',
'bg-${color}-500',
'border-${color}-300',
'border-${color}-500',
'hover:bg-${color}-600',
'hover:border-${color}-600',
'active:border-${color}-600',
'active:outline-${color}-600',
'active:bg-${color}-600',
'text-${color}-500',
'text-${color}-700',
'hover:bg-${color}-100',
'active:bg-${color}-100',
'active:border-${color}-500',
'active:outline-${color}-500',
]
const buttonColors = Object.keys(colors)
buttonColors.push(
'primary',
'text-white',
)
const ignoredDynamicClasses = buttonColors.map((color) => buttonClasses.map((buttonClass) => buttonClass.replace('${color}', kebabCase(color))))
// Add the whitespace class for newlines and text alignment
ignoredDynamicClasses.push(
'whitespace-pre-line',
'text-right',
'text-left',
'text-center',
'font-sans',
'font-serif',
'font-mono',
// avo-pro drag and drop feature:
'!bg-gray-100',
'opacity-50',
'select-none',
)
// Add the backgrounds colors that are used by the charts
const chartColors = ['#0B8AE2', '#34C683', '#FFBE4F', '#FF7676', '#2AB1EE', '#34C6A8', '#EC8CFF', '#80FF91', '#FFFC38', '#1BDBE8']
chartColors.forEach((color) => {
ignoredDynamicClasses.push(`bg-[${color}]`)
})
const content = `# This file was auto-generated using the \`yarn export:tailwind-safelist\` command in \`export-tailwind-safelist.js\`\n${ignoredDynamicClasses.flat().join(' ')}`
// Write them into a safelist.txt file until @tailwindcss/jit supports PurgeCSS options
fs.writeFile('./safelist.txt', content, () => {
// eslint-disable-next-line no-console
console.log(`Generated safelist.txt file with ${ignoredDynamicClasses.flat().length} classes.`)
})