Skip to content

Commit 2ebf66b

Browse files
author
Vladimir Belov
committed
Updated namespace generation
1 parent 366abb9 commit 2ebf66b

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/tools/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import {resolve, basename} from 'path';
44
import Logger from '@bitrix/logger';
5+
import colors from 'colors/safe';
56
import Directory from '../entities/directory';
67
import concat from './concat';
78
import report from './report';
89
import test from './test';
9-
import colors from 'colors/safe';
1010
import rollupBundle from './build/rollup';
1111
import adjustExtension from './build/adjust-extension';
1212
import adjustEncoding from './build/adjust-encoding';

src/utils/build-namespace-name.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
export default function buildNamespaceName({root = '', extensionName} = {}) {
1+
// @flow
2+
interface BuildNamespaceOptions {
3+
root: string,
4+
extensionName: string,
5+
}
6+
7+
function buildNamespaceName({root = '', extensionName}: BuildNamespaceOptions = {}) {
28
if (typeof extensionName === 'string') {
3-
const fragments = extensionName.split('.')
4-
.filter((item, index, arr) => index + 1 < arr.length)
5-
.map(item => `${item.charAt(0).toUpperCase()}${item.slice(1)}`);
6-
const namespace = fragments.join('.');
9+
const namespace = extensionName
10+
.split('.')
11+
.slice(0, -1)
12+
.map((item) => {
13+
if (item.length === 2) {
14+
return item.toUpperCase();
15+
}
16+
17+
return `${item.charAt(0).toUpperCase()}${item.slice(1)}`;
18+
})
19+
.join('.');
720

8-
if (typeof root === 'string' && root !== '') {
21+
if (typeof root === 'string' && root !== '')
22+
{
923
return `${root}.${namespace}`;
1024
}
1125

1226
return namespace;
1327
}
1428

1529
return root;
16-
}
30+
}
31+
32+
export default buildNamespaceName;

test/utils/build-namespace-name/build-namespace-name.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ describe('utils/build-extension-name', () => {
3939
it('Should return empty string if params doesn\'t passed', () => {
4040
assert(buildNamespaceName() === '');
4141
});
42+
43+
it('Should return valid namespace', () => {
44+
const extensionName = 'ui.fonts.opensans.condensed';
45+
const result = 'BX.UI.Fonts.Opensans';
46+
47+
assert.deepStrictEqual(buildNamespaceName({root: 'BX', extensionName}), result);
48+
});
4249
});

0 commit comments

Comments
 (0)