-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathcomponent-names.js
36 lines (29 loc) · 1 KB
/
component-names.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-env node */
'use strict';
var md5 = require('md5');
var path = require('path');
module.exports = {
path: function(actualPath, classicStyleDir) {
var terminator = '/';
var pathSegementToRemove = /^components\//;
if (actualPath.includes(classicStyleDir)) {
terminator = '.';
pathSegementToRemove = 'styles/' + classicStyleDir + '/';
} else { // Colocated component stylesheet
var pathInfo = path.parse(actualPath);
if (pathInfo.name !== 'styles') {
terminator = '.';
}
}
return actualPath.substr(0, actualPath.lastIndexOf(terminator)).replace(pathSegementToRemove, '');
},
class: function(modifiedPath, classicStyleDir, terseClassNames) {
var seperator = '__';
var componentPath = this.path(modifiedPath, classicStyleDir);
var className = seperator + md5(componentPath).slice(-5);
if (!terseClassNames) {
className = seperator + componentPath.replace(/\//g, seperator) + className;
}
return className;
}
};