|
1 | | -'use strict'; |
| 1 | +'use strict' |
2 | 2 | module.exports = function(plugins, file) { // eslint-disable-line func-names |
3 | 3 | function findDependencies(file, dependencyTree) { |
4 | 4 | if (plugins.fs.existsSync(file)) { |
5 | | - const content = plugins.fs.readFileSync(file, 'utf8'), |
6 | | - path = file.replace(/(.*)\/.*/g, '$1'), |
7 | | - regex = /^(?:\s*@import )(?:'|")(.*)(?:'|")/gm; |
| 5 | + const content = plugins.fs.readFileSync(file, 'utf8') |
| 6 | + const path = file.replace(/(.*)\/.*/g, '$1') |
| 7 | + const regex = /^(?:\s*@import )(?:'|")(.*)(?:'|")/gm |
8 | 8 |
|
9 | | - let result = regex.exec(content), |
10 | | - imports = []; |
| 9 | + let result = regex.exec(content) |
| 10 | + let imports = [] |
11 | 11 |
|
12 | 12 | while (result) { |
13 | | - let fullPath = ''; |
| 13 | + let fullPath = '' |
14 | 14 | if (result[1].includes('../')) { |
15 | | - let parentPath = path, |
16 | | - filePath = result[1]; |
| 15 | + let parentPath = path |
| 16 | + let filePath = result[1] |
17 | 17 |
|
18 | 18 | while (filePath.includes('../')) { |
19 | | - parentPath = parentPath.replace(/\/[^/]+$/g, ''); |
20 | | - filePath = filePath.replace(/\.\.\//, ''); |
21 | | - const filePathParts = /(.*)\/(.*)/g.exec(filePath); |
| 19 | + parentPath = parentPath.replace(/\/[^/]+$/g, '') |
| 20 | + filePath = filePath.replace(/\.\.\//, '') |
| 21 | + const filePathParts = /(.*)\/(.*)/g.exec(filePath) |
22 | 22 | if (filePathParts) { |
23 | | - fullPath = parentPath + '/' + filePathParts[1] + '/_' + filePathParts[filePathParts.length - 1] + '.scss'; |
| 23 | + fullPath = plugins.path.join(parentPath, filePathParts[1], `_${filePathParts[filePathParts.length - 1]}.scss`) |
24 | 24 | } |
25 | 25 | else { |
26 | | - fullPath = parentPath + '/_' + filePath + '.scss'; |
| 26 | + fullPath = plugins.path.join(parentPath, `_${filePath}.scss`) |
27 | 27 | } |
28 | 28 | } |
29 | 29 | } |
30 | 30 | else { |
31 | 31 | if (result[1].includes('/')) { |
32 | | - const filePath = /(.*)\/(.*)/g.exec(result[1]); |
33 | | - fullPath = path + '/' + filePath[1] + '/_' + filePath[filePath.length - 1] + '.scss'; |
| 32 | + const filePath = /(.*)\/(.*)/g.exec(result[1]) |
| 33 | + fullPath = plugins.path.join(path, filePath[1], `_${filePath[filePath.length - 1]}.scss`) |
34 | 34 | } |
35 | 35 | else { |
36 | | - fullPath = path + '/_' + result[1] + '.scss'; |
| 36 | + fullPath = plugins.path.join(path, `_${result[1]}.scss`) |
37 | 37 | } |
38 | 38 | } |
39 | | - imports.push(fullPath); |
40 | | - result = regex.exec(content); |
| 39 | + imports.push(fullPath) |
| 40 | + result = regex.exec(content) |
41 | 41 | } |
42 | 42 |
|
43 | 43 | imports.forEach(el => { |
44 | | - imports = imports.concat(findDependencies(el, dependencyTree)); |
45 | | - }); |
| 44 | + imports = imports.concat(findDependencies(el, dependencyTree)) |
| 45 | + }) |
46 | 46 |
|
47 | | - dependencyTree = dependencyTree.concat(file); |
48 | | - dependencyTree = dependencyTree.concat(imports); |
| 47 | + dependencyTree = dependencyTree.concat(file) |
| 48 | + dependencyTree = dependencyTree.concat(imports) |
49 | 49 | } |
50 | | - return dependencyTree; |
| 50 | + return dependencyTree |
51 | 51 | } |
52 | 52 |
|
53 | | - return findDependencies(file, []); |
54 | | -}; |
| 53 | + return findDependencies(file, []) |
| 54 | +} |
0 commit comments