@@ -23,12 +23,27 @@ module.exports = function(grunt) {
23
23
grunt . registerTask ( "finna:lessToSass" , function finnaLessToSassFunc ( ) {
24
24
const exclude = grunt . option ( 'exclude' ) ;
25
25
const excludedFiles = exclude ? exclude . split ( ',' ) : [ ] ;
26
+ const include = grunt . option ( 'include' ) ;
27
+ const includedFiles = include ? include . split ( ',' ) : [ ] ;
26
28
27
29
const sharedFileOpts = {
28
30
expand : true ,
29
31
src : [ '*.less' , '**/*.less' ] ,
30
32
filter : function ( filepath ) {
31
- return ! excludedFiles . includes ( filepath ) ;
33
+ if ( includedFiles . length > 0 ) {
34
+ for ( let included of includedFiles ) {
35
+ if ( filepath . endsWith ( included ) ) {
36
+ return true ;
37
+ }
38
+ }
39
+ return false ;
40
+ }
41
+ for ( let excluded of excludedFiles ) {
42
+ if ( filepath . endsWith ( excluded ) ) {
43
+ return false ;
44
+ }
45
+ }
46
+ return true ;
32
47
} ,
33
48
ext : '.scss'
34
49
} ;
@@ -57,96 +72,166 @@ module.exports = function(grunt) {
57
72
dest : 'themes/custom/scss'
58
73
} ,
59
74
] ;
75
+
76
+ const replacements = [
77
+ // Activate SCSS
78
+ {
79
+ pattern : / \/ \* # S C S S > / gi,
80
+ replacement : "/* #SCSS> */" ,
81
+ order : - 1 // Do before anything else
82
+ } ,
83
+ {
84
+ pattern : / < # S C S S \* \/ / gi,
85
+ replacement : "/* <#SCSS */" ,
86
+ order : - 1
87
+ } ,
88
+ // Deactivate LESS
89
+ {
90
+ pattern : / \/ \* # L E S S > \* \/ .* ?\/ \* < # L E S S \* \/ / gis,
91
+ replacement : "" ,
92
+ order : - 1
93
+ } ,
94
+ { // Change separator in @include statements
95
+ pattern : / @ i n c l u d e ( [ ^ \( ] + ) \( ( [ ^ \) ] + ) \) ; / gi,
96
+ replacement : function mixinCommas ( match , $1 , $2 ) {
97
+ return '@include ' + $1 + '(' + $2 . replace ( / ; / g, ',' ) + ');' ;
98
+ } ,
99
+ order : 4 // after defaults included in less-to-sass
100
+ } ,
101
+ { // Remove unquote
102
+ pattern : / u n q u o t e \( " ( [ ^ " ] + ) " \) / gi,
103
+ replacement : function ununquote ( match , $1 ) {
104
+ return $1 ;
105
+ } ,
106
+ order : 4
107
+ } ,
108
+ { // Fix tilde literals
109
+ pattern : / ~ ' ( .* ?) ' / gi,
110
+ replacement : '$1' ,
111
+ order : 4
112
+ } ,
113
+ { // Inline &:extends converted
114
+ pattern : / & : e x t e n d \( ( [ ^ \) ] + ?) ( a l l ) ? \) / gi,
115
+ replacement : '@extend $1' ,
116
+ order : 4
117
+ } ,
118
+ { // Wrap variables in calcs with #{}
119
+ pattern : / c a l c \( [ ^ ; ] + / gi,
120
+ replacement : function calcVariables ( match ) {
121
+ return match . replace ( / ( \$ [ \w \- ] + ) / gi, '#{$1}' ) ;
122
+ } ,
123
+ order : 4
124
+ } ,
125
+ { // Wrap variables set to css variables with #{}
126
+ pattern : / ( - - [ \w - : ] + : \s * ) ( ( \$ | d a r k e n \( | l i g h t e n \( ) [ ^ ; ] + ) / gi,
127
+ replacement : '$1#{$2}' ,
128
+ order : 5
129
+ } ,
130
+ { // Remove !default from extends (icons.scss)
131
+ pattern : / @ e x t e n d ( [ ^ ; } ] + ) ! d e f a u l t ; / gi,
132
+ replacement : '@extend $1;' ,
133
+ order : 6
134
+ } ,
135
+ { // Revert invalid @ => $ changes for css rules:
136
+ pattern : / \$ ( s u p p o r t s | c o n t a i n e r ) \( / gi,
137
+ replacement : '@$1 (' ,
138
+ order : 7
139
+ } ,
140
+ { // Revert @if => $if change:
141
+ pattern : / \$ i f \( / gi,
142
+ replacement : '@if (' ,
143
+ order : 7
144
+ } ,
145
+ { // Revert @use => $use change:
146
+ pattern : / \$ u s e ' / gi,
147
+ replacement : "@use '" ,
148
+ order : 7
149
+ } ,
150
+ { // Fix comparison:
151
+ pattern : / = = < / gi,
152
+ replacement : ' <= ' ,
153
+ order : 7
154
+ } ,
155
+ { // Remove !important from variables:
156
+ pattern : / (?< ! \( .* ) ( \$ .+ ) : ( .+ ) \s * ! i m p o r t a n t \s * ; / g,
157
+ replacement : '$1:$2;' ,
158
+ order : 8
159
+ } ,
160
+ { // fadein => fade-in:
161
+ pattern : / f a d e i n \( ( \S + ) , \s * ( \S + ) \) / g,
162
+ replacement : function ( match , color , adjustment ) {
163
+ return 'fade-in(' + color + ', ' + ( adjustment . replace ( '%' , '' ) / 100 ) + ')' ;
164
+ } ,
165
+ order : 8
166
+ } ,
167
+ { // fadeout => fade-out:
168
+ pattern : / f a d e o u t \( ( \S + ) , \s * ( \S + ) \) / g,
169
+ replacement : function ( match , color , adjustment ) {
170
+ return 'fade-out(' + color + ', ' + ( adjustment . replace ( '%' , '' ) / 100 ) + ')' ;
171
+ } ,
172
+ order : 8
173
+ } ,
174
+ { // replace invalid characters in variable names:
175
+ pattern : / \$ ( [ ^ : } ; / ] + ) / g,
176
+ replacement : function ( match , variable ) {
177
+ return '$' + variable . replace ( '.' , '__' ) ;
178
+ } ,
179
+ order : 9
180
+ } ,
181
+ ] ;
182
+ if ( ! grunt . option ( 'no-default' ) ) {
183
+ replacements . push (
184
+ { // Add !default (but avoid messing with function params):
185
+ pattern : / (?< ! \( .* ) ( \$ .+ ) : ( .+ ) ; / g,
186
+ replacement : '$1:$2 !default;' ,
187
+ order : 19
188
+ }
189
+ ) ;
190
+ }
191
+ if ( grunt . option ( 'replace-vars' ) ) {
192
+ const vars = {
193
+ 'action-link-color' : '#007c90' ,
194
+ 'gray-lighter' : '#d1d1d1' ,
195
+ 'gray-ultralight' : '#f7f7f7' ,
196
+ 'gray-light' : '#595959' ,
197
+ 'gray-darker' : '#000' ,
198
+ 'gray-dark' : '#121212' ,
199
+ 'gray' : '#2b2b2b' ,
200
+ 'body-bg' : '#fff' ,
201
+ 'screen-xs' : '480px' ,
202
+ 'screen-xs-min' : '480px' ,
203
+ 'screen-xs-max' : '767px' ,
204
+ 'screen-sm' : '768px' ,
205
+ 'screen-sm-min' : '768px' ,
206
+ 'screen-md' : '992px' ,
207
+ 'screen-md-min' : '992px' ,
208
+ 'navbar-default-link-color' : '#fff' ,
209
+ 'content-font-size-base' : '16px' ,
210
+ 'content-headings-font-size-h1' : '28px' ,
211
+ 'content-headings-font-size-h2' : '24px' ,
212
+ 'content-headings-font-size-h3' : '21px' ,
213
+ 'content-headings-font-size-h4' : '18px' ,
214
+ } ;
215
+ let order = 20 ;
216
+ // Change variables where used (but not where declared!):
217
+ Object . entries ( vars ) . forEach ( ( [ src , dst ] ) => {
218
+ replacements . push (
219
+ {
220
+ pattern : new RegExp ( "(.+)\\$(" + src + ")\\b" , "g" ) ,
221
+ replacement : '$1' + dst + ' /* $2 */' ,
222
+ order : order
223
+ }
224
+ ) ;
225
+ ++ order ;
226
+ } ) ;
227
+ }
228
+
60
229
console . log ( themeDir ? "Converting theme " + themeDir : "Converting Finna default themes" ) ;
61
230
grunt . config . set ( 'lessToSass' , {
62
231
convert : {
63
232
files : files ,
64
233
options : {
65
- replacements : [
66
- // Activate SCSS
67
- {
68
- pattern : / \/ \* # S C S S > / gi,
69
- replacement : "/* #SCSS> */" ,
70
- order : - 1 // Do before anything else
71
- } ,
72
- {
73
- pattern : / < # S C S S \* \/ / gi,
74
- replacement : "/* <#SCSS */" ,
75
- order : - 1
76
- } ,
77
- // Deactivate LESS
78
- {
79
- pattern : / \/ \* # L E S S > \* \/ .* ?\/ \* < # L E S S \* \/ / gis,
80
- replacement : "" ,
81
- order : - 1
82
- } ,
83
- { // Change separator in @include statements
84
- pattern : / @ i n c l u d e ( [ ^ \( ] + ) \( ( [ ^ \) ] + ) \) ; / gi,
85
- replacement : function mixinCommas ( match , $1 , $2 ) {
86
- return '@include ' + $1 + '(' + $2 . replace ( / ; / g, ',' ) + ');' ;
87
- } ,
88
- order : 4 // after defaults included in less-to-sass
89
- } ,
90
- { // Remove unquote
91
- pattern : / u n q u o t e \( " ( [ ^ " ] + ) " \) / gi,
92
- replacement : function ununquote ( match , $1 ) {
93
- return $1 ;
94
- } ,
95
- order : 4
96
- } ,
97
- { // Fix tilde literals
98
- pattern : / ~ ' ( .* ?) ' / gi,
99
- replacement : '$1' ,
100
- order : 4
101
- } ,
102
- { // Inline &:extends converted
103
- pattern : / & : e x t e n d \( ( [ ^ \) ] + ?) ( a l l ) ? \) / gi,
104
- replacement : '@extend $1' ,
105
- order : 4
106
- } ,
107
- { // Wrap variables in calcs with #{}
108
- pattern : / c a l c \( [ ^ ; ] + / gi,
109
- replacement : function calcVariables ( match ) {
110
- return match . replace ( / ( \$ [ \w \- ] + ) / gi, '#{$1}' ) ;
111
- } ,
112
- order : 4
113
- } ,
114
- { // Wrap variables set to css variables with #{}
115
- pattern : / ( - - [ \w - : ] + : \s * ) ( ( \$ | d a r k e n \( | l i g h t e n \( ) [ ^ ; ] + ) / gi,
116
- replacement : '$1#{$2}' ,
117
- order : 5
118
- } ,
119
- { // Remove !default from extends (icons.scss)
120
- pattern : / @ e x t e n d ( [ ^ ; } ] + ) ! d e f a u l t ; / gi,
121
- replacement : '@extend $1;' ,
122
- order : 6
123
- } ,
124
- { // Revert invalid @ => $ changes for css rules:
125
- pattern : / \$ ( s u p p o r t s | c o n t a i n e r ) \( / gi,
126
- replacement : '@$1 (' ,
127
- order : 7
128
- } ,
129
- { // Revert @if => $if change:
130
- pattern : / \$ i f \( / gi,
131
- replacement : '@if (' ,
132
- order : 7
133
- } ,
134
- { // Revert @use => $use change:
135
- pattern : / \$ u s e ' / gi,
136
- replacement : "@use '" ,
137
- order : 7
138
- } ,
139
- { // Fix comparison:
140
- pattern : / = = < / gi,
141
- replacement : ' <= ' ,
142
- order : 7
143
- } ,
144
- { // Add !default (but avoid messing with function params):
145
- pattern : / (?< ! \( .* ) ( \$ .+ ) : ( .+ ) ; / g,
146
- replacement : '$1:$2 !default;' ,
147
- order : 8
148
- }
149
- ]
234
+ replacements : replacements
150
235
}
151
236
}
152
237
} ) ;
0 commit comments