frappe-ui 0.1.245 → 0.1.246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/tailwind/colorPalette.js +0 -131
- package/src/tailwind/colors.js +0 -642
- package/src/tailwind/colors.json +0 -499
- package/src/tailwind/figma-variables-to-colors.js +0 -150
- package/src/tailwind/plugin.js +0 -401
- package/src/tailwind/preset.js +0 -9
- package/src/tailwind/update-tailwind-classes.js +0 -102
package/src/tailwind/plugin.js
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import plugin from 'tailwindcss/plugin'
|
|
2
|
-
import {
|
|
3
|
-
generateColorPalette,
|
|
4
|
-
generateSemanticColors,
|
|
5
|
-
generateCSSVariables,
|
|
6
|
-
} from './colorPalette.js'
|
|
7
|
-
|
|
8
|
-
let colorPalette = generateColorPalette()
|
|
9
|
-
let semanticColors = generateSemanticColors()
|
|
10
|
-
let cssVariables = generateCSSVariables()
|
|
11
|
-
|
|
12
|
-
let globalStyles = (theme) => ({
|
|
13
|
-
html: {
|
|
14
|
-
'font-family': `InterVar, ${theme('fontFamily.sans')}`,
|
|
15
|
-
'font-optical-sizing': 'auto',
|
|
16
|
-
},
|
|
17
|
-
'html, body, button, p, span, div': {
|
|
18
|
-
fontVariationSettings: "'opsz' 24",
|
|
19
|
-
WebkitFontSmoothing: 'antialiased',
|
|
20
|
-
MozOsxFontSmoothing: 'grayscale',
|
|
21
|
-
},
|
|
22
|
-
select: {
|
|
23
|
-
backgroundImage:
|
|
24
|
-
'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="%237C7C7C" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" aria-hidden="true" viewBox="0 0 24 24" ><path d="m6 9 6 6 6-6" /></svg>\')',
|
|
25
|
-
backgroundSize: '1.13em',
|
|
26
|
-
backgroundPosition: 'right 0.44rem center',
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
let componentStyles = {
|
|
31
|
-
'.form-input, .form-textarea, .form-select': {
|
|
32
|
-
'@apply h-7 rounded border border-[--surface-gray-2] bg-surface-gray-2 py-1.5 pl-2 pr-2 text-base text-ink-gray-8 placeholder-ink-gray-4 transition-colors hover:border-outline-gray-modals hover:bg-surface-gray-3 focus:border-outline-gray-4 focus:bg-surface-white focus:shadow-sm focus:ring-0 focus-visible:ring-2 focus-visible:ring-outline-gray-3':
|
|
33
|
-
{},
|
|
34
|
-
},
|
|
35
|
-
'.form-checkbox': {
|
|
36
|
-
'@apply rounded-md bg-surface-gray-2 text-ink-blue-2 focus:ring-0 focus-visible:ring-1':
|
|
37
|
-
{},
|
|
38
|
-
},
|
|
39
|
-
"[data-theme='dark'] [type='checkbox']:checked": {
|
|
40
|
-
'background-image': `url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='%230F0F0F' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e")`,
|
|
41
|
-
},
|
|
42
|
-
"[data-theme='dark'] img": {
|
|
43
|
-
filter: 'brightness(.8) contrast(1.2)',
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default plugin(
|
|
48
|
-
function ({ addBase, addComponents, theme }) {
|
|
49
|
-
addBase({ ...globalStyles(theme), ...cssVariables })
|
|
50
|
-
addComponents(componentStyles)
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
theme: {
|
|
54
|
-
colors: colorPalette,
|
|
55
|
-
borderRadius: {
|
|
56
|
-
none: '0px', // 0
|
|
57
|
-
sm: '0.25rem', // 4px
|
|
58
|
-
DEFAULT: '0.5rem', // 8px
|
|
59
|
-
md: '0.625rem', // 10px
|
|
60
|
-
lg: '0.75rem', // 12px
|
|
61
|
-
xl: '1rem', // 16px
|
|
62
|
-
'2xl': '1.25rem', // 20px
|
|
63
|
-
full: '9999px', // 9999px
|
|
64
|
-
},
|
|
65
|
-
boxShadow: {
|
|
66
|
-
sm: '0px 1px 2px rgba(0, 0, 0, 0.1)',
|
|
67
|
-
DEFAULT:
|
|
68
|
-
'0px 0px 1px rgba(0, 0, 0, 0.45), 0px 1px 2px rgba(0, 0, 0, 0.1)',
|
|
69
|
-
md: '0px 0px 1px rgba(0, 0, 0, 0.12), 0px 0.5px 2px rgba(0, 0, 0, 0.15), 0px 2px 3px rgba(0, 0, 0, 0.16)',
|
|
70
|
-
lg: '0px 0px 1px rgba(0, 0, 0, 0.35), 0px 6px 8px -4px rgba(0, 0, 0, 0.1)',
|
|
71
|
-
xl: '0px 0px 1px rgba(0, 0, 0, 0.19), 0px 1px 2px rgba(0, 0, 0, 0.07), 0px 6px 15px -5px rgba(0, 0, 0, 0.11)',
|
|
72
|
-
'2xl':
|
|
73
|
-
'0px 0px 1px rgba(0, 0, 0, 0.2), 0px 1px 3px rgba(0, 0, 0, 0.05), 0px 10px 24px -3px rgba(0, 0, 0, 0.1)',
|
|
74
|
-
none: 'none',
|
|
75
|
-
},
|
|
76
|
-
container: {
|
|
77
|
-
padding: {
|
|
78
|
-
xl: '5rem',
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
fontSize: {
|
|
82
|
-
'2xs': [
|
|
83
|
-
'11px',
|
|
84
|
-
{
|
|
85
|
-
lineHeight: '1.15',
|
|
86
|
-
letterSpacing: '0.01em',
|
|
87
|
-
fontWeight: '420',
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
xs: [
|
|
91
|
-
'12px',
|
|
92
|
-
{
|
|
93
|
-
lineHeight: '1.15',
|
|
94
|
-
letterSpacing: '0.02em',
|
|
95
|
-
fontWeight: '420',
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
sm: [
|
|
99
|
-
'13px',
|
|
100
|
-
{
|
|
101
|
-
lineHeight: '1.15',
|
|
102
|
-
letterSpacing: '0.02em',
|
|
103
|
-
fontWeight: '420',
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
base: [
|
|
107
|
-
'14px',
|
|
108
|
-
{
|
|
109
|
-
lineHeight: '1.15',
|
|
110
|
-
letterSpacing: '0.02em',
|
|
111
|
-
fontWeight: '420',
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
lg: [
|
|
115
|
-
'16px',
|
|
116
|
-
{
|
|
117
|
-
lineHeight: '1.15',
|
|
118
|
-
letterSpacing: '0.02em',
|
|
119
|
-
fontWeight: '400',
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
xl: [
|
|
123
|
-
'18px',
|
|
124
|
-
{
|
|
125
|
-
lineHeight: '1.15',
|
|
126
|
-
letterSpacing: '0.01em',
|
|
127
|
-
fontWeight: '400',
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
'2xl': [
|
|
131
|
-
'20px',
|
|
132
|
-
{
|
|
133
|
-
lineHeight: '1.15',
|
|
134
|
-
letterSpacing: '0.01em',
|
|
135
|
-
fontWeight: '400',
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
'3xl': [
|
|
139
|
-
'24px',
|
|
140
|
-
{
|
|
141
|
-
lineHeight: '1.15',
|
|
142
|
-
fontWeight: 400,
|
|
143
|
-
letterSpacing: '0.005em',
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
// font size for paragraphs
|
|
147
|
-
'p-2xs': [
|
|
148
|
-
'11px',
|
|
149
|
-
{
|
|
150
|
-
lineHeight: '1.6',
|
|
151
|
-
letterSpacing: '0.01em',
|
|
152
|
-
fontWeight: '420',
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
'p-xs': [
|
|
156
|
-
'12px',
|
|
157
|
-
{
|
|
158
|
-
lineHeight: '1.6',
|
|
159
|
-
letterSpacing: '0.02em',
|
|
160
|
-
fontWeight: '420',
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
'p-sm': [
|
|
164
|
-
'13px',
|
|
165
|
-
{
|
|
166
|
-
lineHeight: '1.5',
|
|
167
|
-
letterSpacing: '0.02em',
|
|
168
|
-
fontWeight: '420',
|
|
169
|
-
},
|
|
170
|
-
],
|
|
171
|
-
'p-base': [
|
|
172
|
-
'14px',
|
|
173
|
-
{
|
|
174
|
-
lineHeight: '1.5',
|
|
175
|
-
letterSpacing: '0.02em',
|
|
176
|
-
fontWeight: '420',
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
'p-lg': [
|
|
180
|
-
'16px',
|
|
181
|
-
{
|
|
182
|
-
lineHeight: '1.5',
|
|
183
|
-
letterSpacing: '0.02em',
|
|
184
|
-
fontWeight: '400',
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
'p-xl': [
|
|
188
|
-
'18px',
|
|
189
|
-
{
|
|
190
|
-
lineHeight: '1.42',
|
|
191
|
-
letterSpacing: '0.01em',
|
|
192
|
-
fontWeight: '400',
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
'p-2xl': [
|
|
196
|
-
'20px',
|
|
197
|
-
{
|
|
198
|
-
lineHeight: '1.38',
|
|
199
|
-
letterSpacing: '0.01em',
|
|
200
|
-
fontWeight: '400',
|
|
201
|
-
},
|
|
202
|
-
],
|
|
203
|
-
'p-3xl': [
|
|
204
|
-
'24px',
|
|
205
|
-
{
|
|
206
|
-
lineHeight: '1.2',
|
|
207
|
-
fontWeight: 400,
|
|
208
|
-
letterSpacing: '0.005em',
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
},
|
|
212
|
-
screens: {
|
|
213
|
-
sm: '640px',
|
|
214
|
-
md: '768px',
|
|
215
|
-
lg: '1024px',
|
|
216
|
-
xl: '1280px',
|
|
217
|
-
},
|
|
218
|
-
extend: {
|
|
219
|
-
textColor: {
|
|
220
|
-
ink: semanticColors.ink,
|
|
221
|
-
},
|
|
222
|
-
backgroundColor: {
|
|
223
|
-
surface: semanticColors.surface,
|
|
224
|
-
},
|
|
225
|
-
fill: {
|
|
226
|
-
ink: semanticColors.ink,
|
|
227
|
-
surface: semanticColors.surface,
|
|
228
|
-
},
|
|
229
|
-
stroke: {
|
|
230
|
-
ink: semanticColors.ink,
|
|
231
|
-
},
|
|
232
|
-
placeholderColor: {
|
|
233
|
-
ink: semanticColors.ink,
|
|
234
|
-
},
|
|
235
|
-
borderColor: () => ({
|
|
236
|
-
DEFAULT: 'var(--outline-gray-1)',
|
|
237
|
-
outline: semanticColors.outline,
|
|
238
|
-
}),
|
|
239
|
-
ringColor: {
|
|
240
|
-
outline: semanticColors.outline,
|
|
241
|
-
},
|
|
242
|
-
divideColor: {
|
|
243
|
-
outline: semanticColors.outline,
|
|
244
|
-
},
|
|
245
|
-
spacing: {
|
|
246
|
-
4.5: '1.125rem',
|
|
247
|
-
5.5: '1.375rem',
|
|
248
|
-
6.5: '1.625rem',
|
|
249
|
-
7.5: '1.875rem',
|
|
250
|
-
8.5: '2.125rem',
|
|
251
|
-
9.5: '2.375rem',
|
|
252
|
-
10.5: '2.625rem',
|
|
253
|
-
11.5: '2.875rem',
|
|
254
|
-
12.5: '3.125rem',
|
|
255
|
-
13: '3.25rem',
|
|
256
|
-
13.5: '3.375rem',
|
|
257
|
-
14.5: '3.625rem',
|
|
258
|
-
15: '3.75rem',
|
|
259
|
-
15.5: '3.875rem',
|
|
260
|
-
},
|
|
261
|
-
width: {
|
|
262
|
-
3.5: '0.875rem',
|
|
263
|
-
112: '28rem',
|
|
264
|
-
wizard: '650px',
|
|
265
|
-
},
|
|
266
|
-
height: {
|
|
267
|
-
3.5: '0.875rem',
|
|
268
|
-
},
|
|
269
|
-
minWidth: {
|
|
270
|
-
40: '10rem',
|
|
271
|
-
50: '18rem',
|
|
272
|
-
},
|
|
273
|
-
maxHeight: {
|
|
274
|
-
52: '13rem',
|
|
275
|
-
},
|
|
276
|
-
typography: (theme) => ({
|
|
277
|
-
DEFAULT: {
|
|
278
|
-
css: {
|
|
279
|
-
'--tw-prose-body': 'var(--ink-gray-8)',
|
|
280
|
-
'--tw-prose-headings': 'var(--ink-gray-9)',
|
|
281
|
-
'--tw-prose-lead': 'var(--ink-gray-5)',
|
|
282
|
-
'--tw-prose-links': 'var(--ink-gray-9)',
|
|
283
|
-
'--tw-prose-bold': 'var(--ink-gray-9)',
|
|
284
|
-
'--tw-prose-counters': 'var(--ink-gray-4)',
|
|
285
|
-
'--tw-prose-bullets': 'var(--ink-gray-2)',
|
|
286
|
-
'--tw-prose-hr': 'var(--ink-gray-1)',
|
|
287
|
-
'--tw-prose-quotes': 'var(--ink-gray-8)',
|
|
288
|
-
'--tw-prose-quote-borders': 'var(--ink-gray-1)',
|
|
289
|
-
'--tw-prose-captions': 'var(--ink-gray-4)',
|
|
290
|
-
'--tw-prose-kbd': 'var(--ink-gray-9)',
|
|
291
|
-
'--tw-prose-code': 'var(--ink-gray-9)',
|
|
292
|
-
'--tw-prose-pre-code': 'var(--ink-gray-1)',
|
|
293
|
-
'--tw-prose-pre-bg': 'var(--ink-gray-8)',
|
|
294
|
-
'--tw-prose-th-borders': 'var(--ink-gray-2)',
|
|
295
|
-
'--tw-prose-td-borders': 'var(--ink-gray-1)',
|
|
296
|
-
h1: {
|
|
297
|
-
fontWeight: 600,
|
|
298
|
-
},
|
|
299
|
-
h2: {
|
|
300
|
-
fontWeight: 600,
|
|
301
|
-
},
|
|
302
|
-
h3: {
|
|
303
|
-
fontWeight: 600,
|
|
304
|
-
},
|
|
305
|
-
h4: {
|
|
306
|
-
fontWeight: 600,
|
|
307
|
-
},
|
|
308
|
-
h5: {
|
|
309
|
-
fontWeight: 600,
|
|
310
|
-
},
|
|
311
|
-
'h1 strong': {
|
|
312
|
-
fontWeight: 600,
|
|
313
|
-
},
|
|
314
|
-
'h2 strong': {
|
|
315
|
-
fontWeight: 600,
|
|
316
|
-
},
|
|
317
|
-
'h3 strong': {
|
|
318
|
-
fontWeight: 600,
|
|
319
|
-
},
|
|
320
|
-
'h4 strong': {
|
|
321
|
-
fontWeight: 600,
|
|
322
|
-
},
|
|
323
|
-
'h5 strong': {
|
|
324
|
-
fontWeight: 600,
|
|
325
|
-
},
|
|
326
|
-
'img[data-align=right]': {
|
|
327
|
-
marginLeft: 'auto',
|
|
328
|
-
marginRight: '0',
|
|
329
|
-
},
|
|
330
|
-
'img[data-align=center]': {
|
|
331
|
-
marginLeft: 'auto',
|
|
332
|
-
marginRight: 'auto',
|
|
333
|
-
},
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
sm: {
|
|
337
|
-
css: {
|
|
338
|
-
fontSize: '14px',
|
|
339
|
-
fontWeight: 420,
|
|
340
|
-
lineHeight: 1.5,
|
|
341
|
-
letterSpacing: '0.02em',
|
|
342
|
-
h1: {
|
|
343
|
-
fontSize: em(20, 14),
|
|
344
|
-
},
|
|
345
|
-
h2: {
|
|
346
|
-
fontSize: em(18, 14),
|
|
347
|
-
},
|
|
348
|
-
h3: {
|
|
349
|
-
fontSize: em(16, 14),
|
|
350
|
-
},
|
|
351
|
-
h4: {
|
|
352
|
-
fontSize: em(14, 14),
|
|
353
|
-
},
|
|
354
|
-
h5: {
|
|
355
|
-
fontSize: em(13, 14),
|
|
356
|
-
},
|
|
357
|
-
p: {
|
|
358
|
-
marginTop: '0.5rem',
|
|
359
|
-
marginBottom: '0.5rem',
|
|
360
|
-
},
|
|
361
|
-
'ul > li': {
|
|
362
|
-
margin: '0.5rem 0',
|
|
363
|
-
'> p': {
|
|
364
|
-
margin: '0.5rem 0',
|
|
365
|
-
},
|
|
366
|
-
'> p:first-child:last-child': {
|
|
367
|
-
margin: '0.5rem 0',
|
|
368
|
-
},
|
|
369
|
-
'> p:first-child': {
|
|
370
|
-
marginTop: '0.5rem',
|
|
371
|
-
},
|
|
372
|
-
'> p:last-child': {
|
|
373
|
-
marginBottom: '0.5rem',
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
'ol > li': {
|
|
377
|
-
margin: '0.5rem 0',
|
|
378
|
-
'> p': {
|
|
379
|
-
margin: '0.5rem 0',
|
|
380
|
-
},
|
|
381
|
-
'> p:first-child:last-child': {
|
|
382
|
-
margin: '0.5rem 0',
|
|
383
|
-
},
|
|
384
|
-
'> p:first-child': {
|
|
385
|
-
marginTop: '0.5rem',
|
|
386
|
-
},
|
|
387
|
-
'> p:last-child': {
|
|
388
|
-
marginBottom: '0.5rem',
|
|
389
|
-
},
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
},
|
|
393
|
-
}),
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
}
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
function em(pixels, base = 16) {
|
|
400
|
-
return `${pixels / base}em`
|
|
401
|
-
}
|
package/src/tailwind/preset.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import themePlugin from './plugin.js'
|
|
2
|
-
import forms from '@tailwindcss/forms'
|
|
3
|
-
import typography from '@tailwindcss/typography'
|
|
4
|
-
|
|
5
|
-
/** @type {import('tailwindcss').Config} */
|
|
6
|
-
export default {
|
|
7
|
-
darkMode: ['selector', '[data-theme="dark"]'],
|
|
8
|
-
plugins: [forms, typography, themePlugin],
|
|
9
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import colors from './colors.json' assert { type: 'json' }
|
|
4
|
-
|
|
5
|
-
function generateClassMap() {
|
|
6
|
-
const classMap = {
|
|
7
|
-
'text-white': 'text-ink-white',
|
|
8
|
-
'bg-white': 'bg-surface-white',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Generate surface class map
|
|
12
|
-
Object.keys(colors.themedVariables.light.surface).forEach((key) => {
|
|
13
|
-
const reference = colors.themedVariables.light.surface[key]
|
|
14
|
-
const [mode, color, shade] = reference.split('/')
|
|
15
|
-
const className = `bg-${color}-${shade}`
|
|
16
|
-
const surfaceClassName = `bg-surface-${key}`
|
|
17
|
-
classMap[className] = surfaceClassName
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// Generate outline class map
|
|
21
|
-
Object.keys(colors.themedVariables.light.outline).forEach((key) => {
|
|
22
|
-
const reference = colors.themedVariables.light.outline[key]
|
|
23
|
-
const [mode, color, shade] = reference.split('/')
|
|
24
|
-
const borderClassName = `border-${color}-${shade}`
|
|
25
|
-
const divideClassName = `divide-${color}-${shade}`
|
|
26
|
-
const ringClassName = `ring-${color}-${shade}`
|
|
27
|
-
const outlineClassName = `border-outline-${key}`
|
|
28
|
-
const divideOutlineClassName = `divide-outline-${key}`
|
|
29
|
-
const ringOutlineClassName = `ring-outline-${key}`
|
|
30
|
-
classMap[borderClassName] = outlineClassName
|
|
31
|
-
classMap[divideClassName] = divideOutlineClassName
|
|
32
|
-
classMap[ringClassName] = ringOutlineClassName
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
// Generate ink class map
|
|
36
|
-
Object.keys(colors.themedVariables.light.ink).forEach((key) => {
|
|
37
|
-
const reference = colors.themedVariables.light.ink[key]
|
|
38
|
-
const [mode, color, shade] = reference.split('/')
|
|
39
|
-
const className = `text-${color}-${shade}`
|
|
40
|
-
const inkClassName = `text-ink-${key}`
|
|
41
|
-
const placeholderClassName = `placeholder-${color}-${shade}`
|
|
42
|
-
const placeholderInkClassName = `placeholder-ink-${key}`
|
|
43
|
-
classMap[className] = inkClassName
|
|
44
|
-
classMap[placeholderClassName] = placeholderInkClassName
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
return classMap
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function replaceClassesInFile(filePath, classMap) {
|
|
51
|
-
let fileContent = fs.readFileSync(filePath, 'utf8')
|
|
52
|
-
let classesChanged = 0
|
|
53
|
-
|
|
54
|
-
Object.keys(classMap).forEach((key) => {
|
|
55
|
-
const value = classMap[key]
|
|
56
|
-
const regex = new RegExp(`\\b${key}\\b`, 'g')
|
|
57
|
-
const matches = fileContent.match(regex)
|
|
58
|
-
if (matches) {
|
|
59
|
-
classesChanged += matches.length
|
|
60
|
-
}
|
|
61
|
-
fileContent = fileContent.replace(regex, value)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
fs.writeFileSync(filePath, fileContent, 'utf8')
|
|
65
|
-
console.log(`Replaced ${classesChanged} classes in ${filePath}`)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function replaceClassesInFolder(targetPath, classMap) {
|
|
69
|
-
const files = fs.readdirSync(targetPath)
|
|
70
|
-
|
|
71
|
-
files.forEach((file) => {
|
|
72
|
-
const fullPath = path.join(targetPath, file)
|
|
73
|
-
const stat = fs.statSync(fullPath)
|
|
74
|
-
|
|
75
|
-
if (stat.isDirectory()) {
|
|
76
|
-
replaceClassesInFolder(fullPath, classMap)
|
|
77
|
-
} else if (stat.isFile()) {
|
|
78
|
-
replaceClassesInFile(fullPath, classMap)
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getPath() {
|
|
84
|
-
let targetPath = process.argv[2]
|
|
85
|
-
let fullPath = path.resolve(process.cwd(), targetPath)
|
|
86
|
-
if (fs.existsSync(fullPath)) {
|
|
87
|
-
return fullPath
|
|
88
|
-
}
|
|
89
|
-
console.error(`Invalid path: ${fullPath}`)
|
|
90
|
-
process.exit(1)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Generate the class map
|
|
94
|
-
const classMap = generateClassMap()
|
|
95
|
-
|
|
96
|
-
const targetPath = getPath()
|
|
97
|
-
let stats = fs.statSync(targetPath)
|
|
98
|
-
if (stats.isFile()) {
|
|
99
|
-
replaceClassesInFile(targetPath, classMap)
|
|
100
|
-
} else if (stats.isDirectory()) {
|
|
101
|
-
replaceClassesInFolder(targetPath, classMap)
|
|
102
|
-
}
|