Total Complexity | 5 |
Complexity/F | 5 |
Lines of Code | 27 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import JsYaml from 'js-yaml'; |
||
2 | import * as util from './util'; |
||
3 | |||
4 | export default function (source) { |
||
5 | this.cacheable && this.cacheable(); |
||
6 | |||
7 | try { |
||
8 | const yamlStr = util.readFile(this.resourcePath).toString(); |
||
9 | const yamlJSON = JsYaml.safeLoad(yamlStr); |
||
10 | let yamlURL = ''; |
||
11 | |||
12 | if (this.loaders.length > 1) { |
||
13 | const parentLoader = this.loaders[this.loaderIndex + 1]; |
||
14 | if (parentLoader && parentLoader.path.split('/').indexOf('file-loader') >= 0) { |
||
15 | yamlURL = `/${source.split('"')[1]}`; |
||
16 | } |
||
17 | } |
||
18 | |||
19 | return 'module.exports = ' + JSON.stringify({ |
||
20 | url: yamlURL, |
||
21 | text: yamlStr, |
||
22 | json: yamlJSON |
||
23 | }); |
||
24 | } catch(error) { |
||
25 | throw new Error(error); |
||
26 | } |
||
27 | } |
||
28 |