-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjson.js
30 lines (24 loc) · 1.07 KB
/
json.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
var path = require('path');
const fs = require('fs');
const loaderUtils = require('loader-utils');
const jsonLoader = require('./json-loader');
module.exports = function (indexContent) {
let options = {};
let baseDirectory;
let loaderPath = 'node_modules' + path.sep + '@kirschbaum-development' + path.sep + 'laravel-translations-loader' + path.sep + 'json.js';
try {
options = loaderUtils.getOptions(this);
} catch (e) { }
if (path.dirname(this.resource).includes(path.dirname(loaderPath))) {
baseDirectory = path.dirname(this.resource) + path.sep + '..' + path.sep + '..' + path.sep + '..' + path.sep + 'lang';
if (! fs.existsSync(baseDirectory)) {
baseDirectory = path.dirname(this.resource) + path.sep + '..' + path.sep + '..' + path.sep + '..' + path.sep + 'resources' + path.sep + 'lang';
}
} else {
baseDirectory = path.dirname(this.resource);
}
this.addDependency(baseDirectory);
return "module.exports = " + JSON.stringify(
jsonLoader.execute(baseDirectory, options, this)
);
}