-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathall.js
34 lines (27 loc) · 1.29 KB
/
all.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
const fs = require('fs');
const _ = require('lodash');
const path = require('path');
const phpLoader = require('./php-loader');
const jsonLoader = require('./json-loader');
const loaderUtils = require('loader-utils');
module.exports = function (indexContent) {
let options = {};
let baseDirectory;
let loaderPath = 'node_modules' + path.sep + '@kirschbaum-development' + path.sep + 'laravel-translations-loader' + path.sep + 'all.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);
const jsonContents = jsonLoader.execute(baseDirectory, options, this);
const phpContents = phpLoader.execute(baseDirectory, options, this);
const bundle = _.merge(phpContents, jsonContents);
return "module.exports = " + JSON.stringify(bundle);
}