Skip to content

Commit 8a31cbd

Browse files
authored
Merge pull request #20 from dolymood/master
add camel2Dash option
2 parents ebe612c + 9017dce commit 8a31cbd

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,4 @@ or
133133
- `["component", { "style": cssFilePath }]`: import style css from filePath
134134
- `["component", { "libDir": "lib" }]`: lib directory
135135
- `["component", { "root": "index" }]`: main file dir
136+
- `["component", { "camel2Dash": false }]`: whether parse name to dash mode or not, default `true`

β€Žsrc/core.jsβ€Ž

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export default function (defaultLibraryName) {
1111
let selectedMethods;
1212
let moduleArr;
1313

14-
function camel2Dash(_str) {
14+
function parseName(_str, camel2Dash) {
15+
if (!camel2Dash) {
16+
return _str;
17+
}
1518
const str = _str[0].toLowerCase() + _str.substr(1);
1619
return str.replace(/([A-Z])/g, ($1) => `-${$1.toLowerCase()}`);
1720
}
@@ -35,6 +38,7 @@ export default function (defaultLibraryName) {
3538
style,
3639
styleLibrary,
3740
root = '',
41+
camel2Dash = true,
3842
} = options;
3943
let styleLibraryName = options.styleLibraryName;
4044
let _root = root;
@@ -52,7 +56,7 @@ export default function (defaultLibraryName) {
5256
importAll[path] = true;
5357
}
5458
} else {
55-
path = `${libraryName}/${libDir}/${camel2Dash(methodName)}`;
59+
path = `${libraryName}/${libDir}/${parseName(methodName, camel2Dash)}`;
5660
}
5761
const _path = path;
5862

@@ -83,11 +87,12 @@ export default function (defaultLibraryName) {
8387
} else {
8488
if (cache[libraryName] !== 1) {
8589
/* if set styleLibrary.path(format: [module]/module.css) */
90+
const parsedMethodName = parseName(methodName, camel2Dash);
8691
if (modulePathTpl) {
87-
const modulePath = modulePathTpl.replace(/\[module]/ig, camel2Dash(methodName));
92+
const modulePath = modulePathTpl.replace(/\[module]/ig, parsedMethodName);
8893
path = `${cachePath[libraryName]}/${modulePath}`;
8994
} else {
90-
path = `${cachePath[libraryName]}/${camel2Dash(methodName)}.css`;
95+
path = `${cachePath[libraryName]}/${parsedMethodName}.css`;
9196
}
9297
if (mixin && !isExist(path)) {
9398
path = style === true ? `${_path}/style.css` : `${_path}/${style}`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { inputNumber } from 'antd';
2+
3+
console.log(inputNumber);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var _inputNumber = require('antd/lib/inputNumber');
4+
5+
var _inputNumber2 = _interopRequireDefault(_inputNumber);
6+
7+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8+
9+
console.log(_inputNumber2.default);

β€Žtest/index-test.jsβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ describe('index', () => {
140140
]];
141141
}
142142

143+
if (caseName === 'camel-to-dash-option') {
144+
cssPlugin = [plugin, [
145+
{
146+
libraryName: 'antd',
147+
camel2Dash: false
148+
},
149+
]];
150+
}
151+
143152
const actual = transformFileSync(actualFile, {
144153
presets: ['react'],
145154
plugins: [cssPlugin || plugin],

0 commit comments

Comments
 (0)