1 | 'use strict';
|
2 |
|
3 | var _ = require('lodash');
|
4 | var path = require('path');
|
5 |
|
6 | module.exports = {
|
7 | getCompiledType: getCompiledType,
|
8 | getType: getType,
|
9 | stripIgnoredBasePath: stripIgnoredBasePath,
|
10 | changeExt: changeExt
|
11 | };
|
12 |
|
13 | function getCompiledType(type) {
|
14 |
|
15 | type = _.get(type, 'type') || type;
|
16 |
|
17 | var typeMap = {
|
18 | css: ['sass', 'less', 'stylus'],
|
19 | js: ['coffee']
|
20 | };
|
21 | return _.findKey(typeMap, function (types) {
|
22 | return _.includes(types, type);
|
23 | });
|
24 | }
|
25 |
|
26 | function getType(ext) {
|
27 | var typeMap = {
|
28 | js: 'js',
|
29 | css: 'css',
|
30 | scss: 'sass',
|
31 | less: 'less',
|
32 | styl: 'stylus',
|
33 | coffee: 'coffee'
|
34 | };
|
35 | return typeMap[_.trimStart(ext, '.')];
|
36 | }
|
37 |
|
38 | function stripIgnoredBasePath(_path, basePaths) {
|
39 |
|
40 | var trimmedPath = _.trimStart(_path, './\\');
|
41 |
|
42 | var ignored = basePaths.find(function (base) {
|
43 | return _.startsWith(trimmedPath, _.trimEnd(base, './\\'));
|
44 | });
|
45 | var ignoredLength = ignored ? (ignored + path.sep).length : 0;
|
46 | return trimmedPath.substring(ignoredLength);
|
47 | }
|
48 |
|
49 | function changeExt(file, toExt, fromExt) {
|
50 | var _path$parse = path.parse(file),
|
51 | dir = _path$parse.dir,
|
52 | name = _path$parse.name;
|
53 |
|
54 | return path.join(dir, (fromExt ? path.basename(file, fromExt) : name) + toExt);
|
55 | } |
\ | No newline at end of file |