File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const genericNames = require('generic-names');
5
5
const globToRegex = require ( 'glob-to-regexp' ) ;
6
6
const identity = require ( 'lodash' ) . identity ;
7
7
const negate = require ( 'lodash' ) . negate ;
8
+ const camelCaseFunc = require ( 'lodash' ) . camelCase ;
8
9
const readFileSync = require ( 'fs' ) . readFileSync ;
9
10
const relative = require ( 'path' ) . relative ;
10
11
const resolve = require ( 'path' ) . resolve ;
@@ -27,6 +28,7 @@ module.exports = function setupHook({
27
28
preprocessCss = identity ,
28
29
processCss,
29
30
processorOpts,
31
+ camelCase,
30
32
append = [ ] ,
31
33
prepend = [ ] ,
32
34
createImportedName,
@@ -103,6 +105,11 @@ module.exports = function setupHook({
103
105
104
106
tokens = lazyResult . root . tokens ;
105
107
108
+ if ( camelCase ) {
109
+ tokens = Object . assign ( { } , tokens ,
110
+ ...Object . keys ( tokens ) . map ( key => ( { [ camelCaseFunc ( key ) ] : tokens [ key ] } ) ) )
111
+ }
112
+
106
113
if ( ! debugMode ) {
107
114
// updating cache
108
115
tokensByFile [ filename ] = tokens ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const rules = {
10
10
preprocessCss : 'function' ,
11
11
processCss : 'function' ,
12
12
processorOpts : 'object' ,
13
+ camelCase : 'boolean' ,
13
14
// plugins
14
15
append : 'array' ,
15
16
prepend : 'array' ,
Original file line number Diff line number Diff line change
1
+ const detachHook = require ( '../sugar' ) . detachHook ;
2
+ const dropCache = require ( '../sugar' ) . dropCache ;
3
+
4
+ suite ( 'api/camelCase' , ( ) => {
5
+ test ( 'should add camel case keys in token' , ( ) => {
6
+ const tokens = require ( './fixture/bem.css' ) ;
7
+ assert . deepEqual ( tokens , {
8
+ blockElementModifier : '_test_api_fixture_bem__block__element--modifier' ,
9
+ 'block__element--modifier' : '_test_api_fixture_bem__block__element--modifier' ,
10
+ } ) ;
11
+ } ) ;
12
+
13
+ setup ( ( ) => hook ( { camelCase : true } ) ) ;
14
+
15
+ teardown ( ( ) => {
16
+ detachHook ( '.css' ) ;
17
+ dropCache ( './api/fixture/bem.css' ) ;
18
+ } ) ;
19
+ } ) ;
Original file line number Diff line number Diff line change
1
+ .block__element--modifier {
2
+ background : # 1e2a35 ;
3
+ }
You can’t perform that action at this time.
0 commit comments